GRASS 8 Programmer's Manual 8.6.0dev(2026)-f6f2c534ea
Loading...
Searching...
No Matches
spindex.c File Reference

Vector library - spatial index (lower level functions) More...

#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <grass/vector.h>
#include <grass/glocale.h>
Include dependency graph for spindex.c:

Go to the source code of this file.

Functions

int dig_spidx_init (struct Plus_head *Plus)
 Initit spatial index (nodes, lines, areas, isles)
 
void dig_spidx_free_nodes (struct Plus_head *Plus)
 Free spatial index for nodes.
 
void dig_spidx_free_lines (struct Plus_head *Plus)
 Free spatial index for lines.
 
void dig_spidx_free_areas (struct Plus_head *Plus)
 Reset spatial index for areas.
 
void dig_spidx_free_isles (struct Plus_head *Plus)
 Reset spatial index for isles.
 
void dig_spidx_free (struct Plus_head *Plus)
 Free spatial index (nodes, lines, areas, isles)
 
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_spidx_add_line (struct Plus_head *Plus, int line, const struct bound_box *box)
 Add new line to spatial index.
 
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_add_isle (struct Plus_head *Plus, int isle, const struct bound_box *box)
 Add new island 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_spidx_del_area (struct Plus_head *Plus, int area)
 Delete area from spatial index.
 
int dig_spidx_del_isle (struct Plus_head *Plus, int isle)
 Delete isle from spatial index.
 
int dig_select_nodes (struct Plus_head *Plus, const struct bound_box *box, struct ilist *list)
 Select nodes by bbox.
 
int dig_find_node (struct Plus_head *Plus, double x, double y, double z)
 Find one node by coordinates.
 
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_line_box (struct Plus_head *Plus, int line, struct bound_box *box)
 Find box for line.
 
int dig_select_areas (struct Plus_head *Plus, const struct bound_box *box, struct boxlist *list)
 Select areas 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_select_isles (struct Plus_head *Plus, const struct bound_box *box, struct boxlist *list)
 Select isles with boxes by box.
 
int dig_find_isle_box (struct Plus_head *Plus, int isle, struct bound_box *box)
 Find box for isle.
 

Detailed Description

Vector library - spatial index (lower level functions)

Vector library - spatial index - read/write (lower level functions)

Lower level functions for reading/writing/manipulating vectors.

(C) 2001-2009 by the GRASS Development Team

This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.

Author
Original author CERL, probably Dave Gerdes
Update to GRASS 5.7 Radim Blazek
Update to GRASS 7 Markus Metz

Definition in file spindex.c.

Function Documentation

◆ dig_find_area_box()

int dig_find_area_box ( struct Plus_head Plus,
int  area,
struct bound_box box 
)

Find bounding box for given area.

Parameters
Pluspointer to Plus_head structure
areaarea id
[out]boxbounding box
Returns
> 0 bounding box for area found
0 not found

Definition at line 918 of file spindex.c.

References RTree_Rect::boundary, G_debug(), G_malloc, P_area::lines, P_topo_b::N1, rtree_search(), RTreeSearch(), P_line::topo, P_node::x, P_node::y, and P_node::z.

Referenced by Vect_get_area_box().

◆ dig_find_isle_box()

int dig_find_isle_box ( struct Plus_head Plus,
int  isle,
struct bound_box box 
)

Find box for isle.

Parameters
Pluspointer to Plus_head structure
isleisle id
[out]boxbounding box
Returns
> 0 bounding box for isle found
0 not found

Definition at line 1014 of file spindex.c.

References RTree_Rect::boundary, G_debug(), G_malloc, P_isle::lines, P_topo_b::N1, rtree_search(), RTreeSearch(), P_line::topo, P_node::x, P_node::y, and P_node::z.

Referenced by Vect_get_isle_box().

◆ dig_find_line_box()

int dig_find_line_box ( struct Plus_head Plus,
int  line,
struct bound_box box 
)

Find box for line.

Parameters
Pluspointer to Plus_head structure
lineline id
[out]boxbounding box
Returns
> 0 bounding box for line found
0 not found

Definition at line 802 of file spindex.c.

References RTree_Rect::boundary, G_debug(), G_fatal_error(), G_malloc, GV_BOUNDARY, GV_LINE, GV_LINES, P_topo_l::N1, P_topo_b::N1, NULL, rtree_search(), RTreeSearch(), P_line::topo, P_line::type, P_node::x, P_node::y, and P_node::z.

Referenced by Vect_get_line_box().

◆ dig_find_node()

int dig_find_node ( struct Plus_head Plus,
double  x,
double  y,
double  z 
)

Find one node by coordinates.

