[postgis-devel] Patch for PostGis Envelope Bug

Charlie Savage cfis at savagexi.com
Sun Sep 9 00:25:16 PDT 2007


>> However, is this another bug then?
>>
>> select astext(extent(GeomFromText('POINT(-104 40)')))
>>
>> "POLYGON((-104 40,-104 40,-104 40,-104 40,-104 40))"

Martin Davis wrote:

> Looks like the same bug/design issue.  JTS would return the envelope as 
> a POINT in this case.

This issue has been causing me problems, so I dug into.  Geos in fact
does return a POINT when you ask for the envelope of a POINT.

It's PostGIS that is wrong.  The method LWGEOM_envelope (line 2493 in
lwgeom_functions_basic.c) *always* returns a polygon.  So I changed it
to return a point if the input geometry is a point.

I've attached a patch that fixes this issue.  The patch checks to see if
the input geometry is a point or a multipoint with just one geometry.

There may be 2 issues with the patch:

1.  The check ins't foolproof, one could subvert it by:

select asText(Envelope(GeomFromText('MULTIPOINT(10 10, 10 10)')));

Maybe checking the bounds (or area) of the envelope would be better?

2.  I'm not sure I handled the SRID correctly for a mutlipoint.  I just
took it from the multipoint itself.  Can the first point in a multipoint
have a different SRID?

Anyway, it would be great if someone could review this patch and apply
it if it seems ok.  I think its important because its easy to create
invalid geometries that don't work with GeomUnion/Contains/Within/etc.
We run into this problem a lot now that we've upgraded to GEOS 3 (GEOS
2.1 seemed to work ok, although maybe that was pure luck.).

Thanks,

Charlie

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: envelope.patch
URL: <http://lists.osgeo.org/pipermail/postgis-devel/attachments/20070909/39d92b24/attachment.ksh>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3237 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://lists.osgeo.org/pipermail/postgis-devel/attachments/20070909/39d92b24/attachment.bin>


More information about the postgis-devel mailing list