我正在嘗試將英國Northing/Eastings座標系(BritishNationalGridOSGB36)的shapefile讀入經度/緯度(WGS1984)。關於如何使用NetTopologySuite執行此操作,我發現了一篇優秀的文章here。 shapefile的讀取工作正常,但在加載期間轉換地理位置時出現問題。使用NetTopologySuite時發生錯誤TransformGeometry
我已將問題歸結爲NetTopologySuite TransformGeometry方法。如果我使用DotSpatial ReprojectPoints轉換點,它可以正常工作(一旦我對BritishNationalGridOSGB36有正確的定義,請參閱here以獲取有用的文章)。但是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測試上都失敗。
您的幫助,將不勝感激。