<div dir="ltr">Thanks, Mike. I've changed my second query and it returns what I expect:<div><br></div><div>select name from places where location::geometry && ST_setSRID(ST_MakeBox2d (ST_Point(57,35), </div><div>
ST_Point(-28,69)),4326)::geometry and name like 'Sagrada%';<br></div><div><div><br></div><div> name </div><div>-----------------</div><div> Sagrada Família</div></div><div><br></div><div>Does this mean that all bounding box queries have to be written with casting to geometry type? Bounding box originates from the browser with google maps.</div>
<div><br></div><div>Related question. Do I really need geography type for my locations if my queries are only bounding box and st_dwithin ?</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/9/2 Mike Toews <span dir="ltr"><<a href="mailto:mwtoews@gmail.com" target="_blank">mwtoews@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This behaviour can be explained if your places.location column was a<br>
geography type, where they don't intersect on a spheroid:<br>
<br>
postgis=# SELECT ST_MakeBox2d(ST_Point(57, 35), ST_Point(-28,<br>
69))::geometry && 'POINT (2 41)'::geography;<br>
?column?<br>
----------<br>
f<br>
(1 row)<br>
<br>
If you want a Cartesian plane intersection, cast places.location to a geometry<br>
<br>
postgis=# SELECT ST_MakeBox2d(ST_Point(57, 35), ST_Point(-28,<br>
69))::geometry && 'POINT (2 41)'::geography::geometry;<br>
?column?<br>
----------<br>
t<br>
(1 row)<br>
<br>
-Mike<br>
<div><div class="h5"><br>
On 2 September 2013 08:21, Alexander Ulanov <<a href="mailto:avulanov@gmail.com">avulanov@gmail.com</a>> wrote:<br>
> Hi!<br>
><br>
> I have a spatial db of cities and places inside Postgis v1.5. I've built a<br>
> gist index on location column and run a bounding box query. However, I<br>
> noticed a strange behavior: results of queries with huge bounding boxes are<br>
> very imprecise.<br>
><br>
> For example, the first query returns Sagrada Familia (longitude ~2 and<br>
> latitude ~41) and second doesn't, although 41 is inside both 34..68 and<br>
> 35..69.<br>
> 1)select name from places where location && ST_setSRID(ST_MakeBox2d<br>
> (ST_Point(57,34), ST_Point(-28,68)),4326) and name like 'Sagrada%';<br>
><br>
> name | st_astext<br>
> -----------------+------------------------------------------<br>
> Sagrada Família | POINT(2.17434883117676 41.4035152693628)<br>
><br>
> 2)select name from places where location && ST_setSRID(ST_MakeBox2d<br>
> (ST_Point(57,35), ST_Point(-28 69)),4326) and name like 'Sagrada%';<br>
><br>
> name | st_astext<br>
> ------+-----------<br>
> (0 rows)<br>
><br>
> Could you explain what is the reason for this and how to fix it?<br>
><br>
><br>
> Best regards, Alexander<br>
><br>
</div></div>> _______________________________________________<br>
> postgis-users mailing list<br>
> <a href="mailto:postgis-users@lists.osgeo.org">postgis-users@lists.osgeo.org</a><br>
> <a href="http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users" target="_blank">http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users</a><br>
_______________________________________________<br>
postgis-users mailing list<br>
<a href="mailto:postgis-users@lists.osgeo.org">postgis-users@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users" target="_blank">http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users</a><br>
</blockquote></div><br></div>