PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ _lwt_MakeRingShell()

static LWPOLY* _lwt_MakeRingShell ( LWT_TOPOLOGY topo,
LWT_ELEMID signed_edge_ids,
uint64_t  num_signed_edge_ids 
)
static

Definition at line 1741 of file lwgeom_topo.c.

1742 {
1743  LWT_ELEMID *edge_ids;
1744  uint64_t numedges, i, j;
1745  LWT_ISO_EDGE *ring_edges;
1746 
1747  /* Construct a polygon using edges of the ring */
1748  numedges = 0;
1749  edge_ids = lwalloc(sizeof(LWT_ELEMID)*num_signed_edge_ids);
1750  for (i=0; i<num_signed_edge_ids; ++i) {
1751  int absid = llabs(signed_edge_ids[i]);
1752  int found = 0;
1753  /* Do not add the same edge twice */
1754  for (j=0; j<numedges; ++j) {
1755  if ( edge_ids[j] == absid ) {
1756  found = 1;
1757  break;
1758  }
1759  }
1760  if ( ! found ) edge_ids[numedges++] = absid;
1761  }
1762  i = numedges;
1763  ring_edges = lwt_be_getEdgeById(topo, edge_ids, &i,
1765  lwfree( edge_ids );
1766  if (i == UINT64_MAX)
1767  {
1768  lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface));
1769  return NULL;
1770  }
1771  else if ( i != numedges )
1772  {
1773  lwfree( signed_edge_ids );
1774  _lwt_release_edges(ring_edges, i);
1775  lwerror("Unexpected error: %d edges found when expecting %d", i, numedges);
1776  return NULL;
1777  }
1778 
1779  /* Should now build a polygon with those edges, in the order
1780  * given by GetRingEdges.
1781  */
1782  POINTARRAY *pa = NULL;
1783  for ( i=0; i<num_signed_edge_ids; ++i )
1784  {
1785  LWT_ELEMID eid = signed_edge_ids[i];
1786  LWDEBUGF(2, "Edge %d in ring is edge %" LWTFMT_ELEMID, i, eid);
1787  LWT_ISO_EDGE *edge = NULL;
1788  POINTARRAY *epa;
1789  for ( j=0; j<numedges; ++j )
1790  {
1791  if ( ring_edges[j].edge_id == llabs(eid) )
1792  {
1793  edge = &(ring_edges[j]);
1794  break;
1795  }
1796  }
1797  if ( edge == NULL )
1798  {
1799  _lwt_release_edges(ring_edges, numedges);
1800  lwerror("missing edge that was found in ring edges loop");
1801  return NULL;
1802  }
1803 
1804  if ( pa == NULL )
1805  {
1806  pa = ptarray_clone_deep(edge->geom->points);
1807  if ( eid < 0 ) ptarray_reverse_in_place(pa);
1808  }
1809  else
1810  {
1811  if ( eid < 0 )
1812  {
1813  epa = ptarray_clone_deep(edge->geom->points);
1815  ptarray_append_ptarray(pa, epa, 0);
1816  ptarray_free(epa);
1817  }
1818  else
1819  {
1820  /* avoid a clone here */
1821  ptarray_append_ptarray(pa, edge->geom->points, 0);
1822  }
1823  }
1824  }
1825  _lwt_release_edges(ring_edges, numedges);
1826  POINTARRAY **points = lwalloc(sizeof(POINTARRAY*));
1827  points[0] = pa;
1828 
1829  /* NOTE: the ring may very well have collapsed components,
1830  * which would make it topologically invalid
1831  */
1832  LWPOLY* shell = lwpoly_construct(0, 0, 1, points);
1833  return shell;
1834 }
int ptarray_append_ptarray(POINTARRAY *pa1, POINTARRAY *pa2, double gap_tolerance)
Append a POINTARRAY, pa2 to the end of an existing POINTARRAY, pa1.
Definition: ptarray.c:177
POINTARRAY * ptarray_clone_deep(const POINTARRAY *ptarray)
Deep clone a pointarray (also clones serialized pointlist)
Definition: ptarray.c:626
void lwfree(void *mem)
Definition: lwutil.c:242
void ptarray_free(POINTARRAY *pa)
Definition: ptarray.c:319
void * lwalloc(size_t size)
Definition: lwutil.c:227
LWPOLY * lwpoly_construct(int32_t srid, GBOX *bbox, uint32_t nrings, POINTARRAY **points)
Definition: lwpoly.c:43
void ptarray_reverse_in_place(POINTARRAY *pa)
Definition: ptarray.c:331
LWT_INT64 LWT_ELEMID
Identifier of topology element.
#define LWT_COL_EDGE_EDGE_ID
Edge fields.
#define LWT_COL_EDGE_GEOM
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
const char * lwt_be_lastErrorMessage(const LWT_BE_IFACE *be)
Definition: lwgeom_topo.c:119
LWT_ISO_EDGE * lwt_be_getEdgeById(LWT_TOPOLOGY *topo, const LWT_ELEMID *ids, uint64_t *numelems, int fields)
Definition: lwgeom_topo.c:220
#define LWTFMT_ELEMID
Definition: lwgeom_topo.c:43
static void _lwt_release_edges(LWT_ISO_EDGE *edges, int num_edges)
Definition: lwgeom_topo.c:451
POINTARRAY * points
Definition: liblwgeom.h:469
LWLINE * geom
const LWT_BE_IFACE * be_iface

References _lwt_release_edges(), LWT_TOPOLOGY_T::be_iface, LWT_ISO_EDGE::geom, lwalloc(), LWDEBUGF, lwerror(), lwfree(), lwpoly_construct(), lwt_be_getEdgeById(), lwt_be_lastErrorMessage(), LWT_COL_EDGE_EDGE_ID, LWT_COL_EDGE_GEOM, LWTFMT_ELEMID, LWLINE::points, ptarray_append_ptarray(), ptarray_clone_deep(), ptarray_free(), and ptarray_reverse_in_place().

Referenced by _lwt_AddFaceSplit().

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