Solr Spatial search with self-intersecting polygon

2019-07-25 05:09发布

问题:

I’m using Solr 4.3.0 with an up to date version of JTS and spatial4j. As field type in my schema.xml i’m using “location_rpt” like the description in the documentation. Documentation

<field name="standort" type="location_rpt" indexed="true" stored="true" />

Now when my Application create a FilterQuery like this

standort:"IsWithin (POLYGON((16.243972778320312 48.27016879304729, 16.411170959472656 48.268340583150504, 16.44275665283203 48.19058119922813, 16.32396697998047 48.15921534239267,16.243972778320312 48.27016879304729)))

everything works fine. My problem is when im trying to use a more complex polygon (self-intersecting) Solr only shows an Error like this:

org.apache.solr.common.SolrException: com.spatial4j.core.exception.InvalidShapeException: Self-intersection at or near point (16.315572194579204, 48.26688289499306, NaN)

the corresponding query looks like this:

standort:"IsWithin (POLYGON((16.253585815429688 48.27748097861045, 16.506271362304688 48.23427822033628, 16.418380737304688 48.18646123261718, 16.286544799804688 48.28958948415696,16.253585815429688 48.27748097861045)))"

Screen of the Polygon

Are there any workarounds to get self-intersecting polgyon querys to work?

回答1:

No, not really. You can use JTS on the client to clean up your polygon so that when Solr gets it, it's valid. See http://tsusiatsoftware.net/jts/jts-faq/jts-faq.html#G