PostGIS  3.1.6dev-r@@SVN_REVISION@@

◆ LWGEOM_makepoly()

Datum LWGEOM_makepoly ( PG_FUNCTION_ARGS  )

Definition at line 1528 of file lwgeom_functions_basic.c.

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

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: