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

Definition at line 1557 of file lwgeom_functions_basic.c.

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

1558 {
1559  GSERIALIZED *pglwg1;
1560  ArrayType *array=NULL;
1561  GSERIALIZED *result=NULL;
1562  const LWLINE *shell=NULL;
1563  const LWLINE **holes=NULL;
1564  LWPOLY *outpoly;
1565  uint32 nholes=0;
1566  uint32 i;
1567  size_t offset=0;
1568 
1569  POSTGIS_DEBUG(2, "LWGEOM_makepoly called.");
1570 
1571  /* Get input shell */
1572  pglwg1 = (GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
1573  if ( gserialized_get_type(pglwg1) != LINETYPE )
1574  {
1575  lwerror("Shell is not a line");
1576  }
1577  shell = lwgeom_as_lwline(lwgeom_from_gserialized(pglwg1));
1578 
1579  /* Get input holes if any */
1580  if ( PG_NARGS() > 1 )
1581  {
1582  array = PG_GETARG_ARRAYTYPE_P(1);
1583  nholes = ArrayGetNItems(ARR_NDIM(array), ARR_DIMS(array));
1584  holes = lwalloc(sizeof(LWLINE *)*nholes);
1585  for (i=0; i<nholes; i++)
1586  {
1587  GSERIALIZED *g = (GSERIALIZED *)(ARR_DATA_PTR(array)+offset);
1588  LWLINE *hole;
1589  offset += INTALIGN(VARSIZE(g));
1590  if ( gserialized_get_type(g) != LINETYPE )
1591  {
1592  lwerror("Hole %d is not a line", i);
1593  }
1595  holes[i] = hole;
1596  }
1597  }
1598 
1599  outpoly = lwpoly_from_lwlines(shell, nholes, holes);
1600  POSTGIS_DEBUGF(3, "%s", lwgeom_summary((LWGEOM*)outpoly, 0));
1601  result = geometry_serialize((LWGEOM *)outpoly);
1602 
1603  lwline_free((LWLINE*)shell);
1604  PG_FREE_IF_COPY(pglwg1, 0);
1605 
1606  for (i=0; i<nholes; i++)
1607  {
1608  lwline_free((LWLINE*)holes[i]);
1609  }
1610 
1611  PG_RETURN_POINTER(result);
1612 }
#define LINETYPE
Definition: liblwgeom.h:61
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:56
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwline_free(LWLINE *line)
Definition: lwline.c:63
char ** result
Definition: liblwgeom.h:218
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:67
unsigned int uint32
Definition: shpopen.c:274
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:89
LWPOLY * lwpoly_from_lwlines(const LWLINE *shell, uint32_t nholes, const LWLINE **holes)
Definition: lwpoly.c:250
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
void * lwalloc(size_t size)
Definition: lwutil.c:175
char * lwgeom_summary(const LWGEOM *lwgeom, int offset)
Definition: lwgeom_debug.c:145

Here is the call graph for this function: