PostGIS  3.3.9dev-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 1788 of file lwgeom_topo.c.

1789 {
1790  LWT_ELEMID *edge_ids;
1791  uint64_t numedges, i, j;
1792  LWT_ISO_EDGE *ring_edges;
1793 
1794  /* Construct a polygon using edges of the ring */
1795  numedges = 0;
1796  edge_ids = lwalloc(sizeof(LWT_ELEMID)*num_signed_edge_ids);
1797  for (i=0; i<num_signed_edge_ids; ++i) {
1798  int absid = llabs(signed_edge_ids[i]);
1799  int found = 0;
1800  /* Do not add the same edge twice */
1801  for (j=0; j<numedges; ++j) {
1802  if ( edge_ids[j] == absid ) {
1803  found = 1;
1804  break;
1805  }
1806  }
1807  if ( ! found ) edge_ids[numedges++] = absid;
1808  }
1809  i = numedges;
1810  ring_edges = lwt_be_getEdgeById(topo, edge_ids, &i,
1812  lwfree( edge_ids );
1813  if (i == UINT64_MAX)
1814  {
1815  lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface));
1816  return NULL;
1817  }
1818  else if ( i != numedges )
1819  {
1820  lwfree( signed_edge_ids );
1821  _lwt_release_edges(ring_edges, i);
1822  lwerror("Unexpected error: %d edges found when expecting %d", i, numedges);
1823  return NULL;
1824  }
1825 
1826  /* Should now build a polygon with those edges, in the order
1827  * given by GetRingEdges.
1828  */
1829  POINTARRAY *pa = NULL;
1830  for ( i=0; i<num_signed_edge_ids; ++i )
1831  {
1832  LWT_ELEMID eid = signed_edge_ids[i];
1833  LWDEBUGF(2, "Edge %d in ring is edge %" LWTFMT_ELEMID, i, eid);
1834  LWT_ISO_EDGE *edge = NULL;
1835  POINTARRAY *epa;
1836  for ( j=0; j<numedges; ++j )
1837  {
1838  if ( ring_edges[j].edge_id == llabs(eid) )
1839  {
1840  edge = &(ring_edges[j]);
1841  break;
1842  }
1843  }
1844  if ( edge == NULL )
1845  {
1846  _lwt_release_edges(ring_edges, numedges);
1847  lwerror("missing edge that was found in ring edges loop");
1848  return NULL;
1849  }
1850 
1851  if ( pa == NULL )
1852  {
1853  pa = ptarray_clone_deep(edge->geom->points);
1854  if ( eid < 0 ) ptarray_reverse_in_place(pa);
1855  }
1856  else
1857  {
1858  if ( eid < 0 )
1859  {
1860  epa = ptarray_clone_deep(edge->geom->points);
1862  ptarray_append_ptarray(pa, epa, 0);
1863  ptarray_free(epa);
1864  }
1865  else
1866  {
1867  /* avoid a clone here */
1868  ptarray_append_ptarray(pa, edge->geom->points, 0);
1869  }
1870  }
1871  }
1872  _lwt_release_edges(ring_edges, numedges);
1873  POINTARRAY **points = lwalloc(sizeof(POINTARRAY*));
1874  points[0] = pa;
1875 
1876  /* NOTE: the ring may very well have collapsed components,
1877  * which would make it topologically invalid
1878  */
1879  LWPOLY* shell = lwpoly_construct(0, 0, 1, points);
1880  return shell;
1881 }
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:634
void lwfree(void *mem)
Definition: lwutil.c:242
void ptarray_free(POINTARRAY *pa)
Definition: ptarray.c:327
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:339
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:465
POINTARRAY * points
Definition: liblwgeom.h:498
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(), and lwt_ChangeEdgeGeom().

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