Solr spatial search with input point and query which polygon within

馋奶兔 提交于 2019-11-30 17:27:36

问题


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?


回答1:


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.




回答2:


We need the external JTS jar file to index Polygon shapes in first place.



来源:https://stackoverflow.com/questions/19368588/solr-spatial-search-with-input-point-and-query-which-polygon-within

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!