forked from ryanong/mongoid_spacial
-
Couldn't load subscription status.
- Fork 31
Open
Labels
Description
When storing a polygon field as array, searching all points within the polygon, as well as intersecting 2 polygons works.
But finding all polygons including a particular point does not work when the polygon field is an array, and seems to works only when the polygon is store as GeoJSON object.
To reproduce:
db.geom.insert({"polygons":
{"type":"Polygon",
coordinates:
[[[ 17.60083012593064, 78.18557739257812],
[ 17.16834652544664, 78.19381713867188],
[ 17.17490690610013, 78.739013671875],
[ 17.613919673106714, 78.73489379882812],
[ 17.60083012593064, 78.18557739257812]
]]
}, "coo": [[ 17.60083012593064, 78.18557739257812],
[ 17.16834652544664, 78.19381713867188],
[ 17.17490690610013, 78.739013671875],
[ 17.613919673106714, 78.73489379882812],
[ 17.60083012593064, 78.18557739257812]
]
});
This works
db.geom.find({polygons:
{$geoIntersects:
{$geometry:{ "type" : "Point",
"coordinates" : [ 17.3734, 78.4738 ] }
}
}
});
This does not work
db.geom.find({coo:
{$geoIntersects:
{$geometry:{ "type" : "Point",
"coordinates" : [ 17.3734, 78.4738 ] }
}
}
});
A solution is to store the polygon as a geoJSON object.
Is there any reason it's stored as a plain array, or is it safe to migrate all the geo field to GeoJSON object ?