PostGIS  2.1.10dev-r@@SVN_REVISION@@
static CIRC_NODE* lwpoly_calculate_circ_tree ( const LWPOLY lwpoly)
static

Definition at line 827 of file lwgeodetic_tree.c.

References circ_nodes_merge(), circ_nodes_sort(), circ_tree_new(), circ_node::geom_type, lwalloc(), lwfree(), lwgeom_get_type(), lwpoly_pt_outside(), LWPOLY::nrings, circ_node::pt_outside, and LWPOLY::rings.

Referenced by lwgeom_calculate_circ_tree().

828 {
829  int i = 0, j = 0;
830  CIRC_NODE** nodes;
831  CIRC_NODE* node;
832 
833  /* One ring? Handle it like a line. */
834  if ( lwpoly->nrings == 1 )
835  {
836  node = circ_tree_new(lwpoly->rings[0]);
837  }
838  else
839  {
840  /* Calculate a tree for each non-trivial ring of the polygon */
841  nodes = lwalloc(lwpoly->nrings * sizeof(CIRC_NODE*));
842  for ( i = 0; i < lwpoly->nrings; i++ )
843  {
844  node = circ_tree_new(lwpoly->rings[i]);
845  if ( node )
846  nodes[j++] = node;
847  }
848  /* Put the trees into a spatially correlated order */
849  circ_nodes_sort(nodes, j);
850  /* Merge the trees pairwise up to a parent node and return */
851  node = circ_nodes_merge(nodes, j);
852  /* Don't need the working list any more */
853  lwfree(nodes);
854  }
855 
856  /* Metatdata about polygons, we need this to apply P-i-P tests */
857  /* selectively when doing distance calculations */
858  node->geom_type = lwgeom_get_type((LWGEOM*)lwpoly);
859  lwpoly_pt_outside(lwpoly, &(node->pt_outside));
860 
861  return node;
862 }
Note that p1 and p2 are pointers into an independent POINTARRAY, do not free them.
void lwfree(void *mem)
Definition: lwutil.c:190
uint32_t lwgeom_get_type(const LWGEOM *geom)
Return LWTYPE number.
Definition: lwgeom.c:785
CIRC_NODE * circ_tree_new(const POINTARRAY *pa)
Build a tree of nodes from a point array, one node per edge.
POINTARRAY ** rings
Definition: liblwgeom.h:413
void lwpoly_pt_outside(const LWPOLY *poly, POINT2D *pt_outside)
Definition: lwgeodetic.c:1422
static CIRC_NODE * circ_nodes_merge(CIRC_NODE **nodes, int num_nodes)
int nrings
Definition: liblwgeom.h:411
static void circ_nodes_sort(CIRC_NODE **nodes, int num_nodes)
Given a list of nodes, sort them into a spatially consistent order, then pairwise merge them up into ...
POINT2D pt_outside
void * lwalloc(size_t size)
Definition: lwutil.c:175

Here is the call graph for this function:

Here is the caller graph for this function: