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

◆ rect_tree_from_lwcollection()

static RECT_NODE * rect_tree_from_lwcollection ( const LWGEOM lwgeom)
static

Definition at line 818 of file lwtree.c.

819{
820 RECT_NODE **nodes;
821 RECT_NODE *tree;
822 uint32_t i, j = 0;
823 const LWCOLLECTION *lwcol = (const LWCOLLECTION*)lwgeom;
824
825 if (lwcol->ngeoms < 1)
826 return NULL;
827
828 /* Build one tree for each sub-geometry, then below */
829 /* we merge the root notes of those trees to get a single */
830 /* top node for the collection */
831 nodes = lwalloc(sizeof(RECT_NODE*) * lwcol->ngeoms);
832 for (i = 0; i < lwcol->ngeoms; i++)
833 {
834 RECT_NODE *node = rect_tree_from_lwgeom(lwcol->geoms[i]);
835 if (node)
836 {
837 /* Curvepolygons are collections where the sub-geometries */
838 /* are the rings, and will need to doint point-in-poly */
839 /* tests in order to do intersects and distance calculations */
840 /* correctly */
841 if (lwgeom->type == CURVEPOLYTYPE)
843 nodes[j++] = node;
844 }
845 }
846 /* Sort the nodes using a z-order curve, so that merging the nodes */
847 /* gives a spatially coherent tree (near things are in near nodes) */
848 /* Note: CompoundCurve has edges already spatially organized, no */
849 /* sorting needed */
850 if (lwgeom->type != COMPOUNDTYPE)
851 qsort(nodes, j, sizeof(RECT_NODE*), rect_node_cmp);
852
853 tree = rect_nodes_merge(nodes, j);
854
855 tree->geom_type = lwgeom->type;
856 lwfree(nodes);
857 return tree;
858}
#define COMPOUNDTYPE
Definition liblwgeom.h:110
#define CURVEPOLYTYPE
Definition liblwgeom.h:111
void * lwalloc(size_t size)
Definition lwutil.c:227
void lwfree(void *mem)
Definition lwutil.c:248
RECT_NODE * rect_tree_from_lwgeom(const LWGEOM *lwgeom)
Create a tree index on top an LWGEOM.
Definition lwtree.c:861
static RECT_NODE * rect_nodes_merge(RECT_NODE **nodes, uint32_t num_nodes)
Definition lwtree.c:596
static int rect_node_cmp(const void *pn1, const void *pn2)
Definition lwtree.c:41
@ RECT_NODE_RING_EXTERIOR
Definition lwtree.h:36
@ RECT_NODE_RING_INTERIOR
Definition lwtree.h:37
uint32_t ngeoms
Definition liblwgeom.h:580
LWGEOM ** geoms
Definition liblwgeom.h:575
uint8_t type
Definition liblwgeom.h:462
RECT_NODE_RING_TYPE ring_type
Definition lwtree.h:60
RECT_NODE_INTERNAL i
Definition lwtree.h:75
unsigned char geom_type
Definition lwtree.h:68

References COMPOUNDTYPE, CURVEPOLYTYPE, rect_node::geom_type, LWCOLLECTION::geoms, rect_node::i, lwalloc(), lwfree(), LWCOLLECTION::ngeoms, rect_node_cmp(), RECT_NODE_RING_EXTERIOR, RECT_NODE_RING_INTERIOR, rect_nodes_merge(), rect_tree_from_lwgeom(), RECT_NODE_INTERNAL::ring_type, and LWGEOM::type.

Referenced by rect_tree_from_lwgeom().

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