PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ LWGEOM_makepoly()

Datum LWGEOM_makepoly ( PG_FUNCTION_ARGS  )

Definition at line 1558 of file lwgeom_functions_basic.c.

1559 {
1560  GSERIALIZED *pglwg1;
1561  ArrayType *array = NULL;
1562  GSERIALIZED *result = NULL;
1563  const LWLINE *shell = NULL;
1564  const LWLINE **holes = NULL;
1565  LWPOLY *outpoly;
1566  uint32 nholes = 0;
1567  uint32 i;
1568  size_t offset = 0;
1569 
1570  POSTGIS_DEBUG(2, "LWGEOM_makepoly called.");
1571 
1572  /* Get input shell */
1573  pglwg1 = PG_GETARG_GSERIALIZED_P(0);
1574  if (gserialized_get_type(pglwg1) != LINETYPE)
1575  {
1576  lwpgerror("Shell is not a line");
1577  }
1578  shell = lwgeom_as_lwline(lwgeom_from_gserialized(pglwg1));
1579 
1580  /* Get input holes if any */
1581  if (PG_NARGS() > 1)
1582  {
1583  array = PG_GETARG_ARRAYTYPE_P(1);
1584  nholes = ArrayGetNItems(ARR_NDIM(array), ARR_DIMS(array));
1585  holes = lwalloc(sizeof(LWLINE *) * nholes);
1586  for (i = 0; i < nholes; i++)
1587  {
1588 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
1589 #pragma GCC diagnostic push
1590 #pragma GCC diagnostic ignored "-Wsign-compare"
1591 #endif
1592  GSERIALIZED *g = (GSERIALIZED *)(ARR_DATA_PTR(array) + offset);
1593 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
1594 #pragma GCC diagnostic pop
1595 #endif
1596  LWLINE *hole;
1597  offset += INTALIGN(VARSIZE(g));
1598  if (gserialized_get_type(g) != LINETYPE)
1599  {
1600  lwpgerror("Hole %d is not a line", i);
1601  }
1603  holes[i] = hole;
1604  }
1605  }
1606 
1607  outpoly = lwpoly_from_lwlines(shell, nholes, holes);
1608  POSTGIS_DEBUGF(3, "%s", lwgeom_summary((LWGEOM *)outpoly, 0));
1609  result = geometry_serialize((LWGEOM *)outpoly);
1610 
1611  lwline_free((LWLINE *)shell);
1612  PG_FREE_IF_COPY(pglwg1, 0);
1613 
1614  for (i = 0; i < nholes; i++)
1615  {
1616  lwline_free((LWLINE *)holes[i]);
1617  }
1618 
1619  PG_RETURN_POINTER(result);
1620 }
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:268
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:118
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:207
#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:359
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: