Creates an rtree given a pointer to the point array.
Must copy the point array.
219{
222 uint32_t i, nodeCount;
223 uint32_t childNodes, parentNodes;
224
225 POSTGIS_DEBUGF(2, "RTreeCreate called with pointarray %p", pointArray);
226
227 nodeCount = pointArray->
npoints - 1;
228
229 POSTGIS_DEBUGF(3, "Total leaf nodes: %d", nodeCount);
230
231
232
233
234 for (i = 0; i < nodeCount; i++)
235 {
237 }
238
239
240
241
242
243
244 childNodes = nodeCount;
245 parentNodes = nodeCount / 2;
246 while (parentNodes > 0)
247 {
248 POSTGIS_DEBUGF(3, "Merging %d children into %d parents.", childNodes, parentNodes);
249
250 i = 0;
251 while (i < parentNodes)
252 {
254 i++;
255 }
256
257
258
259 if (parentNodes * 2 < childNodes)
260 {
261 POSTGIS_DEBUGF(3, "Shuffling child %d to parent %d", childNodes - 1, i);
262
263 nodes[i] = nodes[childNodes - 1];
264 parentNodes++;
265 }
266 childNodes = parentNodes;
267 parentNodes = parentNodes / 2;
268 }
269
270 root = nodes[0];
272 POSTGIS_DEBUGF(3, "RTreeCreate returning %p", root);
273
274 return root;
275}
void * lwalloc(size_t size)
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_NODE * RTreeCreateInteriorNode(RTREE_NODE *left, RTREE_NODE *right)
Creates an interior node given the children.
The following struct and methods are used for a 1D RTree implementation, described at: http://lin-ear...