Hi Jorge, Please see the notes on Polygons: http://wiki.apache.org/solr/SolrAdaptersForLuceneSpatial4#JTS_.2BAC8_WKT_.2BAC8_Polygon_notes
This bullet in particular is relevant: • The standard way to specify a rectangle in WKT is a Polygon -- WKT doesn't have a rectangle shape. If you want to specify a Rectangle via WKT (instead of the Spatial4j basic non-WKT syntax), you should take care to specify the coordinates in counter-clockwise order, the WKT standard. If this is done wrong then the rectangle will go the opposite direction longitudinally, even if it means one that spans nearly the entire globe (>180 degrees width). OpenLayers seems to not honor the WKT standard here, and depending on the corner you drag the rectangle from, might use a clockwise order. Some systems like PostGIS don't care what the ordering is, but the problem there is that there is then no way to specify a rectangle that has >= 180 width because there would be ambiguity. Spatial4j follows the WKT spec. You aren't the first to have run into this problem. Perhaps I should add a mode in which you cannot specify rectangles with a width >= 180 but in exchange your rectangle will always go the way you intended (assuming always < 180) without having to worry about coordinate order. ~ David Smiley On Oct 8, 2012, at 5:25 AM, Jorge Suja wrote: > Hi everyone, > > I've been playing around with the new spatial search functionalities > included in the newer versions of solr (solr 4.1 and solr trunk 5.0), and > i've found something strange when I try to find a point inside a polygon > (particularly inside a square). > > You can reproduce this problem using the spatial-solr-sandbox project that > has the following config for the fields: > > /[...] > <fieldType name="geohash" class="solr.SpatialRecursivePrefixTreeFieldType" > units="degrees" /> > [...] > <field name="geohash" type="geohash" indexed="true" stored="true" > multiValued="false" /> > [...]/ > > I'm trying to find the following document: > > /<doc> > <str name="id">G292223</str> > <str name="name">Dubai</str> > <str name="geohash">55.280000 25.252220</str> > </doc> > / > I want to test if this point is located inside a polygon so i'm using the > following query: > > /q=geohash:"Intersects(POLYGON((55.180000 25.352220,55.380000 > 25.352220,55.380000 25.152220,55.180000 25.152220,55.180000 25.352220)))"/ > > As you can see, it's a small square that contains the point described > before. I get some results, but that document is not there, and the ones > returned are wrong since they are not even inside the square. > > /<result name="response" numFound="8" start="0"> > <doc> > <str name="id">G1809498</str> > <str name="name">Guilin</str> > <str name="geohash">110.286390 25.281940</str> > </doc> > > [...]/ > > However, if i change a little bit the shape of the square (just changed a > little bit one corner), it returns the result as expected > > /q=geohash:"Intersects(POLYGON((55.180000 25.352220,*55.480000* > 25.352220,55.380000 25.152220,55.180000 25.152220,55.180000 25.352220)))"/ > > Now it returns a single result and it's OK > > /<result name="response" numFound="1" start="0"> > <doc> > <str name="id">G292223</str> > <str name="name">Dubai</str> > <str name="geohash">55.280000 25.252220</str> > </doc> > </result>/ > > > If i use a bbox with the same size and position than the first square, it > returns correctly the document. > > /q=geohash:"Intersects(55.180000 25.152220 55.380000 25.352220)" > > <result name="response" numFound="1" start="0"> > <doc> > <str name="id">G292223</str> > <str name="name">Dubai</str> > <str name="geohash">55.280000 25.252220</str> > </doc> > </result>/ > > If you draw another polygon such a triangle it works well too. > > I've tested this against different points and it's always the same, it seems > that if you draw a straight square (or rectangle), > it can't find the point inside it, and it returns wrong results. > > Am i doing anything wrong? > > Thanks in advance > > Jorge > > > > -- > View this message in context: > http://lucene.472066.n3.nabble.com/Solr-4-spatial-search-point-intersects-polygon-tp4012402.html > Sent from the Solr - User mailing list archive at Nabble.com.