/// <summary> /// /// </summary> /// <param name="tokenizer"></param> /// <returns></returns> private static GeoAPI.CoordinateSystems.IGeographicCoordinateSystem ReadGeographicCoordinateSystem(GisSharpBlog.NetTopologySuite.IO.WktStreamTokenizer tokenizer) { /* * GEOGCS["OSGB 1936", * DATUM["OSGB 1936",SPHEROID["Airy 1830",6377563.396,299.3249646,AUTHORITY["EPSG","7001"]]TOWGS84[0,0,0,0,0,0,0],AUTHORITY["EPSG","6277"]] * PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]] * AXIS["Geodetic latitude","NORTH"] * AXIS["Geodetic longitude","EAST"] * AUTHORITY["EPSG","4277"] * ] */ tokenizer.ReadToken("["); string name = tokenizer.ReadDoubleQuotedWord(); tokenizer.ReadToken(","); tokenizer.ReadToken("DATUM"); GeoAPI.CoordinateSystems.IHorizontalDatum horizontalDatum = ReadHorizontalDatum(tokenizer); tokenizer.ReadToken(","); tokenizer.ReadToken("PRIMEM"); GeoAPI.CoordinateSystems.IPrimeMeridian primeMeridian = ReadPrimeMeridian(tokenizer); tokenizer.ReadToken(","); tokenizer.ReadToken("UNIT"); GeoAPI.CoordinateSystems.IUnit angularUnit = ReadUnit(tokenizer); tokenizer.ReadToken(","); string authority = String.Empty; long authorityCode = -1; tokenizer.ReadAuthority(ref authority, ref authorityCode); tokenizer.ReadToken("]"); GeoAPI.CoordinateSystems.IGeographicCoordinateSystem geographicCS = new GeographicCoordinateSystem(angularUnit as GeoAPI.CoordinateSystems.IAngularUnit, horizontalDatum, primeMeridian, new List <GeoAPI.CoordinateSystems.AxisInfo>(), name, authority, authorityCode, String.Empty, String.Empty, String.Empty); return(geographicCS); }
/// <summary> /// Returns a IUnit given a piece of WKT. /// </summary> /// <param name="tokenizer">WktStreamTokenizer that has the WKT.</param> /// <returns>An object that implements the IUnit interface.</returns> private static GeoAPI.CoordinateSystems.IUnit ReadUnit(GisSharpBlog.NetTopologySuite.IO.WktStreamTokenizer tokenizer) { //UNIT["degree",0.01745329251994433,AUTHORITY["EPSG","9102"]] GeoAPI.CoordinateSystems.IUnit unit = null; tokenizer.ReadToken("["); string unitName = tokenizer.ReadDoubleQuotedWord(); tokenizer.ReadToken(","); tokenizer.NextToken(); double unitsPerUnit = tokenizer.GetNumericValue(); tokenizer.ReadToken(","); string authority = String.Empty; long authorityCode = -1; tokenizer.ReadAuthority(ref authority, ref authorityCode); tokenizer.ReadToken("]"); switch (unitName) { // take into account the different spellings of the word meter/metre. case "meter": case "metre": unit = new LinearUnit(unitsPerUnit, String.Empty, authority, authorityCode, unitName, String.Empty, String.Empty); break; case "degree": case "radian": unit = new AngularUnit(unitsPerUnit, String.Empty, authority, authorityCode, unitName, String.Empty, String.Empty); break; default: throw new NotImplementedException(String.Format("{0} is not recognized is a unit of measure.", unitName)); } return(unit); }
/// <summary> /// /// </summary> /// <param name="tokenizer"></param> /// <returns></returns> private static GeoAPI.CoordinateSystems.IProjectedCoordinateSystem ReadProjectedCoordinateSystem(GisSharpBlog.NetTopologySuite.IO.WktStreamTokenizer tokenizer) { /* PROJCS[ * "OSGB 1936 / British National Grid", * GEOGCS[ * "OSGB 1936", * DATUM[...] * PRIMEM[...] * AXIS["Geodetic latitude","NORTH"] * AXIS["Geodetic longitude","EAST"] * AUTHORITY["EPSG","4277"] * ], * PROJECTION["Transverse Mercator"], * PARAMETER["latitude_of_natural_origin",49], * PARAMETER["longitude_of_natural_origin",-2], * PARAMETER["scale_factor_at_natural_origin",0.999601272], * PARAMETER["false_easting",400000], * PARAMETER["false_northing",-100000], * AXIS["Easting","EAST"], * AXIS["Northing","NORTH"], * AUTHORITY["EPSG","27700"] * ] */ tokenizer.ReadToken("["); string name = tokenizer.ReadDoubleQuotedWord(); tokenizer.ReadToken(","); tokenizer.ReadToken("GEOGCS"); GeoAPI.CoordinateSystems.IGeographicCoordinateSystem geographicCS = ReadGeographicCoordinateSystem(tokenizer); tokenizer.ReadToken(","); GeoAPI.CoordinateSystems.IProjection projection = ReadProjection(tokenizer); GeoAPI.CoordinateSystems.IUnit unit = ReadUnit(tokenizer); tokenizer.ReadToken(","); string authority = String.Empty; long authorityCode = -1; tokenizer.ReadAuthority(ref authority, ref authorityCode); tokenizer.ReadToken("]"); List <GeoAPI.CoordinateSystems.AxisInfo> axes = new List <GeoAPI.CoordinateSystems.AxisInfo>(); GeoAPI.CoordinateSystems.IProjectedCoordinateSystem projectedCS = new ProjectedCoordinateSystem(geographicCS.HorizontalDatum, geographicCS, unit as LinearUnit, projection, axes, name, authority, authorityCode, String.Empty, String.Empty, String.Empty); return(projectedCS); }