GRASS GIS 8 Programmer's Manual  8.2.2dev(2023)-3d2c704037
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) More...
 
void dig_spidx_free_nodes (struct Plus_head *Plus)
 Free spatial index for nodes. More...
 
void dig_spidx_free_lines (struct Plus_head *Plus)
 Free spatial index for lines. More...
 
void dig_spidx_free_areas (struct Plus_head *Plus)
 Reset spatial index for areas. More...
 
void dig_spidx_free_isles (struct Plus_head *Plus)
 Reset spatial index for isles. More...
 
void dig_spidx_free (struct Plus_head *Plus)
 Free spatial index (nodes, lines, areas, isles) More...
 
int dig_spidx_add_node (struct Plus_head *Plus, int node, double x, double y, double z)
 Add new node to spatial index. More...
 
int dig_spidx_add_line (struct Plus_head *Plus, int line, const struct bound_box *box)
 Add new line to spatial index. More...
 
int dig_spidx_add_area (struct Plus_head *Plus, int area, const struct bound_box *box)
 Add new area to spatial index. More...
 
int dig_spidx_add_isle (struct Plus_head *Plus, int isle, const struct bound_box *box)
 Add new island to spatial index. More...
 
int dig_spidx_del_node (struct Plus_head *Plus, int node)
 Delete node from spatial index. More...
 
int dig_spidx_del_line (struct Plus_head *Plus, int line, double x, double y, double z)
 Delete line from spatial index. More...
 
int dig_spidx_del_area (struct Plus_head *Plus, int area)
 Delete area from spatial index. More...
 
int dig_spidx_del_isle (struct Plus_head *Plus, int isle)
 Delete isle from spatial index. More...
 
int dig_select_nodes (struct Plus_head *Plus, const struct bound_box *box, struct ilist *list)
 Select nodes by bbox. More...
 
int dig_find_node (struct Plus_head *Plus, double x, double y, double z)
 Find one node by coordinates. More...
 
int dig_select_lines (struct Plus_head *Plus, const struct bound_box *box, struct boxlist *list)
 Select lines with boxes by box. More...
 
int dig_find_line_box (struct Plus_head *Plus, int line, struct bound_box *box)
 Find box for line. More...
 
int dig_select_areas (struct Plus_head *Plus, const struct bound_box *box, struct boxlist *list)
 Select areas with boxes by box. More...
 
int dig_find_area_box (struct Plus_head *Plus, int area, struct bound_box *box)
 Find bounding box for given area. More...
 
int dig_select_isles (struct Plus_head *Plus, const struct bound_box *box, struct boxlist *list)
 Select isles with boxes by box. More...
 
int dig_find_isle_box (struct Plus_head *Plus, int isle, struct bound_box *box)
 Find box for isle. More...
 

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 903 of file spindex.c.

References Plus_head::Area, Plus_head::Area_spidx, RTree_Rect::boundary, G_debug(), G_malloc, if(), Plus_head::Line, P_area::lines, P_topo_b::N1, Plus_head::Node, RTreeSearch(), Plus_head::Spidx_new, 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 997 of file spindex.c.

References RTree_Rect::boundary, G_debug(), G_malloc, if(), Plus_head::Isle, Plus_head::Isle_spidx, Plus_head::Line, P_isle::lines, P_topo_b::N1, Plus_head::Node, RTreeSearch(), Plus_head::Spidx_new, 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 791 of file spindex.c.

◆ 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 710 of file spindex.c.

References RTree_Rect::boundary, G_debug(), G_malloc, Plus_head::Node_spidx, RTreeSearch(), Plus_head::Spidx_new, 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 862 of file spindex.c.

References Plus_head::Area_spidx, bound_box::B, RTree_Rect::boundary, bound_box::E, G_debug(), G_malloc, bound_box::N, boxlist::n_values, RTreeSearch(), bound_box::S, Plus_head::Spidx_new, bound_box::T, and bound_box::W.

◆ 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 956 of file spindex.c.

References bound_box::B, RTree_Rect::boundary, bound_box::E, G_debug(), G_malloc, Plus_head::Isle_spidx, bound_box::N, boxlist::n_values, RTreeSearch(), bound_box::S, Plus_head::Spidx_new, 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 750 of file spindex.c.

References bound_box::B, RTree_Rect::boundary, bound_box::E, G_debug(), G_malloc, Plus_head::Line_spidx, bound_box::N, boxlist::n_values, RTreeSearch(), bound_box::S, Plus_head::Spidx_new, bound_box::T, and bound_box::W.

◆ 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 663 of file spindex.c.

References bound_box::B, RTree_Rect::boundary, bound_box::E, G_debug(), G_malloc, bound_box::N, ilist::n_values, Plus_head::Node_spidx, RTreeSearch(), bound_box::S, Plus_head::Spidx_new, 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 353 of file spindex.c.

References Plus_head::Area_spidx, 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_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 388 of file spindex.c.

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

◆ 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 319 of file spindex.c.

◆ 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 284 of file spindex.c.

References RTree_Rect::boundary, G_debug(), G_malloc, Plus_head::Node_spidx, 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 508 of file spindex.c.

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

◆ 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 561 of file spindex.c.

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

◆ 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 466 of file spindex.c.

◆ 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 423 of file spindex.c.

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

◆ 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 235 of file spindex.c.

References Plus_head::Area_spidx, RTree::fd, Plus_head::Isle_spidx, Plus_head::Line_spidx, Plus_head::Node_spidx, RTreeDestroyTree(), and Plus_head::Spidx_new.

Referenced by dig_free_plus(), and dig_Rd_spidx().

◆ 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 171 of file spindex.c.

References Plus_head::Area_spidx, RTree::fd, and Plus_head::with_z.

◆ 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 203 of file spindex.c.

References RTree::fd, Plus_head::Isle_spidx, and Plus_head::with_z.

◆ 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 139 of file spindex.c.

References RTree::fd, Plus_head::Line_spidx, and Plus_head::with_z.

◆ 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 107 of file spindex.c.

References RTree::fd, Plus_head::Node_spidx, and Plus_head::with_z.

◆ 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 G_debug(), Plus_head::Spidx_file, Plus_head::spidx_with_z, and Plus_head::with_z.

Referenced by dig_init_plus(), and dig_Rd_spidx().