PostGIS  2.5.0beta1dev-r@@SVN_REVISION@@

◆ LWGEOM_makepoly()

Datum LWGEOM_makepoly ( PG_FUNCTION_ARGS  )

Definition at line 1536 of file lwgeom_functions_basic.c.

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

Referenced by LWGEOM_makeline().

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