26 #include "local_proto.h"
28 static off_t V1__write_line_nat(
struct Map_info *, off_t,
int,
31 static void V2__delete_area_cats_from_cidx_nat(
struct Map_info *,
int);
32 static void V2__add_area_cats_to_cidx_nat(
struct Map_info *,
int);
49 return V1__write_line_nat(Map, -1, type, points, cats);
73 G_debug(3,
"V2_write_line_nat(): type=%d", type);
113 G_debug(3,
"V1_rewrite_line_nat(): offset = %" PRId64, offset);
132 return V1__write_line_nat(Map, offset, type, points, cats);
139 return V1__write_line_nat(Map, -1, type, points, cats);
172 off_t offset, old_offset;
187 if (line < 1 || line > plus->
n_lines) {
188 G_warning(
_(
"Attempt to access feature with invalid id (%d)"),
232 offset = V1__write_line_nat(Map, offset, type, points, cats);
253 G_debug(3,
"V1_delete_line_nat(): offset = %" PRId64, offset);
298 G_debug(3,
"V2_delete_line_nat(): line = %d", (
int)line);
303 if (line < 1 || line > plus->
n_lines) {
304 G_warning(
_(
"Attempt to access feature with invalid id (%d)"),
311 G_warning(
_(
"Attempt to access dead feature %d"), (
int)line);
356 "V1_restore_line_nat(): offset = %" PRId64
357 ", line (not used) = %" PRId64,
408 G_debug(3,
"V2_restore_line_nat(): offset = %" PRId64
", line = %" PRId64,
411 if (line < 1 || line > plus->
n_lines) {
412 G_warning(
_(
"Attempt to access feature with invalid id (%" PRId64
")"),
420 G_warning(
_(
"Attempt to access alive feature %d"), (
int)line);
464 off_t V1__write_line_nat(
struct Map_info *Map, off_t offset,
int type,
480 if (offset < Map->head.head_size) {
486 G_debug(3,
"V1__rewrite_line_nat(): offset = %" PRId64, offset);
530 for (i = 0; i < cats->
n_cats; i++) {
531 field = (short)cats->
field[i];
575 void V2__delete_area_cats_from_cidx_nat(
struct Map_info *Map,
int area)
581 G_debug(3,
"V2__delete_area_cats_from_cidx_nat(), area = %d", area);
586 "delete_area_cats_from_cidx()", area);
596 for (i = 0; i < Cats->
n_cats; i++) {
611 void V2__add_area_cats_to_cidx_nat(
struct Map_info *Map,
int area)
617 G_debug(3,
"V2__add_area_cats_to_cidx_nat(), area = %d", area);
622 "add_area_cats_to_cidx():", area);
632 for (i = 0; i < Cats->
n_cats; i++) {
661 int adjacent[4], n_adjacent;
671 if (line < 1 || line > plus->
n_lines) {
672 G_warning(
_(
"Attempt to access feature with invalid id (%d)"), line);
678 G_warning(
_(
"Attempt to access dead feature %d"), line);
684 for (i = 0; i < cats->
n_cats; i++) {
703 if (next_line != 0 && abs(next_line) != line) {
706 adjacent[n_adjacent] = next_line;
710 if (next_line != 0 && abs(next_line) != line) {
713 adjacent[n_adjacent] = -next_line;
718 if (next_line != 0 && abs(next_line) != line) {
721 adjacent[n_adjacent] = next_line;
726 if (next_line != 0 && abs(next_line) != line) {
729 adjacent[n_adjacent] = -next_line;
735 if (topo->
left > 0) {
745 V2__delete_area_cats_from_cidx_nat(Map, topo->
left);
749 else if (topo->
left < 0) {
752 if (topo->
right > 0) {
762 V2__delete_area_cats_from_cidx_nat(Map, topo->
right);
766 else if (topo->
right < 0) {
778 G_debug(3,
"Remove centroid %d from area %d", (
int)line,
781 V2__delete_area_cats_from_cidx_nat(Map, topo->
area);
792 if (0 !=
dig_del_line(plus, line, points->
x[0], points->
y[0], points->
z[0]))
798 int new_areas[4], nnew_areas = 0;
801 for (i = 0; i < n_adjacent; i++) {
804 G_debug(3,
"Build area for line = %d, side = %d", adjacent[i],
817 new_areas[nnew_areas] =
area;
845 for (i = 0; i < nnew_areas; i++) {
846 V2__add_area_cats_to_cidx_nat(Map, new_areas[i]);
852 G_debug(3,
"updated lines : %d , updated nodes : %d",
909 const struct line_cats *cats,
int restore_line,
910 int (*external_routine)(
struct Map_info *,
int))
912 int first, s, n, i, line;
913 int node, next_line,
area, side, sel_area, new_area[2];
916 struct P_line *Line, *NLine;
925 "V2__add_line_to_topo_nat(): offset = %" PRId64
926 " (build level = %d)",
927 offset, plus->
built);
934 if (restore_line > 0)
938 G_debug(3,
" line added to topo with id = %d", line);
940 Line = plus->
Line[line];
954 for (s = 0; s < 2; s++) {
955 node = (s == 0 ? topo->
N1 : topo->
N2);
956 G_debug(3,
" delete neighbour areas/isles: %s node = %d",
957 (s == 0 ?
"first" :
"second"), node);
958 Node = plus->
Node[node];
960 for (i = 0; i < Node->
n_lines; i++) {
966 G_debug(3,
" number of boundaries at node = %d", n);
979 if (next_line != 0) {
980 NLine = plus->
Line[abs(next_line)];
991 G_debug(3,
" next_line = %d area = %d", next_line, area);
1002 V2__delete_area_cats_from_cidx_nat(Map, area);
1005 if (external_routine)
1007 external_routine(Map, area);
1009 else if (area < 0) {
1011 if (external_routine)
1013 external_routine(Map, area);
1023 for (s = 0; s < 2; s++) {
1036 else if (area < 0) {
1062 for (s = 0; s < 2; s++) {
1063 if (new_area[s] > 0) {
1064 V2__add_area_cats_to_cidx_nat(Map, new_area[s]);
1076 G_debug(3,
" new centroid %d is in area %d", line, sel_area);
1078 Area = plus->
Area[sel_area];
1079 Line = plus->
Line[line];
1082 G_debug(3,
" first centroid -> attach to area");
1084 topo->
area = sel_area;
1086 V2__add_area_cats_to_cidx_nat(Map, sel_area);
1090 G_debug(3,
" duplicate centroid -> do not attach to area");
1091 topo->
area = -sel_area;
1099 for (i = 0; i < cats->
n_cats; i++) {
1106 G_debug(3,
"updated lines : %d , updated nodes : %d",
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
void G_warning(const char *,...) __attribute__((format(printf
int G_debug(int, const char *,...) __attribute__((format(printf
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.
int Vect_attach_centroids(struct Map_info *, const struct bound_box *)
(Re)Attach centroids in given bounding box to areas
int Vect_build_line_area(struct Map_info *, int, int)
Build area on given side of line (GV_LEFT or GV_RIGHT)
int Vect_box_extend(struct bound_box *, const struct bound_box *)
Extend box A by box B.
int Vect_read_line(struct Map_info *, struct line_pnts *, struct line_cats *, int)
Read vector feature (topological level required)
int Vect_get_area_box(struct Map_info *, int, struct bound_box *)
Get bounding box of area.
struct line_pnts * Vect_new_line_struct(void)
Creates and initializes a line_pnts structure.
int Vect_get_isle_box(struct Map_info *, int, struct bound_box *)
Get bounding box of isle.
int Vect_attach_isles(struct Map_info *, const struct bound_box *)
(Re)Attach isles in given bounding box to areas
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.
struct line_cats * Vect_new_cats_struct(void)
Creates and initializes line_cats structure.
int Vect_find_area(struct Map_info *, double, double)
Find the nearest area.
int Vect_box_copy(struct bound_box *, const struct bound_box *)
Copy box B to box A.
#define GV_BUILD_ATTACH_ISLES
Topology levels - attach islands to areas.
#define GV_BUILD_BASE
Topology levels - basic level (without areas and isles)
#define GV_BUILD_AREAS
Topology levels - build areas.
#define GV_BUILD_CENTROIDS
Topology levels - assign centroids to areas.
#define GV_LEFT
Boundary side indicator left/right.
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.
int dig_angle_next_line(struct Plus_head *, plus_t, int, int, float *)
Find line number of next angle to follow a line.
int dig__fwrite_port_C(const char *, size_t, struct gvfile *)
Write chars to the Portable Vector Format.
int dig_del_line(struct Plus_head *, int, double, double, double)
Delete line from Plus_head structure.
int dig__fwrite_port_I(const int *, size_t, struct gvfile *)
Write integers to the Portable Vector Format.
off_t dig_ftell(struct gvfile *file)
Get struct gvfile position.
int dig_del_area(struct Plus_head *, int)
Delete area from Plus_head structure.
int dig_set_cur_port(struct Port_info *)
Set current Port_info structure.
int dig__fwrite_port_D(const double *, size_t, struct gvfile *)
Write doubles to the Portable Vector Format.
int dig__fread_port_C(char *, size_t, struct gvfile *)
Read chars from the Portable Vector Format.
int dig_del_isle(struct Plus_head *, int)
Delete island from Plus_head structure.
int dig_cidx_del_cat(struct Plus_head *, int, int, int, int)
int dig_fseek(struct gvfile *file, off_t offset, int whence)
Set struct gvfile position.
int dig_cidx_add_cat_sorted(struct Plus_head *, int, int, int, int)
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.
int dig_line_box(const struct line_pnts *, struct bound_box *)
int dig__fwrite_port_S(const short *, size_t, struct gvfile *)
Write shorts to the Portable Vector Format.
int dig_type_to_store(int)
Convert type to store type.
struct gvfile dig_fp
GV file pointer (native format only)
struct dig_head head
Header info.
struct Plus_head plus
Plus info (topology, version, ...)
plus_t centroid
Number of first centroid within area.
off_t offset
Offset in coor file for line.
void * topo
Topology info.
Topological feature - node.
plus_t n_lines
Number of attached lines (size of lines, angle)
plus_t * lines
List of connected lines.
plus_t left
Area number to the left, negative for isle.
plus_t right
Area number to the right, negative for isle.
plus_t area
Area number, negative for duplicate centroid.
Basic topology-related info.
int do_uplist
Indicates if the list of updated features is maintained.
struct P_line ** Line
Array of vector geometries.
plus_t n_lines
Current number of lines.
int n_upnodes
number of updated nodes
struct P_area ** Area
Array of areas.
int cidx_up_to_date
Category index to be updated.
int update_cidx
Update category index if vector is modified.
struct Plus_head::@10 uplist
List of updated lines/nodes.
struct bound_box box
Bounding box of features.
int n_uplines
Number of updated lines.
struct P_node ** Node
Array of nodes.
int built
Highest level of topology currently available.
int minor
Current version (minor)
struct Version_info coor_version
Version info for coor file.
int with_z
2D/3D vector data
struct Port_info port
Portability information.
int * field
Array of layers (fields)
int * cat
Array of categories.
int n_cats
Number of categories attached to element.
Feature geometry info - coordinates.
double * y
Array of Y coordinates.
double * x
Array of X coordinates.
int n_points
Number of points.
double * z
Array of Z coordinates.
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)(struct Map_info *, int))
Add feature (line) to topology (internal use only)
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)
int V1_delete_line_nat(struct Map_info *Map, off_t offset)
Deletes feature at level 1 (internal use only)
int V2_restore_line_nat(struct Map_info *Map, off_t offset, off_t line)
Restores feature at topological level (internal use only)
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)
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__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)
int V2_delete_line_nat(struct Map_info *Map, off_t line)
Deletes feature at topological level (internal use only)
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)
int V1_restore_line_nat(struct Map_info *Map, off_t offset, off_t line)
Restores feature at level 1 (internal use only)