30 #include <grass/gis.h>
31 #include <grass/Vect.h>
32 #include <grass/glocale.h>
40 static void delete_area_cats_from_cidx(
struct Map_info *
Map,
int area)
44 static struct line_cats *Cats =
NULL;
46 G_debug(3,
"delete_area_cats_from_cidx() area = %d", area);
48 Area = Map->plus.Area[area];
51 "delete_area_cats_from_cidx()", area);
53 if (Area->centroid == 0)
61 for (i = 0; i < Cats->n_cats; i++) {
73 static void add_area_cats_to_cidx(
struct Map_info *Map,
int area)
77 static struct line_cats *Cats =
NULL;
79 G_debug(3,
"add_area_cats_to_cidx() area = %d", area);
81 Area = Map->plus.Area[area];
84 "add_area_cats_to_cidx():", area);
86 if (Area->centroid == 0)
94 for (i = 0; i < Cats->n_cats; i++) {
131 static void add_line_to_topo(
struct Map_info *Map,
int line,
132 struct line_pnts *points,
struct line_cats *cats)
135 int type, node, next_line, area, side, sel_area, new_area[2];
137 struct Plus_head *plus;
138 P_LINE *Line, *NLine;
145 Line = plus->Line[line];
148 if (plus->built >= GV_BUILD_AREAS) {
149 if (type == GV_BOUNDARY) {
152 for (s = 1; s < 3; s++) {
158 " delete neighbour areas/iseles: side = %d node = %d",
160 Node = plus->Node[node];
162 for (i = 0; i < Node->n_lines; i++) {
163 NLine = plus->Line[abs(Node->lines[i])];
164 if (NLine->type == GV_BOUNDARY)
168 G_debug(3,
" number of boundaries at node = %d", n);
181 if (next_line != 0) {
182 NLine = plus->Line[abs(next_line)];
185 else if (next_line < 0)
188 G_debug(3,
" next_line = %d area = %d", next_line,
199 if (plus->update_cidx) {
200 delete_area_cats_from_cidx(Map, area);
213 for (s = 1; s < 3; s++) {
218 G_debug(3,
" build area/isle on side = %d", side);
220 G_debug(3,
"Build area for line = %d, side = %d", line, side);
222 G_debug(3,
"Build area for line = %d, side = %d", line, side);
242 new_area[s - 1] = area;
248 if (plus->built >= GV_BUILD_ATTACH_ISLES)
252 if (plus->built >= GV_BUILD_CENTROIDS)
256 if (plus->update_cidx) {
257 for (s = 1; s < 3; s++) {
258 if (new_area[s - 1] > 0) {
259 add_area_cats_to_cidx(Map, new_area[s - 1]);
267 if (plus->built >= GV_BUILD_CENTROIDS) {
268 if (type == GV_CENTROID) {
270 G_debug(3,
" new centroid %d is in area %d", line, sel_area);
272 Area = plus->Area[sel_area];
273 Line = plus->Line[line];
274 if (Area->centroid == 0) {
275 G_debug(3,
" first centroid -> attach to area");
276 Area->centroid = line;
277 Line->left = sel_area;
278 if (plus->update_cidx) {
279 add_area_cats_to_cidx(Map, sel_area);
284 " duplicate centroid -> do not attach to area");
285 Line->left = -sel_area;
292 for (i = 0; i < cats->n_cats; i++) {
301 struct line_pnts *points,
struct line_cats *cats);
315 int type,
struct line_pnts *points,
struct line_cats *cats)
319 if (
dig_fseek(&(Map->dig_fp), 0L, SEEK_END) == -1)
341 int type,
struct line_pnts *points,
struct line_cats *cats)
345 struct Plus_head *plus;
350 G_debug(3,
"V2_write_line_nat()");
358 if (plus->built >= GV_BUILD_BASE) {
360 G_debug(3,
" line added to topo with id = %d", line);
369 add_line_to_topo(Map,
372 G_debug(3,
"updated lines : %d , updated nodes : %d", plus->n_uplines,
400 struct line_pnts *points,
struct line_cats *cats)
403 struct line_pnts *old_points;
404 struct line_cats *old_cats;
418 && points->n_points == old_points->n_points
419 && cats->n_cats == old_cats->n_cats
420 && (((type & GV_POINTS) && (old_type & GV_POINTS))
421 || ((type &
GV_LINES) && (old_type & GV_LINES)))) {
432 if (
dig_fseek(&(Map->dig_fp), 0L, SEEK_END) == -1)
436 if (new_offset == -1)
460 struct line_pnts *points,
struct line_cats *cats)
488 struct line_pnts *points,
struct line_cats *cats)
496 dig_fp = &(Map->dig_fp);
510 if (cats->n_cats > 0) {
519 if (cats->n_cats > 0) {
520 if (Map->head.Version_Minor == 1) {
525 nc = (char)cats->n_cats;
530 if (cats->n_cats > 0) {
531 if (Map->head.Version_Minor == 1) {
537 for (i = 0; i < cats->n_cats; i++) {
538 field = (short)cats->field[i];
548 if (type & GV_POINTS) {
552 n_points = points->n_points;
562 if (Map->head.with_z) {
587 G_debug(3,
"V1_delete_line_nat(), offset = %ld", offset);
590 dig_fp = &(Map->dig_fp);
624 int ret, i, side, type = 0, first = 0, next_line, area;
627 struct Plus_head *plus;
629 int adjacent[4], n_adjacent = 0;
630 static struct line_cats *Cats =
NULL;
632 G_debug(3,
"V2_delete_line_nat(), line = %d", line);
636 if (plus->built >= GV_BUILD_BASE) {
637 Line = Map->plus.Line[line];
649 if (plus->update_cidx) {
652 for (i = 0; i < Cats->n_cats; i++) {
665 if (plus->built >= GV_BUILD_AREAS && type == GV_BOUNDARY) {
671 if (next_line != 0 && abs(next_line) != line) {
673 adjacent[n_adjacent] = next_line;
677 if (next_line != 0 && abs(next_line) != line) {
679 adjacent[n_adjacent] = -next_line;
683 if (next_line != 0 && abs(next_line) != line) {
685 adjacent[n_adjacent] = next_line;
689 if (next_line != 0 && abs(next_line) != line) {
691 adjacent[n_adjacent] = -next_line;
697 if (Line->left > 0) {
706 if (plus->update_cidx) {
707 delete_area_cats_from_cidx(Map, Line->left);
711 else if (Line->left < 0) {
714 if (Line->right > 0) {
723 if (plus->update_cidx) {
724 delete_area_cats_from_cidx(Map, Line->right);
728 else if (Line->right < 0) {
734 if (plus->built >= GV_BUILD_CENTROIDS && type == GV_CENTROID) {
735 if (Line->left > 0) {
736 G_debug(3,
"Remove centroid %d from area %d", line, Line->left);
737 if (plus->update_cidx) {
738 delete_area_cats_from_cidx(Map, Line->left);
740 Area = Map->plus.Area[Line->left];
749 if (plus->built >= GV_BUILD_AREAS && type == GV_BOUNDARY) {
750 int *new_areas, nnew_areas;
753 new_areas = (
int *)G_malloc(2 * n_adjacent *
sizeof(
int));
755 for (i = 0; i < n_adjacent; i++) {
761 G_debug(3,
"Build area for line = %d, side = %d", adjacent[i],
774 new_areas[nnew_areas] = area;
792 if (plus->built >= GV_BUILD_ATTACH_ISLES)
796 if (plus->built >= GV_BUILD_CENTROIDS)
800 if (plus->update_cidx) {
801 for (i = 0; i < nnew_areas; i++) {
802 add_area_cats_to_cidx(Map, new_areas[i]);
807 G_debug(3,
"updated lines : %d , updated nodes : %d", plus->n_uplines,
826 G_debug(3,
"V1_restore_line_nat(), offset = %ld", offset);
829 dig_fp = &(Map->dig_fp);
868 struct Plus_head *plus;
871 static struct line_pnts *points =
NULL;
872 static struct line_cats *cats =
NULL;
877 G_debug(3,
"V2_restore_line_nat(), line = %d", line);
881 if (plus->built >= GV_BUILD_BASE) {
882 Line = Map->plus.Line[line];
910 if (plus->update_cidx) {
911 for (i = 0; i < cats->n_cats; i++) {
917 if (plus->built >= GV_BUILD_BASE) {
919 G_debug(3,
" line restored in topo with id = %d", line);
925 add_line_to_topo(Map,
928 G_debug(3,
"updated lines : %d , updated nodes : %d", plus->n_uplines,
int dig_set_cur_port(struct Port_info *port)
int V2_restore_line_nat(struct Map_info *Map, int line, long offset)
Restores feature (topology level)
int dig_del_isle(struct Plus_head *plus, int isle)
Delete island from Plus_head structure.
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)
int dig_cidx_add_cat_sorted(struct Plus_head *Plus, int field, int cat, int line, int type)
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.
int dig_del_area(struct Plus_head *plus, int area)
Delete area from Plus_head structure.
int dig_add_line(struct Plus_head *plus, int type, struct line_pnts *Points, long offset)
Add new line to Plus_head structure.
long V1__rewrite_line_nat(struct Map_info *Map, long offset, int type, struct line_pnts *points, struct line_cats *cats)
Rewrites feature at the given offset.
int V2_read_line_nat(struct Map_info *Map, struct line_pnts *line_p, struct line_cats *line_c, int line)
Reads any specified line, this is NOT affected by constraints.
int dig__fwrite_port_D(double *buf, int cnt, GVFILE *fp)
int dig_angle_next_line(struct Plus_head *plus, plus_t current_line, int side, int type)
Find number line of next angle to follow an line.
int Vect_get_area_box(struct Map_info *Map, int area, BOUND_BOX *Box)
Get boundary box of area.
int dig__fwrite_port_I(int *buf, int cnt, GVFILE *fp)
int dig_fseek(GVFILE *file, long offset, int whence)
Set GVFILE position.
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_cidx_add_cat(struct Plus_head *Plus, int field, int cat, int line, int type)
long V2_write_line_nat(struct Map_info *Map, int type, struct line_pnts *points, struct line_cats *cats)
Writes feature to 'coor' file (topology level)
long V1_write_line_nat(struct Map_info *Map, int type, struct line_pnts *points, struct line_cats *cats)
Writes feature to 'coor' file.
int Vect_box_copy(BOUND_BOX *A, BOUND_BOX *B)
Copy box B to box A.
int Vect_attach_centroids(struct Map_info *Map, BOUND_BOX *box)
(Re)Attach centroids to areas in given box
long V1_rewrite_line_nat(struct Map_info *Map, long offset, int type, struct line_pnts *points, struct line_cats *cats)
Rewrites feature at the given offset.
int dig_del_line(struct Plus_head *plus, int line)
Delete line from Plus_head structure.
int dig_restore_line(struct Plus_head *plus, int lineid, int type, struct line_pnts *Points, long offset)
Restore line in Plus_head structure.
int V2_rewrite_line_nat(struct Map_info *Map, int line, int type, struct line_pnts *points, struct line_cats *cats)
Rewrites feature (topology level)
int Vect_get_isle_box(struct Map_info *Map, int isle, BOUND_BOX *Box)
Get boundary box of isle.
int dig__fread_port_C(char *buf, int cnt, GVFILE *fp)
struct line_cats * Vect_new_cats_struct()
Creates and initializes line_cats structure.
int dig_fflush(GVFILE *file)
Flush GVFILE.
int V1_read_line_nat(struct Map_info *Map, struct line_pnts *Points, struct line_cats *Cats, long offset)
Read line from coor file on given offset.
int dig_type_to_store(int type)
Convert type to store type.
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 V1_delete_line_nat(struct Map_info *Map, long offset)
Deletes feature at the given offset.
int dig__fwrite_port_C(char *buf, int cnt, GVFILE *fp)
int dig__fwrite_port_S(short *buf, int cnt, GVFILE *fp)
int G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
int dig_cidx_del_cat(struct Plus_head *Plus, int field, int cat, int line, int type)
long dig_ftell(GVFILE *file)
Get GVFILE position.
int dig_line_set_box(struct Plus_head *plus, plus_t line, BOUND_BOX *Box)
Set line bounding box.
int V2_delete_line_nat(struct Map_info *Map, int line)
Deletes feature (topology level).
int V1_restore_line_nat(struct Map_info *Map, long offset)
Restores feature at the given offset.