19 #include <sys/types.h> 39 ndims = (Plus->
with_z != 0) ? 3 : 2;
42 G_debug(1,
"dig_spidx_init(), %d dims", ndims);
49 fd = open(filename, O_RDWR | O_CREAT | O_EXCL, 0600);
54 fd = open(filename, O_RDWR | O_CREAT | O_EXCL, 0600);
59 fd = open(filename, O_RDWR | O_CREAT | O_EXCL, 0600);
64 fd = open(filename, O_RDWR | O_CREAT | O_EXCL, 0600);
111 ndims = Plus->
with_z ? 3 : 2;
122 fd = open(filename, O_RDWR | O_CREAT | O_EXCL, 0600);
143 ndims = Plus->
with_z ? 3 : 2;
154 fd = open(filename, O_RDWR | O_CREAT | O_EXCL, 0600);
175 ndims = Plus->
with_z ? 3 : 2;
186 fd = open(filename, O_RDWR | O_CREAT | O_EXCL, 0600);
207 ndims = Plus->
with_z ? 3 : 2;
218 fd = open(filename, O_RDWR | O_CREAT | O_EXCL, 0600);
285 double x,
double y,
double z)
288 static int rect_init = 0;
296 G_debug(3,
"dig_spidx_add_node(): node = %d, x,y,z = %f, %f, %f", node, x,
323 static int rect_init = 0;
331 G_debug(3,
"dig_spidx_add_line(): line = %d", line);
357 static int rect_init = 0;
365 G_debug(3,
"dig_spidx_add_area(): area = %d", area);
392 static int rect_init = 0;
400 G_debug(3,
"dig_spidx_add_isle(): isle = %d", isle);
428 static int rect_init = 0;
436 G_debug(3,
"dig_spidx_del_node(): node = %d", node);
438 Node = Plus->
Node[node];
450 G_fatal_error(
_(
"Unable to delete node %d from spatial index"), node);
467 double x,
double y,
double z)
471 static int rect_init = 0;
479 G_debug(3,
"dig_spidx_del_line(): line = %d", line);
493 G_fatal_error(
_(
"Unable to delete line %d from spatial index"), line);
516 static int rect_init = 0;
524 G_debug(3,
"dig_spidx_del_area(): area = %d", area);
526 Area = Plus->
Area[area];
534 Node = Plus->
Node[topo->
N1];
546 G_fatal_error(
_(
"Unable to delete area %d from spatial index"), area);
569 static int rect_init = 0;
577 G_debug(3,
"dig_spidx_del_isle(): isle = %d", isle);
579 Isle = Plus->
Isle[isle];
583 Node = Plus->
Node[topo->
N1];
595 G_fatal_error(
_(
"Unable to delete isle %d from spatial index"), isle);
601 static int _add_item(
int id,
const struct RTree_Rect *rect,
610 static int _add_item_with_box(
int id,
const struct RTree_Rect *rect,
634 static int _set_item_box(
int id,
const struct RTree_Rect *rect,
635 struct boxid *box_id)
637 if (
id == box_id->id) {
667 static int rect_init = 0;
675 G_debug(3,
"dig_select_nodes()");
695 static int _add_node(
int id,
const struct RTree_Rect *rect,
int *node)
714 static int rect_init = 0;
754 static int rect_init = 0;
762 G_debug(3,
"dig_select_lines_with_box()");
798 static int rect_init = 0;
800 G_debug(3,
"dig_find_line_box()");
808 Line = Plus->
Line[line];
818 Node = Plus->
Node[topo->
N1];
823 Node = Plus->
Node[topo->
N1];
847 G_fatal_error(
"Bug in vector lib: dig_find_line_box() may only be used for lines and boundaries.");
866 static int rect_init = 0;
874 G_debug(3,
"dig_select_areas_with_box()");
913 static int rect_init = 0;
915 G_debug(3,
"dig_find_area_box()");
923 Area = Plus->
Area[area];
926 Node = Plus->
Node[topo->
N1];
960 static int rect_init = 0;
968 G_debug(3,
"dig_select_areas_with_box()");
1001 struct boxid box_id;
1007 static int rect_init = 0;
1009 G_debug(3,
"dig_find_isle_box()");
1017 Isle = Plus->
Isle[isle];
1020 Node = Plus->
Node[topo->
N1];
int Spidx_new
Build new spatial index.
int RTreeInsertRect(struct RTree_Rect *r, int tid, struct RTree *t)
Insert an item into a R*-Tree.
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
int dig_spidx_del_line(struct Plus_head *Plus, int line, double x, double y, double z)
Delete line from spatial index.
void dig_spidx_free(struct Plus_head *Plus)
Free spatial index (nodes, lines, areas, isles)
struct RTree * Face_spidx
Faces spatial index.
int dig_select_lines(struct Plus_head *Plus, const struct bound_box *box, struct boxlist *list)
Select lines with boxes by box.
off_t Isle_spidx_offset
Offset of isles in sidx file.
struct RTree * Hole_spidx
Holes spatial index.
struct P_line ** Line
Array of vector geometries.
int spidx_with_z
2D/3D spatial index
void RTreeDestroyTree(struct RTree *t)
Destroy an R*-Tree.
int with_z
2D/3D vector data
struct P_area ** Area
Array of areas.
struct P_node ** Node
Array of nodes.
int dig_spidx_del_node(struct Plus_head *Plus, int node)
Delete node from spatial index.
struct RTree * Isle_spidx
Isles spatial index.
int RTreeSearch(struct RTree *t, struct RTree_Rect *r, SearchHitCallback *shcb, void *cbarg)
Search an R*-Tree.
int dig_spidx_init(struct Plus_head *Plus)
Initit spatial index (nodes, lines, areas, isles)
struct RTree * Node_spidx
Node spatial index.
int n_values
Number of values in the list.
struct P_isle ** Isle
Array of isles.
struct RTree * Line_spidx
Line spatial index.
struct RTree * Volume_spidx
Volumes spatial index.
int Spidx_built
Spatial index built?
int n_values
Number of items in the list.
void dig_spidx_free_lines(struct Plus_head *Plus)
Free spatial index for lines.
int dig_boxlist_add(struct boxlist *, int, const struct bound_box *)
off_t Area_spidx_offset
Offset of areas in sidx file.
int RTreeDeleteRect(struct RTree_Rect *r, int tid, struct RTree *t)
Delete an item from a R*-Tree.
void dig_spidx_free_areas(struct Plus_head *Plus)
Reset spatial index for areas.
int rtree_search(struct RTree *, struct RTree_Rect *, SearchHitCallback, void *, struct Plus_head *)
Search spatial index file Can't use regular RTreeSearch() here because sidx must be read with dig__fr...
double z
Z coordinate (used only for 3D data)
int dig_spidx_add_area(struct Plus_head *Plus, int area, const struct bound_box *box)
Add new area to spatial index.
void G_ilist_add(struct ilist *, int)
Add item to ilist.
plus_t * lines
List of boundary lines.
int dig_spidx_del_area(struct Plus_head *Plus, int area)
Delete area from spatial index.
Basic topology-related info.
void * topo
Topology info.
int Spidx_file
Build new spatial index in file.
char * G_tempfile(void)
Returns a temporary file name.
struct RTree * Area_spidx
Area spatial index.
void dig_spidx_free_isles(struct Plus_head *Plus)
Reset spatial index for isles.
int dig_select_isles(struct Plus_head *Plus, const struct bound_box *box, struct boxlist *list)
Select isles with boxes by box.
plus_t * lines
List of boundary lines.
int dig_select_nodes(struct Plus_head *Plus, const struct bound_box *box, struct ilist *list)
Select nodes by bbox.
Topological feature - node.
int dig_spidx_del_isle(struct Plus_head *Plus, int isle)
Delete isle from spatial index.
int dig_spidx_add_node(struct Plus_head *Plus, int node, double x, double y, double z)
Add new node to spatial index.
off_t Line_spidx_offset
Offset of lines in sidx file.
int dig_spidx_add_line(struct Plus_head *Plus, int line, const struct bound_box *box)
Add new line to spatial index.
int dig_find_isle_box(struct Plus_head *Plus, int isle, struct bound_box *box)
Find box for isle.
int dig_find_line_box(struct Plus_head *Plus, int line, struct bound_box *box)
Find box for line.
List of bounding boxes with id.
off_t Volume_spidx_offset
Offset of volumes in sidx file.
int dig_find_area_box(struct Plus_head *Plus, int area, struct bound_box *box)
Find bounding box for given area.
off_t Node_spidx_offset
Offset of nodes in sidx file.
int dig_find_node(struct Plus_head *Plus, double x, double y, double z)
Find one node by coordinates.
int dig_spidx_add_isle(struct Plus_head *Plus, int isle, const struct bound_box *box)
Add new island to spatial index.
void dig_spidx_free_nodes(struct Plus_head *Plus)
Free spatial index for nodes.
off_t Hole_spidx_offset
Offset of holes in sidx file.
int G_debug(int, const char *,...) __attribute__((format(printf
struct RTree * RTreeCreateTree(int fd, off_t rootpos, int ndims)
Create new empty R*-Tree.
int dig_select_areas(struct Plus_head *Plus, const struct bound_box *box, struct boxlist *list)
Select areas with boxes by box.
off_t Face_spidx_offset
Offset of faces in sidx file.