Parameters
Pluspointer to Plus_head structure
x,y,zcoordinates
Returns
number of node
0 not found

Definition at line 717 of file spindex.c.

References RTree_Rect::boundary, G_debug(), G_malloc, rtree_search(), RTreeSearch(), and x.

◆ dig_select_areas()

int dig_select_areas ( struct Plus_head Plus,
const struct bound_box box,
struct boxlist list 
)

Select areas with boxes by box.

Parameters
Pluspointer to Plus_head structure
boxbounding box
listboxlist of selected areas
Returns
number of selected areas

Definition at line 875 of file spindex.c.

References bound_box::B, RTree_Rect::boundary, bound_box::E, G_debug(), G_malloc, bound_box::N, rtree_search(), RTreeSearch(), bound_box::S, bound_box::T, and bound_box::W.

Referenced by Vect_select_areas_by_box().

◆ dig_select_isles()

int dig_select_isles ( struct Plus_head Plus,
const struct bound_box box,
struct boxlist list 
)

Select isles with boxes by box.

Parameters
Pluspointer to Plus_head structure
boxbounding box
listboxlist of selected isles
Returns
number of selected isles

Definition at line 971 of file spindex.c.

References bound_box::B, RTree_Rect::boundary, bound_box::E, G_debug(), G_malloc, bound_box::N, rtree_search(), RTreeSearch(), bound_box::S, bound_box::T, and bound_box::W.

Referenced by Vect_select_isles_by_box().

◆ dig_select_lines()

int dig_select_lines ( struct Plus_head Plus,
const struct bound_box box,
struct boxlist list 
)

Select lines with boxes by box.

Parameters
Pluspointer to Plus_head structure
boxbounding box
listboxlist of selected lines
Returns
number of selected lines
0 not found

Definition at line 759 of file spindex.c.

References bound_box::B, RTree_Rect::boundary, bound_box::E, G_debug(), G_malloc, bound_box::N, rtree_search(), RTreeSearch(), bound_box::S, bound_box::T, and bound_box::W.

Referenced by Vect_select_lines_by_box().

◆ dig_select_nodes()

int dig_select_nodes ( struct Plus_head Plus,
const struct bound_box box,
struct ilist list 
)

Select nodes by bbox.

Parameters
Pluspointer to Plus_head structure
boxbounding box
listlist of selected lines
Returns
number of selected nodes
-1 on error

Definition at line 668 of file spindex.c.

References bound_box::B, RTree_Rect::boundary, bound_box::E, G_debug(), G_malloc, bound_box::N, rtree_search(), RTreeSearch(), bound_box::S, bound_box::T, and bound_box::W.

Referenced by Vect_select_nodes_by_box().

◆ dig_spidx_add_area()

int dig_spidx_add_area ( struct Plus_head Plus,
int  area,
const struct bound_box box 
)

Add new area to spatial index.

Parameters
Pluspointer to Plus_head structure
areaarea id
boxbounding box
Returns
0

Definition at line 360 of file spindex.c.

References bound_box::B, RTree_Rect::boundary, bound_box::E, G_debug(), G_malloc, bound_box::N, RTreeInsertRect(), bound_box::S, bound_box::T, and bound_box::W.

Referenced by dig_add_area(), and Vect__load_plus_pg().

◆ dig_spidx_add_isle()

int dig_spidx_add_isle ( struct Plus_head Plus,
int  isle,
const struct bound_box box 
)

Add new island to spatial index.

Parameters
Pluspointer to Plus_head structure
isleisle id
boxbounding box
Returns
0

Definition at line 394 of file spindex.c.

References bound_box::B, RTree_Rect::boundary, bound_box::E, G_debug(), G_malloc, bound_box::N, RTreeInsertRect(), bound_box::S, bound_box::T, and bound_box::W.

Referenced by dig_add_isle(), and Vect__load_plus_pg().

◆ dig_spidx_add_line()

int dig_spidx_add_line ( struct Plus_head Plus,
int  line,
const struct bound_box box 
)

Add new line to spatial index.

Parameters
Pluspointer to Plus_head structure
lineline id
boxbounding box
Returns
0

Definition at line 326 of file spindex.c.

References bound_box::B, RTree_Rect::boundary, bound_box::E, G_debug(), G_malloc, bound_box::N, RTreeInsertRect(), bound_box::S, bound_box::T, and bound_box::W.

◆ dig_spidx_add_node()

int dig_spidx_add_node ( struct Plus_head Plus,
int  node,
double  x,
double  y,
double  z 
)

Add new node to spatial index.

Parameters
Pluspointer to Plus_head structure
nodenode id
x,y,znode coordinates
Returns
1 OK
0 on error

Definition at line 291 of file spindex.c.

