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);
55 fd = open(filename, O_RDWR | O_CREAT | O_EXCL, 0600);
61 fd = open(filename, O_RDWR | O_CREAT | O_EXCL, 0600);
67 fd = open(filename, O_RDWR | O_CREAT | O_EXCL, 0600);
115 ndims = Plus->
with_z ? 3 : 2;
126 fd = open(filename, O_RDWR | O_CREAT | O_EXCL, 0600);
148 ndims = Plus->
with_z ? 3 : 2;
159 fd = open(filename, O_RDWR | O_CREAT | O_EXCL, 0600);
181 ndims = Plus->
with_z ? 3 : 2;
192 fd = open(filename, O_RDWR | O_CREAT | O_EXCL, 0600);
214 ndims = Plus->
with_z ? 3 : 2;
225 fd = open(filename, O_RDWR | O_CREAT | O_EXCL, 0600);
295 static int rect_init = 0;
303 G_debug(3,
"dig_spidx_add_node(): node = %d, x,y,z = %f, %f, %f", node,
x,
330 static int rect_init = 0;
338 G_debug(3,
"dig_spidx_add_line(): line = %d", line);
364 static int rect_init = 0;
372 G_debug(3,
"dig_spidx_add_area(): area = %d", area);
399 static int rect_init = 0;
407 G_debug(3,
"dig_spidx_add_isle(): isle = %d", isle);
435 static int rect_init = 0;
443 G_debug(3,
"dig_spidx_del_node(): node = %d", node);
445 Node = Plus->
Node[node];
457 G_fatal_error(
_(
"Unable to delete node %d from spatial index"), node);
478 static int rect_init = 0;
486 G_debug(3,
"dig_spidx_del_line(): line = %d", line);
500 G_fatal_error(
_(
"Unable to delete line %d from spatial index"), line);
523 static int rect_init = 0;
531 G_debug(3,
"dig_spidx_del_area(): area = %d", area);
533 Area = Plus->
Area[area];
541 Node = Plus->
Node[topo->
N1];
553 G_fatal_error(
_(
"Unable to delete area %d from spatial index"), area);
576 static int rect_init = 0;
584 G_debug(3,
"dig_spidx_del_isle(): isle = %d", isle);
586 Isle = Plus->
Isle[isle];
590 Node = Plus->
Node[topo->
N1];
602 G_fatal_error(
_(
"Unable to delete isle %d from spatial index"), isle);
618 static int _add_item_with_box(
int id,
const struct RTree_Rect *rect,
641 static int _set_item_box(
int id,
const struct RTree_Rect *rect,
642 struct boxid *box_id)
644 if (
id == box_id->id) {
673 static int rect_init = 0;
681 G_debug(3,
"dig_select_nodes()");
699 return (
list->n_values);
703 static int _add_node(
int id,
const struct RTree_Rect *rect
UNUSED,
int *node)
722 static int rect_init = 0;
764 static int rect_init = 0;
772 G_debug(3,
"dig_select_lines_with_box()");
790 return (
list->n_values);
809 static int rect_init = 0;
811 G_debug(3,
"dig_find_line_box()");
819 Line = Plus->
Line[line];
829 Node = Plus->
Node[topo->
N1];
834 Node = Plus->
Node[topo->
N1];
861 G_fatal_error(
"Bug in vector lib: dig_find_line_box() may only be used for "
862 "lines and boundaries.");
880 static int rect_init = 0;
888 G_debug(3,
"dig_select_areas_with_box()");
906 return (
list->n_values);
928 static int rect_init = 0;
930 G_debug(3,
"dig_find_area_box()");
938 Area = Plus->
Area[area];
941 Node = Plus->
Node[topo->
N1];
976 static int rect_init = 0;
984 G_debug(3,
"dig_select_areas_with_box()");
1002 return (
list->n_values);
1018 struct boxid box_id;
1024 static int rect_init = 0;
1026 G_debug(3,
"dig_find_isle_box()");
1034 Isle = Plus->
Isle[isle];
1037 Node = Plus->
Node[topo->
N1];
void G_free(void *)
Free allocated memory.
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.