start polygon
This commit is contained in:
1 parent
5aca82244e
commit
6e5e25a141
22 files changed
+431
-210
No files matched your search
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using uWine.Core.Domain.Entities;
|
||||
|
||||
namespace uWine.Core.Infrastructure.Helpers
|
||||
{
|
||||
public class CoordinatesHelper
|
||||
{
|
||||
public static string ToWktPolygon(Dictionary<int, Coordinates> coordinatesDict)
|
||||
{
|
||||
if (coordinatesDict == null || !coordinatesDict.Any())
|
||||
{
|
||||
throw new ArgumentException("Il dictionary di coordinate non può essere nullo o vuoto.");
|
||||
}
|
||||
|
||||
// Ordina le coordinate in base alla chiave (indice)
|
||||
var orderedCoordinates = coordinatesDict.OrderBy(kv => kv.Key)
|
||||
.Select(kv => kv.Value)
|
||||
.ToList();
|
||||
|
||||
// Costruisci la stringa dei punti "longitude latitude"
|
||||
// Ricorda che i sistemi GIS spesso usano (longitude, latitude) ovvero (x, y)
|
||||
var points = orderedCoordinates.Select(c => $"{c.Longitude} {c.Latitude}");
|
||||
|
||||
// Aggiungi il primo punto alla fine per chiudere il poligono
|
||||
var firstPoint = orderedCoordinates.First();
|
||||
var closedPoints = string.Join(",", points) + $",{firstPoint.Longitude} {firstPoint.Latitude}";
|
||||
|
||||
return $"POLYGON(({closedPoints}))";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user