MongoDB / Geojson $geointersects problems

[亡魂溺海] 提交于 2020-06-17 13:21:27

问题


It's been now 8 hours I'm trying to deal with a MongoDB Geojson $geoIntersects issue :

It's working very well when my polygon is a square, or a rectangle, but I'm unable to get some results from a $geoIntersects request when my Polygon has crossing vertices, like this example :

(Image from (https://geoman.io/geojson-editor))

The polygon data looks like this :

{
        "type": "Feature",
        "properties": {
            "shape": "Polygon"
        },
        "geometry": {
            "type": "Polygon",
            "coordinates": [
                [
                    [-1.565584, 47.226352],
                    [-1.564704, 47.226927],
                    [-1.564093, 47.225616],
                    [-1.563138, 47.226374],
                    [-1.565584, 47.226352]
                ]
            ]
        },
        "id": "dda54a42-090b-46ea-9dd0-fdda6d240f90"
    }

For this example, I need to know if the Polygon includes my Point coordinates. This is my simple query :

db.geojsondatas.find({
    geometry: {
        $geoIntersects: {
            $geometry: {
                type: "Point",
                coordinates: [ -1.555638, 47.216245 ]
            }
        }
    }
});

Anyone knows if there is a way to do this ?

Thanks by advance.


回答1:


Maybe try with JTS Topology Suite and investigate your polygon:

I don't think $geoIntersects supports Self-intersecting polygon.



来源:https://stackoverflow.com/questions/62195561/mongodb-geojson-geointersects-problems

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