PostGIS  2.5.0dev-r@@SVN_REVISION@@
Datum LWGEOM_makepoly ( PG_FUNCTION_ARGS  )

Definition at line 1533 of file lwgeom_functions_basic.c.

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

1534 {
1535  GSERIALIZED *pglwg1;
1536  ArrayType *array=NULL;
1537  GSERIALIZED *result=NULL;
1538  const LWLINE *shell=NULL;
1539  const LWLINE **holes=NULL;
1540  LWPOLY *outpoly;
1541  uint32 nholes=0;
1542  uint32 i;
1543  size_t offset=0;
1544 
1545  POSTGIS_DEBUG(2, "LWGEOM_makepoly called.");
1546 
1547  /* Get input shell */
1548  pglwg1 = PG_GETARG_GSERIALIZED_P(0);
1549  if ( gserialized_get_type(pglwg1) != LINETYPE )
1550  {
1551  lwpgerror("Shell is not a line");
1552  }
1553  shell = lwgeom_as_lwline(lwgeom_from_gserialized(pglwg1));
1554 
1555  /* Get input holes if any */
1556  if ( PG_NARGS() > 1 )
1557  {
1558  array = PG_GETARG_ARRAYTYPE_P(1);
1559  nholes = ArrayGetNItems(ARR_NDIM(array), ARR_DIMS(array));
1560  holes = lwalloc(sizeof(LWLINE *)*nholes);
1561  for (i=0; i<nholes; i++)
1562  {
1563 #pragma GCC diagnostic push
1564 #pragma GCC diagnostic ignored "-Wsign-compare"
1565  GSERIALIZED *g = (GSERIALIZED *)(ARR_DATA_PTR(array)+offset);
1566 #pragma GCC diagnostic pop
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 }
#define LINETYPE
Definition: liblwgeom.h:85
uint32_t gserialized_get_type(const GSERIALIZED *s)
Extract the geometry type from the serialized form (it hides in the anonymous data area...
Definition: g_serialized.c:86
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwline_free(LWLINE *line)
Definition: lwline.c:76
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:169
LWPOLY * lwpoly_from_lwlines(const LWLINE *shell, uint32_t nholes, const LWLINE **holes)
Definition: lwpoly.c:358
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
void * lwalloc(size_t size)
Definition: lwutil.c:229
char * lwgeom_summary(const LWGEOM *lwgeom, int offset)
Definition: lwgeom_debug.c:158

Here is the call graph for this function: