PostGIS  2.3.7dev-r@@SVN_REVISION@@
LWMLINE* RTreeFindLineSegments ( RTREE_NODE root,
double  value 
)

Retrieves a collection of line segments given the root and crossing value.

The collection is a multilinestring consisting of two point lines representing the segments of the ring that may be crossed by the horizontal projection line at the given y value.

Definition at line 450 of file lwgeom_rtree.c.

References LWLINE::flags, LWMLINE::flags, FLAGS_GET_Z, rtree_node::interval, IntervalIsContained(), rtree_node::leftNode, lwalloc(), lwcollection_construct(), MULTILINETYPE, rtree_node::rightNode, RTreeFindLineSegments(), RTreeMergeMultiLines(), rtree_node::segment, SRID_UNKNOWN, LWLINE::type, and LWMLINE::type.

Referenced by point_in_ring_rtree(), and RTreeFindLineSegments().

451 {
452  LWMLINE *tmp, *result;
453  LWGEOM **lwgeoms;
454 
455  POSTGIS_DEBUGF(2, "RTreeFindLineSegments called for tree %p and value %8.3f", root, value);
456 
457  result = NULL;
458 
459  if (!IntervalIsContained(root->interval, value))
460  {
461  POSTGIS_DEBUGF(3, "RTreeFindLineSegments %p: not contained.", root);
462 
463  return NULL;
464  }
465 
466  /* If there is a segment defined for this node, include it. */
467  if (root->segment)
468  {
469  POSTGIS_DEBUGF(3, "RTreeFindLineSegments %p: adding segment %p %d.", root, root->segment, root->segment->type);
470 
471  lwgeoms = lwalloc(sizeof(LWGEOM *));
472  lwgeoms[0] = (LWGEOM *)root->segment;
473 
474  POSTGIS_DEBUGF(3, "Found geom %p, type %d, dim %d", root->segment, root->segment->type, FLAGS_GET_Z(root->segment->flags));
475 
476  result = (LWMLINE *)lwcollection_construct(MULTILINETYPE, SRID_UNKNOWN, NULL, 1, lwgeoms);
477  }
478 
479  /* If there is a left child node, recursively include its results. */
480  if (root->leftNode)
481  {
482  POSTGIS_DEBUGF(3, "RTreeFindLineSegments %p: recursing left.", root);
483 
484  tmp = RTreeFindLineSegments(root->leftNode, value);
485  if (tmp)
486  {
487  POSTGIS_DEBUGF(3, "Found geom %p, type %d, dim %d", tmp, tmp->type, FLAGS_GET_Z(tmp->flags));
488 
489  if (result)
490  result = RTreeMergeMultiLines(result, tmp);
491  else
492  result = tmp;
493  }
494  }
495 
496  /* Same for any right child. */
497  if (root->rightNode)
498  {
499  POSTGIS_DEBUGF(3, "RTreeFindLineSegments %p: recursing right.", root);
500 
501  tmp = RTreeFindLineSegments(root->rightNode, value);
502  if (tmp)
503  {
504  POSTGIS_DEBUGF(3, "Found geom %p, type %d, dim %d", tmp, tmp->type, FLAGS_GET_Z(tmp->flags));
505 
506  if (result)
507  result = RTreeMergeMultiLines(result, tmp);
508  else
509  result = tmp;
510  }
511  }
512 
513  return result;
514 }
uint8_t type
Definition: liblwgeom.h:417
uint8_t type
Definition: liblwgeom.h:476
LWCOLLECTION * lwcollection_construct(uint8_t type, int srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms)
Definition: lwcollection.c:43
static LWMLINE * RTreeMergeMultiLines(LWMLINE *line1, LWMLINE *line2)
Merges two multilinestrings into a single multilinestring.
Definition: lwgeom_rtree.c:282
struct rtree_node * leftNode
Definition: lwgeom_rtree.h:48
LWMLINE * RTreeFindLineSegments(RTREE_NODE *root, double value)
Retrieves a collection of line segments given the root and crossing value.
Definition: lwgeom_rtree.c:450
static uint32 IntervalIsContained(RTREE_INTERVAL *interval, double value)
Returns 1 if min < value <= max, 0 otherwise.
Definition: lwgeom_rtree.c:101
RTREE_INTERVAL * interval
Definition: lwgeom_rtree.h:47
uint8_t flags
Definition: liblwgeom.h:477
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:187
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:139
LWLINE * segment
Definition: lwgeom_rtree.h:50
struct rtree_node * rightNode
Definition: lwgeom_rtree.h:49
void * lwalloc(size_t size)
Definition: lwutil.c:227
#define MULTILINETYPE
Definition: liblwgeom.h:88
uint8_t flags
Definition: liblwgeom.h:418

Here is the call graph for this function:

Here is the caller graph for this function: