PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ RTreeCreateLeafNode()

static RTREE_NODE* RTreeCreateLeafNode ( POINTARRAY pa,
int  startPoint 
)
static

Creates a leaf node given the pointer to the start point of the segment.

Definition at line 169 of file lwgeom_rtree.c.

References getPoint4d_p(), rtree_node::interval, rtree_node::leftNode, LW_TRUE, lwalloc(), lwline_construct(), POINTARRAY::npoints, ptarray_append_point(), ptarray_construct_empty(), rtree_node::rightNode, RTreeCreateInterval(), rtree_node::segment, SRID_UNKNOWN, and POINT4D::y.

Referenced by RTreeCreate().

170 {
171  RTREE_NODE *parent;
172  LWLINE *line;
173  double value1;
174  double value2;
175  POINT4D tmp;
176  POINTARRAY *npa;
177 
178  POSTGIS_DEBUGF(2, "RTreeCreateLeafNode called for point %d of %p", startPoint, pa);
179 
180  if (pa->npoints < startPoint + 2)
181  {
182  lwpgerror("RTreeCreateLeafNode: npoints = %d, startPoint = %d", pa->npoints, startPoint);
183  }
184 
185  /*
186  * The given point array will be part of a geometry that will be freed
187  * independently of the index. Since we may want to cache the index,
188  * we must create independent arrays.
189  */
190  npa = ptarray_construct_empty(0,0,2);
191 
192  getPoint4d_p(pa, startPoint, &tmp);
193  value1 = tmp.y;
194  ptarray_append_point(npa,&tmp,LW_TRUE);
195 
196  getPoint4d_p(pa, startPoint+1, &tmp);
197  value2 = tmp.y;
198  ptarray_append_point(npa,&tmp,LW_TRUE);
199 
200  line = lwline_construct(SRID_UNKNOWN, NULL, npa);
201 
202  parent = lwalloc(sizeof(RTREE_NODE));
203  parent->interval = RTreeCreateInterval(value1, value2);
204  parent->segment = line;
205  parent->leftNode = NULL;
206  parent->rightNode = NULL;
207 
208  POSTGIS_DEBUGF(3, "RTreeCreateLeafNode returning %p", parent);
209 
210  return parent;
211 }
int npoints
Definition: liblwgeom.h:371
The following struct and methods are used for a 1D RTree implementation, described at: http://lin-ear...
Definition: lwgeom_rtree.h:45
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
Definition: ptarray.c:70
struct rtree_node * leftNode
Definition: lwgeom_rtree.h:48
RTREE_INTERVAL * interval
Definition: lwgeom_rtree.h:47
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, then a duplicate point will not be added.
Definition: ptarray.c:156
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:76
LWLINE * lwline_construct(int srid, GBOX *bbox, POINTARRAY *points)
Definition: lwline.c:42
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:188
LWLINE * segment
Definition: lwgeom_rtree.h:50
struct rtree_node * rightNode
Definition: lwgeom_rtree.h:49
static RTREE_INTERVAL * RTreeCreateInterval(double value1, double value2)
Creates an interval given the min and max values, in arbitrary order.
Definition: lwgeom_rtree.c:129
void * lwalloc(size_t size)
Definition: lwutil.c:229
double y
Definition: liblwgeom.h:352
int getPoint4d_p(const POINTARRAY *pa, int n, POINT4D *point)
Definition: lwgeom_api.c:122
Here is the call graph for this function:
Here is the caller graph for this function: