PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ LWGEOM_makepoly()

Datum LWGEOM_makepoly ( PG_FUNCTION_ARGS  )

Definition at line 1529 of file lwgeom_functions_basic.c.

1530 {
1531  GSERIALIZED *pglwg1;
1532  ArrayType *array = NULL;
1533  GSERIALIZED *result = NULL;
1534  const LWLINE *shell = NULL;
1535  const LWLINE **holes = NULL;
1536  LWPOLY *outpoly;
1537  uint32 nholes = 0;
1538  uint32 i;
1539  size_t offset = 0;
1540 
1541  POSTGIS_DEBUG(2, "LWGEOM_makepoly called.");
1542 
1543  /* Get input shell */
1544  pglwg1 = PG_GETARG_GSERIALIZED_P(0);
1545  if (gserialized_get_type(pglwg1) != LINETYPE)
1546  {
1547  lwpgerror("Shell is not a line");
1548  }
1549  shell = lwgeom_as_lwline(lwgeom_from_gserialized(pglwg1));
1550 
1551  /* Get input holes if any */
1552  if (PG_NARGS() > 1)
1553  {
1554  array = PG_GETARG_ARRAYTYPE_P(1);
1555  nholes = ArrayGetNItems(ARR_NDIM(array), ARR_DIMS(array));
1556  holes = lwalloc(sizeof(LWLINE *) * nholes);
1557  for (i = 0; i < nholes; i++)
1558  {
1559 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
1560 #pragma GCC diagnostic push
1561 #pragma GCC diagnostic ignored "-Wsign-compare"
1562 #endif
1563  GSERIALIZED *g = (GSERIALIZED *)(ARR_DATA_PTR(array) + offset);
1564 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
1565 #pragma GCC diagnostic pop
1566 #endif
1567  LWLINE *hole;
1568  offset += INTALIGN(VARSIZE(g));
1569  if (gserialized_get_type(g) != LINETYPE)
1570  {
1571  lwpgerror("Hole %d is not a line", i);
1572  }
1574  holes[i] = hole;
1575  }
1576  }
1577 
1578  outpoly = lwpoly_from_lwlines(shell, nholes, holes);
1579  POSTGIS_DEBUGF(3, "%s", lwgeom_summary((LWGEOM *)outpoly, 0));
1580  result = geometry_serialize((LWGEOM *)outpoly);
1581 
1582  lwline_free((LWLINE *)shell);
1583  PG_FREE_IF_COPY(pglwg1, 0);
1584 
1585  for (i = 0; i < nholes; i++)
1586  {
1587  lwline_free((LWLINE *)holes[i]);
1588  }
1589 
1590  PG_RETURN_POINTER(result);
1591 }
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:161
#define LINETYPE
Definition: liblwgeom.h:117
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
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)

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

Here is the call graph for this function: