[postgis-users] Select polygons within polygon with PostGIS 2.0

Sandro Santilli strk at keybit.net
Wed Oct 10 02:27:30 PDT 2012


On Wed, Oct 10, 2012 at 10:27:42AM +0200, Michal Zimmermann wrote:
> Hi to all,
> I have a relation representing all the counties in my country and the
> other one containing all the districts - e. g. each and every county
> is composed of several districts. How do I select them with spatial
> query? I tried with
> select nazorp from kraje as k, orp_wgs as o WHERE ST_Within(o.geom,k.geom) AND
> k.nazev = 'Liberecký' // name of the county
> 
> but had wrong results returned (well, they are probably not wrong,
> they are just not what I expected them to be). ST_Within only returns
> districts that don't share a boundary with the county, but I need to
> get all the districts within the county. Is that possible? I haven't
> found any built-in function suitable for my needs yet.

Try ST_Covers, which includes the boundaries.

PS: yours is the perfect use case for PostGIS Topology !

--strk;

 http://www.cartodb.com - Map, analyze and build applications with your data

                                       ~~ http://strk.keybit.net 




More information about the postgis-users mailing list