Creates an rtree given a pointer to the point array.
Must copy the point array.
223 int childNodes, parentNodes;
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);
The following struct and methods are used for a 1D RTree implementation, described at: http://lin-ear...
static RTREE_NODE * RTreeCreateInteriorNode(RTREE_NODE *left, RTREE_NODE *right)
Creates an interior node given the children.
static RTREE_NODE * RTreeCreateLeafNode(POINTARRAY *pa, int startPoint)
Creates a leaf node given the pointer to the start point of the segment.
void * lwalloc(size_t size)