WKTCoordSysParserTests.cs
上传用户:sex100000
上传日期:2013-11-09
资源大小:1377k
文件大小:7k
源码类别:

GIS编程

开发平台:

C#

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using SharpMap.Converters.WellKnownText;
  5. using SharpMap.CoordinateSystems;
  6. using NUnit.Framework;
  7. namespace UnitTests.Converters.WKT
  8. {
  9. [TestFixture]
  10. public class WKTCoordSysParserTests
  11. {
  12. /// <summary>
  13. /// Parses a coordinate system WKTs
  14. /// </summary>
  15. /// <remarks><code>
  16. /// PROJCS["NAD83(HARN) / Texas Central (ftUS)",
  17. ///  GEOGCS[
  18. ///  "NAD83(HARN)",
  19. ///  DATUM[
  20. ///  "NAD83_High_Accuracy_Regional_Network",
  21. ///  SPHEROID[
  22. ///  "GRS 1980",
  23. ///  6378137,
  24. ///  298.257222101,
  25. ///  AUTHORITY["EPSG","7019"]
  26. ///  ],
  27. /// TOWGS84[725,685,536,0,0,0,0],
  28. ///  AUTHORITY["EPSG","6152"]
  29. ///  ],
  30. ///  PRIMEM[
  31. ///  "Greenwich",
  32. ///  0,
  33. ///  AUTHORITY["EPSG","8901"]
  34. ///  ],
  35. ///  UNIT[
  36. ///  "degree",
  37. ///  0.01745329251994328,
  38. ///  AUTHORITY["EPSG","9122"]
  39. ///  ],
  40. ///  AUTHORITY["EPSG","4152"]
  41. ///  ],
  42. ///  PROJECTION["Lambert_Conformal_Conic_2SP"],
  43. ///  PARAMETER["standard_parallel_1",31.88333333333333],
  44. ///  PARAMETER["standard_parallel_2",30.11666666666667],
  45. ///  PARAMETER["latitude_of_origin",29.66666666666667],
  46. ///  PARAMETER["central_meridian",-100.3333333333333],
  47. ///  PARAMETER["false_easting",2296583.333],
  48. ///  PARAMETER["false_northing",9842500.000000002],
  49. ///  UNIT[
  50. ///  "US survey foot",
  51. ///  0.3048006096012192,
  52. ///  AUTHORITY["EPSG","9003"]
  53. ///  ],
  54. ///  AUTHORITY["EPSG","2918"]
  55. /// ]
  56. /// </code></remarks>
  57. [Test]
  58. public void ParseCoordSys()
  59. {
  60. CoordinateSystemFactory fac = new CoordinateSystemFactory();
  61. string wkt = "PROJCS["NAD83(HARN) / Texas Central (ftUS)", GEOGCS["NAD83(HARN)", DATUM["NAD83_High_Accuracy_Regional_Network", SPHEROID["GRS 1980", 6378137, 298.257222101, AUTHORITY["EPSG", "7019"]], TOWGS84[725, 685, 536, 0, 0, 0, 0], AUTHORITY["EPSG", "6152"]], PRIMEM["Greenwich", 0, AUTHORITY["EPSG", "8901"]], UNIT["degree", 0.0174532925199433, AUTHORITY["EPSG", "9122"]], AUTHORITY["EPSG", "4152"]], PROJECTION["Lambert_Conformal_Conic_2SP"], PARAMETER["standard_parallel_1", 31.883333333333], PARAMETER["standard_parallel_2", 30.1166666667], PARAMETER["latitude_of_origin", 29.6666666667], PARAMETER["central_meridian", -100.333333333333], PARAMETER["false_easting", 2296583.333], PARAMETER["false_northing", 9842500], UNIT["US survey foot", 0.304800609601219, AUTHORITY["EPSG", "9003"]], AUTHORITY["EPSG", "2918"]]";
  62. ProjectedCoordinateSystem pcs = CoordinateSystemWktReader.Parse(wkt) as ProjectedCoordinateSystem;
  63. Assert.IsNotNull(pcs, "Could not parse WKT: " + wkt);
  64. Assert.AreEqual("NAD83(HARN) / Texas Central (ftUS)", pcs.Name);
  65. Assert.AreEqual("NAD83(HARN)", pcs.GeographicCoordinateSystem.Name);
  66. Assert.AreEqual("NAD83_High_Accuracy_Regional_Network", pcs.GeographicCoordinateSystem.HorizontalDatum.Name);
  67. Assert.AreEqual("GRS 1980", pcs.GeographicCoordinateSystem.HorizontalDatum.Ellipsoid.Name);
  68. Assert.AreEqual(6378137, pcs.GeographicCoordinateSystem.HorizontalDatum.Ellipsoid.SemiMajorAxis);
  69. Assert.AreEqual(298.257222101, pcs.GeographicCoordinateSystem.HorizontalDatum.Ellipsoid.InverseFlattening);
  70. Assert.AreEqual("EPSG", pcs.GeographicCoordinateSystem.HorizontalDatum.Ellipsoid.Authority);
  71. Assert.AreEqual(7019, pcs.GeographicCoordinateSystem.HorizontalDatum.Ellipsoid.AuthorityCode);
  72. Assert.AreEqual("EPSG", pcs.GeographicCoordinateSystem.HorizontalDatum.Authority);
  73. Assert.AreEqual(6152, pcs.GeographicCoordinateSystem.HorizontalDatum.AuthorityCode);
  74. Assert.AreEqual(new Wgs84ConversionInfo(725,685,536,0,0,0,0), pcs.GeographicCoordinateSystem.HorizontalDatum.Wgs84Parameters);
  75. Assert.AreEqual("Greenwich", pcs.GeographicCoordinateSystem.PrimeMeridian.Name);
  76. Assert.AreEqual(0, pcs.GeographicCoordinateSystem.PrimeMeridian.Longitude);
  77. Assert.AreEqual("EPSG", pcs.GeographicCoordinateSystem.PrimeMeridian.Authority);
  78. Assert.AreEqual(8901, pcs.GeographicCoordinateSystem.PrimeMeridian.AuthorityCode, 8901);
  79. Assert.AreEqual("degree", pcs.GeographicCoordinateSystem.AngularUnit.Name);
  80. Assert.AreEqual(0.0174532925199433, pcs.GeographicCoordinateSystem.AngularUnit.RadiansPerUnit);
  81. Assert.AreEqual("EPSG", pcs.GeographicCoordinateSystem.AngularUnit.Authority);
  82. Assert.AreEqual(9122, pcs.GeographicCoordinateSystem.AngularUnit.AuthorityCode);
  83. Assert.AreEqual("EPSG", pcs.GeographicCoordinateSystem.Authority);
  84. Assert.AreEqual(4152, pcs.GeographicCoordinateSystem.AuthorityCode, 4152);
  85. Assert.AreEqual("Lambert_Conformal_Conic_2SP", pcs.Projection.ClassName, "Projection Classname");
  86. ProjectionParameter latitude_of_origin = pcs.Projection.GetParameter("latitude_of_origin");
  87. Assert.IsNotNull(latitude_of_origin);
  88. Assert.AreEqual(29.6666666667, latitude_of_origin.Value);
  89. ProjectionParameter central_meridian = pcs.Projection.GetParameter("central_meridian");
  90. Assert.IsNotNull(central_meridian);
  91. Assert.AreEqual(-100.333333333333, central_meridian.Value);
  92. ProjectionParameter standard_parallel_1 = pcs.Projection.GetParameter("standard_parallel_1");
  93. Assert.IsNotNull(standard_parallel_1);
  94. Assert.AreEqual(31.883333333333, standard_parallel_1.Value);
  95. ProjectionParameter standard_parallel_2 = pcs.Projection.GetParameter("standard_parallel_2");
  96. Assert.IsNotNull(standard_parallel_2);
  97. Assert.AreEqual(30.1166666667, standard_parallel_2.Value);
  98. ProjectionParameter false_easting = pcs.Projection.GetParameter("false_easting");
  99. Assert.IsNotNull(false_easting);
  100. Assert.AreEqual(2296583.333, false_easting.Value);
  101. ProjectionParameter false_northing = pcs.Projection.GetParameter("false_northing");
  102. Assert.IsNotNull(false_northing);
  103. Assert.AreEqual(9842500, false_northing.Value);
  104. Assert.AreEqual("US survey foot", pcs.LinearUnit.Name);
  105. Assert.AreEqual(0.304800609601219, pcs.LinearUnit.MetersPerUnit);
  106. Assert.AreEqual("EPSG", pcs.LinearUnit.Authority);
  107. Assert.AreEqual(9003, pcs.LinearUnit.AuthorityCode);
  108. Assert.AreEqual("EPSG", pcs.Authority);
  109. Assert.AreEqual(2918, pcs.AuthorityCode);
  110. Assert.AreEqual(wkt, pcs.WKT);
  111. }
  112. [Test]
  113. public void ParseAllWKTs()
  114. {
  115. CoordinateSystemFactory fac = new CoordinateSystemFactory();
  116. int parsecount = 0;
  117. System.IO.StreamReader sr = System.IO.File.OpenText(@"....SharpMapSRID.csv");
  118. string line = "";
  119. while (!sr.EndOfStream)
  120. {
  121. line = sr.ReadLine();
  122. int split = line.IndexOf(';');
  123. if (split > -1)
  124. {
  125. string srid = line.Substring(0, split);
  126. string wkt = line.Substring(split + 1);
  127. ICoordinateSystem cs = SharpMap.Converters.WellKnownText.CoordinateSystemWktReader.Parse(wkt) as ICoordinateSystem;
  128. Assert.IsNotNull(cs,"Could not parse WKT: " + wkt);
  129. parsecount++;
  130. }
  131. }
  132. sr.Close();
  133. Assert.AreEqual(parsecount, 2671, "Not all WKT was parsed");
  134. }
  135. }
  136. }