NetTopologySuite Geometry,设置WGS 84坐标系

问题描述 投票:0回答:0

我有两个几何体 - PointPolygon。 这些几何图形的所有点都以 WGS 84 格式加载,因此它们是 degree 格式。我还有一个 distanceInMeter 变量,表示以米为单位的值。当几何点以度为单位且 distanceInMeter 以米为单位时,如何使用 IGeometry.IsWithinDistance 比较这些几何。 我想我在创建 IGeometry 时出错了。

谢谢

var boundingBox = new BoundingBox(wbl, ebl, nbl, sbl);

var polygon = boundingBox?.GetPolygon();

var distanceInMeter = 1000; //meters

Point = new GeometryFactory(new PrecisionModel(), 4326).CreateGeometry(Point);

return Point.IsWithinDistance(polygon, distanceInMeter);

边界框.cs

    public class BoundingBox
{
    private double WestBoundLongitude { get; set; }
    private double EastBoundLongitude { get; set; }
    private double NorthBoundLatitude { get; set; }
    private double SouthBoundLatitude { get; set; }

    public BoundingBox(double westBoundLongitude, double eastBoundLongitude, 
        double northBoundLatitude, double southBoundLatitude)
    {
        WestBoundLongitude = westBoundLongitude;
        EastBoundLongitude = eastBoundLongitude;
        NorthBoundLatitude = northBoundLatitude;
        SouthBoundLatitude = southBoundLatitude;
    }

    public IGeometry GetPolygon()
    {
        return new GeometryFactory(new PrecisionModel(), 4326)
            ?.CreatePolygon(GetCoordinates());
    }

    private Coordinate[] GetCoordinates()
    {
        return new Coordinate[]
        {
            new Coordinate(NorthBoundLatitude, WestBoundLongitude),
            new Coordinate(NorthBoundLatitude, EastBoundLongitude),
            new Coordinate(SouthBoundLatitude, WestBoundLongitude),
            new Coordinate(SouthBoundLatitude, EastBoundLongitude),
            new Coordinate(NorthBoundLatitude, WestBoundLongitude),
        };
    }
}
c# asp.net-core geometry coordinate-systems nettopologysuite
© www.soinside.com 2019 - 2024. All rights reserved.