PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ 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, lwgeom_ndims((LWGEOM *)(root->segment)));
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, lwgeom_ndims((LWGEOM *)tmp));
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, lwgeom_ndims((LWGEOM *)tmp));
505
506 if (result)
507 result = RTreeMergeMultiLines(result, tmp);
508 else
509 result = tmp;
510 }
511 }
512
513 return result;
514}
LWCOLLECTION * lwcollection_construct(uint8_t type, int32_t srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms)
int lwgeom_ndims(const LWGEOM *geom)
Return the number of dimensions (2, 3, 4) in a geometry.
Definition lwgeom.c:937
#define MULTILINETYPE
Definition liblwgeom.h:120
void * lwalloc(size_t size)
Definition lwutil.c:227
#define SRID_UNKNOWN
Unknown SRID value.
Definition liblwgeom.h:229
LWMLINE * RTreeFindLineSegments(RTREE_NODE *root, double value)
Retrieves a collection of line segments given the root and crossing value.
static LWMLINE * RTreeMergeMultiLines(LWMLINE *line1, LWMLINE *line2)
Merges two multilinestrings into a single multilinestring.
static uint32 IntervalIsContained(RTREE_INTERVAL *interval, double value)
Returns 1 if min < value <= max, 0 otherwise.
uint8_t type
Definition liblwgeom.h:472
uint8_t type
Definition liblwgeom.h:536
struct rtree_node * leftNode
struct rtree_node * rightNode
LWLINE * segment
RTREE_INTERVAL * interval

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

Referenced by point_in_ring_rtree(), and RTreeFindLineSegments().

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