PostGIS  3.4.0dev-r@@SVN_REVISION@@
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Pages

◆ LWGEOM_makepoly()

Datum LWGEOM_makepoly ( PG_FUNCTION_ARGS  )

Definition at line 1592 of file lwgeom_functions_basic.c.

1593 {
1594  GSERIALIZED *pglwg1;
1595  ArrayType *array = NULL;
1596  GSERIALIZED *result = NULL;
1597  const LWLINE *shell = NULL;
1598  const LWLINE **holes = NULL;
1599  LWPOLY *outpoly;
1600  uint32 nholes = 0;
1601  uint32 i;
1602  size_t offset = 0;
1603 
1604  POSTGIS_DEBUG(2, "LWGEOM_makepoly called.");
1605 
1606  /* Get input shell */
1607  pglwg1 = PG_GETARG_GSERIALIZED_P(0);
1608  if (gserialized_get_type(pglwg1) != LINETYPE)
1609  {
1610  lwpgerror("Shell is not a line");
1611  }
1612  shell = lwgeom_as_lwline(lwgeom_from_gserialized(pglwg1));
1613 
1614  /* Get input holes if any */
1615  if (PG_NARGS() > 1)
1616  {
1617  array = PG_GETARG_ARRAYTYPE_P(1);
1618  nholes = ArrayGetNItems(ARR_NDIM(array), ARR_DIMS(array));
1619  holes = lwalloc(sizeof(LWLINE *) * nholes);
1620  for (i = 0; i < nholes; i++)
1621  {
1622 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
1623 #pragma GCC diagnostic push
1624 #pragma GCC diagnostic ignored "-Wsign-compare"
1625 #endif
1626  GSERIALIZED *g = (GSERIALIZED *)(ARR_DATA_PTR(array) + offset);
1627 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
1628 #pragma GCC diagnostic pop
1629 #endif
1630  LWLINE *hole;
1631  offset += INTALIGN(VARSIZE(g));
1632  if (gserialized_get_type(g) != LINETYPE)
1633  {
1634  lwpgerror("Hole %d is not a line", i);
1635  }
1637  holes[i] = hole;
1638  }
1639  }
1640 
1641  outpoly = lwpoly_from_lwlines(shell, nholes, holes);
1642  POSTGIS_DEBUGF(3, "%s", lwgeom_summary((LWGEOM *)outpoly, 0));
1643  result = geometry_serialize((LWGEOM *)outpoly);
1644 
1645  lwline_free((LWLINE *)shell);
1646  PG_FREE_IF_COPY(pglwg1, 0);
1647 
1648  for (i = 0; i < nholes; i++)
1649  {
1650  lwline_free((LWLINE *)holes[i]);
1651  }
1652 
1653  PG_RETURN_POINTER(result);
1654 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:262
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:103
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: