22 #include <grass/glocale.h>
23 #include <grass/gis.h>
24 #include <grass/Vect.h>
39 int j, area, isle, n_lines, line,
type, direction;
42 struct Plus_head *plus;
44 static struct line_pnts *Points, *APoints;
50 G_debug(3,
"Vect_build_line_area() line = %d, side = %d", iline, side);
60 G_debug(3,
" area/isle = %d -> skip", area);
65 G_debug(3,
" n_lines = %d", n_lines);
72 for (j = 0; j < n_lines; j++) {
74 BLine = plus->Line[line];
75 offset = BLine->offset;
76 G_debug(3,
" line[%d] = %d, offset = %ld", j, line, offset);
79 direction = GV_FORWARD;
81 direction = GV_BACKWARD;
86 G_debug(3,
" area/isle size = %f", area_size);
93 G_fatal_error(_(
"Unable to add area (map closed, topo saved)"));
95 G_debug(3,
" -> area %d", area);
98 else if (area_size < 0) {
102 G_fatal_error(_(
"Unable to add isle (map closed, topo saved)"));
104 G_debug(3,
" -> isle %d", isle);
112 G_warning(_(
"Area of size = 0.0 ignored"));
128 int j, line, node, sel_area,
first, area, poly;
129 static int first_call = 1;
130 struct Plus_head *plus;
135 double size, cur_size;
137 static struct ilist *List;
138 static struct line_pnts *APoints;
144 G_debug(3,
"Vect_isle_find_area () island = %d", isle);
147 if (plus->Isle[isle] ==
NULL) {
148 G_warning(_(
"Request to find area outside nonexistent isle"));
158 Isle = plus->Isle[isle];
159 line = abs(Isle->lines[0]);
160 Line = plus->Line[line];
162 Node = plus->Node[node];
169 box.T = PORT_DOUBLE_MAX;
170 box.B = -PORT_DOUBLE_MAX;
172 G_debug(3,
"%d areas overlap island boundary point", List->n_values);
178 for (j = 0; j < List->n_values; j++) {
179 area = List->value[j];
182 Area = plus->Area[area];
185 if (abs(Isle->lines[0]) == abs(Area->lines[0])) {
186 G_debug(3,
" area inside isolated isle");
197 if (box.E > abox.E || box.W < abox.W || box.N > abox.N ||
199 G_debug(3,
" isle not completely inside area box");
204 G_debug(3,
" poly = %d", poly);
220 G_debug(3,
" first area size = %f (n points = %d)",
221 cur_size, APoints->n_points);
229 G_debug(3,
" area size = %f (n points = %d)", cur_size,
232 if (size < cur_size) {
237 G_debug(3,
"sel_area = %d cur_size = %f", sel_area, cur_size);
241 G_debug(3,
"Island %d in area %d", isle, sel_area);
244 G_debug(3,
"Island %d is not in area", isle);
262 struct Plus_head *plus;
266 G_debug(3,
"Vect_attach_isle (): isle = %d", isle);
271 G_debug(3,
" isle = %d -> area outside = %d", isle, sel_area);
273 Isle = plus->Isle[isle];
274 if (Isle->area > 0) {
276 "Attempt to attach isle %d to more areas (=>topology is not clean)",
280 Isle->area = sel_area;
298 static int first = 1;
299 static struct ilist *List;
300 struct Plus_head *plus;
302 G_debug(3,
"Vect_attach_isles ()");
312 G_debug(3,
" number of isles to attach = %d", List->n_values);
314 for (i = 0; i < List->n_values; i++) {
315 isle = List->value[i];
316 if (plus->Isle[isle]->area > 0) {
318 plus->Isle[isle]->area = 0;
335 int i, sel_area, centr;
336 static int first = 1;
337 static struct ilist *List;
340 struct Plus_head *plus;
342 G_debug(3,
"Vect_attach_centroids ()");
374 G_debug(3,
" number of centroids to reattach = %d", List->n_values);
375 for (i = 0; i < List->n_values; i++) {
378 centr = List->value[i];
379 Line = plus->Line[centr];
382 orig_area = Line->left;
384 if (plus->Area[orig_area] !=
NULL) {
385 plus->Area[orig_area]->centroid = 0;
391 G_debug(3,
" centroid %d is in area %d", centr, sel_area);
393 Area = plus->Area[sel_area];
394 if (Area->centroid == 0) {
395 G_debug(3,
" first centroid -> attach to area");
396 Area->centroid = centr;
397 Line->left = sel_area;
399 if (sel_area != orig_area && plus->do_uplist)
402 else if (Area->centroid != centr) {
405 G_debug(3,
" duplicate centroid -> do not attach to area");
406 Line->left = -sel_area;
408 if (-sel_area != orig_area && plus->do_uplist)
412 else if (orig_area != 0 && plus->do_uplist)
430 struct Plus_head *plus;
431 int i,
s,
type, lineid;
433 int side, line, area;
434 struct line_pnts *Points, *APoints;
435 struct line_cats *Cats;
442 G_debug(3,
"Vect_build_nat() build = %d", build);
446 if (build == plus->built)
450 if (build < plus->built) {
453 if (plus->built >= GV_BUILD_CENTROIDS && build < GV_BUILD_CENTROIDS) {
457 for (line = 1; line <= nlines; line++) {
458 Line = plus->Line[line];
459 if (Line && Line->type == GV_CENTROID)
469 if (plus->built >= GV_BUILD_AREAS && build < GV_BUILD_AREAS) {
473 for (line = 1; line <= nlines; line++) {
474 Line = plus->Line[line];
475 if (Line && Line->type == GV_BOUNDARY) {
485 if (plus->built >= GV_BUILD_BASE && build < GV_BUILD_BASE) {
501 if (plus->built < GV_BUILD_BASE) {
514 G_message(_(
"Registering primitives..."));
523 G_warning(_(
"Unable to read vector map"));
526 else if (type == -2) {
530 npoints += Points->n_points;
532 offset = Map->head.last_offset;
534 G_debug(3,
"Register line: offset = %ld", offset);
543 if (build == GV_BUILD_ALL) {
546 for (c = 0; c < Cats->n_cats; c++) {
550 if (Cats->n_cats == 0)
555 if (format == G_INFO_FORMAT_PLAIN)
556 fprintf(stderr,
"%d..", i);
558 fprintf(stderr,
"%9d\b\b\b\b\b\b\b\b\b", i);
565 fprintf(stderr,
"\r");
567 G_message(_(
"%d primitives registered"), plus->n_lines);
568 G_message(_(
"%d vertices registered"), npoints);
570 plus->built = GV_BUILD_BASE;
573 if (build < GV_BUILD_AREAS)
576 if (plus->built < GV_BUILD_AREAS) {
580 for (i = 1; i <= plus->n_lines; i++) {
584 if (plus->Line[i] ==
NULL) {
587 Line = plus->Line[i];
588 if (Line->type != GV_BOUNDARY) {
592 for (s = 0; s < 2; s++) {
598 G_debug(3,
"Build area for line = %d, side = %d", i, side);
602 G_message(_(
"%d areas built"), plus->n_areas);
603 G_message(_(
"%d isles built"), plus->n_isles);
604 plus->built = GV_BUILD_AREAS;
607 if (build < GV_BUILD_ATTACH_ISLES)
611 if (plus->built < GV_BUILD_ATTACH_ISLES) {
613 for (i = 1; i <= plus->n_isles; i++) {
617 plus->built = GV_BUILD_ATTACH_ISLES;
620 if (build < GV_BUILD_CENTROIDS)
624 if (plus->built < GV_BUILD_CENTROIDS) {
630 for (line = 1; line <= nlines; line++) {
633 Line = plus->Line[line];
637 if (Line->type != GV_CENTROID)
640 Node = plus->Node[Line->N1];
645 G_debug(3,
"Centroid (line=%d) in area %d", line, area);
647 Area = plus->Area[area];
649 if (Area->centroid == 0) {
650 Area->centroid = line;
658 plus->built = GV_BUILD_CENTROIDS;
662 for (area = 1; area <= plus->n_areas; area++) {
665 if (plus->Area[area] ==
NULL)
668 if (plus->Area[area]->centroid > 0) {
671 for (c = 0; c < Cats->n_cats; c++) {
677 if (plus->Area[area]->centroid == 0 || Cats->n_cats == 0)
int Vect_build_nat(struct Map_info *Map, int build)
Build topology.
void dig_free_plus_lines(struct Plus_head *Plus)
Free Plus->Line structure.
int Vect_select_isles_by_box(struct Map_info *Map, BOUND_BOX *Box, struct ilist *list)
Select isles by box.
int Vect_build_line_area(struct Map_info *Map, int iline, int side)
Build area on given side of line (GV_LEFT or GV_RIGHT)
double G_area_of_polygon(const double *x, const double *y, int n)
Area in square meters of polygon.
int Vect_read_next_line(struct Map_info *Map, struct line_pnts *line_p, struct line_cats *line_c)
Read next vector feature (level 1 and 2)
int dig_line_box(struct line_pnts *Points, BOUND_BOX *Box)
struct line_pnts * Vect_new_line_struct()
Creates and initializes a struct line_pnts.
void G_important_message(const char *msg,...)
Print a message to stderr even in brief mode (verbosity=1)
struct ilist * Vect_new_list(void)
Creates and initializes a struct ilist.
int dig_add_line(struct Plus_head *plus, int type, struct line_pnts *Points, long offset)
Add new line to Plus_head structure.
int Vect_append_points(struct line_pnts *Points, struct line_pnts *APoints, int direction)
Appends points to the end of a line.
int Vect_reset_line(struct line_pnts *Points)
Reset line.
int Vect_get_area_box(struct Map_info *Map, int area, BOUND_BOX *Box)
Get boundary box of area.
void dig_free_plus_areas(struct Plus_head *Plus)
Free Plus->Area structure.
void dig_spidx_free_lines(struct Plus_head *Plus)
Free spatial index for lines.
int Vect_get_area_points(struct Map_info *Map, int area, struct line_pnts *BPoints)
Returns the polygon array of points in BPoints.
void dig_spidx_free_areas(struct Plus_head *Plus)
Free spatial index for areas.
int Vect_isle_find_area(struct Map_info *Map, int isle)
Find area outside island.
int G_percent(long n, long d, int s)
Print percent complete messages.
int Vect_box_extend(BOUND_BOX *A, BOUND_BOX *B)
Extend box A by box B.
int Vect_find_area(struct Map_info *Map, double x, double y)
Find the nearest area.
int dig_area_add_isle(struct Plus_head *plus, int area, int isle)
Add isle to area if does not exist yet.
int dig_build_area_with_line(struct Plus_head *plus, plus_t first_line, int side, plus_t **lines)
Build topo for area from lines.
int Vect_point_in_area_outer_ring(double X, double Y, struct Map_info *Map, int area)
Determines if a point (X,Y) is inside an area outer ring. Islands are not considered.
int dig_cidx_add_cat(struct Plus_head *Plus, int field, int cat, int line, int type)
void G_message(const char *msg,...)
Print a message to stderr.
int G_begin_polygon_area_calculations(void)
Begin polygon area calculations.
int Vect_attach_isle(struct Map_info *Map, int isle)
(Re)Attach isle to area
int Vect_box_copy(BOUND_BOX *A, BOUND_BOX *B)
Copy box B to box A.
int G_info_format(void)
Get current message format.
void dig_spidx_free_isles(struct Plus_head *Plus)
Free spatial index for isles.
int Vect_attach_centroids(struct Map_info *Map, BOUND_BOX *box)
(Re)Attach centroids to areas in given box
int G_verbose(void)
Get current verbosity level.
void dig_free_plus_isles(struct Plus_head *Plus)
Free Plus->Isle structure.
int Vect_get_isle_box(struct Map_info *Map, int isle, BOUND_BOX *Box)
Get boundary box of isle.
int Vect_close(struct Map_info *Map)
Close vector data file.
int Vect_select_lines_by_box(struct Map_info *Map, BOUND_BOX *Box, int type, struct ilist *list)
Select lines by box.
struct line_cats * Vect_new_cats_struct()
Creates and initializes line_cats structure.
int Vect_select_areas_by_box(struct Map_info *Map, BOUND_BOX *Box, struct ilist *list)
Select areas by box.
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
int Vect_get_num_lines(struct Map_info *map)
Fetch number of features (points, lines, boundaries, centroids) in vector map.
int Vect_attach_isles(struct Map_info *Map, BOUND_BOX *box)
(Re)Attach isles to areas in given box
int G_debug(int level, const char *msg,...)
Print debugging message.
int dig_find_area_poly(struct line_pnts *Points, double *totalarea)
void dig_line_add_updated(struct Plus_head *Plus, int line)
Add new line to updated.
int G_verbose_min(void)
Get min verbosity level.
int G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
int dig_add_isle(struct Plus_head *plus, int n_lines, plus_t *lines)
Allocate space for new island and create boundary info from array.
void dig_spidx_free_nodes(struct Plus_head *Plus)
Free spatial index for nodes.
plus_t dig_line_get_area(struct Plus_head *plus, plus_t line, int side)
Get area number on line side.
int dig_add_area(struct Plus_head *plus, int n_lines, plus_t *lines)
Allocate space for new area and create boundary info from array.
void dig_free_plus_nodes(struct Plus_head *Plus)
Free Plus->Node structure.
int Vect_read_line(struct Map_info *Map, struct line_pnts *line_p, struct line_cats *line_c, int line)
Read vector feature.
int Vect_rewind(struct Map_info *Map)
Rewind vector data file to cause reads to start at beginning.
int dig_area_del_isle(struct Plus_head *plus, int area, int isle)
Delete isle from area.