PostGIS  3.3.9dev-r@@SVN_REVISION@@

◆ LWGEOM_makepoly()

Datum LWGEOM_makepoly ( PG_FUNCTION_ARGS  )

Definition at line 1589 of file lwgeom_functions_basic.c.

1590 {
1591  GSERIALIZED *pglwg1;
1592  ArrayType *array = NULL;
1593  GSERIALIZED *result = NULL;
1594  const LWLINE *shell = NULL;
1595  const LWLINE **holes = NULL;
1596  LWPOLY *outpoly;
1597  uint32 nholes = 0;
1598  uint32 i;
1599  size_t offset = 0;
1600 
1601  POSTGIS_DEBUG(2, "LWGEOM_makepoly called.");
1602 
1603  /* Get input shell */
1604  pglwg1 = PG_GETARG_GSERIALIZED_P(0);
1605  if (gserialized_get_type(pglwg1) != LINETYPE)
1606  {
1607  lwpgerror("Shell is not a line");
1608  }
1609  shell = lwgeom_as_lwline(lwgeom_from_gserialized(pglwg1));
1610 
1611  /* Get input holes if any */
1612  if (PG_NARGS() > 1)
1613  {
1614  array = PG_GETARG_ARRAYTYPE_P(1);
1615  nholes = ArrayGetNItems(ARR_NDIM(array), ARR_DIMS(array));
1616  holes = lwalloc(sizeof(LWLINE *) * nholes);
1617  for (i = 0; i < nholes; i++)
1618  {
1619 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
1620 #pragma GCC diagnostic push
1621 #pragma GCC diagnostic ignored "-Wsign-compare"
1622 #endif
1623  GSERIALIZED *g = (GSERIALIZED *)(ARR_DATA_PTR(array) + offset);
1624 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
1625 #pragma GCC diagnostic pop
1626 #endif
1627  LWLINE *hole;
1628  offset += INTALIGN(VARSIZE(g));
1629  if (gserialized_get_type(g) != LINETYPE)
1630  {
1631  lwpgerror("Hole %d is not a line", i);
1632  }
1634  holes[i] = hole;
1635  }
1636  }
1637 
1638  outpoly = lwpoly_from_lwlines(shell, nholes, holes);
1639  POSTGIS_DEBUGF(3, "%s", lwgeom_summary((LWGEOM *)outpoly, 0));
1640  result = geometry_serialize((LWGEOM *)outpoly);
1641 
1642  lwline_free((LWLINE *)shell);
1643  PG_FREE_IF_COPY(pglwg1, 0);
1644 
1645  for (i = 0; i < nholes; i++)
1646  {
1647  lwline_free((LWLINE *)holes[i]);
1648  }
1649 
1650  PG_RETURN_POINTER(result);
1651 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:267
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Definition: gserialized.c:239
uint32_t gserialized_get_type(const GSERIALIZED *g)
Extract the geometry type from the serialized form (it hides in the anonymous data area,...
Definition: gserialized.c:89
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:179
#define LINETYPE
Definition: liblwgeom.h:118
char * lwgeom_summary(const LWGEOM *lwgeom, int offset)
Definition: lwgeom_debug.c:166
void * lwalloc(size_t size)
Definition: lwutil.c:227
LWPOLY * lwpoly_from_lwlines(const LWLINE *shell, uint32_t nholes, const LWLINE **holes)
Definition: lwpoly.c:360
void lwline_free(LWLINE *line)
Definition: lwline.c:67

References gserialized_get_type(), LINETYPE, lwalloc(), lwgeom_as_lwline(), lwgeom_from_gserialized(), lwgeom_summary(), lwline_free(), lwpoly_from_lwlines(), and result.

Here is the call graph for this function: