DbGeography make circle with center and radius

2019-04-01 19:02发布

I create a DbGeography-point like this:

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

I also have a radius R.

I want to create a curvepolygon with the shape of a circle with the specified radius from the point-coordinate. Be aware that I am using DbGeography, and not DbGeometry.

How do I create the CIRCULARSTRING? Or is there a better way than using a CIRCULARSTRING?


Something like this perhaps?

String polyString = String.Format("CURVEPOLYGON(CIRCULARSTRING(xx yy, xx yy, xx yy, xx yy, xx yy))");
DbGeography polygon = DbGeography.FromText(polyString, 4326);

Thanks.

2条回答
手持菜刀,她持情操
2楼-- · 2019-04-01 19:08

Look at Buffer method: http://msdn.microsoft.com/en-us/library/hh506085(v=vs.110).aspx

It creates a circular buffer around a point. It can be used on other types of geometries/geographies as well.

Be careful if the radius is quite big when using for geography (few kilometers should be OK)

I am not sure how it is implemented in C# but I would definetely use that in other spatial tools.

查看更多
Juvenile、少年°
3楼-- · 2019-04-01 19:27

Create a DbGeography Circle by creating a PointFromText and then Buffer that point by the radius. For the WGS84 coordinate system the DbGeography radius units appear to be in kilometers.

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

Edited with info from adrian about DbGeography.DefaultCoordinateSystemId.

查看更多
登录 后发表回答