i am newbie for Geospatial Query of mongodb and i try search for point within polygon which have code like below :
db.properties.find({
location:{
$geoWithin : {
$geometry : {
type:"Polygon",
coordinates: [[
[104.9172382, 11.57934524],
[104.9146632, 11.5724502],
[104.92753788, 11.57976566]
]]
}
}
}
})
and my data table look like below :
i want to get result of all point is inside polygon.but i really have no clue
this error alway popup
|____/ Mongo Server error (MongoQueryException): Query failed with error code 2 and error message 'Loop is not closed: [ [ 104.9172382, 11.57934524 ], [ 104.9146632, 11.5724502 ], [ 104.92753788, 11.57976566 ] ]' on server
thank for any idea !
i found answer that we need to start coordinate and close coordinates are the same value.
db.properties.find({
location:{
$geoWithin : {
$geometry : {
type:"Polygon",
coordinates:[
[
[ 104.9212999921292 , 11.575955591122819 ] , // start loop
[ 104.92129194550216 , 11.575198826419006 ] ,
[ 104.92298978380859 , 11.575238241297862 ] ,
[ 104.92291736416519 , 11.576023910057827 ] ,
[ 104.9212999921292 , 11.575955591122819 ] // close loop
]
]
}
}
}
})
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