|
2 | 2 | using System.Linq; |
3 | 3 | using NUnit.Framework; |
4 | 4 | using ProjNet.CoordinateSystems; |
| 5 | +using ProjNet.CoordinateSystems.Projections; |
5 | 6 | using ProjNet.CoordinateSystems.Transformations; |
6 | 7 | using ProjNet.Geometries; |
7 | 8 | using ProjNet.IO.CoordinateSystems; |
@@ -322,6 +323,82 @@ public void TestLambertConicConformal2SP_Projection() |
322 | 323 |
|
323 | 324 | } |
324 | 325 |
|
| 326 | + private ICoordinateTransformation CreateGeo2Laea(double centralMeridian, double latitudeOfOrigin) |
| 327 | + { |
| 328 | + var wgs84 = GeographicCoordinateSystem.WGS84; |
| 329 | + |
| 330 | + var coordsys = CoordinateSystemFactory.CreateFromWkt("" + |
| 331 | + "PROJCS[\"Lambert_Azimuthal_Equal_Area_Custom\"," + |
| 332 | + "GEOGCS[\"GCS_WGS_1984\"," + |
| 333 | + "DATUM[\"D_WGS_1984\"," + |
| 334 | + "SPHEROID[\"WGS_1984\",6378137.0,298.257223563]]," + |
| 335 | + "PRIMEM[\"Greenwich\",0.0]," + |
| 336 | + "UNIT[\"Degree\",0.0174532925199433]]," + |
| 337 | + "PROJECTION[\"Lambert_Azimuthal_Equal_Area\"]," + |
| 338 | + "PARAMETER[\"False_Easting\",0.0]," + |
| 339 | + "PARAMETER[\"False_Northing\",0.0]," + |
| 340 | + $"PARAMETER[\"Central_Meridian\",{centralMeridian}]," + |
| 341 | + $"PARAMETER[\"Latitude_Of_Origin\",{latitudeOfOrigin}]," + |
| 342 | + "UNIT[\"Meter\",1.0]]"); |
| 343 | + |
| 344 | + return CoordinateTransformationFactory.CreateFromCoordinateSystems(wgs84, coordsys); |
| 345 | + } |
| 346 | + |
| 347 | + [Test] |
| 348 | + [Repeat(1000)] |
| 349 | + public void TestLambertAzimuthalEqualArea_Projection_round_trip_on_origin() |
| 350 | + { |
| 351 | + double centralMeridian = Random.Next(-180, +180); |
| 352 | + double latitudeOfOrigin = Random.Next(-90, +90); |
| 353 | + |
| 354 | + var trans = CreateGeo2Laea(centralMeridian, latitudeOfOrigin); |
| 355 | + |
| 356 | + var forward = trans.MathTransform; |
| 357 | + var reverse = forward.Inverse(); |
| 358 | + |
| 359 | + double[] pGeo = new[] { centralMeridian, latitudeOfOrigin }; |
| 360 | + |
| 361 | + double[] pLaea = forward.Transform(pGeo); |
| 362 | + |
| 363 | + double[] pGeo2 = reverse.Transform(pLaea); |
| 364 | + |
| 365 | + double[] expectedPLaea = new double[2] { 0, 0 }; |
| 366 | + |
| 367 | + Assert.IsTrue(ToleranceLessThan(pLaea, expectedPLaea, 0.05), TransformationError("Lambert_Azimuthal_Equal_Area", expectedPLaea, pLaea)); |
| 368 | + Assert.IsTrue(ToleranceLessThan(pGeo, pGeo2, 0.0000001), TransformationError("Lambert_Azimuthal_Equal_Area", pGeo, pGeo2, true)); |
| 369 | + } |
| 370 | + |
| 371 | + [Test] |
| 372 | + [Repeat(1000)] |
| 373 | + public void TestLambertAzimuthalEqualArea_Projection_round_trip_on_arbitrary_point() |
| 374 | + { |
| 375 | + int GetRandomSign() |
| 376 | + { |
| 377 | + return Random.Next() % 2 == 0 ? -1 : +1; |
| 378 | + } |
| 379 | + |
| 380 | + double centralMeridian = Random.Next(-150, +150); |
| 381 | + double latitudeOfOrigin = Random.Next(-70, +70); |
| 382 | + |
| 383 | + var trans = CreateGeo2Laea(centralMeridian, latitudeOfOrigin); |
| 384 | + |
| 385 | + var forward = trans.MathTransform; |
| 386 | + var reverse = forward.Inverse(); |
| 387 | + |
| 388 | + double lat = latitudeOfOrigin + (0.01 + Random.NextDouble()) * GetRandomSign(); |
| 389 | + double lon = centralMeridian + (0.01 + Random.NextDouble()) * GetRandomSign(); |
| 390 | + |
| 391 | + double[] pGeo = new[] { lon, lat }; |
| 392 | + |
| 393 | + double[] pLaea = forward.Transform(pGeo); |
| 394 | + |
| 395 | + double[] pGeo2 = reverse.Transform(pLaea); |
| 396 | + |
| 397 | + Assert.NotZero(pLaea[0]); |
| 398 | + Assert.NotZero(pLaea[1]); |
| 399 | + Assert.IsTrue(ToleranceLessThan(pGeo, pGeo2, 0.0000001), TransformationError("Lambert_Azimuthal_Equal_Area", pGeo, pGeo2, true)); |
| 400 | + } |
| 401 | + |
325 | 402 | [Test] |
326 | 403 | public void TestGeocentric() |
327 | 404 | { |
|
0 commit comments