DbGeography make circle with center and radius

廉价感情. 提交于 2020-01-01 07:03:16

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/20281297/dbgeography-make-circle-with-center-and-radius

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