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);
287 static int rect_init = 0;
295 G_debug(3,
"dig_spidx_add_node(): node = %d, x,y,z = %f, %f, %f", node,
x,
322 static int rect_init = 0;
330 G_debug(3,
"dig_spidx_add_line(): line = %d", line);
356 static int rect_init = 0;
364 G_debug(3,
"dig_spidx_add_area(): area = %d", area);
391 static int rect_init = 0;
399 G_debug(3,
"dig_spidx_add_isle(): isle = %d", isle);
427 static int rect_init = 0;
435 G_debug(3,
"dig_spidx_del_node(): node = %d", node);
437 Node = Plus->
Node[node];
449 G_fatal_error(
_(
"Unable to delete node %d from spatial index"), node);
470 static int rect_init = 0;
478 G_debug(3,
"dig_spidx_del_line(): line = %d", line);
492 G_fatal_error(
_(
"Unable to delete line %d from spatial index"), line);
515 static int rect_init = 0;
523 G_debug(3,
"dig_spidx_del_area(): area = %d", area);
525 Area = Plus->
Area[area];
533 Node = Plus->
Node[topo->
N1];
545 G_fatal_error(
_(
"Unable to delete area %d from spatial index"), area);
568 static int rect_init = 0;
576 G_debug(3,
"dig_spidx_del_isle(): isle = %d", isle);
578 Isle = Plus->
Isle[isle];
582 Node = Plus->
Node[topo->
N1];
594 G_fatal_error(
_(
"Unable to delete isle %d from spatial index"), isle);
610 static int _add_item_with_box(
int id,
const struct RTree_Rect *rect,
633 static int _set_item_box(
int id,
const struct RTree_Rect *rect,
634 struct boxid *box_id)
636 if (
id == box_id->id) {
665 static int rect_init = 0;
673 G_debug(3,
"dig_select_nodes()");
691 return (
list->n_values);
695 static int _add_node(
int id,
const struct RTree_Rect *rect
UNUSED,
int *node)
714 static int rect_init = 0;
756 static int rect_init = 0;
764 G_debug(3,
"dig_select_lines_with_box()");
782 return (
list->n_values);
801 static int rect_init = 0;
803 G_debug(3,
"dig_find_line_box()");
811 Line = Plus->
Line[line];
821 Node = Plus->
Node[topo->
N1];
826 Node = Plus->
Node[topo->
N1];
853 G_fatal_error(
"Bug in vector lib: dig_find_line_box() may only be used for "
854 "lines and boundaries.");
872 static int rect_init = 0;
880 G_debug(3,
"dig_select_areas_with_box()");
898 return (
list->n_values);
920 static int rect_init = 0;
922 G_debug(3,
"dig_find_area_box()");
930 Area = Plus->
Area[area];
933 Node = Plus->
Node[topo->
N1];
968 static int rect_init = 0;
976 G_debug(3,
"dig_select_areas_with_box()");
994 return (
list->n_values);
1010 struct boxid box_id;
1016 static int rect_init = 0;
1018 G_debug(3,
"dig_find_isle_box()");
1026 Isle = Plus->
Isle[isle];
1029 Node = Plus->
Node[topo->
N1];
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
char * G_tempfile(void)
Returns a temporary file name.
void G_ilist_add(struct ilist *, int)
Add item to ilist.
int G_debug(int, const char *,...) __attribute__((format(printf
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...
int dig_boxlist_add(struct boxlist *, int, const struct bound_box *)
#define UNUSED
A macro for an attribute, if attached to a variable, indicating that the variable is not used.
int SearchHitCallback(int id, const struct RTree_Rect *rect, void *arg)
int dig_select_isles(struct Plus_head *Plus, const struct bound_box *box, struct boxlist *list)
Select isles with boxes by box.
int dig_spidx_del_area(struct Plus_head *Plus, int area)
Delete area from spatial index.
void dig_spidx_free_areas(struct Plus_head *Plus)
Reset spatial index for areas.
int dig_spidx_add_line(struct Plus_head *Plus, int line, const struct bound_box *box)
Add new line to spatial index.
int dig_spidx_del_isle(struct Plus_head *Plus, int isle)
Delete isle from spatial index.
int dig_find_node(struct Plus_head *Plus, double x, double y, double z)
Find one node by coordinates.
int dig_find_isle_box(struct Plus_head *Plus, int isle, struct bound_box *box)
Find box for isle.
void dig_spidx_free_lines(struct Plus_head *Plus)
Free spatial index for lines.
int dig_select_areas(struct Plus_head *Plus, const struct bound_box *box, struct boxlist *list)
Select areas with boxes by box.
int dig_spidx_add_node(struct Plus_head *Plus, int node, double x, double y, double z)
Add new node to spatial index.
int dig_select_nodes(struct Plus_head *Plus, const struct bound_box *box, struct ilist *list)
Select nodes by bbox.
void dig_spidx_free_isles(struct Plus_head *Plus)
Reset spatial index for isles.
void dig_spidx_free_nodes(struct Plus_head *Plus)
Free spatial index for nodes.
int dig_spidx_add_area(struct Plus_head *Plus, int area, const struct bound_box *box)
Add new area to spatial index.
int dig_spidx_del_node(struct Plus_head *Plus, int node)
Delete node from spatial index.
int dig_spidx_del_line(struct Plus_head *Plus, int line, double x, double y, double z)
Delete line from spatial index.
int dig_find_line_box(struct Plus_head *Plus, int line, struct bound_box *box)
Find box for line.
void dig_spidx_free(struct Plus_head *Plus)
Free spatial index (nodes, lines, areas, isles)
int dig_spidx_init(struct Plus_head *Plus)
Initit spatial index (nodes, lines, areas, isles)
int dig_select_lines(struct Plus_head *Plus, const struct bound_box *box, struct boxlist *list)
Select lines with boxes by box.
int dig_find_area_box(struct Plus_head *Plus, int area, struct bound_box *box)
Find bounding box for given area.
int dig_spidx_add_isle(struct Plus_head *Plus, int isle, const struct bound_box *box)
Add new island to spatial index.
plus_t * lines
List of boundary lines.
plus_t * lines
List of boundary lines.
void * topo
Topology info.
Topological feature - node.
double z
Z coordinate (used only for 3D data)
Basic topology-related info.
int Spidx_built
Spatial index built?
off_t Area_spidx_offset
Offset of areas in sidx file.
int with_z
2D/3D vector data
off_t Isle_spidx_offset
Offset of isles in sidx file.
struct P_line ** Line
Array of vector geometries.
off_t Hole_spidx_offset
Offset of holes in sidx file.
int Spidx_new
Build new spatial index.
struct RTree * Isle_spidx
Isles spatial index.
off_t Face_spidx_offset
Offset of faces in sidx file.
struct RTree * Area_spidx
Area spatial index.
int Spidx_file
Build new spatial index in file.
off_t Volume_spidx_offset
Offset of volumes in sidx file.
struct RTree * Line_spidx
Line spatial index.
struct P_area ** Area
Array of areas.
struct RTree * Volume_spidx
Volumes spatial index.
int spidx_with_z
2D/3D spatial index
struct RTree * Face_spidx
Faces spatial index.
off_t Line_spidx_offset
Offset of lines in sidx file.
struct RTree * Node_spidx
Node spatial index.
struct P_isle ** Isle
Array of isles.
struct P_node ** Node
Array of nodes.
off_t Node_spidx_offset
Offset of nodes in sidx file.
struct RTree * Hole_spidx
Holes spatial index.
List of bounding boxes with id.
int RTreeDeleteRect(struct RTree_Rect *r, int tid, struct RTree *t)
Delete an item from a R*-Tree.
int RTreeInsertRect(struct RTree_Rect *r, int tid, struct RTree *t)
Insert an item into a R*-Tree.
void RTreeDestroyTree(struct RTree *t)
Destroy an R*-Tree.
int RTreeSearch(struct RTree *t, struct RTree_Rect *r, SearchHitCallback *shcb, void *cbarg)
Search an R*-Tree.
struct RTree * RTreeCreateTree(int fd, off_t rootpos, int ndims)
Create new empty R*-Tree.