NetTopologySuite reverse a polygon to have it CCW

1.2k Views Asked by At

I have added a check to identify if the polygon coords are in the wrong order and if the condition is verified I want to fix it, but I get that the Reverse() function is deprecated:

List<Coordinate> polygonCoords = new List<Coordinate>();
foreach(LatLngDto latlng in latlngs.LatLngs)
{
    Coordinate vertex = new Coordinate(latlng.Lng, latlng.Lat);
    polygonCoords.Add(vertex);
}
polygonCoords.Add(new Coordinate(latlngs.LatLngs[0].Lng, latlngs.LatLngs[0].Lat));

var geometryFactory = NtsGeometryServices.Instance.CreateGeometryFactory(srid: 4326);
var customShape = geometryFactory.CreatePolygon(polygonCoords.ToArray());

if (!customShape.Shell.IsCCW)
{
    customShape = (Polygon)customShape.Reverse();
}

List<int> gridCellCodes = (from gc in grid5KmCellRepo.GetAll()
                        where gc.Grid5KmCellCoords.Intersects(customShape)
                        select gc.Grid5KmCellId).ToList();

What should I use?

I haven't found any relevant documentation on NetTopologySuite and the method is still in their documentation: https://nettopologysuite.github.io/NetTopologySuite/api/NetTopologySuite.Geometries.Geometry.html#NetTopologySuite_Geometries_Geometry_Reverse

1

There are 1 best solutions below

0
On BEST ANSWER

The overload Polygon.Reverse() is obsolete, the base implementation Geometry.Reverse() is not.

customShape = (Polygon)(((Geometry)customShape).Reverse());

should make the Obsolete warning go away.