NetTopologySuite 反转多边形以使其逆时针旋转

问题描述

添加一个检查来确定多边形坐标的顺序是否错误,如果条件得到验证我想修复它,但我知道 Reverse() 函数已被弃用:

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();

我应该用什么?

我没有在 NetTopologySuite 上找到任何相关文档,该方法仍在他们的文档中: https://nettopologysuite.github.io/NetTopologySuite/api/NetTopologySuite.Geometries.Geometry.html#NetTopologySuite_Geometries_Geometry_Reverse

解决方法

重载 Polygon.Reverse() 已过时,基本实现 Geometry.Reverse() 未过时。

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

应该使 Obsolete 警告消失。