GRASS GIS 8 Programmer's Manual
8.2.2dev(2023)-3d2c704037
|
R-Tree library - Multidimensional index. More...
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <assert.h>
#include <grass/gis.h>
#include "index.h"
Go to the source code of this file.
Functions | |
struct RTree * | RTreeCreateTree (int fd, off_t rootpos, int ndims) |
Create new empty R*-Tree. More... | |
void | RTreeSetOverflow (struct RTree *t, char overflow) |
Enable/disable R*-tree forced reinsertion (overflow) More... | |
void | RTreeDestroyTree (struct RTree *t) |
Destroy an R*-Tree. More... | |
int | RTreeSearch (struct RTree *t, struct RTree_Rect *r, SearchHitCallback *shcb, void *cbarg) |
Search an R*-Tree. More... | |
int | RTreeInsertRect (struct RTree_Rect *r, int tid, struct RTree *t) |
Insert an item into a R*-Tree. More... | |
int | RTreeDeleteRect (struct RTree_Rect *r, int tid, struct RTree *t) |
Delete an item from a R*-Tree. More... | |
struct RTree_ListNode * | RTreeNewListNode (void) |
void | RTreeFreeListNode (struct RTree_ListNode *p) |
void | RTreeReInsertNode (struct RTree_Node *n, struct RTree_ListNode **ee) |
void | RTreeFreeListBranch (struct RTree_ListBranch *p) |
R-Tree library - Multidimensional index.
Higher level functions for managing R*-Trees.
(C) 2010-2012 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.
Definition in file vector/rtree/index.c.
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::branchsize, RTree::fd, RTree::free_nodes, RTree_Node::level, malloc(), MAXCARD, MAXLEVEL, RTree::ndims, RTree::ndims_alloc, NODE_BUFFER_SIZE, RTree::nsides, RTree::nsides_alloc, NULL, RTree::_recycle::pos, RTree_Branch::rect, RTree::rectsize, RTree::rootpos, RTreeAllocBoundary(), RTreeAllocNode(), RTreeDeleteRectF(), RTreeDeleteRectM(), RTreeFreeNode(), RTreeInsertRectF(), RTreeInsertRectM(), RTreeSearchF(), RTreeSearchM(), RTreeValidChildF(), RTreeValidChildM(), and RTreeWriteNode().
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 342 of file vector/rtree/index.c.
References assert, RTree::delete_rect, and RTree_Child::id.
Referenced by dig_spidx_del_area(), dig_spidx_del_isle(), dig_spidx_del_node(), and Vect_spatial_index_del_item().
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 222 of file vector/rtree/index.c.
References RTree::_recycle::alloc, assert, RTree_Node::branch, RTree::BranchBuf, RTree::c, RTree::center_n, RTree_PartitionVars::cover, RTree::fd, free(), RTree::free_nodes, RTree::leafcard, RTree_Node::level, MAXCARD, MAXLEVEL, NodeBuffer::n, RTree::nb, NODE_BUFFER_SIZE, RTree::nodecard, RTree::ns, RTree::orect, RTree::p, RTree::_recycle::pos, RTree_Branch::rect, RTree::root, RTreeDestroyNode(), RTreeFreeBoundary(), and RTree::used.
Referenced by dig_spidx_free(), and Vect_spatial_index_destroy().
void RTreeFreeListBranch | ( | struct RTree_ListBranch * | p | ) |
Definition at line 389 of file vector/rtree/index.c.
References RTree_ListBranch::b, free(), RTree_Branch::rect, and RTreeFreeBoundary().
void RTreeFreeListNode | ( | struct RTree_ListNode * | p | ) |
Definition at line 368 of file vector/rtree/index.c.
References free().
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 315 of file vector/rtree/index.c.
References assert, RTree_Child::id, RTree::insert_rect, and RTree::n_leafs.
Referenced by dig_spidx_add_area(), dig_spidx_add_isle(), dig_spidx_add_node(), and Vect_spatial_index_add_item().
struct RTree_ListNode* RTreeNewListNode | ( | void | ) |
Definition at line 363 of file vector/rtree/index.c.
References malloc().
Referenced by RTreeReInsertNode().
void RTreeReInsertNode | ( | struct RTree_Node * | n, |
struct RTree_ListNode ** | ee | ||
) |
Definition at line 377 of file vector/rtree/index.c.
References l, RTree_ListNode::next, RTree_ListNode::node, and RTreeNewListNode().
int RTreeSearch | ( | struct RTree * | t, |
struct RTree_Rect * | r, | ||
SearchHitCallback * | shcb, | ||
void * | cbarg | ||
) |
Search an R*-Tree.
Search in an RTree for all data retangles 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 298 of file vector/rtree/index.c.
References assert, and RTree::search_rect.
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 204 of file vector/rtree/index.c.
References RTree::overflow.