PostGIS  2.2.8dev-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 155 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().

156 {
157  RTREE_NODE *parent;
158  LWLINE *line;
159  double value1;
160  double value2;
161  POINT4D tmp;
162  POINTARRAY *npa;
163 
164  POSTGIS_DEBUGF(2, "RTreeCreateLeafNode called for point %d of %p", startPoint, pa);
165 
166  if (pa->npoints < startPoint + 2)
167  {
168  lwpgerror("RTreeCreateLeafNode: npoints = %d, startPoint = %d", pa->npoints, startPoint);
169  }
170 
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);
177 
178  getPoint4d_p(pa, startPoint, &tmp);
179  value1 = tmp.y;
180  ptarray_append_point(npa,&tmp,LW_TRUE);
181 
182  getPoint4d_p(pa, startPoint+1, &tmp);
183  value2 = tmp.y;
184  ptarray_append_point(npa,&tmp,LW_TRUE);
185 
186  line = lwline_construct(SRID_UNKNOWN, NULL, npa);
187 
188  parent = lwalloc(sizeof(RTREE_NODE));
189  parent->interval = RTreeCreateInterval(value1, value2);
190  parent->segment = line;
191  parent->leftNode = NULL;
192  parent->rightNode = NULL;
193 
194  POSTGIS_DEBUGF(3, "RTreeCreateLeafNode returning %p", parent);
195 
196  return parent;
197 }
int npoints
Definition: liblwgeom.h:355
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:70
struct rtree_node * leftNode
Definition: lwgeom_rtree.h:24
RTREE_INTERVAL * interval
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:156
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:61
LWLINE * lwline_construct(int srid, GBOX *bbox, POINTARRAY *points)
Definition: lwline.c:29
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:172
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:199
double y
Definition: liblwgeom.h:336
int getPoint4d_p(const POINTARRAY *pa, int n, POINT4D *point)
Definition: lwgeom_api.c:231
Here is the call graph for this function:
Here is the caller graph for this function: