使用输入点进行 Solr 空间搜索并查询其中的多边形 [英] Solr spatial search with input point and query which polygon within
问题描述
我在 Solr 中索引了一些多边形.是否可以使用点(纬度,经度)进行查询并查看哪个多边形内有该点?
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?
推荐答案
是的,这里有描述:http://wiki.apache.org/solr/SolrAdaptersForLuceneSpatial4你的 Solr 版本必须是 4 或更高,你必须导入 JTS jar 文件,你可以从 http://sourceforge.net/projects/jts-topo-suite/您必须定义一个 fieldType 为 location_rpt 的字段
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"
/>
在 schema.xml 中.然后你必须索引多边形,如:
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.
对于查询,您只需使用过滤查询 fq=geo:"Intersects(10.12 50.02)"
where 10.12
and 50.02
代表您点的纬度和经度.
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.
这篇关于使用输入点进行 Solr 空间搜索并查询其中的多边形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!