[postgis-devel] Patching Envelope - Advice Needed

strk strk at keybit.net
Sat Sep 22 00:29:59 PDT 2007


On Fri, Sep 21, 2007 at 12:46:23PM -0600, Charlie Savage wrote:
> Ok - I'm back to fixing up Envelope/Extent to return valid geometries - 
> as we've been discussion the last week on the mailing list.
> 
> Since I'm not that familiar with PostGIS I was wondering if someone 
> could provide advice.  Is is okay to return the original geometry - to 
> should I make a copy.  In my last patch I derialized a Point, created a 
> new one, and returned it.  But would returning the geometry directly be 
> ok?  Like this:
> 
> 
> PG_FUNCTION_INFO_V1(LWGEOM_envelope);
> Datum LWGEOM_envelope(PG_FUNCTION_ARGS)
> {
> 	PG_LWGEOM *geom = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
> 	BOX2DFLOAT4 box;
> 	POINT2D *pts = lwalloc(sizeof(POINT2D)*5);
> 	POINTARRAY *pa[1];
> 	LWPOLY *poly;
> 	int SRID;
> 	PG_LWGEOM *result;
> 	uchar *ser;
> 
> 
> SRID = lwgeom_getsrid(SERIALIZED_FORM(geom));
> 	
> 	if (lwgeom_getType(geom->type) == POINTTYPE ||
> 	    lwgeom_getType(geom->type) == LINETYPE)
> 	{
> 		PG_RETURN_POINTER(geom);
> 	}
> 
> Or will that cause all sorts of havoc?

is fine, but the POINT2D array you allocated before will leak, so lwfree it,
or avoid allocating at all if not needed.

--strk;



More information about the postgis-devel mailing list