203 POSTGIS_DEBUG(2,
"geometry_to_polygon called");
205 if ( PG_ARGISNULL(0) )
208 geom = PG_GETARG_GSERIALIZED_P(0);
211 elog(ERROR,
"geometry_to_polygon only accepts Polygons");
218 pa = lwpoly->
rings[0];
220 size = offsetof(POLYGON, p[0]) +
sizeof(polygon->p[0]) * pa->
npoints;
221 polygon = (POLYGON*)palloc0(size);
222 SET_VARSIZE(polygon, size);
227 polygon->boundbox.low.x = gbox.
xmin;
228 polygon->boundbox.low.y = gbox.
ymin;
229 polygon->boundbox.high.x = gbox.
xmax;
230 polygon->boundbox.high.y = gbox.
ymax;
232 for ( i = 0; i < pa->
npoints; i++ )
235 (polygon->p[i]).
x = pt->
x;
236 (polygon->p[i]).y = pt->
y;
240 PG_FREE_IF_COPY(geom,0);
242 PG_RETURN_POLYGON_P(polygon);
uint32_t gserialized_get_type(const GSERIALIZED *s)
Extract the geometry type from the serialized form (it hides in the anonymous data area...
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwgeom_free(LWGEOM *geom)
LWPOLY * lwgeom_as_lwpoly(const LWGEOM *lwgeom)
int lwgeom_calculate_gbox(const LWGEOM *lwgeom, GBOX *gbox)
Calculate bounding box of a geometry, automatically taking into account whether it is cartesian or ge...
const POINT2D * getPoint2d_cp(const POINTARRAY *pa, int n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from...
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members) ...