50 struct line_pnts *points;
51 struct line_cats *Cats =
NULL;
52 geoline *top, *gln, *prev;
53 int np, i, n, nareas, nl = 0, area, type, is3d;
54 struct Cell_head wind;
60 G_warning(_(
"Vector map <%s> not found"), grassname);
64 Vect_set_open_level(2);
65 if (Vect_open_old(&map, grassname,
"") == -1) {
66 G_warning(_(
"Unable to open vector map <%s>"),
71 top = gln = (geoline *)G_malloc(
sizeof(geoline));
79 Tot_mem +=
sizeof(geoline);
82 points = Vect_new_line_struct();
83 Cats = Vect_new_cats_struct();
86 Vect_set_constraint_region(&map, wind.north, wind.south, wind.east,
87 wind.west, PORT_DOUBLE_MAX, -PORT_DOUBLE_MAX);
89 is3d = Vect_is_3d(&map);
92 n = Vect_get_num_areas(&map);
94 G_debug(3,
"Reading vector areas (nareas = %d)", n);
95 for (area = 1; area <= n; area++) {
97 Vect_get_area_points(&map, area, points);
98 if (points->n_points < 3)
102 gln->highlighted = 0;
104 gln->type = OGSF_POLYGON;
105 gln->npts = np = points->n_points;
111 (Point3 *)G_calloc(np,
sizeof(Point3));
116 Tot_mem += (np *
sizeof(Point3));
122 (Point2 *)G_calloc(np,
sizeof(Point2));
127 Tot_mem += (np *
sizeof(Point2));
131 for (i = 0; i < np; i++) {
133 gln->p3[i][
X] = points->x[i];
134 gln->p3[i][
Y] = points->y[i];
135 gln->p3[i][Z] = points->z[i];
138 gln->p2[i][
X] = points->x[i];
139 gln->p2[i][
Y] = points->y[i];
144 vect[0][
X] = (float)(gln->p3[0][
X] - gln->p3[1][
X]);
145 vect[0][
Y] = (float)(gln->p3[0][
Y] - gln->p3[1][
Y]);
146 vect[0][Z] = (float)(gln->p3[0][Z] - gln->p3[1][Z]);
147 vect[1][
X] = (float)(gln->p3[2][
X] - gln->p3[1][
X]);
148 vect[1][
Y] = (float)(gln->p3[2][
Y] - gln->p3[1][
Y]);
149 vect[1][Z] = (float)(gln->p3[2][Z] - gln->p3[1][Z]);
154 gln->next = (geoline *)G_malloc(
sizeof(geoline));
160 Tot_mem +=
sizeof(geoline);
167 G_debug(3,
"%d areas loaded", nareas);
170 G_debug(3,
"Reading vector lines ...");
171 while (-1 < (type = Vect_read_next_line(&map, points, Cats))) {
172 G_debug(3,
"line type = %d", type);
173 if (type & (GV_LINES | GV_FACE)) {
174 if (type & (GV_LINES)) {
175 gln->type = OGSF_LINE;
178 gln->type = OGSF_POLYGON;
184 gln->highlighted = 0;
186 gln->npts = np = points->n_points;
192 (Point3 *)G_calloc(np,
sizeof(Point3));
197 Tot_mem += (np *
sizeof(Point3));
203 (Point2 *)G_calloc(np,
sizeof(Point2));
208 Tot_mem += (np *
sizeof(Point2));
212 for (i = 0; i < np; i++) {
214 gln->p3[i][
X] = points->x[i];
215 gln->p3[i][
Y] = points->y[i];
216 gln->p3[i][Z] = points->z[i];
219 gln->p2[i][
X] = points->x[i];
220 gln->p2[i][
Y] = points->y[i];
224 if (is3d && gln->type == OGSF_POLYGON) {
225 vect[0][
X] = (float)(gln->p3[0][
X] - gln->p3[1][
X]);
226 vect[0][
Y] = (float)(gln->p3[0][
Y] - gln->p3[1][
Y]);
227 vect[0][Z] = (float)(gln->p3[0][Z] - gln->p3[1][Z]);
228 vect[1][
X] = (float)(gln->p3[2][
X] - gln->p3[1][
X]);
229 vect[1][
Y] = (float)(gln->p3[2][
Y] - gln->p3[1][
Y]);
230 vect[1][Z] = (float)(gln->p3[2][Z] - gln->p3[1][Z]);
232 G_debug(3,
"norm %f %f %f", gln->norm[0], gln->norm[1],
237 if (Cats->n_cats > 0) {
239 Cats = Vect_new_cats_struct();
243 Vect_reset_cats(Cats);
247 (geoline *)G_malloc(
sizeof(geoline));
252 Tot_mem +=
sizeof(geoline);
260 G_debug(3,
"%d lines loaded", nl);
268 Tot_mem -=
sizeof(geoline);
275 _(
"No features from vector map <%s> fall within current region"),
280 G_message(_(
"Vector map <%s> loaded (%d features)"),
287 G_debug(3,
"Total vect memory = %d Kbytes", Tot_mem / 1000);
324 struct field_info *Fi;
326 int nvals, cat, nlines, nskipped;
334 if (!gv || !gv->tstyle || !gv->filename)
342 Vect_set_open_level(1);
343 if (Vect_open_old(&Map, gv->filename,
"") == -1) {
348 Fi = Vect_get_field(&Map, gv->tstyle->layer);
350 G_warning(_(
"Database connection not defined for layer %d"),
354 driver = db_start_driver_open_database(Fi->driver, Fi->database);
356 G_fatal_error(_(
"Unable to open database <%s> by driver <%s>"),
357 Fi->database, Fi->driver);
359 G_message(_(
"Loading thematic vector layer <%s>..."),
361 nlines = nskipped = 0;
362 for (gvt = gv->lines; gvt; gvt = gvt->next) {
363 gvt->style = (gvstyle *)G_malloc(
sizeof(gvstyle));
364 G_zero(gvt->style,
sizeof(gvstyle));
367 gvt->style->color = gv->style->color;
368 gvt->style->symbol = gv->style->symbol;
369 gvt->style->size = gv->style->size;
370 gvt->style->width = gv->style->width;
374 Vect_cat_get(gvt->cats, gv->tstyle->layer, &cat);
382 if (!Rast_get_c_color((
const CELL *)&cat, &red, &grn, &blu,
384 G_warning(_(
"No color rule defined for category %d"), cat);
385 gvt->style->color = gv->style->color;
387 gvt->style->color = (red &
RED_MASK) +
392 if (gv->tstyle->color_column) {
393 nvals = db_select_value(
driver, Fi->table, Fi->key, cat,
394 gv->tstyle->color_column, &value);
397 str = db_get_value_string(&value);
401 G_warning(_(
"Invalid color definition (%s)"), str);
402 gvt->style->color = gv->style->color;
405 gvt->style->color = (red &
RED_MASK) +
412 if (gv->tstyle->width_column) {
413 nvals = db_select_value(
driver, Fi->table, Fi->key, cat,
414 gv->tstyle->width_column, &value);
417 gvt->style->width = db_get_value_int(&value);
425 _(
"%d features without category. "
426 "Unable to determine color rules for features without category."),
int G_str_to_color(const char *str, int *red, int *grn, int *blu)
Parse color string and set red,green,blue.
void G_zero(void *buf, int i)
Zero out a buffer, buf, of length i.