PostGIS  2.1.10dev-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 436 of file lwgeom_rtree.c.

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

Referenced by point_in_ring_rtree(), and RTreeFindLineSegments().

437 {
438  LWMLINE *tmp, *result;
439  LWGEOM **lwgeoms;
440 
441  POSTGIS_DEBUGF(2, "RTreeFindLineSegments called for tree %p and value %8.3f", root, value);
442 
443  result = NULL;
444 
445  if (!IntervalIsContained(root->interval, value))
446  {
447  POSTGIS_DEBUGF(3, "RTreeFindLineSegments %p: not contained.", root);
448 
449  return NULL;
450  }
451 
452  /* If there is a segment defined for this node, include it. */
453  if (root->segment)
454  {
455  POSTGIS_DEBUGF(3, "RTreeFindLineSegments %p: adding segment %p %d.", root, root->segment, root->segment->type);
456 
457  lwgeoms = lwalloc(sizeof(LWGEOM *));
458  lwgeoms[0] = (LWGEOM *)root->segment;
459 
460  POSTGIS_DEBUGF(3, "Found geom %p, type %d, dim %d", root->segment, root->segment->type, FLAGS_GET_Z(root->segment->flags));
461 
462  result = (LWMLINE *)lwcollection_construct(MULTILINETYPE, SRID_UNKNOWN, NULL, 1, lwgeoms);
463  }
464 
465  /* If there is a left child node, recursively include its results. */
466  if (root->leftNode)
467  {
468  POSTGIS_DEBUGF(3, "RTreeFindLineSegments %p: recursing left.", root);
469 
470  tmp = RTreeFindLineSegments(root->leftNode, value);
471  if (tmp)
472  {
473  POSTGIS_DEBUGF(3, "Found geom %p, type %d, dim %d", tmp, tmp->type, FLAGS_GET_Z(tmp->flags));
474 
475  if (result)
476  result = RTreeMergeMultiLines(result, tmp);
477  else
478  result = tmp;
479  }
480  }
481 
482  /* Same for any right child. */
483  if (root->rightNode)
484  {
485  POSTGIS_DEBUGF(3, "RTreeFindLineSegments %p: recursing right.", root);
486 
487  tmp = RTreeFindLineSegments(root->rightNode, value);
488  if (tmp)
489  {
490  POSTGIS_DEBUGF(3, "Found geom %p, type %d, dim %d", tmp, tmp->type, FLAGS_GET_Z(tmp->flags));
491 
492  if (result)
493  result = RTreeMergeMultiLines(result, tmp);
494  else
495  result = tmp;
496  }
497  }
498 
499  return result;
500 }
uint8_t type
Definition: liblwgeom.h:374
uint8_t type
Definition: liblwgeom.h:433
LWCOLLECTION * lwcollection_construct(uint8_t type, int srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms)
Definition: lwcollection.c:30
static LWMLINE * RTreeMergeMultiLines(LWMLINE *line1, LWMLINE *line2)
Merges two multilinestrings into a single multilinestring.
Definition: lwgeom_rtree.c:268
struct rtree_node * leftNode
Definition: lwgeom_rtree.h:24
LWMLINE * RTreeFindLineSegments(RTREE_NODE *root, double value)
Retrieves a collection of line segments given the root and crossing value.
Definition: lwgeom_rtree.c:436
char ** result
Definition: liblwgeom.h:218
static uint32 IntervalIsContained(RTREE_INTERVAL *interval, double value)
Returns 1 if min < value <= max, 0 otherwise.
Definition: lwgeom_rtree.c:87
RTREE_INTERVAL * interval
Definition: lwgeom_rtree.h:23
uint8_t flags
Definition: liblwgeom.h:434
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:154
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:106
LWLINE * segment
Definition: lwgeom_rtree.h:26
struct rtree_node * rightNode
Definition: lwgeom_rtree.h:25
void * lwalloc(size_t size)
Definition: lwutil.c:175
#define MULTILINETYPE
Definition: liblwgeom.h:64
uint8_t flags
Definition: liblwgeom.h:375

Here is the call graph for this function:

Here is the caller graph for this function: