PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ RTreeFindLineSegments()

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.

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 }
#define MULTILINETYPE
Definition: liblwgeom.h:89
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:140
LWCOLLECTION * lwcollection_construct(uint8_t type, int srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms)
Definition: lwcollection.c:43
void * lwalloc(size_t size)
Definition: lwutil.c:229
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:188
static LWMLINE * RTreeMergeMultiLines(LWMLINE *line1, LWMLINE *line2)
Merges two multilinestrings into a single multilinestring.
Definition: lwgeom_rtree.c:282
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
int value
Definition: genraster.py:61
uint8_t flags
Definition: liblwgeom.h:422
uint8_t type
Definition: liblwgeom.h:421
uint8_t type
Definition: liblwgeom.h:480
uint8_t flags
Definition: liblwgeom.h:481
struct rtree_node * leftNode
Definition: lwgeom_rtree.h:49
struct rtree_node * rightNode
Definition: lwgeom_rtree.h:50
LWLINE * segment
Definition: lwgeom_rtree.h:51
RTREE_INTERVAL * interval
Definition: lwgeom_rtree.h:48

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

Referenced by point_in_ring_rtree().

Here is the call graph for this function:
Here is the caller graph for this function: