I get the following error with mongodb 2.4.3
Can't extract geo keys from object, malformed geometry?
{type: "Polygon",
coordinates: [
[
[
103.8324334524412,
1.284232321447769
],
[
103.8342325475588,
1.284232321447769
],
[
103.8342325469261,
1.282433678236006
],
[
103.8324334530738,
1.282433678236006
]
]
]}
Can someone help me understand the problem? it looks like a valid geoJSON object. My index is of type 2dsphere
.
The two steps i am running are :
collection.ensureIndex {'geometry' : "2dsphere"}, (error) =>
# some error checking
# and then
collection.insert features, (error) =>
# features is an array of geoJSON feature objects
# {"type" : "Feature"
# "geometry" : <the Polygon object above>
}
The insert query gives this error. The complete document i am trying to insert is:
{
"type":"Feature",
"geometry": {
"type":"Polygon",
"coordinates":[
[
[103.83243345244122,1.2842323214477689],
[103.83423254755876,1.2842323214477689],
[103.83423254692615,1.2824336782360055],
[103.83243345307383,1.2824336782360055]
]
]
},
"properties":{"name" : "My location"}
}
The polygon object in geoJSON requires first point ([lon, lat]) to be same as last point. By making this change:
{type: "Polygon",
coordinates: [
[
[
103.8324334524412,
1.284232321447769
],
[
103.8342325475588,
1.284232321447769
],
[
103.8342325469261,
1.282433678236006
],
[
103.8324334530738,
1.282433678236006
],
[
103.8324334524412,
1.284232321447769
]
]
]}
The insert query works fine.
In my case the issue was the same as above but the solution to that what worked for me is
point ([longitude, latitude])
I had just done the opposite like
point ([latitude, longitude])
That was pretty stupid of me, but really hard to figure out by the error Can't extract geo keys from object, malformed geometry?
But just incase someone like me find this please check this as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With