[postgis-users] point-in-poly query

Arnaud Lesauvage thewild at freesurf.fr
Wed Jan 18 00:19:00 PST 2006


John.C.Cartwright at noaa.gov a écrit :
> Hello,
> 
> given a table of country polygons and a table of city points, I'm trying
> to find all the cities that fall w/in a given country.  The query listed
> below runs slowly and also produces incorrect results.  Can someone
> correct what I'm doing wrong?
> 
> select cities.city_name,cities.cntry_name
> from cities p, country a 
> where p.shape && a.shape and 
>   intersects(p.shape,a.shape) and 
>   a.gmi_cntry = 'USA';   

I think your query is OK (apart from what Michael pointed out).
If your cities are points, I'd rather use "within" instead of 
"intersects" though, but I don't know whether it will run faster 
or not.

--
Arnaud




More information about the postgis-users mailing list