简体   繁体   中英

MongoDB GeoJSON “Can't extract geo keys from object, malformed geometry?” when inserting type Polygon

I'm getting the error "Can't extract geo keys from object, malformed geometry?". The polygon is closed and the format looks good, as it is inserting correctly into Mongo. I'm using Mongo version 2.6.3, running on Centos 6.5 x64.

What is wrong with the Polygon below? I followed the Mongo examples quite closely.

db.test.remove({});
db.test.insert({testPoly: {type: "Polygon", coordinates: [[0,0],[0,20],[10,30],[20,20],[20,0],[0,0]]}});
db.test.ensureIndex({testPoly: "2dsphere" });
db.test.find();

/* 0 */
{
    "connectionId" : 2385,
    "err" : "Can't extract geo keys from object, malformed geometry?: { _id: ObjectId('54008301eb55d4628c080370'), testPoly: { type: \"Polygon\", coordinates: [ [ 0.0, 0.0 ], [ 0.0, 20.0 ], [ 10.0, 30.0 ], [ 20.0, 20.0 ], [ 20.0, 0.0 ], [ 0.0, 0.0 ] ] } }",
    "code" : 16755,
    "n" : 0,
    "ok" : 1
}

/* 0 */
{
    "_id" : ObjectId("54008301eb55d4628c080370"),
    "testPoly" : {
        "type" : "Polygon",
        "coordinates" : [ 
            [ 
                0, 
                0
            ], 
            [ 
                0, 
                20
            ], 
            [ 
                10, 
                30
            ], 
            [ 
                20, 
                20
            ], 
            [ 
                20, 
                0
            ], 
            [ 
                0, 
                0
            ]
        ]
    }
}

You are missing an array level in the coordinates:

coordinates: [[0,0],[0,20],[10,30],[20,20],[20,0],[0,0]]

Should be:

coordinates: [[[0,0],[0,20],[10,30],[20,20],[20,0],[0,0]]]

See http://geojson.org/geojson-spec.html#id4

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