【问题标题】:NetTopologySuite reverse a polygon to have it CCWNetTopologySuite 反转多边形以使其逆时针方向
【发布时间】:2021-02-02 23:09:59
【问题描述】:

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

【问题讨论】:

标签: c# gis nettopologysuite


【解决方案1】:

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

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

应该让Obsolete 警告消失。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-18
    • 1970-01-01
    • 2014-05-23
    • 2012-03-17
    • 1970-01-01
    • 2013-02-12
    • 1970-01-01
    • 2012-10-29
    相关资源
    最近更新 更多