[postgis-users] Combining squares

Andreas ml at 3.141592654.de
Tue Dec 22 17:59:38 PST 2009


Hi,
 
> SELECT
> ST_Difference(ST_Union(the_geom), (SELECT the_geom FROM squares WHERE
> id='S'))
> FROM squares
> [...]
> Does this return a multipolyon or a single polygon? 

I think it depends on whether or not the result is presentable as a single polygon. I had a test case which consisted of disjoint squares which touch each other - in this case the upper query resulted in a single polygon.

> I didn't state
> this originally, but I have disjointed squares. So if you look at a
> grid :
> ABCDEF
> OPQRST
> UVWXYZ
> I might have ABCEFOQUVW
> ABC EF
> O Q
> UVW
> So I would want one polygon with ABCQWVU and one with EF

As far as I know, you may want to produce a multi-polygon M and then use generate_series [1] and ST_GeometryN [2] for retrieving one row for each single-polygon in M - I'm not quite sure on how to do that syntactically, but there is an example in [2], which may help you out.

Best regards,
Andreas

[1] http://www.postgresql.org/docs/8.4/interactive/functions-srf.html
[2] http://postgis.refractions.net/docs/ST_GeometryN.html



More information about the postgis-users mailing list