[geos-devel] Re: [postgis-users] General PostGIS & GEOS comments and questions

David Blasby dblasby at refractions.net
Thu Sep 4 12:42:49 EDT 2003

Thanks for the feedback, Vinko.  I've been very busy and havent had much 
time to actually do full testing.

Vinko Vrsalovic wrote:
> 	I guess you are aware of this, but just in case, with the latest
> 	cvs code, when passing a wrong parameter (typically geometry
> 	collections, I guess this is the reason for the warning in the docs :)) 
> 	to a GEOS powered function, postgres (7.3.4) crashes.
 > 	boundary(), when passed a geometry collection, throws an error
 > 	but it doesn't crash the server.

Almost all the GEOS functions should throw an error if you have a 
GeometryCollection as an argument.  This is because the symantics of a 
GeometryCollection for most operations are illdefined.  The Geos or JTS 
list would be a better place to discuss the details of this.

I havent been able to reproduce your bug - could you give me an example 
that crashes the server?

> 	Will there ever be support for geometry collections on GEOS
> 	powered functions, at least for some of them? Is this possible
> 	at all in all (or any) cases?

I'll forward your message to the GEOS list (geos-devel at geos.refractions.net)

> 	And a related issue, is there/will there be a function to obtain 
> 	an envelope of the actual geometries, not their bounding boxes?

OGC defines the envelope of a geometry as it's bounding box.

select envelope(<geom>);

Will return the bounding box as a POLYGON.

> 	In fact, what I'm looking for is to be able to do a
> 	contains(geom,collect(other_geom)), where geom is a POLYGON
> 	column, and other_geom is a column of GEOMETRY type, which 
> 	has different types of geometries. So far, the closest I've 
> 	arrived is to obtain the envelope()'s of the collect()'s, and
> 	then contains(geom,envelope).

I've not sure what you're trying to do here.
Are you trying to find geometries in one table ("other_geom") that are 
contained by a polygon in another table ("geom").

If so, then something like:

SELECT distinct * FROM table_polygon, table_other_geom WHERE
   contains(table_polygon.geom, table_other_geom.other_geom) AND
   table_polygon.geom && table_other_geom.other_geom

should be giving you what you want.

* remember, this is testing each geometry against a single polygon.
   This isnt doing any polygon dissolving.
   If your geometry ("other_geom") is multiparted, all the parts have
   to be contained by one polygon.

I have seen a lot of use for a union(<geometrycollection>) function.
Its implementation would be something like:

accum = initial_geometry.getGeometryN(0).union( 		
		initial_geometry.getGeometryN(1) );

accum = accum.union( 		
		initial_geometry.getGeometryN(2) );

accum = accum.union( 		
		initial_geometry.getGeometryN(3) );
return accum;

More information about the geos-devel mailing list