|
5 | 5 | using GeoAPI.CoordinateSystems;
|
6 | 6 | using GeoAPI.CoordinateSystems.Transformations;
|
7 | 7 | using NUnit.Framework;
|
| 8 | +using NUnit.Framework.Constraints; |
8 | 9 | using ProjNet.CoordinateSystems;
|
9 | 10 | using ProjNet.CoordinateSystems.Transformations;
|
10 | 11 |
|
@@ -323,5 +324,87 @@ public void ParseFittedCoordinateSystemWkt ()
|
323 | 324 | Assert.AreEqual ("EPSG", fcs.BaseCoordinateSystem.Authority);
|
324 | 325 | Assert.AreEqual (31467, fcs.BaseCoordinateSystem.AuthorityCode);
|
325 | 326 | }
|
| 327 | + |
| 328 | + [Test] |
| 329 | + public void TestGeocentricCoordinateSystem() |
| 330 | + { |
| 331 | + var fac = new CoordinateSystemFactory(); |
| 332 | + IGeocentricCoordinateSystem fcs = null; |
| 333 | + |
| 334 | + string wkt = "GEOCCS[\"TUREF\", " + |
| 335 | + "DATUM[\"Turkish_National_Reference_Frame\", SPHEROID[\"GRS 1980\", 6378137, 298.257222101, AUTHORITY[\"EPSG\", \"7019\"]], AUTHORITY[\"EPSG\", \"1057\"]], " + |
| 336 | + "PRIMEM[\"Greenwich\", 0, AUTHORITY[\"EPSG\", \"8901\"]], " + |
| 337 | + "UNIT[\"metre\", 1, AUTHORITY[\"EPSG\", \"9001\"]], " + |
| 338 | + "AXIS[\"Geocentric X\", OTHER], AXIS[\"Geocentric Y\", OTHER], AXIS[\"Geocentric Z\", NORTH], " + |
| 339 | + "AUTHORITY[\"EPSG\", \"5250\"]]"; |
| 340 | + |
| 341 | + try |
| 342 | + { |
| 343 | + fcs = fac.CreateFromWkt(wkt) as IGeocentricCoordinateSystem; |
| 344 | + } |
| 345 | + catch (Exception ex) |
| 346 | + { |
| 347 | + Assert.Fail("Could not create fitted coordinate system from:\r\n" + wkt + "\r\n" + ex.Message); |
| 348 | + } |
| 349 | + |
| 350 | + Assert.That(fcs, Is.Not.Null); |
| 351 | + Assert.That(CheckInfo(fcs, "TUREF", "EPSG", 5250L)); |
| 352 | + Assert.That(CheckHorizontalDatum(fcs.HorizontalDatum, "Turkish_National_Reference_Frame", "EPSG", 1057L), Is.True); |
| 353 | + Assert.That(CheckEllipsoid(fcs.HorizontalDatum.Ellipsoid, "GRS 1980", 6378137, 298.257222101, "EPSG", 7019), Is.True); |
| 354 | + Assert.That(CheckPrimem(fcs.PrimeMeridian, "Greenwich", 0, "EPSG", 8901L), Is.True); |
| 355 | + Assert.That(CheckUnit(fcs.PrimeMeridian.AngularUnit, "degree", null, null, null), Is.True); |
| 356 | + Assert.That(CheckUnit(fcs.LinearUnit, "metre", 1, "EPSG", 9001L), Is.True); |
| 357 | + |
| 358 | + Assert.That(fcs.Authority, Is.EqualTo("EPSG")); |
| 359 | + Assert.That(fcs.AuthorityCode, Is.EqualTo(5250L)); |
| 360 | + } |
| 361 | + |
| 362 | + private bool CheckPrimem(IPrimeMeridian primeMeridian, string name, double? longitude, string authority, long? code) |
| 363 | + { |
| 364 | + Assert.That(primeMeridian, Is.Not.Null); |
| 365 | + Assert.That(CheckInfo(primeMeridian, name, authority, code)); |
| 366 | + Assert.That(primeMeridian.Longitude, Is.EqualTo(longitude)); |
| 367 | + return true; |
| 368 | + } |
| 369 | + |
| 370 | + private static bool CheckUnit(IUnit unit, string name, double? value, string authority, long? code) |
| 371 | + { |
| 372 | + Assert.That(unit, Is.Not.Null); |
| 373 | + Assert.That(CheckInfo(unit, name, authority, code)); |
| 374 | + if (!value.HasValue) return true; |
| 375 | + if (unit is ILinearUnit lunit) |
| 376 | + Assert.That(lunit.MetersPerUnit, Is.EqualTo(value)); |
| 377 | + else if (unit is IAngularUnit aunit) |
| 378 | + Assert.That(aunit.RadiansPerUnit, Is.EqualTo(value)); |
| 379 | + return true; |
| 380 | + } |
| 381 | + |
| 382 | + private static bool CheckEllipsoid(IEllipsoid ellipsoid, string name, double? semiMajor, double? inverseFlattening, string authority, long? code) |
| 383 | + { |
| 384 | + Assert.That(ellipsoid, Is.Not.Null); |
| 385 | + Assert.That(CheckInfo(ellipsoid, name, authority, code)); |
| 386 | + if (semiMajor.HasValue) Assert.That(ellipsoid.SemiMajorAxis, Is.EqualTo(semiMajor)); |
| 387 | + if (inverseFlattening.HasValue) Assert.That(ellipsoid.InverseFlattening, Is.EqualTo(inverseFlattening)); |
| 388 | + |
| 389 | + return true; |
| 390 | + } |
| 391 | + |
| 392 | + private static bool CheckHorizontalDatum(IHorizontalDatum datum, string name, string authority, long? code) |
| 393 | + { |
| 394 | + Assert.That(datum, Is.Not.Null); |
| 395 | + Assert.That(CheckInfo(datum, name,authority, code), Is.True); |
| 396 | + |
| 397 | + return true; |
| 398 | + } |
| 399 | + |
| 400 | + private static bool CheckInfo(IInfo info, string name, string authority, long? code) |
| 401 | + { |
| 402 | + Assert.That(info, Is.Not.Null); |
| 403 | + if (!string.IsNullOrEmpty(name)) Assert.That(info.Name, Is.EqualTo(name)); |
| 404 | + if (!string.IsNullOrEmpty(authority)) Assert.That(info.Authority, Is.EqualTo(authority)); |
| 405 | + if (code.HasValue) Assert.That(info.AuthorityCode, Is.EqualTo(code)); |
| 406 | + |
| 407 | + return true; |
| 408 | + } |
326 | 409 | }
|
327 | 410 | }
|
0 commit comments