PostGIS 3.6.2dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ LWGEOM_makepoly()

Datum LWGEOM_makepoly ( PG_FUNCTION_ARGS  )

Definition at line 1556 of file lwgeom_functions_basic.c.

1557{
1558 GSERIALIZED *pglwg1;
1559 ArrayType *array = NULL;
1560 GSERIALIZED *result = NULL;
1561 const LWLINE *shell = NULL;
1562 const LWLINE **holes = NULL;
1563 LWPOLY *outpoly;
1564 uint32 nholes = 0;
1565 uint32 i;
1566 size_t offset = 0;
1567
1568 POSTGIS_DEBUG(2, "LWGEOM_makepoly called.");
1569
1570 /* Get input shell */
1571 pglwg1 = PG_GETARG_GSERIALIZED_P(0);
1572 if (gserialized_get_type(pglwg1) != LINETYPE)
1573 {
1574 lwpgerror("Shell is not a line");
1575 }
1577
1578 /* Get input holes if any */
1579 if (PG_NARGS() > 1)
1580 {
1581 array = PG_GETARG_ARRAYTYPE_P(1);
1582 nholes = ArrayGetNItems(ARR_NDIM(array), ARR_DIMS(array));
1583 holes = lwalloc(sizeof(LWLINE *) * nholes);
1584 for (i = 0; i < nholes; i++)
1585 {
1586#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
1587#pragma GCC diagnostic push
1588#pragma GCC diagnostic ignored "-Wsign-compare"
1589#endif
1590 GSERIALIZED *g = (GSERIALIZED *)(ARR_DATA_PTR(array) + offset);
1591#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
1592#pragma GCC diagnostic pop
1593#endif
1594 LWLINE *hole;
1595 offset += INTALIGN(VARSIZE(g));
1597 {
1598 lwpgerror("Hole %d is not a line", i);
1599 }
1601 holes[i] = hole;
1602 }
1603 }
1604
1605 outpoly = lwpoly_from_lwlines(shell, nholes, holes);
1606 POSTGIS_DEBUGF(3, "%s", lwgeom_summary((LWGEOM *)outpoly, 0));
1607 result = geometry_serialize((LWGEOM *)outpoly);
1608
1609 lwline_free((LWLINE *)shell);
1610 PG_FREE_IF_COPY(pglwg1, 0);
1611
1612 for (i = 0; i < nholes; i++)
1613 {
1614 lwline_free((LWLINE *)holes[i]);
1615 }
1616
1617 PG_RETURN_POINTER(result);
1618}
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.
uint32_t gserialized_get_type(const GSERIALIZED *g)
Extract the geometry type from the serialized form (it hides in the anonymous data area,...
char * lwgeom_summary(const LWGEOM *lwgeom, int offset)
LWPOLY * lwpoly_from_lwlines(const LWLINE *shell, uint32_t nholes, const LWLINE **holes)
Definition lwpoly.c:360
#define LINETYPE
Definition liblwgeom.h:103
void * lwalloc(size_t size)
Definition lwutil.c:227
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition lwgeom.c:179
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: