I have some polygons indexed in Solr. Is it possible to query with a point(lat,lon) and see which polygon has that point inside?
Yes it is possible and described here: http://wiki.apache.org/solr/SolrAdaptersForLuceneSpatial4 Your Solr Version must be 4 or higher and you have to import the JTS jar-file which you can get from http://sourceforge.net/projects/jts-topo-suite/ You have to define a field with a fieldType of location_rpt
<fieldType name="location_rpt" class="solr.SpatialRecursivePrefixTreeFieldType"
spatialContextFactory="com.spatial4j.core.context.jts.JtsSpatialContextFactory"
distErrPct="0.025"
maxDistErr="0.000009"
units="degrees"
/>
in the schema.xml. Then you have to index the polygons like:
<field name="geo">POLYGON((-10 30, -40 40, -10 -20, 40 20, 0 0, -10 30))</field>
But i think you already did it this way because you wrote that you already have them indexed.
For the query you simply have to use the filter query fq=geo:"Intersects(10.12 50.02)"
where 10.12
and 50.02
represent the latitude and longitude of your point.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With