DbGeography 用圆心和半径做圆

ull*_*trm 3 c# sql-server entity-framework geo sql-server-2012

我像这样创建了一个 DbGeography 点:

String selectedLocation = String.Format("POINT ({0} {1})", lon, lat).Replace(",", ".");
DbGeography selectedLocationGeo = DbGeography.FromText(selectedLocation, 4326);
Run Code Online (Sandbox Code Playgroud)

我也有一个半径 R。

我想从点坐标创建一个具有指定半径的圆形形状的曲线多边形。请注意,我使用的是 DbGeography,而不是 DbGeometry。

如何创建循环字符串?或者有比使用 CIRCULARSTRING 更好的方法吗?


也许是这样的?

String polyString = String.Format("CURVEPOLYGON(CIRCULARSTRING(xx yy, xx yy, xx yy, xx yy, xx yy))");
DbGeography polygon = DbGeography.FromText(polyString, 4326);
Run Code Online (Sandbox Code Playgroud)

谢谢。

小智 5

通过创建一个PointFromText创建一个DbGeography Circle ,然后通过半径缓冲该点。对于 WGS84 坐标系,DbGeography 半径单位显示为公里。

string textPoint = String.Format("POINT ({0} {1})", longitude, latitude);
DbGeography point = DbGeography.PointFromText(textPoint, DbGeography.DefaultCoordinateSystemId); //4326 = [WGS84]
DbGeography targetCircle = point.Buffer(radiusKilometers);
Run Code Online (Sandbox Code Playgroud)

使用来自adrian 的关于 DbGeography.DefaultCoordinateSystemId 的信息进行编辑。

  • 值得注意的是,您可以使用 `DbGeography.DefaultCoordinateSystemId` 而不是幻数 4326,因为 WGS84 是使用的默认系统。此外,我发现 `Buffer` 参数的单位是米,而不是公里。 (3认同)