25 #include "local_proto.h" 27 static off_t V1__write_line_nat(
struct Map_info *, off_t,
int,
29 static void V2__delete_area_cats_from_cidx_nat(
struct Map_info *,
int);
30 static void V2__add_area_cats_to_cidx_nat(
struct Map_info *,
int);
46 return V1__write_line_nat(Map, -1, type, points, cats);
69 G_debug(3,
"V2_write_line_nat(): type=%d", type);
124 && (((type &
GV_POINTS) && (old_type & GV_POINTS))
125 || ((type &
GV_LINES) && (old_type & GV_LINES)))) {
128 return V1__write_line_nat(Map, offset, type, points, cats);
135 return V1__write_line_nat(Map, -1, type, points, cats);
166 off_t offset, old_offset;
181 if (line < 1 || line > plus->
n_lines) {
182 G_warning(
_(
"Attempt to access feature with invalid id (%d)"), (
int)line);
207 && (((type &
GV_POINTS) && (old_type & GV_POINTS))
208 || ((type &
GV_LINES) && (old_type & GV_LINES)))) {
224 offset = V1__write_line_nat(Map, offset, type, points, cats);
289 G_debug(3,
"V2_delete_line_nat(): line = %d", (
int)line);
294 if (line < 1 || line > plus->
n_lines) {
295 G_warning(
_(
"Attempt to access feature with invalid id (%d)"), (
int)line);
301 G_warning(
_(
"Attempt to access dead feature %d"), (
int)line);
397 if (line < 1 || line > plus->
n_lines) {
398 G_warning(
_(
"Attempt to access feature with invalid id (%" PRI_OFF_T
")"), line);
404 G_warning(
_(
"Attempt to access alive feature %d"), (
int)line);
445 off_t V1__write_line_nat(
struct Map_info *Map, off_t offset,
int type,
461 if (offset < Map->head.head_size) {
511 for (i = 0; i < cats->
n_cats; i++) {
512 field = (short)cats->
field[i];
556 void V2__delete_area_cats_from_cidx_nat(
struct Map_info *Map,
int area)
562 G_debug(3,
"V2__delete_area_cats_from_cidx_nat(), area = %d", area);
567 "delete_area_cats_from_cidx()", area);
577 for (i = 0; i < Cats->
n_cats; i++) {
592 void V2__add_area_cats_to_cidx_nat(
struct Map_info *Map,
int area)
598 G_debug(3,
"V2__add_area_cats_to_cidx_nat(), area = %d", area);
603 "add_area_cats_to_cidx():", area);
613 for (i = 0; i < Cats->
n_cats; i++) {
640 int adjacent[4], n_adjacent;
650 if (line < 1 || line > plus->
n_lines) {
651 G_warning(
_(
"Attempt to access feature with invalid id (%d)"), line);
657 G_warning(
_(
"Attempt to access dead feature %d"), line);
663 for (i = 0; i < cats->
n_cats; i++) {
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;
697 if (next_line != 0 && abs(next_line) != line) {
699 adjacent[n_adjacent] = -next_line;
705 if (topo->
left > 0) {
715 V2__delete_area_cats_from_cidx_nat(Map, topo->
left);
719 else if (topo->
left < 0) {
722 if (topo->
right > 0) {
732 V2__delete_area_cats_from_cidx_nat(Map, topo->
right);
736 else if (topo->
right < 0) {
748 G_debug(3,
"Remove centroid %d from area %d", (
int) line, topo->
area);
750 V2__delete_area_cats_from_cidx_nat(Map, topo->
area);
761 if (0 !=
dig_del_line(plus, line, points->
x[0], points->
y[0], points->
z[0]))
767 int new_areas[4], nnew_areas = 0;
770 for (i = 0; i < n_adjacent; i++) {
773 G_debug(3,
"Build area for line = %d, side = %d", adjacent[i],
786 new_areas[nnew_areas] =
area;
813 for (i = 0; i < nnew_areas; i++) {
814 V2__add_area_cats_to_cidx_nat(Map, new_areas[i]);
874 int (*external_routine) (
const struct Map_info *,
int))
876 int first, s, n, i, line;
877 int node, next_line,
area, side, sel_area, new_area[2];
880 struct P_line *Line, *NLine;
888 G_debug(3,
"V2__add_line_to_topo_nat(): offset = %" PRI_OFF_T " (build level = %d)", offset, plus->built);
895 if (restore_line > 0)
899 G_debug(3,
" line added to topo with id = %d", line);
901 Line = plus->Line[line];
916 for (s = 0; s < 2; s++) {
917 node = (s == 0 ? topo->
N1 : topo->
N2);
919 " delete neighbour areas/isles: %s node = %d",
920 (s == 0 ?
"first" :
"second"), node);
921 Node = plus->Node[node];
923 for (i = 0; i < Node->
n_lines; i++) {
924 NLine = plus->Line[abs(Node->
lines[i])];
929 G_debug(3,
" number of boundaries at node = %d", n);
944 if (next_line != 0) {
945 NLine = plus->Line[abs(next_line)];
950 else if (next_line < 0)
953 G_debug(3,
" next_line = %d area = %d", next_line,
964 if (plus->update_cidx) {
965 V2__delete_area_cats_from_cidx_nat(Map, area);
968 if (external_routine)
969 external_routine(Map, area);
973 if (external_routine)
974 external_routine(Map, area);
984 for (s = 0; s < 2; s++) {
1022 if (plus->update_cidx) {
1023 for (s = 0; s < 2; s++) {
1024 if (new_area[s] > 0) {
1025 V2__add_area_cats_to_cidx_nat(Map, new_area[s]);
1037 G_debug(3,
" new centroid %d is in area %d", line, sel_area);
1039 Area = plus->Area[sel_area];
1040 Line = plus->Line[line];
1043 G_debug(3,
" first centroid -> attach to area");
1045 topo->
area = sel_area;
1046 if (plus->update_cidx) {
1047 V2__add_area_cats_to_cidx_nat(Map, sel_area);
1052 " duplicate centroid -> do not attach to area");
1053 topo->
area = -sel_area;
1060 if (plus->update_cidx && cats) {
1061 for (i = 0; i < cats->
n_cats; i++) {
1067 if (plus->uplist.do_uplist) {
1068 G_debug(3,
"updated lines : %d , updated nodes : %d", plus->uplist.n_uplines,
1069 plus->uplist.n_upnodes);
int Vect_get_area_box(const struct Map_info *, int, struct bound_box *)
Get bounding box of area.
off_t V2_rewrite_line_nat(struct Map_info *Map, off_t line, int type, const struct line_pnts *points, const struct line_cats *cats)
Rewrites feature to 'coor' file at topological level (internal use only)
struct Version_info coor_version
Version info for coor file.
int Vect_build_line_area(struct Map_info *, int, int)
Build area on given side of line (GV_LEFT or GV_RIGHT)
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
int built
Highest level of topology currently available.
plus_t area
Area number, negative for duplicate centroid.
#define GV_LEFT
Boundary side indicator left/right.
int Vect_attach_isles(struct Map_info *, const struct bound_box *)
(Re)Attach isles in given bounding box to areas
int n_uplines
Number of updated lines.
int dig__fwrite_port_I(const int *, size_t, struct gvfile *)
Write integers to the Portable Vector Format.
off_t offset
Offset in coor file for line.
int dig_type_to_store(int)
Convert type to store type.
int dig__fwrite_port_C(const char *, size_t, struct gvfile *)
Write chars to the Portable Vector Format.
struct P_line ** Line
Array of vector geometries.
int Vect_box_copy(struct bound_box *, const struct bound_box *)
Copy box B to box A.
int Vect_attach_centroids(struct Map_info *, const struct bound_box *)
(Re)Attach centroids in given bounding box to areas
int dig__fread_port_C(char *, size_t, struct gvfile *)
Read chars from the Portable Vector Format.
plus_t right
Area number to the right, negative for isle.
#define GV_BUILD_BASE
Topology levels - basic level (without areas and isles)
struct P_area ** Area
Array of areas.
int dig_line_box(const struct line_pnts *, struct bound_box *)
int n_points
Number of points.
plus_t n_lines
Number of attached lines (size of lines, angle)
plus_t left
Area number to the left, negative for isle.
plus_t * lines
List of connected lines.
plus_t centroid
Number of first centroid within area.
int do_uplist
Indicates if the list of updated features is maintained.
int V1_restore_line_nat(struct Map_info *Map, off_t offset, off_t line)
Restores feature at level 1 (internal use only)
off_t dig_ftell(struct gvfile *file)
Get struct gvfile position.
int dig_del_line(struct Plus_head *, int, double, double, double)
Delete line from Plus_head structure.
plus_t n_lines
Current number of lines.
int dig_fflush(struct gvfile *file)
Flush struct gvfile.
int dig_add_line(struct Plus_head *, int, const struct line_pnts *, const struct bound_box *, off_t)
Add new line to Plus_head structure.
double * x
Array of X coordinates.
int dig_angle_next_line(struct Plus_head *, plus_t, int, int, float *)
Find line number of next angle to follow a line.
int cidx_up_to_date
Category index to be updated.
Feature geometry info - coordinates.
int with_z
2D/3D vector data
int dig_restore_line(struct Plus_head *, int, int, const struct line_pnts *, const struct bound_box *, off_t)
Restore line in Plus_head structure.
Basic topology-related info.
int dig_cidx_del_cat(struct Plus_head *, int, int, int, int)
off_t V1_rewrite_line_nat(struct Map_info *Map, off_t offset, int type, const struct line_pnts *points, const struct line_cats *cats)
Rewrites feature to 'coor' file at level 1 (internal use only)
#define GV_BUILD_AREAS
Topology levels - build areas.
struct Port_info port
Portability information.
struct line_pnts * Vect_new_line_struct(void)
Creates and initializes a line_pnts structure.
void * topo
Topology info.
int n_upnodes
number of updated nodes
int dig_del_isle(struct Plus_head *, int)
Delete island from Plus_head structure.
int n_cats
Number of categories attached to element.
int * cat
Array of categories.
off_t V1_write_line_nat(struct Map_info *Map, int type, const struct line_pnts *points, const struct line_cats *cats)
Writes feature to 'coor' file at level 1 (internal use only)
int V2_read_line_nat(struct Map_info *, struct line_pnts *, struct line_cats *, int)
Read vector feature on topological level (level 2) - native format - internal use only...
struct Plus_head plus
Plus info (topology, version, ...)
off_t V2_write_line_nat(struct Map_info *Map, int type, const struct line_pnts *points, const struct line_cats *cats)
Writes feature to 'coor' file at topological level (internal use only)
int Vect_box_extend(struct bound_box *, const struct bound_box *)
Extend box A by box B.
Topological feature - node.
int Vect_get_isle_box(const struct Map_info *, int, struct bound_box *)
Get bounding box of isle.
struct dig_head head
Header info.
#define GV_BUILD_ATTACH_ISLES
Topology levels - attach islands to areas.
int Vect_find_area(struct Map_info *, double, double)
Find the nearest area.
int V2__add_line_to_topo_nat(struct Map_info *Map, off_t offset, int type, const struct line_pnts *points, const struct line_cats *cats, int restore_line, int(*external_routine)(const struct Map_info *, int))
Add feature (line) to topology (internal use only)
double * y
Array of Y coordinates.
int V2_restore_line_nat(struct Map_info *Map, off_t offset, off_t line)
Restores feature at topological level (internal use only)
struct line_cats * Vect_new_cats_struct(void)
Creates and initializes line_cats structure.
int V1_read_line_nat(struct Map_info *, struct line_pnts *, struct line_cats *, off_t)
Read vector feature on non-topological level (level 1) - native format - internal use only...
int dig__fwrite_port_S(const short *, size_t, struct gvfile *)
Write shorts to the Portable Vector Format.
void G_warning(const char *,...) __attribute__((format(printf
int V1_delete_line_nat(struct Map_info *Map, off_t offset)
Deletes feature at level 1 (internal use only)
int V2__delete_line_from_topo_nat(struct Map_info *Map, int line, int type, const struct line_pnts *points, const struct line_cats *cats)
Delete feature from topology (internal use only)
double * z
Array of Z coordinates.
struct gvfile dig_fp
GV file pointer (native format only)
#define GV_BUILD_CENTROIDS
Topology levels - assign centroids to areas.
int * field
Array of layers (fields)
int minor
Current version (minor)
int dig_set_cur_port(struct Port_info *)
Set current Port_info structure.
struct Plus_head::@10 uplist
List of updated lines/nodes.
int dig_del_area(struct Plus_head *, int)
Delete area from Plus_head structure.
int dig_cidx_add_cat_sorted(struct Plus_head *, int, int, int, int)
int update_cidx
Update category index if vector is modified.
int Vect_read_line(const struct Map_info *, struct line_pnts *, struct line_cats *, int)
Read vector feature (topological level required)
int G_debug(int, const char *,...) __attribute__((format(printf
int dig_fseek(struct gvfile *file, off_t offset, int whence)
Set struct gvfile position.
int dig__fwrite_port_D(const double *, size_t, struct gvfile *)
Write doubles to the Portable Vector Format.
int V2_delete_line_nat(struct Map_info *Map, off_t line)
Deletes feature at topological level (internal use only)