1

我添加了一项检查以确定多边形坐标的顺序是否错误,如果条件得到验证,我想修复它,但我知道 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.Geometry.Geometry.html#NetTopologySuite_Geometries_Geometry_Reverse

4

1 回答 1

3

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

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

应该使Obsolete警告消失。

于 2021-02-03T09:10:15.870 回答