从 DbGeography 点集合创建 DbGeography 多边形

Dra*_*uka 4 entity-framework geospatial

谁能告诉我如何从“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)
Run Code Online (Sandbox Code Playgroud)

问题是从 DbGeography(POINTS) 列表创建初始多点地理对象

小智 6

使用 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);
Run Code Online (Sandbox Code Playgroud)

有两点需要注意:

  • WKT 格式是 Longitude 然后 Latitude,不是更直观的 Lat, Long
  • 对于多边形,最后一个点必须与第一个点匹配才能“关闭它”

希望这会有所帮助 - 我也努力学习多边形的东西!

有关 WKT 格式的额外提示,请参阅本文:http : //en.wikipedia.org/wiki/Well-known_text