我正在尝试将具有英国北/东坐标系(BritishNationalGridOSGB36)的shapefile读入纬度/经度(WGS1984)。我在这里找到了一篇关于如何使用 NetTopologySuite 执行此操作的优秀帖子。shapefile 的读取工作正常,但在加载期间转换地理时遇到问题。
我已将问题归结为 NetTopologySuite TransformGeometry 方法。如果我使用 DotSpatial ReprojectPoints 转换一个点,它可以正常工作(一旦我对 BritishNationalGridOSGB36 有了正确的定义,请参阅此处以获取有关此内容的有用帖子)。但是 NetTopologySuite 的 TransformGeometry 给了我一个错误的答案。答案在两个方面是错误的
- 它在经度中有纬度值(应该是-0.095399303)
- 纬度是 181560(应该是 51.517489)
我想使用 NetTopologySuite 的 TransformGeometry,因为它比解开每个坐标并更改它更好地处理几何。我也认为我一定做了一些愚蠢的事情,所以我想修复它并学习。
这是我的 NUNIT 测试代码。
class TestConvert
{
//The standard DotSpatial definition, KnownCoordinateSystems.Projected.NationalGrids.BritishNationalGridOSGB36, is incorrect so needed defined string below
const string BritishNationalGridOsgb36String = "+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +towgs84=446.448,-125.157,542.060,0.1502,0.2470,0.8421,-20.4894 +units=m +no_defs";
readonly ProjectionInfo _britishNationalGridOsgb36 = ProjectionInfo.FromProj4String(BritishNationalGridOsgb36String);
readonly ProjectionInfo _wgs84 = KnownCoordinateSystems.Geographic.World.WGS1984;
[Test]
public void ConvertAPointUsingDotSpatialReproject()
{
//SETUP
var xy = new double[] { 532248.29992272425, 181560.30052819476 };
var z = new double[] { 0 };
//ATTEMPT
Reproject.ReprojectPoints(xy, z,
_britishNationalGridOsgb36, _wgs84, 0, z.Length);
//VERIFY
xy[0].ShouldEqualWithTolerance(-0.095399303, 0.001);
xy[1].ShouldEqualWithTolerance(51.517489, 0.001);
}
[Test]
public void ConvertAPointUsingNetTopologySuiteTransformGeometry()
{
//SETUP
var factory = NetTopologySuite.Geometries.GeometryFactory.Default;
var pointNatGrid = new NetTopologySuite.Geometries.Point(532248.29992272425, 181560.30052819476);
//ATTEMPT
var transform = new DotSpatialMathTransform(
_britishNationalGridOsgb36, _wgs84);
var result = GeometryTransform.TransformGeometry(
factory, pointNatGrid, transform);
//VERIFY
result.GeometryType.ShouldEqual("Point");
result.Coordinates.Count().ShouldEqual(1);
result.Coordinates[0].X.ShouldEqualWithTolerance(-0.095399303, 0.001);
result.Coordinates[0].Y.ShouldEqualWithTolerance(51.517489, 0.001);
}
}
第一个测试通过,第二个测试在两个 ShouldEqualWithTolerance 测试中均失败。
您的帮助将不胜感激。