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

GIS编程

开发平台:

C#

  1. // Copyright 2005, 2006 - Morten Nielsen (www.iter.dk)
  2. //
  3. // This file is part of SharpMap.
  4. // SharpMap is free software; you can redistribute it and/or modify
  5. // it under the terms of the GNU Lesser General Public License as published by
  6. // the Free Software Foundation; either version 2 of the License, or
  7. // (at your option) any later version.
  8. // 
  9. // SharpMap is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. // GNU Lesser General Public License for more details.
  13. // You should have received a copy of the GNU Lesser General Public License
  14. // along with SharpMap; if not, write to the Free Software
  15. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
  16. // SOURCECODE IS MODIFIED FROM ANOTHER WORK AND IS ORIGINALLY BASED ON GeoTools.NET:
  17. /*
  18.  *  Copyright (C) 2002 Urban Science Applications, Inc. 
  19.  *
  20.  *  This library is free software; you can redistribute it and/or
  21.  *  modify it under the terms of the GNU Lesser General Public
  22.  *  License as published by the Free Software Foundation; either
  23.  *  version 2.1 of the License, or (at your option) any later version.
  24.  *
  25.  *  This library is distributed in the hope that it will be useful,
  26.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  27.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  28.  *  Lesser General Public License for more details.
  29.  *
  30.  *  You should have received a copy of the GNU Lesser General Public
  31.  *  License along with this library; if not, write to the Free Software
  32.  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  33.  *
  34.  */
  35. using System;
  36. using System.IO;
  37. using System.Collections.Generic;
  38. using System.Collections.ObjectModel;
  39. using SharpMap.CoordinateSystems;
  40. namespace SharpMap.Converters.WellKnownText
  41. {
  42. /// <summary>
  43. /// Creates an object based on the supplied Well Known Text (WKT).
  44. /// </summary>
  45. public class CoordinateSystemWktReader
  46. {
  47. /// <summary>
  48. /// Reads and parses a WKT-formatted projection string.
  49. /// </summary>
  50. /// <param name="wkt">String containing WKT.</param>
  51. /// <returns>Object representation of the WKT.</returns>
  52. /// <exception cref="System.ArgumentException">If a token is not recognised.</exception>
  53. public static IInfo Parse(string wkt)
  54. {
  55. IInfo returnObject = null;
  56. StringReader reader = new StringReader(wkt);
  57. WktStreamTokenizer tokenizer = new WktStreamTokenizer(reader);
  58. tokenizer.NextToken();
  59. string objectName = tokenizer.GetStringValue();
  60. switch (objectName)
  61. {
  62. case "UNIT":
  63. returnObject = ReadUnit(tokenizer);
  64. break;
  65. //case "VERT_DATUM":
  66. //    IVerticalDatum verticalDatum = ReadVerticalDatum(tokenizer);
  67. //    returnObject = verticalDatum;
  68. //    break;
  69. case "SPHEROID":
  70. returnObject = ReadEllipsoid(tokenizer);
  71. break;
  72. case "DATUM":
  73. returnObject = ReadHorizontalDatum(tokenizer); ;
  74. break;
  75. case "PRIMEM":
  76. returnObject = ReadPrimeMeridian(tokenizer);
  77. break;
  78. case "VERT_CS":
  79. case "GEOGCS":
  80. case "PROJCS":
  81. case "COMPD_CS":
  82. case "GEOCCS":
  83. case "FITTED_CS":
  84. case "LOCAL_CS":
  85. returnObject = ReadCoordinateSystem(wkt, tokenizer);
  86. break;
  87. default:
  88. throw new ArgumentException(String.Format("'{0'} is not recongnized.", objectName));
  89. }
  90. reader.Close();
  91. return returnObject;
  92. }
  93. /// <summary>
  94. /// Returns a IUnit given a piece of WKT.
  95. /// </summary>
  96. /// <param name="tokenizer">WktStreamTokenizer that has the WKT.</param>
  97. /// <returns>An object that implements the IUnit interface.</returns>
  98. private static IUnit ReadUnit(WktStreamTokenizer tokenizer)
  99. {
  100. tokenizer.ReadToken("[");
  101. string unitName = tokenizer.ReadDoubleQuotedWord();
  102. tokenizer.ReadToken(",");
  103. tokenizer.NextToken();
  104. double unitsPerUnit = tokenizer.GetNumericValue();
  105. string authority = String.Empty;
  106. long authorityCode = -1;
  107. tokenizer.NextToken();
  108. if (tokenizer.GetStringValue() == ",")
  109. {
  110. tokenizer.ReadAuthority(ref authority, ref authorityCode);
  111. tokenizer.ReadToken("]");
  112. }
  113. return new Unit(unitsPerUnit, unitName, authority, authorityCode, String.Empty, String.Empty, String.Empty);
  114. }
  115. /// <summary>
  116. /// Returns a <see cref="LinearUnit"/> given a piece of WKT.
  117. /// </summary>
  118. /// <param name="tokenizer">WktStreamTokenizer that has the WKT.</param>
  119. /// <returns>An object that implements the IUnit interface.</returns>
  120. private static ILinearUnit ReadLinearUnit(WktStreamTokenizer tokenizer)
  121. {
  122. tokenizer.ReadToken("[");
  123. string unitName = tokenizer.ReadDoubleQuotedWord();
  124. tokenizer.ReadToken(",");
  125. tokenizer.NextToken();
  126. double unitsPerUnit = tokenizer.GetNumericValue();
  127. string authority = String.Empty;
  128. long authorityCode = -1;
  129. tokenizer.NextToken();
  130. if (tokenizer.GetStringValue() == ",")
  131. {
  132. tokenizer.ReadAuthority(ref authority, ref authorityCode);
  133. tokenizer.ReadToken("]");
  134. }
  135. return new LinearUnit(unitsPerUnit, unitName, authority, authorityCode, String.Empty, String.Empty, String.Empty);
  136. }
  137. /// <summary>
  138. /// Returns a <see cref="AngularUnit"/> given a piece of WKT.
  139. /// </summary>
  140. /// <param name="tokenizer">WktStreamTokenizer that has the WKT.</param>
  141. /// <returns>An object that implements the IUnit interface.</returns>
  142. private static IAngularUnit ReadAngularUnit(WktStreamTokenizer tokenizer)
  143. {
  144. tokenizer.ReadToken("[");
  145. string unitName = tokenizer.ReadDoubleQuotedWord();
  146. tokenizer.ReadToken(",");
  147. tokenizer.NextToken();
  148. double unitsPerUnit = tokenizer.GetNumericValue();
  149. string authority = String.Empty;
  150. long authorityCode = -1;
  151. tokenizer.NextToken();
  152. if (tokenizer.GetStringValue() == ",")
  153. {
  154. tokenizer.ReadAuthority(ref authority, ref authorityCode);
  155. tokenizer.ReadToken("]");
  156. }
  157. return new AngularUnit(unitsPerUnit, unitName, authority, authorityCode, String.Empty, String.Empty, String.Empty);
  158. }
  159. /// <summary>
  160. /// Returns a <see cref="AxisInfo"/> given a piece of WKT.
  161. /// </summary>
  162. /// <param name="tokenizer">WktStreamTokenizer that has the WKT.</param>
  163. /// <returns>An AxisInfo object.</returns>
  164. private static AxisInfo ReadAxis(WktStreamTokenizer tokenizer)
  165. {
  166. if (tokenizer.GetStringValue() != "AXIS")
  167. tokenizer.ReadToken("AXIS");
  168. tokenizer.ReadToken("[");
  169. string axisName = tokenizer.ReadDoubleQuotedWord();
  170. tokenizer.ReadToken(",");
  171. tokenizer.NextToken();
  172. string unitname = tokenizer.GetStringValue();
  173. tokenizer.ReadToken("]");
  174. switch (unitname.ToUpper())
  175. {
  176. case "DOWN": return new AxisInfo(axisName, AxisOrientationEnum.Down);
  177. case "EAST": return new AxisInfo(axisName, AxisOrientationEnum.East);
  178. case "NORTH": return new AxisInfo(axisName, AxisOrientationEnum.North);
  179. case "OTHER": return new AxisInfo(axisName, AxisOrientationEnum.Other);
  180. case "SOUTH": return new AxisInfo(axisName, AxisOrientationEnum.South);
  181. case "UP": return new AxisInfo(axisName, AxisOrientationEnum.Up);
  182. case "WEST": return new AxisInfo(axisName, AxisOrientationEnum.West);
  183. default:
  184. throw new ArgumentException("Invalid axis name '" + unitname + "' in WKT");
  185. }
  186. }
  187. /// <summary>
  188. /// 
  189. /// </summary>
  190. /// <param name="coordinateSystem"></param>
  191. /// <param name="tokenizer"></param>
  192. /// <returns></returns>
  193. private static ICoordinateSystem ReadCoordinateSystem(string coordinateSystem, WktStreamTokenizer tokenizer)
  194. {
  195. switch (tokenizer.GetStringValue())
  196. {
  197. case "GEOGCS":
  198. return ReadGeographicCoordinateSystem(tokenizer);
  199. case "PROJCS":
  200. return ReadProjectedCoordinateSystem(tokenizer);
  201. case "COMPD_CS":
  202. /* ICompoundCoordinateSystem compoundCS = ReadCompoundCoordinateSystem(tokenizer);
  203. returnCS = compoundCS;
  204. break;*/
  205. case "VERT_CS":
  206. /* IVerticalCoordinateSystem verticalCS = ReadVerticalCoordinateSystem(tokenizer);
  207. returnCS = verticalCS;
  208. break;*/
  209. case "GEOCCS":
  210. case "FITTED_CS":
  211. case "LOCAL_CS":
  212. throw new NotSupportedException(String.Format("{0} coordinate system is not supported.", coordinateSystem));
  213. default:
  214. throw new InvalidOperationException(String.Format("{0} coordinate system is not recognized.", coordinateSystem));
  215. }
  216. }
  217. /// <summary>
  218. /// Reads either 3, 6 or 7 parameter Bursa-Wolf values from TOWGS84 token
  219. /// </summary>
  220. /// <param name="tokenizer"></param>
  221. /// <returns></returns>
  222. private static Wgs84ConversionInfo ReadWGS84ConversionInfo(WktStreamTokenizer tokenizer)
  223. {
  224. //TOWGS84[0,0,0,0,0,0,0]
  225. tokenizer.ReadToken("[");
  226. Wgs84ConversionInfo info = new Wgs84ConversionInfo();
  227. tokenizer.NextToken();
  228. info.Dx = tokenizer.GetNumericValue();
  229. tokenizer.ReadToken(",");
  230. tokenizer.NextToken();
  231. info.Dy = tokenizer.GetNumericValue();
  232. tokenizer.ReadToken(",");
  233. tokenizer.NextToken();
  234. info.Dz = tokenizer.GetNumericValue();
  235. tokenizer.NextToken();
  236. if (tokenizer.GetStringValue() == ",")
  237. {
  238. tokenizer.NextToken();
  239. info.Ex = tokenizer.GetNumericValue();
  240. tokenizer.ReadToken(",");
  241. tokenizer.NextToken();
  242. info.Ey = tokenizer.GetNumericValue();
  243. tokenizer.ReadToken(",");
  244. tokenizer.NextToken();
  245. info.Ez = tokenizer.GetNumericValue();
  246. tokenizer.NextToken();
  247. if (tokenizer.GetStringValue() == ",")
  248. {
  249. tokenizer.NextToken();
  250. info.Ppm = tokenizer.GetNumericValue();
  251. }
  252. }
  253. if (tokenizer.GetStringValue() != "]")
  254. tokenizer.ReadToken("]");
  255. return info;
  256. }
  257. /*
  258. /// <summary>
  259. /// 
  260. /// </summary>
  261. /// <param name="tokenizer"></param>
  262. /// <returns></returns>
  263. private static ICompoundCoordinateSystem ReadCompoundCoordinateSystem(WktStreamTokenizer tokenizer)
  264. {
  265. //COMPD_CS[
  266. //"OSGB36 / British National Grid + ODN",
  267. //PROJCS[]
  268. //VERT_CS[]
  269. //AUTHORITY["EPSG","7405"]
  270. //]
  271. tokenizer.ReadToken("[");
  272. string name=tokenizer.ReadDoubleQuotedWord();
  273. tokenizer.ReadToken(",");
  274. tokenizer.NextToken();
  275. string headCSCode =  tokenizer.GetStringValue();
  276. ICoordinateSystem headCS = ReadCoordinateSystem(headCSCode,tokenizer);
  277. tokenizer.ReadToken(",");
  278. tokenizer.NextToken();
  279. string tailCSCode =  tokenizer.GetStringValue();
  280. ICoordinateSystem tailCS = ReadCoordinateSystem(tailCSCode,tokenizer);
  281. tokenizer.ReadToken(",");
  282. string authority=String.Empty;
  283. string authorityCode=String.Empty; 
  284. tokenizer.ReadAuthority(ref authority, ref authorityCode);
  285. tokenizer.ReadToken("]");
  286. ICompoundCoordinateSystem compoundCS = new CompoundCoordinateSystem(headCS,tailCS,String.Empty,authority,authorityCode,name,String.Empty,String.Empty); 
  287. return compoundCS;
  288. }*/
  289. /// <summary>
  290. /// 
  291. /// </summary>
  292. /// <param name="tokenizer"></param>
  293. /// <returns></returns>
  294. private static IEllipsoid ReadEllipsoid(WktStreamTokenizer tokenizer)
  295. {
  296. //SPHEROID["Airy 1830",6377563.396,299.3249646,AUTHORITY["EPSG","7001"]]
  297. tokenizer.ReadToken("[");
  298. string name = tokenizer.ReadDoubleQuotedWord();
  299. tokenizer.ReadToken(",");
  300. tokenizer.NextToken();
  301. double majorAxis = tokenizer.GetNumericValue();
  302. tokenizer.ReadToken(",");
  303. tokenizer.NextToken();
  304. double e = tokenizer.GetNumericValue();
  305. //
  306. //tokenizer.ReadToken(",");
  307. tokenizer.NextToken();
  308. string authority = String.Empty;
  309. long authorityCode = -1;
  310. if (tokenizer.GetStringValue() == ",") //Read authority
  311. {
  312. tokenizer.ReadAuthority(ref authority, ref authorityCode);
  313. tokenizer.ReadToken("]");
  314. }
  315. IEllipsoid ellipsoid = new Ellipsoid(majorAxis, 0.0, e, true, LinearUnit.Metre, name, authority, authorityCode, String.Empty, string.Empty, string.Empty);
  316. return ellipsoid;
  317. }
  318. /// <summary>
  319. /// 
  320. /// </summary>
  321. /// <param name="tokenizer"></param>
  322. /// <returns></returns>
  323. private static IProjection ReadProjection(WktStreamTokenizer tokenizer)
  324. {
  325. //tokenizer.NextToken();// PROJECTION
  326. tokenizer.ReadToken("PROJECTION");
  327. tokenizer.ReadToken("[");//[
  328. string projectionName = tokenizer.ReadDoubleQuotedWord();
  329. tokenizer.ReadToken("]");//]
  330. tokenizer.ReadToken(",");//,
  331. tokenizer.ReadToken("PARAMETER");
  332. Collection<ProjectionParameter> paramList = new Collection<ProjectionParameter>();
  333. while (tokenizer.GetStringValue() == "PARAMETER")
  334. {
  335. tokenizer.ReadToken("[");
  336. string paramName = tokenizer.ReadDoubleQuotedWord();
  337. tokenizer.ReadToken(",");
  338. tokenizer.NextToken();
  339. double paramValue = tokenizer.GetNumericValue();
  340. tokenizer.ReadToken("]");
  341. tokenizer.ReadToken(",");
  342. paramList.Add(new ProjectionParameter(paramName, paramValue));
  343. tokenizer.NextToken();
  344. }
  345. string authority = String.Empty;
  346. long authorityCode = -1;
  347. IProjection projection = new Projection(projectionName, paramList, projectionName, authority, authorityCode, String.Empty, String.Empty, string.Empty);
  348. return projection;
  349. }
  350. /// <summary>
  351. /// 
  352. /// </summary>
  353. /// <param name="tokenizer"></param>
  354. /// <returns></returns>
  355. private static IProjectedCoordinateSystem ReadProjectedCoordinateSystem(WktStreamTokenizer tokenizer)
  356. {
  357. /*PROJCS[
  358. "OSGB 1936 / British National Grid",
  359. GEOGCS[
  360. "OSGB 1936",
  361. DATUM[...]
  362. PRIMEM[...]
  363. AXIS["Geodetic latitude","NORTH"]
  364. AXIS["Geodetic longitude","EAST"]
  365. AUTHORITY["EPSG","4277"]
  366. ],
  367. PROJECTION["Transverse Mercator"],
  368. PARAMETER["latitude_of_natural_origin",49],
  369. PARAMETER["longitude_of_natural_origin",-2],
  370. PARAMETER["scale_factor_at_natural_origin",0.999601272],
  371. PARAMETER["false_easting",400000],
  372. PARAMETER["false_northing",-100000],
  373. AXIS["Easting","EAST"],
  374. AXIS["Northing","NORTH"],
  375. AUTHORITY["EPSG","27700"]
  376. ]
  377. */
  378. tokenizer.ReadToken("[");
  379. string name = tokenizer.ReadDoubleQuotedWord();
  380. tokenizer.ReadToken(",");
  381. tokenizer.ReadToken("GEOGCS");
  382. IGeographicCoordinateSystem geographicCS = ReadGeographicCoordinateSystem(tokenizer);
  383. tokenizer.ReadToken(",");
  384. IProjection projection = ReadProjection(tokenizer);
  385. IUnit unit = ReadLinearUnit(tokenizer);
  386. string authority = String.Empty;
  387. long authorityCode = -1;
  388. tokenizer.NextToken();
  389.             //Collection<AxisInfo> axes = new Collection<AxisInfo>(2);
  390.             Collection<AxisInfo> axes = new Collection<AxisInfo>();
  391. if (tokenizer.GetStringValue() == ",")
  392. {
  393. tokenizer.NextToken();
  394. while (tokenizer.GetStringValue() == "AXIS")
  395. {
  396. axes.Add(ReadAxis(tokenizer));
  397. tokenizer.NextToken();
  398. }
  399. if (tokenizer.GetStringValue() == "AUTHORITY")
  400. {
  401. tokenizer.ReadAuthority(ref authority, ref authorityCode);
  402. tokenizer.ReadToken("]");
  403. }
  404. }
  405. //This is default axis values if not specified.
  406. if (axes.Count == 0)
  407. {
  408. axes.Add(new AxisInfo("X", AxisOrientationEnum.East));
  409. axes.Add(new AxisInfo("Y", AxisOrientationEnum.North));
  410. }
  411. IProjectedCoordinateSystem projectedCS = new ProjectedCoordinateSystem(geographicCS.HorizontalDatum, geographicCS, unit as LinearUnit, projection, axes, name, authority, authorityCode, String.Empty, String.Empty, String.Empty);
  412. return projectedCS;
  413. }
  414. /// <summary>
  415. /// 
  416. /// </summary>
  417. /// <param name="tokenizer"></param>
  418. /// <returns></returns>
  419. private static IGeographicCoordinateSystem ReadGeographicCoordinateSystem(WktStreamTokenizer tokenizer)
  420. {
  421. /*
  422. GEOGCS["OSGB 1936",
  423. DATUM["OSGB 1936",SPHEROID["Airy 1830",6377563.396,299.3249646,AUTHORITY["EPSG","7001"]]TOWGS84[0,0,0,0,0,0,0],AUTHORITY["EPSG","6277"]]
  424. PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]]
  425. AXIS["Geodetic latitude","NORTH"]
  426. AXIS["Geodetic longitude","EAST"]
  427. AUTHORITY["EPSG","4277"]
  428. ]
  429. */
  430. tokenizer.ReadToken("[");
  431. string name = tokenizer.ReadDoubleQuotedWord();
  432. tokenizer.ReadToken(",");
  433. tokenizer.ReadToken("DATUM");
  434. IHorizontalDatum horizontalDatum = ReadHorizontalDatum(tokenizer);
  435. tokenizer.ReadToken(",");
  436. tokenizer.ReadToken("PRIMEM");
  437. IPrimeMeridian primeMeridian = ReadPrimeMeridian(tokenizer);
  438. tokenizer.ReadToken(",");
  439. tokenizer.ReadToken("UNIT");
  440. IAngularUnit angularUnit = ReadAngularUnit(tokenizer);
  441. string authority = String.Empty;
  442. long authorityCode = -1;
  443. tokenizer.NextToken();
  444.             //Collection<AxisInfo> info = new Collection<AxisInfo>(2);
  445.             Collection<AxisInfo> info = new Collection<AxisInfo>();
  446. if (tokenizer.GetStringValue() == ",")
  447. {
  448. tokenizer.NextToken();
  449. while (tokenizer.GetStringValue() == "AXIS")
  450. {
  451. info.Add(ReadAxis(tokenizer));
  452. tokenizer.NextToken();
  453. }
  454. if (tokenizer.GetStringValue() == "AUTHORITY")
  455. {
  456. tokenizer.ReadAuthority(ref authority, ref authorityCode);
  457. tokenizer.ReadToken("]");
  458. }
  459. }
  460. //This is default axis values if not specified.
  461. if (info.Count == 0)
  462. {
  463. info.Add(new AxisInfo("Lon", AxisOrientationEnum.East));
  464. info.Add(new AxisInfo("Lat", AxisOrientationEnum.North));
  465. }
  466. IGeographicCoordinateSystem geographicCS = new GeographicCoordinateSystem(angularUnit, horizontalDatum,
  467. primeMeridian, info, name, authority, authorityCode, String.Empty, String.Empty, String.Empty);
  468. return geographicCS;
  469. }
  470. /// <summary>
  471. /// 
  472. /// </summary>
  473. /// <param name="tokenizer"></param>
  474. /// <returns></returns>
  475. private static IHorizontalDatum ReadHorizontalDatum(WktStreamTokenizer tokenizer)
  476. {
  477. //DATUM["OSGB 1936",SPHEROID["Airy 1830",6377563.396,299.3249646,AUTHORITY["EPSG","7001"]]TOWGS84[0,0,0,0,0,0,0],AUTHORITY["EPSG","6277"]]
  478. Wgs84ConversionInfo wgsInfo = null;
  479. string authority = String.Empty;
  480. long authorityCode = -1;
  481. tokenizer.ReadToken("[");
  482. string name = tokenizer.ReadDoubleQuotedWord();
  483. tokenizer.ReadToken(",");
  484. tokenizer.ReadToken("SPHEROID");
  485. IEllipsoid ellipsoid = ReadEllipsoid(tokenizer);
  486. tokenizer.NextToken();
  487. while (tokenizer.GetStringValue() == ",")
  488. {
  489. tokenizer.NextToken();
  490. if (tokenizer.GetStringValue() == "TOWGS84")
  491. {
  492. wgsInfo = ReadWGS84ConversionInfo(tokenizer);
  493. tokenizer.NextToken();
  494. }
  495. else if (tokenizer.GetStringValue() == "AUTHORITY")
  496. {
  497. tokenizer.ReadAuthority(ref authority, ref authorityCode);
  498. tokenizer.ReadToken("]");
  499. }
  500. }
  501. // make an assumption about the datum type.
  502. IHorizontalDatum horizontalDatum = new HorizontalDatum(ellipsoid, wgsInfo, DatumType.HD_Geocentric, name, authority, authorityCode, String.Empty, String.Empty, String.Empty);
  503. return horizontalDatum;
  504. }
  505. /// <summary>
  506. /// 
  507. /// </summary>
  508. /// <param name="tokenizer"></param>
  509. /// <returns></returns>
  510. private static IPrimeMeridian ReadPrimeMeridian(WktStreamTokenizer tokenizer)
  511. {
  512. //PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]]
  513. tokenizer.ReadToken("[");
  514. string name = tokenizer.ReadDoubleQuotedWord();
  515. tokenizer.ReadToken(",");
  516. tokenizer.NextToken();
  517. double longitude = tokenizer.GetNumericValue();
  518. tokenizer.NextToken();
  519. string authority = String.Empty;
  520. long authorityCode = -1;
  521. if (tokenizer.GetStringValue() == ",")
  522. {
  523. tokenizer.ReadAuthority(ref authority, ref authorityCode);
  524. tokenizer.ReadToken("]");
  525. }
  526. // make an assumption about the Angular units - degrees.
  527. IPrimeMeridian primeMeridian = new PrimeMeridian(longitude, AngularUnit.Degrees, name, authority, authorityCode, String.Empty, String.Empty, String.Empty);
  528. return primeMeridian;
  529. }
  530. /*
  531. /// <summary>
  532. /// 
  533. /// </summary>
  534. /// <param name="tokenizer"></param>
  535. /// <returns></returns>
  536. private static IVerticalCoordinateSystem ReadVerticalCoordinateSystem(WktStreamTokenizer tokenizer)
  537. {
  538. //VERT_CS["Newlyn",
  539. //VERT_DATUM["Ordnance Datum Newlyn",2005,AUTHORITY["EPSG","5101"]]
  540. //UNIT["metre",1,AUTHORITY["EPSG","9001"]]
  541. //AUTHORITY["EPSG","5701"]
  542. tokenizer.ReadToken("[");
  543. string name=tokenizer.ReadDoubleQuotedWord();
  544. tokenizer.ReadToken(",");
  545. tokenizer.ReadToken("VERT_DATUM");
  546. IVerticalDatum verticalDatum = ReadVerticalDatum(tokenizer);
  547. tokenizer.ReadToken("UNIT");
  548. IUnit unit = ReadUnit(tokenizer);
  549. string authority=String.Empty;
  550. string authorityCode=String.Empty; 
  551. tokenizer.ReadAuthority(ref authority, ref authorityCode);
  552. tokenizer.ReadToken("]");
  553. IVerticalCoordinateSystem verticalCS = new VerticalCoordinateSystem(name,verticalDatum,String.Empty,authority,authorityCode,String.Empty,String.Empty);
  554. return verticalCS;
  555. }*/
  556. /*
  557. /// <summary>
  558. /// 
  559. /// </summary>
  560. /// <param name="tokenizer"></param>
  561. /// <returns></returns>
  562. private static IVerticalDatum  ReadVerticalDatum(WktStreamTokenizer tokenizer)
  563. {
  564. //VERT_DATUM["Ordnance Datum Newlyn",2005,AUTHORITY["5101","EPSG"]]
  565. tokenizer.ReadToken("[");
  566. string datumName=tokenizer.ReadDoubleQuotedWord();
  567. tokenizer.ReadToken(",");
  568. tokenizer.NextToken();
  569. string datumTypeNumber = tokenizer.GetStringValue();
  570. tokenizer.ReadToken(",");
  571. string authority=String.Empty;
  572. string authorityCode=String.Empty; 
  573. tokenizer.ReadAuthority(ref authority, ref authorityCode);
  574. DatumType datumType = (DatumType)Enum.Parse(typeof(DatumType),datumTypeNumber);
  575. IVerticalDatum verticalDatum = new VerticalDatum(datumType,String.Empty,authorityCode,authority,datumName,String.Empty,String.Empty);
  576. tokenizer.ReadToken("]");
  577. return verticalDatum;
  578. }*/
  579. /*
  580. /// <summary>
  581. /// 
  582. /// </summary>
  583. /// <param name="tokenizer"></param>
  584. /// <returns></returns>
  585. [Obsolete("Since the related objects have not been implemented")]
  586. private static IGeocentricCoordinateSystem ReadGeocentricCoordinateSystem(WktStreamTokenizer tokenizer)
  587. {
  588. throw new NotImplementedException("IGeocentricCoordinateSystem is not implemented");
  589. }*/
  590. }
  591. }