20 #include <grass/gis.h>
21 #include <grass/colors.h>
22 #include <grass/raster.h>
23 #include <grass/vector.h>
24 #include <grass/dbmi.h>
25 #include <grass/glocale.h>
26 #include <grass/ogsf.h>
31 static void free_geopoint_list(geopoint *top);
48 static struct line_pnts *Points =
NULL;
49 struct line_cats *Cats =
NULL;
50 geopoint *top, *gpt, *prev;
52 struct Cell_head wind;
65 Vect_set_open_level(1);
66 if (Vect_open_old(&map,
name,
"") == -1) {
71 Points = Vect_new_line_struct();
72 Cats = Vect_new_cats_struct();
74 top = gpt = (geopoint *)G_malloc(
sizeof(geopoint));
75 G_zero(gpt,
sizeof(geopoint));
81 Vect_set_constraint_region(&map, wind.north, wind.south, wind.east,
82 wind.west, PORT_DOUBLE_MAX, -PORT_DOUBLE_MAX);
87 if (Vect_is_3d(&map)) {
94 ltype = Vect_read_next_line(&map, Points, Cats);
97 G_warning(_(
"Unable to read vector map <%s>"), mname);
99 free_geopoint_list(top);
108 if ((ltype & GV_POINTS)) {
110 gpt->p3[
X] = Points->x[0];
111 gpt->p3[
Y] = Points->y[0];
115 gpt->p3[Z] = Points->z[0];
122 if (Cats->n_cats > 0) {
124 Cats = Vect_new_cats_struct();
127 Vect_reset_cats(Cats);
130 gpt->highlighted = 0;
132 G_debug(5,
"loading vector point %d x=%f y=%f ncats=%d", np,
133 Points->x[0], Points->y[0], Cats->n_cats);
136 (geopoint *)G_malloc(
sizeof(geopoint));
137 G_zero(gpt->next,
sizeof(geopoint));
139 free_geopoint_list(top);
156 _(
"No points from vector map <%s> fall within current region"),
159 free_geopoint_list(top);
163 G_message(_(
"Vector map <%s> loaded (%d points)"), mname, np);
186 struct field_info *Fi;
188 int nvals, cat, npts, nskipped;
197 if (!gp || !gp->tstyle || !gp->filename)
205 Vect_set_open_level(1);
206 if (Vect_open_old(&Map, gp->filename,
"") == -1) {
211 Fi = Vect_get_field(&Map, gp->tstyle->layer);
213 G_warning(_(
"Database connection not defined for layer %d"),
217 driver = db_start_driver_open_database(Fi->driver, Fi->database);
219 G_fatal_error(_(
"Unable to open database <%s> by driver <%s>"),
220 Fi->database, Fi->driver);
223 G_message(_(
"Loading thematic points layer <%s>..."), fname);
226 for (gpt = gp->points; gpt; gpt = gpt->next) {
227 gpt->style = (gvstyle *)G_malloc(
sizeof(gvstyle));
228 G_zero(gpt->style,
sizeof(gvstyle));
231 gpt->style->color = gp->style->color;
232 gpt->style->symbol = gp->style->symbol;
233 gpt->style->size = gp->style->size;
234 gpt->style->width = gp->style->width;
238 Vect_cat_get(gpt->cats, gp->tstyle->layer, &cat);
246 if (!Rast_get_c_color((
const CELL *)&cat, &red, &grn, &blu,
248 G_warning(_(
"No color rule defined for category %d"), cat);
249 gpt->style->color = gp->style->color;
251 gpt->style->color = (red &
RED_MASK) +
255 if (gp->tstyle->color_column) {
257 nvals = db_select_value(
driver, Fi->table, Fi->key, cat,
258 gp->tstyle->color_column, &value);
261 str = db_get_value_string(&value);
266 G_warning(_(
"Invalid color definition (%s)"), str);
267 gpt->style->color = gp->style->color;
270 gpt->style->color = (red &
RED_MASK) +
277 if (gp->tstyle->size_column) {
278 nvals = db_select_value(
driver, Fi->table, Fi->key, cat,
279 gp->tstyle->size_column, &value);
282 gpt->style->size = db_get_value_int(&value);
286 if (gp->tstyle->width_column) {
287 nvals = db_select_value(
driver, Fi->table, Fi->key, cat,
288 gp->tstyle->width_column, &value);
291 gpt->style->width = db_get_value_int(&value);
295 if (gp->tstyle->symbol_column) {
296 nvals = db_select_value(
driver, Fi->table, Fi->key, cat,
297 gp->tstyle->symbol_column, &value);
300 str = db_get_value_string(&value);
309 _(
"%d points without category. "
310 "Unable to determine color rules for features without category."),
313 db_close_database_shutdown_driver(
driver);
314 Vect_destroy_field_info(Fi);
318 static void free_geopoint_list(geopoint *top)
321 geopoint *next = top->next;
void G_free(void *buf)
Free allocated memory.
int G_str_to_color(const char *str, int *red, int *grn, int *blu)
Parse color string and set red,green,blue.
int G_debug(int level, const char *msg,...)
Print debugging message.
const char * G_find_vector2(const char *name, const char *mapset)
Find a vector map (look but don't touch)
void G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
void G_message(const char *msg,...)
Print a message to stderr.
void G_warning(const char *msg,...)
Print a warning message to stderr.
void G_get_set_window(struct Cell_head *window)
Get the current working window (region)
int GP_str_to_marker(const char *str)
Determine point marker symbol for string.
int Gp_load_sites_thematic(geosite *gp, struct Colors *colors)
Load styles for geopoints based on thematic mapping.
geopoint * Gp_load_sites(const char *name, int *nsites, int *has_z)
Load to points to memory.
char * G_fully_qualified_name(const char *name, const char *mapset)
Get fully qualified element name.
void G_zero(void *buf, int i)
Zero out a buffer, buf, of length i.