任何人都可以告诉我如何从“POINT”类型的DbGeography对象集合中创建“Polygon”类型的DbGeography对象
到目前为止,我已经有了这个创建多边形,但我错过了最初的步骤。
1. DbGeography multipoint = DbGeography.MultiPointFromText("MULTIPOINT(53.095124 -0.864716, 53.021255 -1.337128, 52.808019 -1.345367, 52.86153 -1.018524)", 4326)
2. DbGeometry temp_multipoint = DbGeometry.MultiPointFromBinary(multipoint.AsBinary(), 4326)
3. DbGeography polygon = DbGeography.PolygonFromBinary(temp_multipoint.ConvexHull.AsBinary(), 4326); (RESULT)
问题是从DbGeography(POINTS)列表中创建初始多点地理对象
答案 0 :(得分:4)
使用WKT:
将每个点创建为DbGeography对象DbGeography point1 = DbGeography.FromText("POINT(53.095124 -0.864716)", 4326);
DbGeography point2 = DbGeography.FromText("POINT(53.021255 -1.337128)", 4326);
DbGeography point3 = DbGeography.FromText("POINT(52.808019 -1.345367)", 4326);
...
DbGeography polygon = DbGeography.PolygonFromText("POLYGON((53.095124 -0.864716, 53.021255 -1.337128, 52.808019 -1.345367, 53.095124 -0.864716))", 4326);
有两点需要注意:
希望这会有所帮助 - 我也在努力学习多边形的东西!
有关WKT格式的其他提示,请参阅此文章:http://en.wikipedia.org/wiki/Well-known_text
答案 1 :(得分:2)
我最终找到了如何从多个点创建多边形而无需从WKT创建多边形。以下解释略有简化,但仍然是
var PolygonFromMultiplePoints = new DbGeography();
using (var db = new LocationContext())
{
//Select Locations known to be within a certain area which should define the polygon.
foreach (var item in db.Locations)
{
PolygonFromMultiplePoints.Union(item.GeoLocation);
}
}
var temp_multipointgeometry = DbGeometry.MultiPointFromBinary(PolygonFromMultiplePoints.AsBinary(), DbGeometry.DefaultCoordinateSystemId);
PolygonFromMultiplePoints = DbGeography.PolygonFromBinary(temp_multipointgeometry.ConvexHull.AsBinary(), DbGeography.DefaultCoordinateSystemId);
代码示例假定您已经在数据库中存储了作为点存储的dbgeography集合。我的数据库信息来自GeoNames的导入位置。
答案 2 :(得分:0)
你应该在C#中真正做到这一点,以迭代的方式添加点有几个原因:
您正在处理空间数据,但复杂形状的构造从未用于T-SQL。最糟糕的是把它放在CLR功能中。