[postgis-users] Precision of the bounding box query

Mike Toews mwtoews at gmail.com
Sun Sep 1 16:46:37 PDT 2013


This behaviour can be explained if your places.location column was a
geography type, where they don't intersect on a spheroid:

postgis=# SELECT ST_MakeBox2d(ST_Point(57, 35), ST_Point(-28,
69))::geometry && 'POINT (2 41)'::geography;
 ?column?
----------
 f
(1 row)

If you want a Cartesian plane intersection, cast places.location to a geometry

postgis=# SELECT ST_MakeBox2d(ST_Point(57, 35), ST_Point(-28,
69))::geometry && 'POINT (2 41)'::geography::geometry;
 ?column?
----------
 t
(1 row)

-Mike

On 2 September 2013 08:21, Alexander Ulanov <avulanov at gmail.com> wrote:
> Hi!
>
> I have a spatial db of cities and places inside Postgis v1.5. I've built a
> gist index on location column and run a bounding box query. However, I
> noticed a strange behavior: results of queries with huge bounding boxes are
> very imprecise.
>
> For example, the first query returns Sagrada Familia (longitude ~2 and
> latitude ~41) and second doesn't, although 41 is inside both 34..68 and
> 35..69.
> 1)select name from places where location && ST_setSRID(ST_MakeBox2d
> (ST_Point(57,34), ST_Point(-28,68)),4326) and name like 'Sagrada%';
>
>       name       |                st_astext
> -----------------+------------------------------------------
>  Sagrada Família | POINT(2.17434883117676 41.4035152693628)
>
> 2)select name from places where location && ST_setSRID(ST_MakeBox2d
> (ST_Point(57,35), ST_Point(-28 69)),4326) and name like 'Sagrada%';
>
> name | st_astext
> ------+-----------
> (0 rows)
>
> Could you explain what is the reason for this and how to fix it?
>
>
> Best regards, Alexander
>
> _______________________________________________
> postgis-users mailing list
> postgis-users at lists.osgeo.org
> http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users


More information about the postgis-users mailing list