blob: 0377d19fcae218ae477be4da541377fff8ea3736 [file] [log] [blame]
You can also store any GeoJSON shape using the @grails.mongodb.geo.Shape@ super class:
{code}
import grails.mongodb.geo.*
...
class Entry {
ObjectId id
Shape shape
static mapping = {
location geoIndex:'2dsphere'
}
}
...
new Entry(shape: Polygon.valueOf([[[3, 1], [1, 2], [5, 6], [9, 2], [4, 3], [3, 1]]]) ).save()
new Entry(shape: LineString.valueOf([[5, 2], [7, 3], [7, 5], [9, 4]]) ).save()
new Entry(shape: Point.valueOf([5, 2])).save()
{code}
And then use the @findBy*GeoIntersects@ method to figure out whether shapes intersect with each other:
{code}
assert Entry.findByShapeGeoIntersects( Polygon.valueOf( [[ [0,0], [3,0], [3,3], [0,3], [0,0] ]] ) )
assert Entry.findByShapeGeoIntersects( LineString.valueOf( [[1,4], [8,4]] ) )
{code}