28 #include "../postgis_config.h"
29 #include "lwgeom_pg.h"
32 #include "lwgeom_cache.h"
58 POSTGIS_DEBUGF(2,
"RTreeFree called for %p", root);
79 POSTGIS_DEBUGF(2,
"RTreeCacheClear called for %p", cache);
114 POSTGIS_DEBUGF(2,
"RTreeMergeIntervals called with %p, %p", inter1, inter2);
120 POSTGIS_DEBUGF(3,
"interval min = %8.3f, max = %8.3f", interval->
min, interval->
max);
133 POSTGIS_DEBUGF(2,
"RTreeCreateInterval called with %8.3f, %8.3f", value1, value2);
139 POSTGIS_DEBUGF(3,
"interval min = %8.3f, max = %8.3f", interval->
min, interval->
max);
152 POSTGIS_DEBUGF(2,
"RTreeCreateInteriorNode called for children %p, %p", left, right);
160 POSTGIS_DEBUGF(3,
"RTreeCreateInteriorNode returning %p", parent);
178 POSTGIS_DEBUGF(2,
"RTreeCreateLeafNode called for point %d of %p", startPoint, pa);
180 if (pa->
npoints < startPoint + 2)
182 lwpgerror(
"RTreeCreateLeafNode: npoints = %d, startPoint = %d", pa->
npoints, startPoint);
208 POSTGIS_DEBUGF(3,
"RTreeCreateLeafNode returning %p", parent);
225 POSTGIS_DEBUGF(2,
"RTreeCreate called with pointarray %p", pointArray);
227 nodeCount = pointArray->
npoints - 1;
229 POSTGIS_DEBUGF(3,
"Total leaf nodes: %d", nodeCount);
234 for (i = 0; i < nodeCount; i++)
244 childNodes = nodeCount;
245 parentNodes = nodeCount / 2;
246 while (parentNodes > 0)
248 POSTGIS_DEBUGF(3,
"Merging %d children into %d parents.", childNodes, parentNodes);
251 while (i < parentNodes)
259 if (parentNodes * 2 < childNodes)
261 POSTGIS_DEBUGF(3,
"Shuffling child %d to parent %d", childNodes - 1, i);
263 nodes[i] = nodes[childNodes - 1];
266 childNodes = parentNodes;
267 parentNodes = parentNodes / 2;
272 POSTGIS_DEBUGF(3,
"RTreeCreate returning %p", root);
288 POSTGIS_DEBUGF(2,
"RTreeMergeMultiLines called on %p, %d, %d; %p, %d, %d", line1, line1->
ngeoms, line1->
type, line2, line2->
ngeoms, line2->
type);
294 for (i = 0; i < line1->
ngeoms; i++, j++)
298 for (i = 0; i < line2->
ngeoms; i++, j++)
304 POSTGIS_DEBUGF(3,
"RTreeMergeMultiLines returning %p, %d, %d", col, col->
ngeoms, col->
type);
328 if ( rtree_cache->
index )
330 lwpgerror(
"RTreeBuilder asked to build index where one already exists.");
336 POSTGIS_DEBUG(2,
"RTreeBuilder MULTIPOLYGON");
345 for ( i = 0; i < mpoly->
ngeoms; i++ )
356 for ( p = 0; p < mpoly->
ngeoms; p++ )
364 rtree_cache->
index = currentCache;
368 POSTGIS_DEBUG(2,
"RTreeBuilder POLYGON");
378 for ( i = 0; i < poly->
nrings; i++ )
382 rtree_cache->
index = currentCache;
387 lwpgerror(
"RTreeBuilder got asked to build index on non-polygon");
405 if ( rtree_cache->
index )
409 rtree_cache->
index = 0;
410 rtree_cache->
gcache.argnum = 0;
420 return (GeomCache*)cache;
438 index = cache->
index;
455 POSTGIS_DEBUGF(2,
"RTreeFindLineSegments called for tree %p and value %8.3f", root,
value);
461 POSTGIS_DEBUGF(3,
"RTreeFindLineSegments %p: not contained.", root);
469 POSTGIS_DEBUGF(3,
"RTreeFindLineSegments %p: adding segment %p %d.", root, root->
segment, root->
segment->
type);
482 POSTGIS_DEBUGF(3,
"RTreeFindLineSegments %p: recursing left.", root);
499 POSTGIS_DEBUGF(3,
"RTreeFindLineSegments %p: recursing right.", root);
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
int getPoint4d_p(const POINTARRAY *pa, uint32_t n, POINT4D *point)
LWCOLLECTION * lwcollection_construct(uint8_t type, int srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms)
LWGEOM * lwgeom_clone(const LWGEOM *lwgeom)
Clone LWGEOM object.
int ptarray_append_point(POINTARRAY *pa, const POINT4D *pt, int allow_duplicates)
Append a point to the end of an existing POINTARRAY If allow_duplicate is LW_FALSE,...
void * lwalloc(size_t size)
#define LW_TRUE
Return types for functions with status returns.
#define SRID_UNKNOWN
Unknown SRID value.
LWLINE * lwline_construct(int srid, GBOX *bbox, POINTARRAY *points)
void lwline_free(LWLINE *line)
This library is the generic geometry handling section of PostGIS.
#define FP_CONTAINS_INCL(A, X, B)
static GeomCache * RTreeAllocator(void)
static RTREE_NODE * RTreeCreateLeafNode(POINTARRAY *pa, uint32_t startPoint)
Creates a leaf node given the pointer to the start point of the segment.
static RTREE_INTERVAL * RTreeCreateInterval(double value1, double value2)
Creates an interval given the min and max values, in arbitrary order.
static LWMLINE * RTreeMergeMultiLines(LWMLINE *line1, LWMLINE *line2)
Merges two multilinestrings into a single multilinestring.
static RTREE_INTERVAL * RTreeMergeIntervals(RTREE_INTERVAL *inter1, RTREE_INTERVAL *inter2)
Creates an interval with the total extents of the two given intervals.
static RTREE_POLY_CACHE * RTreeCacheCreate()
Allocate a fresh clean RTREE_POLY_CACHE.
static RTREE_NODE * RTreeCreate(POINTARRAY *pointArray)
Creates an rtree given a pointer to the point array.
static void RTreeCacheClear(RTREE_POLY_CACHE *cache)
Free the cache object and all the sub-objects properly.
static void RTreeFree(RTREE_NODE *root)
Recursively frees the child nodes, the interval and the line before freeing the root node.
LWMLINE * RTreeFindLineSegments(RTREE_NODE *root, double value)
Retrieves a collection of line segments given the root and crossing value.
static uint32 IntervalIsContained(RTREE_INTERVAL *interval, double value)
Returns 1 if min < value <= max, 0 otherwise.
static RTREE_NODE * RTreeCreateInteriorNode(RTREE_NODE *left, RTREE_NODE *right)
Creates an interior node given the children.
static GeomCacheMethods RTreeCacheMethods
static int RTreeBuilder(const LWGEOM *lwgeom, GeomCache *cache)
Callback function sent into the GetGeomCache generic caching system.
RTREE_POLY_CACHE * GetRtreeCache(FunctionCallInfo fcinfo, GSERIALIZED *g1)
Checks for a cache hit against the provided geometry and returns a pre-built index structure (RTREE_P...
static int RTreeFreer(GeomCache *cache)
Callback function sent into the GetGeomCache generic caching system.
Representation for the y-axis interval spanned by an edge.
RTREE_NODE ** ringIndices
The tree structure used for fast P-i-P tests by point_in_multipolygon_rtree()
struct rtree_node * leftNode
struct rtree_node * rightNode
RTREE_INTERVAL * interval
The following struct and methods are used for a 1D RTree implementation, described at: http://lin-ear...