References RTree_Rect::boundary, G_debug(), G_malloc, RTreeInsertRect(), and x.

Referenced by dig_add_node().

◆ dig_spidx_del_area()

int dig_spidx_del_area ( struct Plus_head Plus,
int  area 
)

Delete area from spatial index.

G_fatal_error() called on error.

Parameters
Pluspointer to Plus_head structure
areaarea id
Returns
0

Definition at line 514 of file spindex.c.

References _, RTree_Rect::boundary, G_debug(), G_fatal_error(), G_malloc, P_area::lines, P_topo_b::N1, NULL, RTreeDeleteRect(), P_line::topo, P_node::x, P_node::y, and P_node::z.

Referenced by dig_del_area().

◆ dig_spidx_del_isle()

int dig_spidx_del_isle ( struct Plus_head Plus,
int  isle 
)

Delete isle from spatial index.

G_fatal_error() called on error.

Parameters
Pluspointer to Plus_head structure
isleisle id
Returns
0

Definition at line 567 of file spindex.c.

References _, RTree_Rect::boundary, G_debug(), G_fatal_error(), G_malloc, P_isle::lines, P_topo_b::N1, RTreeDeleteRect(), P_line::topo, P_node::x, P_node::y, and P_node::z.

Referenced by dig_del_isle().

◆ dig_spidx_del_line()

int dig_spidx_del_line ( struct Plus_head Plus,
int  line,
double  x,
double  y,
double  z 
)

Delete line from spatial index.

G_fatal_error() called on error.

Parameters
Pluspointer to Plus_head structure
lineline id
x,y,zcoordinates
Returns
0

Definition at line 472 of file spindex.c.

References _, RTree_Rect::boundary, G_debug(), G_fatal_error(), G_malloc, RTreeDeleteRect(), and x.

Referenced by dig_del_line().

◆ dig_spidx_del_node()

int dig_spidx_del_node ( struct Plus_head Plus,
int  node 
)

Delete node from spatial index.

G_fatal_error() called on error.

Parameters
Pluspointer to Plus_head structure
nodenode id
Returns
0

Definition at line 429 of file spindex.c.

References _, RTree_Rect::boundary, G_debug(), G_fatal_error(), G_malloc, RTreeDeleteRect(), P_node::x, P_node::y, and P_node::z.

Referenced by dig_del_line().

◆ dig_spidx_free()

void dig_spidx_free ( struct Plus_head Plus)

Free spatial index (nodes, lines, areas, isles)

Parameters
Pluspointer to Plus_head structure

Definition at line 243 of file spindex.c.

References close, and RTreeDestroyTree().

Referenced by dig_free_plus(), dig_Rd_spidx(), and Vect_open_sidx().

◆ dig_spidx_free_areas()

void dig_spidx_free_areas ( struct Plus_head Plus)

Reset spatial index for areas.

Parameters
Pluspointer to Plus_head structure

Definition at line 177 of file spindex.c.

References close, G_free(), G_tempfile(), open, RTreeCreateTree(), and RTreeDestroyTree().

Referenced by Vect__build_downgrade().

◆ dig_spidx_free_isles()

void dig_spidx_free_isles ( struct Plus_head Plus)

Reset spatial index for isles.

Parameters
Pluspointer to Plus_head structure

Definition at line 210 of file spindex.c.

References close, G_free(), G_tempfile(), open, RTreeCreateTree(), and RTreeDestroyTree().

Referenced by Vect__build_downgrade().

◆ dig_spidx_free_lines()

void dig_spidx_free_lines ( struct Plus_head Plus)

Free spatial index for lines.

Parameters
Pluspointer to Plus_head structure

Definition at line 144 of file spindex.c.

References close, G_free(), G_tempfile(), open, RTreeCreateTree(), and RTreeDestroyTree().

Referenced by Vect__build_downgrade().

◆ dig_spidx_free_nodes()

void dig_spidx_free_nodes ( struct Plus_head Plus)

Free spatial index for nodes.

Parameters
Pluspointer to Plus_head structure

Definition at line 111 of file spindex.c.

References close, G_free(), G_tempfile(), open, RTreeCreateTree(), and RTreeDestroyTree().

Referenced by Vect__build_downgrade().

◆ dig_spidx_init()

int dig_spidx_init ( struct Plus_head Plus)

Initit spatial index (nodes, lines, areas, isles)

Parameters
Pluspointer to Plus_head structure
Returns
1 OK
0 on error

Definition at line 35 of file spindex.c.

References close, FALSE, G_debug(), G_free(), G_tempfile(), NULL, open, and RTreeCreateTree().

Referenced by dig_init_plus(), dig_Rd_spidx(), and Vect_open_sidx().