GRASS GIS 8 Programmer's Manual
8.5.0dev(2024)-b4e4cb0fe9
|
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <grass/config.h>
Go to the source code of this file.
Data Structures | |
struct | RTree_Rect |
union | RTree_Child |
struct | RTree_Branch |
struct | RTree_Node |
struct | nstack |
struct | NodeBuffer |
struct | RTree_PartitionVars |
struct | RTree |
struct | RTree::_recycle |
Macros | |
#define | TRUE 1 |
#define | FALSE 0 |
#define | MAXCARD 9 |
#define | NODECARD MAXCARD |
#define | LEAFCARD MAXCARD |
#define | MAXLEVEL 20 /* 8^MAXLEVEL items are guaranteed to fit into the tree */ |
#define | NODE_BUFFER_SIZE 32 |
Typedefs | |
typedef double | RectReal |
typedef int | SearchHitCallback(int id, const struct RTree_Rect *rect, void *arg) |
typedef int | rt_search_fn(struct RTree *, struct RTree_Rect *, SearchHitCallback *, void *) |
typedef int | rt_insert_fn(struct RTree_Rect *, union RTree_Child, int, struct RTree *) |
typedef int | rt_delete_fn(struct RTree_Rect *, union RTree_Child, struct RTree *) |
typedef int | rt_valid_child_fn(union RTree_Child *) |
Functions | |
int | RTreeSearch (struct RTree *, struct RTree_Rect *, SearchHitCallback *, void *) |
Search an R*-Tree. More... | |
int | RTreeInsertRect (struct RTree_Rect *, int, struct RTree *) |
Insert an item into a R*-Tree. More... | |
void | RTreeSetRect1D (struct RTree_Rect *r, struct RTree *t, double x_min, double x_max) |
Set one dimensional coordinates of a rectangle for a given tree. More... | |
void | RTreeSetRect2D (struct RTree_Rect *r, struct RTree *t, double x_min, double x_max, double y_min, double y_max) |
Set two dimensional coordinates of a rectangle for a given tree. More... | |
void | RTreeSetRect3D (struct RTree_Rect *r, struct RTree *t, double x_min, double x_max, double y_min, double y_max, double z_min, double z_max) |
Set three dimensional coordinates of a rectangle for a given tree. More... | |
void | RTreeSetRect4D (struct RTree_Rect *r, struct RTree *t, double x_min, double x_max, double y_min, double y_max, double z_min, double z_max, double t_min, double t_max) |
Set 4 dimensional coordinates of a rectangle for a given tree. More... | |
int | RTreeDeleteRect (struct RTree_Rect *, int, struct RTree *) |
Delete an item from a R*-Tree. More... | |
void | RTreePrintRect (struct RTree_Rect *, int, struct RTree *) |
struct RTree * | RTreeCreateTree (int, off_t, int) |
Create new empty R*-Tree. More... | |
void | RTreeSetOverflow (struct RTree *, char) |
Enable/disable R*-tree forced reinsertion (overflow) More... | |
void | RTreeDestroyTree (struct RTree *) |
Destroy an R*-Tree. More... | |
int | RTreeOverlap (struct RTree_Rect *, struct RTree_Rect *, struct RTree *) |
int | RTreeContained (struct RTree_Rect *, struct RTree_Rect *, struct RTree *) |
int | RTreeContains (struct RTree_Rect *, struct RTree_Rect *, struct RTree *) |
struct RTree_Node * | RTreeAllocNode (struct RTree *, int) |
void | RTreeInitNode (struct RTree *, struct RTree_Node *, int) |
void | RTreeCopyNode (struct RTree_Node *, struct RTree_Node *, struct RTree *) |
void | RTreeFreeNode (struct RTree_Node *) |
void | RTreeDestroyNode (struct RTree_Node *, int) |
struct RTree_Rect * | RTreeAllocRect (struct RTree *t) |
Create a new rectangle for a given tree. More... | |
void | RTreeFreeRect (struct RTree_Rect *r) |
Delete a rectangle. More... | |
RectReal * | RTreeAllocBoundary (struct RTree *t) |
Allocate the boundary array of a rectangle for a given tree. More... | |
void | RTreeFreeBoundary (struct RTree_Rect *r) |
Delete the boundary of a rectangle. More... | |
size_t | RTreeReadNode (struct RTree_Node *, off_t, struct RTree *) |
size_t | RTreeWriteNode (struct RTree_Node *, struct RTree *) |
off_t | RTreeGetNodePos (struct RTree *) |
void | RTreeFlushBuffer (struct RTree *) |
#define MAXLEVEL 20 /* 8^MAXLEVEL items are guaranteed to fit into the tree */ |
typedef int rt_delete_fn(struct RTree_Rect *, union RTree_Child, struct RTree *) |
typedef int rt_insert_fn(struct RTree_Rect *, union RTree_Child, int, struct RTree *) |
typedef int rt_search_fn(struct RTree *, struct RTree_Rect *, SearchHitCallback *, void *) |
typedef int rt_valid_child_fn(union RTree_Child *) |
typedef int SearchHitCallback(int id, const struct RTree_Rect *rect, void *arg) |
Allocate the boundary array of a rectangle for a given tree.
This method allocated the boundary coordinates array in provided rectangle. It does not release previously allocated memory.
r | The pointer to rectangle to initialize the boundary coordinates. This is usually a rectangle that was created on the stack or self allocated. |
t | The pointer to a RTree struct |
Definition at line 81 of file rect.c.
References assert, RTree_Rect::boundary, malloc(), and t.
Referenced by RTreeAllocNode(), RTreeAllocRect(), and RTreeCreateTree().
struct RTree_Node* RTreeAllocNode | ( | struct RTree * | t, |
int | level | ||
) |
Definition at line 74 of file node.c.
References assert, RTree_Rect::boundary, RTree_Node::branch, RTree_Node::count, RTree_Node::level, malloc(), MAXCARD, RTree_Branch::rect, RTreeAllocBoundary(), and t.
Referenced by RTreeCreateTree(), and RTreeInsertRectF().
struct RTree_Rect* RTreeAllocRect | ( | struct RTree * | t | ) |
Create a new rectangle for a given tree.
This method allocates a new rectangle and initializes the internal boundary coordinates based on the tree dimension.
Hence a call to RTreeNewBoundary() is not necessary.
t | The pointer to a RTree struct |
Definition at line 42 of file rect.c.
References assert, malloc(), r, RTreeAllocBoundary(), and t.
int RTreeContained | ( | struct RTree_Rect * | r, |
struct RTree_Rect * | s, | ||
struct RTree * | t | ||
) |
int RTreeContains | ( | struct RTree_Rect * | r, |
struct RTree_Rect * | s, | ||
struct RTree * | t | ||
) |
void RTreeCopyNode | ( | struct RTree_Node * | n1, |
struct RTree_Node * | n2, | ||
struct RTree * | t | ||
) |
Definition at line 109 of file node.c.
References assert, RTree_Node::branch, RTree_Node::count, RTree_Node::level, MAXCARD, RTreeCopyBranch(), and t.
struct RTree* RTreeCreateTree | ( | int | fd, |
off_t | rootpos, | ||
int | ndims | ||
) |
Create new empty R*-Tree.
This method creates a new RTree, either in memory (fd < 0) or in file. If the file descriptor is positive, the corresponding file must have been opened for reading and writing. This method must also be called if an existing tree previously saved to file is going to be accessed.
fd | file descriptor to hold data, negative toggles memory mode |
rootpos | offset in file to root node (past any header info) |
ndims | number of dimensions for the new tree: min 2, max 20 |
Definition at line 61 of file vector/rtree/index.c.
References RTree::_recycle::alloc, RTree::_recycle::avail, RTree_Rect::boundary, RTree_Node::branch, RTree::BranchBuf, RTree::branchsize, RTree::c, RTree::center_n, RTree_PartitionVars::cover, RTree::delete_rect, NodeBuffer::dirty, RTree::fd, RTree::free_nodes, RTree::insert_rect, RTree::leafcard, RTree_Node::level, malloc(), MAXCARD, MAXLEVEL, RTree::min_leaf_fill, RTree::min_node_fill, RTree::minfill_leaf_split, RTree::minfill_node_split, NodeBuffer::n, RTree::n_leafs, RTree::n_nodes, RTree::nb, RTree::ndims, RTree::ndims_alloc, NODE_BUFFER_SIZE, RTree::nodecard, RTree::nodesize, RTree::ns, RTree::nsides, RTree::nsides_alloc, NULL, RTree::orect, RTree::overflow, RTree::p, NodeBuffer::pos, RTree::_recycle::pos, RTree_Branch::rect, RTree::rectsize, RTree::root, RTree::rootlevel, RTree::rootpos, RTreeAllocBoundary(), RTreeAllocNode(), RTreeDeleteRectF(), RTreeDeleteRectM(), RTreeFreeNode(), RTreeInsertRectF(), RTreeInsertRectM(), RTreeSearchF(), RTreeSearchM(), RTreeValidChildF(), RTreeValidChildM(), RTreeWriteNode(), RTree::search_rect, RTree::used, and RTree::valid_child.
Referenced by Vect_spatial_index_init().
int RTreeDeleteRect | ( | struct RTree_Rect * | r, |
int | tid, | ||
struct RTree * | t | ||
) |
Delete an item from a R*-Tree.
This method deletes an item from the RTree. The rectangle passed to this method does not need to be the exact rectangle, the only requirement is that this rectangle overlaps with the rectangle to be deleted. The rectangle to be deleted is identified by its id.
r | pointer to rectangle to use for searching |
tid | id of the data to be deleted, must be > 0 |
t | pointer to RTree structure |
Definition at line 347 of file vector/rtree/index.c.
References assert, RTree_Child::id, r, and t.
Referenced by dig_spidx_del_area(), dig_spidx_del_isle(), dig_spidx_del_node(), and Vect_spatial_index_del_item().
void RTreeDestroyNode | ( | struct RTree_Node * | n, |
int | nodes | ||
) |
Definition at line 291 of file node.c.
References RTree_Node::branch, RTree_Branch::child, RTree_Node::level, RTree_Child::ptr, and RTreeFreeNode().
Referenced by RTreeDestroyTree().
void RTreeDestroyTree | ( | struct RTree * | t | ) |
Destroy an R*-Tree.
This method releases all memory allocated to a RTree. It deletes all rectangles and all memory allocated for internal support data. Note that for a file-based RTree, the file is not deleted and not closed. The file can thus be used to permanently store an RTree.
t | pointer to RTree structure |
Definition at line 227 of file vector/rtree/index.c.
References assert, free(), MAXCARD, MAXLEVEL, NODE_BUFFER_SIZE, RTreeDestroyNode(), RTreeFreeBoundary(), and t.
Referenced by dig_spidx_free(), and Vect_spatial_index_destroy().
void RTreeFlushBuffer | ( | struct RTree * | t | ) |
Definition at line 233 of file io.c.
References NODE_BUFFER_SIZE, RTreeRewriteNode(), and t.
void RTreeFreeBoundary | ( | struct RTree_Rect * | r | ) |
Delete the boundary of a rectangle.
This method deletes (free) the memory of the boundary of a rectangle and sets the boundary pointer to NULL.
r | The pointer to the rectangle to delete the boundary from. |
Definition at line 98 of file rect.c.
References assert, free(), NULL, and r.
Referenced by RTreeDestroyTree(), RTreeFreeListBranch(), RTreeFreeNode(), and RTreeFreeRect().
void RTreeFreeNode | ( | struct RTree_Node * | n | ) |
Definition at line 95 of file node.c.
References assert, RTree_Node::branch, free(), MAXCARD, RTree_Branch::rect, and RTreeFreeBoundary().
Referenced by RTreeCreateTree(), and RTreeDestroyNode().
void RTreeFreeRect | ( | struct RTree_Rect * | r | ) |
void RTreeInitNode | ( | struct RTree * | t, |
struct RTree_Node * | n, | ||
int | type | ||
) |
int RTreeInsertRect | ( | struct RTree_Rect * | r, |
int | tid, | ||
struct RTree * | t | ||
) |
Insert an item into a R*-Tree.
r | pointer to rectangle to use for searching |
tid | data id stored with rectangle, must be > 0 |
t | pointer to RTree structure |
Definition at line 320 of file vector/rtree/index.c.
References assert, RTree_Child::id, r, and t.
Referenced by dig_spidx_add_area(), dig_spidx_add_isle(), dig_spidx_add_node(), and Vect_spatial_index_add_item().
int RTreeOverlap | ( | struct RTree_Rect * | r, |
struct RTree_Rect * | s, | ||
struct RTree * | t | ||
) |
void RTreePrintRect | ( | struct RTree_Rect * | R, |
int | depth, | ||
struct RTree * | t | ||
) |
size_t RTreeReadNode | ( | struct RTree_Node * | n, |
off_t | nodepos, | ||
struct RTree * | t | ||
) |
Definition at line 94 of file io.c.
References RTree_Node::branch, RTree_Node::count, RTree_Node::level, MAXCARD, RTreeReadBranch(), and t.
Referenced by RTreeGetNode().
int RTreeSearch | ( | struct RTree * | t, |
struct RTree_Rect * | r, | ||
SearchHitCallback * | shcb, | ||
void * | cbarg | ||
) |
Search an R*-Tree.
Search in an RTree for all data rectangles that overlap or touch the argument rectangle. Return the number of qualifying data rectangles. The search stops if the SearchHitCallBack function returns 0 (zero) or if there are no more qualifying data rectangles.
t | pointer to RTree structure |
r | pointer to rectangle to use for searching |
shcb | Search Hit CallBack function |
cbarg | custom pointer used as argument for the shcb fn |
Definition at line 303 of file vector/rtree/index.c.
Referenced by dig_find_area_box(), dig_find_isle_box(), dig_find_node(), dig_select_areas(), dig_select_isles(), dig_select_lines(), dig_select_nodes(), and Vect_spatial_index_select().
void RTreeSetOverflow | ( | struct RTree * | t, |
char | overflow | ||
) |
Enable/disable R*-tree forced reinsertion (overflow)
For dynamic R*-trees with runtime insertion and deletion, forced reinsertion results in a more compact tree, searches are a bit faster. For static R*-trees (no insertion/deletion after creation) forced reinsertion can be disabled at the cost of slower searches.
t | pointer to RTree structure |
overflow | binary flag |
Definition at line 209 of file vector/rtree/index.c.
References t.
void RTreeSetRect1D | ( | struct RTree_Rect * | r, |
struct RTree * | t, | ||
double | x_min, | ||
double | x_max | ||
) |
Set one dimensional coordinates of a rectangle for a given tree.
All coordinates of the rectangle will be initialized to 0 before the x coordinates are set.
r | The pointer to the rectangle |
t | The pointer to the RTree |
x_min | The lower x coordinate |
x_max | The higher x coordinate |
Definition at line 128 of file rect.c.
References r, RTreeInitRect(), and t.
void RTreeSetRect2D | ( | struct RTree_Rect * | r, |
struct RTree * | t, | ||
double | x_min, | ||
double | x_max, | ||
double | y_min, | ||
double | y_max | ||
) |
Set two dimensional coordinates of a rectangle for a given tree.
All coordinates of the rectangle will be initialized to 0 before the x and y coordinates are set.
r | The pointer to the rectangle |
t | The pointer to the RTree |
x_min | The lower x coordinate |
x_max | The higher x coordinate |
y_min | The lower y coordinate |
y_max | The higher y coordinate |
Definition at line 149 of file rect.c.
References r, RTreeInitRect(), and t.
void RTreeSetRect3D | ( | struct RTree_Rect * | r, |
struct RTree * | t, | ||
double | x_min, | ||
double | x_max, | ||
double | y_min, | ||
double | y_max, | ||
double | z_min, | ||
double | z_max | ||
) |
Set three dimensional coordinates of a rectangle for a given tree.
All coordinates of the rectangle will be initialized to 0 before the x,y and z coordinates are set.
r | The pointer to the rectangle |
t | The pointer to the RTree |
x_min | The lower x coordinate |
x_max | The higher x coordinate |
y_min | The lower y coordinate |
y_max | The higher y coordinate |
z_min | The lower z coordinate |
z_max | The higher z coordinate |
Definition at line 174 of file rect.c.
References r, RTreeInitRect(), and t.
void RTreeSetRect4D | ( | struct RTree_Rect * | r, |
struct RTree * | t, | ||
double | x_min, | ||
double | x_max, | ||
double | y_min, | ||
double | y_max, | ||
double | z_min, | ||
double | z_max, | ||
double | t_min, | ||
double | t_max | ||
) |
Set 4 dimensional coordinates of a rectangle for a given tree.
All coordinates of the rectangle will be initialized to 0 before the x,y,z and t coordinates are set.
r | The pointer to the rectangle |
t | The pointer to the RTree |
x_min | The lower x coordinate |
x_max | The higher x coordinate |
y_min | The lower y coordinate |
y_max | The higher y coordinate |
z_min | The lower z coordinate |
z_max | The higher z coordinate |
t_min | The lower t coordinate |
t_max | The higher t coordinate |
Definition at line 204 of file rect.c.
References assert, r, RTreeInitRect(), and t.
size_t RTreeWriteNode | ( | struct RTree_Node * | n, |
struct RTree * | t | ||
) |
Definition at line 170 of file io.c.
References RTree_Node::branch, RTree_Node::count, G_fatal_error(), RTree_Node::level, MAXCARD, RTreeWriteBranch(), and t.
Referenced by RTreeCreateTree(), and RTreeRewriteNode().