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 static struct line_pnts *old_points =
NULL;
404 static struct line_cats *old_cats =
NULL;
420 && points->n_points == old_points->n_points
421 && cats->n_cats == old_cats->n_cats
422 && (((type & GV_POINTS) && (old_type & GV_POINTS))
423 || ((type &
GV_LINES) && (old_type & GV_LINES)))) {
434 if (
dig_fseek(&(Map->dig_fp), 0L, SEEK_END) == -1)
438 if (new_offset == -1)
462 struct line_pnts *points,
struct line_cats *cats)
490 struct line_pnts *points,
struct line_cats *cats)
498 dig_fp = &(Map->dig_fp);
512 if (cats->n_cats > 0) {
521 if (cats->n_cats > 0) {
522 if (Map->head.Version_Minor == 1) {
527 nc = (char)cats->n_cats;
532 if (cats->n_cats > 0) {
533 if (Map->head.Version_Minor == 1) {
539 for (i = 0; i < cats->n_cats; i++) {
540 field = (short)cats->field[i];
550 if (type & GV_POINTS) {
554 n_points = points->n_points;
564 if (Map->head.with_z) {
589 G_debug(3,
"V1_delete_line_nat(), offset = %ld", offset);
592 dig_fp = &(Map->dig_fp);
626 int ret, i, side, type = 0, first = 0, next_line, area;
629 struct Plus_head *plus;
631 int adjacent[4], n_adjacent = 0;
632 static struct line_cats *Cats =
NULL;
634 G_debug(3,
"V2_delete_line_nat(), line = %d", line);
638 if (plus->built >= GV_BUILD_BASE) {
639 Line = Map->plus.Line[line];
651 if (plus->update_cidx) {
654 for (i = 0; i < Cats->n_cats; i++) {
667 if (plus->built >= GV_BUILD_AREAS && type == GV_BOUNDARY) {
673 if (next_line != 0 && abs(next_line) != line) {
675 adjacent[n_adjacent] = next_line;
679 if (next_line != 0 && abs(next_line) != line) {
681 adjacent[n_adjacent] = -next_line;
685 if (next_line != 0 && abs(next_line) != line) {
687 adjacent[n_adjacent] = next_line;
691 if (next_line != 0 && abs(next_line) != line) {
693 adjacent[n_adjacent] = -next_line;
699 if (Line->left > 0) {
708 if (plus->update_cidx) {
709 delete_area_cats_from_cidx(Map, Line->left);
713 else if (Line->left < 0) {
716 if (Line->right > 0) {
725 if (plus->update_cidx) {
726 delete_area_cats_from_cidx(Map, Line->right);
730 else if (Line->right < 0) {
736 if (plus->built >= GV_BUILD_CENTROIDS && type == GV_CENTROID) {
737 if (Line->left > 0) {
738 G_debug(3,
"Remove centroid %d from area %d", line, Line->left);
739 if (plus->update_cidx) {
740 delete_area_cats_from_cidx(Map, Line->left);
742 Area = Map->plus.Area[Line->left];
751 if (plus->built >= GV_BUILD_AREAS && type == GV_BOUNDARY) {
752 int *new_areas, nnew_areas;
755 new_areas = (
int *)G_malloc(2 * n_adjacent *
sizeof(
int));
757 for (i = 0; i < n_adjacent; i++) {
763 G_debug(3,
"Build area for line = %d, side = %d", adjacent[i],
776 new_areas[nnew_areas] = area;
794 if (plus->built >= GV_BUILD_ATTACH_ISLES)
798 if (plus->built >= GV_BUILD_CENTROIDS)
802 if (plus->update_cidx) {
803 for (i = 0; i < nnew_areas; i++) {
804 add_area_cats_to_cidx(Map, new_areas[i]);
809 G_debug(3,
"updated lines : %d , updated nodes : %d", plus->n_uplines,
828 G_debug(3,
"V1_restore_line_nat(), offset = %ld", offset);
831 dig_fp = &(Map->dig_fp);
870 struct Plus_head *plus;
873 static struct line_pnts *points =
NULL;
874 static struct line_cats *cats =
NULL;
879 G_debug(3,
"V2_restore_line_nat(), line = %d", line);
883 if (plus->built >= GV_BUILD_BASE) {
884 Line = Map->plus.Line[line];
912 if (plus->update_cidx) {
913 for (i = 0; i < cats->n_cats; i++) {
919 if (plus->built >= GV_BUILD_BASE) {
921 G_debug(3,
" line restored in topo with id = %d", line);
927 add_line_to_topo(Map,
930 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.