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

Definition at line 1485 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().

1486 {
1487  GSERIALIZED *pglwg1;
1488  ArrayType *array=NULL;
1489  GSERIALIZED *result=NULL;
1490  const LWLINE *shell=NULL;
1491  const LWLINE **holes=NULL;
1492  LWPOLY *outpoly;
1493  uint32 nholes=0;
1494  uint32 i;
1495  size_t offset=0;
1496 
1497  POSTGIS_DEBUG(2, "LWGEOM_makepoly called.");
1498 
1499  /* Get input shell */
1500  pglwg1 = PG_GETARG_GSERIALIZED_P(0);
1501  if ( gserialized_get_type(pglwg1) != LINETYPE )
1502  {
1503  lwpgerror("Shell is not a line");
1504  }
1505  shell = lwgeom_as_lwline(lwgeom_from_gserialized(pglwg1));
1506 
1507  /* Get input holes if any */
1508  if ( PG_NARGS() > 1 )
1509  {
1510  array = PG_GETARG_ARRAYTYPE_P(1);
1511  nholes = ArrayGetNItems(ARR_NDIM(array), ARR_DIMS(array));
1512  holes = lwalloc(sizeof(LWLINE *)*nholes);
1513  for (i=0; i<nholes; i++)
1514  {
1515  GSERIALIZED *g = (GSERIALIZED *)(ARR_DATA_PTR(array)+offset);
1516  LWLINE *hole;
1517  offset += INTALIGN(VARSIZE(g));
1518  if ( gserialized_get_type(g) != LINETYPE )
1519  {
1520  lwpgerror("Hole %d is not a line", i);
1521  }
1523  holes[i] = hole;
1524  }
1525  }
1526 
1527  outpoly = lwpoly_from_lwlines(shell, nholes, holes);
1528  POSTGIS_DEBUGF(3, "%s", lwgeom_summary((LWGEOM*)outpoly, 0));
1529  result = geometry_serialize((LWGEOM *)outpoly);
1530 
1531  lwline_free((LWLINE*)shell);
1532  PG_FREE_IF_COPY(pglwg1, 0);
1533 
1534  for (i=0; i<nholes; i++)
1535  {
1536  lwline_free((LWLINE*)holes[i]);
1537  }
1538 
1539  PG_RETURN_POINTER(result);
1540 }
#define LINETYPE
Definition: liblwgeom.h:71
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:55
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwline_free(LWLINE *line)
Definition: lwline.c:63
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:255
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
void * lwalloc(size_t size)
Definition: lwutil.c:199
char * lwgeom_summary(const LWGEOM *lwgeom, int offset)
Definition: lwgeom_debug.c:145

Here is the call graph for this function: