refact program.cs vineyardController, service e repo
This commit is contained in:
1 parent
a373201ca4
commit
3a1a0ca7ef
17 files changed
+769
-306
No files matched your search
@@ -1,15 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using uWine.Core.Domain.Entities;
|
||||
using NetTopologySuite.Geometries;
|
||||
using NetTopologySuite.IO;
|
||||
|
||||
namespace uWine.Core.Infrastructure.Helpers
|
||||
{
|
||||
public class CoordinatesHelper
|
||||
{
|
||||
public static string ToWktPolygon(Dictionary<int, Coordinates> coordinatesDict)
|
||||
public static string ToWktPolygon(Dictionary<int, Domain.Entities.Coordinates> coordinatesDict)
|
||||
{
|
||||
if (coordinatesDict == null || !coordinatesDict.Any())
|
||||
{
|
||||
@@ -31,5 +27,42 @@ namespace uWine.Core.Infrastructure.Helpers
|
||||
|
||||
return $"POLYGON(({closedPoints}))";
|
||||
}
|
||||
|
||||
public static Dictionary<int, Domain.Entities.Coordinates> WktPolygonToDictionary(string wktPolygon)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(wktPolygon))
|
||||
{
|
||||
throw new ArgumentException("La stringa WKT del poligono non può essere nulla o vuota.");
|
||||
}
|
||||
|
||||
var reader = new WKTReader();
|
||||
NetTopologySuite.Geometries.Geometry geometry = reader.Read(wktPolygon);
|
||||
|
||||
if (!(geometry is Polygon polygon))
|
||||
{
|
||||
throw new ArgumentException("La stringa WKT non rappresenta un poligono valido.");
|
||||
}
|
||||
|
||||
var coordinatesDict = new Dictionary<int, Domain.Entities.Coordinates>();
|
||||
var points = polygon.ExteriorRing.Coordinates; // Ottieni i punti dell'anello esterno
|
||||
|
||||
// Nota: i poligoni WKT ripetono il primo punto alla fine per chiudere.
|
||||
// Dobbiamo escludere l'ultimo punto se è identico al primo per non duplicarlo nel dictionary,
|
||||
// a meno che tu non voglia mantenere anche il punto di chiusura.
|
||||
int count = points.Length;
|
||||
if (count > 0 && points[0].Equals2D(points[count - 1]))
|
||||
{
|
||||
count--; // Escludi l'ultimo punto se è una duplicazione del primo
|
||||
}
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
// Ricorda che NetTopologySuite usa (X, Y) che corrispondono a (Longitude, Latitude) per WGS84
|
||||
coordinatesDict.Add(i, new Domain.Entities.Coordinates(points[i].Y, points[i].X ));
|
||||
}
|
||||
|
||||
return coordinatesDict;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user