简体   繁体   中英

MongoDB / Geojson $geointersects problems

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.

Maybe try with JTS Topology Suite and investigate your polygon:

在此处输入图像描述

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM