[postgis-users] WHERE POINT @ the_geom; returning two polygons/zip codes instead of one

Steve Wormley steve at wormley.com
Wed Aug 24 15:34:56 PDT 2005


On 2005-08-24 14:53, "Matt Farley" <mfarley at sac-yolomvcd.com> wrote:

> SELECT zip FROM zipcodes WHERE POINT '(-121.447,38.570264)' @ the_geom;  -
> Returns two zip codes, 95816 and 95819
> 
> However
> (a 0.001 longitude change to the east)
> SELECT zip FROM zipcodes WHERE POINT '(-121.446,38.570264)' @ the_geom; -
> Returns zip code 95819 properly
> 
> Both points are in 95819 and are near the border of 95816.
> 
> Any idea why the first query is returning both 95816 and 95819 -- the point
> should only be found in 95819.

If the areas you imported are not exactly square then their bounding boxes
may overlap and thus the @ operator will return multiple matches.

You'll need to use Intersects or Within or distance(a,b) = 0
to determine exactly which zip code they are in.

For speed you'll need an indexable query for your geometry index (I believe
@ counts) before you use the more expensive Intersects query.


-Steve







More information about the postgis-users mailing list