Hello
I need to convert a polygon geometry to System.Data.Entity.Spatial.DbGeography , I have been trying to do with something like that
StringBuilder text = new StringBuilder();
string firstPoint = string.Empty, textToAppend;
var parts = ((Polygon)(geometry)).Parts;
for (int i = 0; i < parts[0].Points.Count; i++)
{
var normalizedPoint = GeometryEngine.NormalizeCentralMeridian(parts[0].Points[i]);
var projectedCenter = GeometryEngine.Project(normalizedPoint, SpatialReferences.Wgs84) as MapPoint;
textToAppend = $"{projectedCenter.X} {projectedCenter.Y}";
textToAppend= textToAppend.Replace(',', '.');
textToAppend = $"{textToAppend},";
text.Append(textToAppend);
if (string.IsNullOrWhiteSpace(firstPoint))
{
firstPoint = $"{projectedCenter.X} {projectedCenter.Y}";
firstPoint = firstPoint.Replace(',', '.');
}
}
text.Append(firstPoint);
var dbGeography=DbGeography.PolygonFromText($"POLYGON(({text}))", 4326);
And it works, but when i saved it to a SQL database on a column of type Geography, it does not work correctly.
What is the correct way to achieve this?
Thanks