182{
183 POLYGON *polygon;
189 uint32_t i;
190 size_t size;
191
192 POSTGIS_DEBUG(2, "geometry_to_polygon called");
193
194 if ( PG_ARGISNULL(0) )
195 PG_RETURN_NULL();
196
197 geom = PG_GETARG_GSERIALIZED_P(0);
198
200 elog(ERROR, "geometry_to_polygon only accepts Polygons");
201
204 PG_RETURN_NULL();
206
207 pa = lwpoly->
rings[0];
208
209 size = offsetof(POLYGON, p[0]) +
sizeof(polygon->p[0]) * pa->
npoints;
210 polygon = (POLYGON*)palloc0(size);
211 SET_VARSIZE(polygon, size);
212
214
216 polygon->boundbox.low.x = gbox.
xmin;
217 polygon->boundbox.low.y = gbox.
ymin;
218 polygon->boundbox.high.x = gbox.
xmax;
219 polygon->boundbox.high.y = gbox.
ymax;
220
221 for ( i = 0; i < pa->
npoints; i++ )
222 {
224 (polygon->p[i]).x = pt->
x;
225 (polygon->p[i]).y = pt->y;
226 }
227
229 PG_FREE_IF_COPY(geom,0);
230
231 PG_RETURN_POLYGON_P(polygon);
232}
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,...
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...
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
static const POINT2D * getPoint2d_cp(const POINTARRAY *pa, uint32_t n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from.