22 #include <grass/glocale.h>
23 #include <grass/gis.h>
24 #include <grass/Vect.h>
25 #include <grass/glocale.h>
36 G_debug(1,
"Vect_spatial_index_init()");
52 G_debug(1,
"Vect_spatial_index_destroy()");
70 G_debug(3,
"Vect_spatial_index_add_item(): id = %d",
id);
94 G_debug(3,
"Vect_spatial_index_del_item(): id = %d",
id);
97 G_fatal_error(
"Vect_spatial_index_del_item() %s", _(
"not implemented"));
109 G_fatal_error(_(
"Unable to delete item %d from spatial index"),
id);
126 if (Map->level < 2) {
127 G_fatal_error(_(
"Unable to build spatial index from topology, "
128 "vector map is not opened at topo level 2"));
130 if (!(Map->plus.Spidx_built)) {
147 struct Plus_head *plus;
154 G_debug(3,
"Vect_build_sidx_from_topo()");
160 total = plus->n_nodes + plus->n_lines + plus->n_areas + plus->n_isles;
163 for (i = 1; i <= plus->n_nodes; i++) {
166 Node = plus->Node[i];
168 G_fatal_error(_(
"BUG (Vect_build_sidx_from_topo): node does not exist"));
174 done = plus->n_nodes;
175 for (i = 1; i <= plus->n_lines; i++) {
178 Line = plus->Line[i];
180 G_fatal_error(_(
"BUG (Vect_build_sidx_from_topo): line does not exist"));
193 done += plus->n_lines;
194 for (i = 1; i <= plus->n_areas; i++) {
197 Area = plus->Area[i];
199 G_fatal_error(_(
"BUG (Vect_build_sidx_from_topo): area does not exist"));
212 done += plus->n_areas;
213 for (i = 1; i <= plus->n_isles; i++) {
216 Isle = plus->Isle[i];
218 G_fatal_error(_(
"BUG (Vect_build_sidx_from_topo): isle does not exist"));
230 Map->plus.Spidx_built = 1;
232 G_debug(3,
"Spatial index was built");
239 static int _add_item(
int id,
struct ilist *list)
260 G_debug(3,
"Vect_spatial_index_select()");
270 RTreeSearch(si->root, &rect, (
void *)_add_item, list);
272 G_debug(3,
" %d items selected", list->n_values);
273 return (list->n_values);
RectReal boundary[NUMSIDES]
int dig_list_add(struct ilist *list, int val)
int Vect_build_sidx_from_topo(struct Map_info *Map)
Create spatial index from topo if necessary.
int dig_spidx_add_line(struct Plus_head *Plus, int line, BOUND_BOX *box)
Add new line to spatial index.
int RTreeSearch(struct Node *N, struct Rect *R, SearchHitCallback shcb, void *cbarg)
int dig_spidx_init(struct Plus_head *Plus)
Initit spatial index (nodes, lines, areas, isles)
void RTreeDestroyNode(struct Node *)
int RTreeInsertRect(struct Rect *R, int Tid, struct Node **Root, int Level)
int dig_spidx_add_area(struct Plus_head *Plus, int area, BOUND_BOX *box)
Add new area to spatial index.
int G_percent(long n, long d, int s)
Print percent complete messages.
int dig_spidx_add_isle(struct Plus_head *Plus, int isle, BOUND_BOX *box)
Add new island to spatial index.
void Vect_spatial_index_init(SPATIAL_INDEX *si)
Init 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.
void Vect_spatial_index_del_item(SPATIAL_INDEX *si, int id)
Delete item from spatial index.
void Vect_spatial_index_destroy(SPATIAL_INDEX *si)
Destroy existing spatial index.
int G_debug(int level, const char *msg,...)
Print debugging message.
struct Node * RTreeNewIndex(void)
int Vect_build_spatial_index(struct Map_info *Map)
Create spatial index if necessary.
int RTreeDeleteRect(struct Rect *R, int Tid, struct Node **Nn)
int G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
void Vect_spatial_index_add_item(SPATIAL_INDEX *si, int id, BOUND_BOX *box)
Add a new item to spatial index.
int Vect_spatial_index_select(SPATIAL_INDEX *si, BOUND_BOX *box, struct ilist *list)
Select items by bounding box to list.