Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DbGeography make circle with center and radius

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.

like image 357
ullstrm Avatar asked Sep 15 '25 06:09

ullstrm


1 Answers

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.

like image 76
Eric Conway Avatar answered Sep 17 '25 00:09

Eric Conway