PostGIS  3.4.0dev-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 1761 of file lwgeom_topo.c.

1762 {
1763  LWT_ELEMID *edge_ids;
1764  uint64_t numedges, i, j;
1765  LWT_ISO_EDGE *ring_edges;
1766 
1767  /* Construct a polygon using edges of the ring */
1768  numedges = 0;
1769  edge_ids = lwalloc(sizeof(LWT_ELEMID)*num_signed_edge_ids);
1770  for (i=0; i<num_signed_edge_ids; ++i) {
1771  int absid = llabs(signed_edge_ids[i]);
1772  int found = 0;
1773  /* Do not add the same edge twice */
1774  for (j=0; j<numedges; ++j) {
1775  if ( edge_ids[j] == absid ) {
1776  found = 1;
1777  break;
1778  }
1779  }
1780  if ( ! found ) edge_ids[numedges++] = absid;
1781  }
1782  i = numedges;
1783  ring_edges = lwt_be_getEdgeById(topo, edge_ids, &i,
1785  lwfree( edge_ids );
1786  if (i == UINT64_MAX)
1787  {
1788  lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface));
1789  return NULL;
1790  }
1791  else if ( i != numedges )
1792  {
1793  lwfree( signed_edge_ids );
1794  _lwt_release_edges(ring_edges, i);
1795  lwerror("Unexpected error: %d edges found when expecting %d", i, numedges);
1796  return NULL;
1797  }
1798 
1799  /* Should now build a polygon with those edges, in the order
1800  * given by GetRingEdges.
1801  */
1802  POINTARRAY *pa = NULL;
1803  for ( i=0; i<num_signed_edge_ids; ++i )
1804  {
1805  LWT_ELEMID eid = signed_edge_ids[i];
1806  LWDEBUGF(2, "Edge %d in ring is edge %" LWTFMT_ELEMID, i, eid);
1807  LWT_ISO_EDGE *edge = NULL;
1808  POINTARRAY *epa;
1809  for ( j=0; j<numedges; ++j )
1810  {
1811  if ( ring_edges[j].edge_id == llabs(eid) )
1812  {
1813  edge = &(ring_edges[j]);
1814  break;
1815  }
1816  }
1817  if ( edge == NULL )
1818  {
1819  _lwt_release_edges(ring_edges, numedges);
1820  lwerror("missing edge that was found in ring edges loop");
1821  return NULL;
1822  }
1823 
1824  if ( pa == NULL )
1825  {
1826  pa = ptarray_clone_deep(edge->geom->points);
1827  if ( eid < 0 ) ptarray_reverse_in_place(pa);
1828  }
1829  else
1830  {
1831  if ( eid < 0 )
1832  {
1833  epa = ptarray_clone_deep(edge->geom->points);
1835  ptarray_append_ptarray(pa, epa, 0);
1836  ptarray_free(epa);
1837  }
1838  else
1839  {
1840  /* avoid a clone here */
1841  ptarray_append_ptarray(pa, edge->geom->points, 0);
1842  }
1843  }
1844  }
1845  _lwt_release_edges(ring_edges, numedges);
1846  POINTARRAY **points = lwalloc(sizeof(POINTARRAY*));
1847  points[0] = pa;
1848 
1849  /* NOTE: the ring may very well have collapsed components,
1850  * which would make it topologically invalid
1851  */
1852  LWPOLY* shell = lwpoly_construct(0, 0, 1, points);
1853  return shell;
1854 }
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:647
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:125
LWT_ISO_EDGE * lwt_be_getEdgeById(LWT_TOPOLOGY *topo, const LWT_ELEMID *ids, uint64_t *numelems, int fields)
Definition: lwgeom_topo.c:226
#define LWTFMT_ELEMID
Definition: lwgeom_topo.c:43
static void _lwt_release_edges(LWT_ISO_EDGE *edges, int num_edges)
Definition: lwgeom_topo.c:471
POINTARRAY * points
Definition: liblwgeom.h:483
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: