Loading polygons from MongoDB that entirely contain a known polygon

对着背影说爱祢 提交于 2019-12-25 04:26:11

问题


We have a set of GeoJsonPolygons stored in MongoDB and we're using C# to interact with Mongo.

Previously we were loading polygons which contained a GeoJson.Point by using:

var point = GeoJson.Point(GeoJson.Geographic(known.Longitude, known.Latitude));
var query = Query<OurStoredPolygons>.GeoIntersects(x => x.Polygon, point);
var polygonsThatContainTheKnownPoint = collection.FindAs<OurStoredPolygons>(query);

Now I want to load polygons if another known polygon is entirely within them. I can do the similar operation:

var linearRingCoordinates = new GeoJsonLinearRingCoordinates<GeoJson2DCoordinates>(coordinates);
var polygonCoordinates = new GeoJsonPolygonCoordinates<GeoJson2DCoordinates>(linearRingCoordinates);
var geoCircle = new GeoJsonPolygon<GeoJson2DCoordinates>(polygonCoordinates);
var query = Query<OurStoredPolygons>.GeoIntersects(x => x.Polygon, geoCircle);
var geofences = collection.FindAs<OurStoredPolygons>(query);

But this query will load any polygon that overlaps or even shares an edge at all with the test point. And I only want polygons that entirely contains the test point.

I suppose I could test every point in the polygon edge to load polygons that contain it and then reduce the results to only stored polygons common to every result but that seems like a potentially very slow operation (with a large test polygon and many polygons in the DB)

Is it possible to make that query in Mongo? (or indeed in C#)

来源:https://stackoverflow.com/questions/27620617/loading-polygons-from-mongodb-that-entirely-contain-a-known-polygon

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!