PostGIS  2.1.10dev-r@@SVN_REVISION@@
static RTREE_NODE* RTreeCreateLeafNode ( POINTARRAY pa,
int  startPoint 

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

Definition at line 155 of file lwgeom_rtree.c.

References getPoint4d_p(), rtree_node::interval, rtree_node::leftNode, LW_TRUE, lwalloc(), lwerror(), 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().

156 {
157  RTREE_NODE *parent;
158  LWLINE *line;
159  double value1;
160  double value2;
161  POINT4D tmp;
162  POINTARRAY *npa;
164  POSTGIS_DEBUGF(2, "RTreeCreateLeafNode called for point %d of %p", startPoint, pa);
166  if (pa->npoints < startPoint + 2)
167  {
168  lwerror("RTreeCreateLeafNode: npoints = %d, startPoint = %d", pa->npoints, startPoint);
169  }
171  /*
172  * The given point array will be part of a geometry that will be freed
173  * independently of the index. Since we may want to cache the index,
174  * we must create independent arrays.
175  */
176  npa = ptarray_construct_empty(0,0,2);
178  getPoint4d_p(pa, startPoint, &tmp);
179  value1 = tmp.y;
180  ptarray_append_point(npa,&tmp,LW_TRUE);
182  getPoint4d_p(pa, startPoint+1, &tmp);
183  value2 = tmp.y;
184  ptarray_append_point(npa,&tmp,LW_TRUE);
186  line = lwline_construct(SRID_UNKNOWN, NULL, npa);
188  parent = lwalloc(sizeof(RTREE_NODE));
189  parent->interval = RTreeCreateInterval(value1, value2);
190  parent->segment = line;
191  parent->leftNode = NULL;
192  parent->rightNode = NULL;
194  POSTGIS_DEBUGF(3, "RTreeCreateLeafNode returning %p", parent);
196  return parent;
197 }
int npoints
Definition: liblwgeom.h:327
The following struct and methods are used for a 1D RTree implementation, described at: http://lin-ear...
Definition: lwgeom_rtree.h:21
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
Definition: ptarray.c:57
struct rtree_node * leftNode
Definition: lwgeom_rtree.h:24
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:67
Definition: lwgeom_rtree.h:23
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_TRUE, then a duplicate point will not be added.
Definition: ptarray.c:141
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:51
LWLINE * lwline_construct(int srid, GBOX *bbox, POINTARRAY *points)
Definition: lwline.c:29
Unknown SRID value.
Definition: liblwgeom.h:154
LWLINE * segment
Definition: lwgeom_rtree.h:26
struct rtree_node * rightNode
Definition: lwgeom_rtree.h:25
static RTREE_INTERVAL * RTreeCreateInterval(double value1, double value2)
Creates an interval given the min and max values, in arbitrary order.
Definition: lwgeom_rtree.c:115
void * lwalloc(size_t size)
Definition: lwutil.c:175
double y
Definition: liblwgeom.h:308
int getPoint4d_p(const POINTARRAY *pa, int n, POINT4D *point)
Definition: lwgeom_api.c:217

Here is the call graph for this function:

Here is the caller graph for this function: