private static IHorizontalDatum ReadHorizontalDatum(WktStreamTokenizer tokenizer) { //DATUM["OSGB 1936",SPHEROID["Airy 1830",6377563.396,299.3249646,AUTHORITY["EPSG","7001"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY["EPSG","6277"]] Wgs84ConversionInfo wgsInfo = null; string authority = String.Empty; long authorityCode = -1; tokenizer.ReadToken("["); string name = tokenizer.ReadDoubleQuotedWord(); tokenizer.ReadToken(","); tokenizer.ReadToken("SPHEROID"); IEllipsoid ellipsoid = ReadEllipsoid(tokenizer); tokenizer.NextToken(); while (tokenizer.GetStringValue() == ",") { tokenizer.NextToken(); if (tokenizer.GetStringValue() == "TOWGS84") { wgsInfo = ReadWGS84ConversionInfo(tokenizer); tokenizer.NextToken(); } else if (tokenizer.GetStringValue() == "AUTHORITY") { tokenizer.ReadAuthority(ref authority, ref authorityCode); tokenizer.ReadToken("]"); } } // make an assumption about the datum type. IHorizontalDatum horizontalDatum = new HorizontalDatum(ellipsoid, wgsInfo, DatumType.HD_Geocentric, name, authority, authorityCode, String.Empty, String.Empty, String.Empty); return(horizontalDatum); }
private static IEllipsoid ReadEllipsoid(WktStreamTokenizer tokenizer) { //SPHEROID["Airy 1830",6377563.396,299.3249646,AUTHORITY["EPSG","7001"]] tokenizer.ReadToken("["); string name = tokenizer.ReadDoubleQuotedWord(); tokenizer.ReadToken(","); tokenizer.NextToken(); double majorAxis = tokenizer.GetNumericValue(); tokenizer.ReadToken(","); tokenizer.NextToken(); double e = tokenizer.GetNumericValue(); tokenizer.NextToken(); string authority = String.Empty; long authorityCode = -1; if (tokenizer.GetStringValue() == ",") //Read authority { tokenizer.ReadAuthority(ref authority, ref authorityCode); tokenizer.ReadToken("]"); } IEllipsoid ellipsoid = new Ellipsoid(majorAxis, 0.0, e, true, LinearUnit.Metre, name, authority, authorityCode, String.Empty, string.Empty, string.Empty); return(ellipsoid); }
private static IFittedCoordinateSystem ReadFittedCoordinateSystem(WktStreamTokenizer tokenizer) { /* * FITTED_CS[ * "Local coordinate system MNAU (based on Gauss-Krueger)", * PARAM_MT[ * "Affine", * PARAMETER["num_row",3], * PARAMETER["num_col",3], * PARAMETER["elt_0_0", 0.883485346527455], * PARAMETER["elt_0_1", -0.468458794848877], * PARAMETER["elt_0_2", 3455869.17937689], * PARAMETER["elt_1_0", 0.468458794848877], * PARAMETER["elt_1_1", 0.883485346527455], * PARAMETER["elt_1_2", 5478710.88035753], * PARAMETER["elt_2_2", 1], * ], * PROJCS["DHDN / Gauss-Kruger zone 3", GEOGCS["DHDN", DATUM["Deutsches_Hauptdreiecksnetz", SPHEROID["Bessel 1841", 6377397.155, 299.1528128, AUTHORITY["EPSG", "7004"]], TOWGS84[612.4, 77, 440.2, -0.054, 0.057, -2.797, 0.525975255930096], AUTHORITY["EPSG", "6314"]], PRIMEM["Greenwich", 0, AUTHORITY["EPSG", "8901"]], UNIT["degree", 0.0174532925199433, AUTHORITY["EPSG", "9122"]], AUTHORITY["EPSG", "4314"]], UNIT["metre", 1, AUTHORITY["EPSG", "9001"]], PROJECTION["Transverse_Mercator"], PARAMETER["latitude_of_origin", 0], PARAMETER["central_meridian", 9], PARAMETER["scale_factor", 1], PARAMETER["false_easting", 3500000], PARAMETER["false_northing", 0], AUTHORITY["EPSG", "31467"]] * AUTHORITY["CUSTOM","12345"] * ] */ tokenizer.ReadToken("["); string name = tokenizer.ReadDoubleQuotedWord(); tokenizer.ReadToken(","); tokenizer.ReadToken("PARAM_MT"); IMathTransform toBaseTransform = MathTransformWktReader.ReadMathTransform(tokenizer); tokenizer.ReadToken(","); tokenizer.NextToken(); ICoordinateSystem baseCS = ReadCoordinateSystem(null, tokenizer); string authority = String.Empty; long authorityCode = -1; TokenType ct = tokenizer.NextToken(); while (ct != TokenType.Eol && ct != TokenType.Eof) { switch (tokenizer.GetStringValue()) { case ",": case "]": break; case "AUTHORITY": tokenizer.ReadAuthority(ref authority, ref authorityCode); //tokenizer.ReadToken("]"); break; } ct = tokenizer.NextToken(); } IFittedCoordinateSystem fittedCS = new FittedCoordinateSystem(baseCS, toBaseTransform, name, authority, authorityCode, string.Empty, string.Empty, string.Empty); return(fittedCS); }
private static IProjection ReadProjection(WktStreamTokenizer tokenizer) { if (tokenizer.GetStringValue() != "PROJECTION") { tokenizer.ReadToken("PROJECTION"); } tokenizer.ReadToken("[");//[ string projectionName = tokenizer.ReadDoubleQuotedWord(); string authority = string.Empty; long authorityCode = -1L; tokenizer.NextToken(true); if (tokenizer.GetStringValue() == ",") { tokenizer.ReadAuthority(ref authority, ref authorityCode); tokenizer.ReadToken("]"); } tokenizer.ReadToken(",");//, tokenizer.ReadToken("PARAMETER"); List <ProjectionParameter> paramList = new List <ProjectionParameter>(); while (tokenizer.GetStringValue() == "PARAMETER") { tokenizer.ReadToken("["); string paramName = tokenizer.ReadDoubleQuotedWord(); tokenizer.ReadToken(","); tokenizer.NextToken(); double paramValue = tokenizer.GetNumericValue(); tokenizer.ReadToken("]"); paramList.Add(new ProjectionParameter(paramName, paramValue)); tokenizer.NextToken(); if (tokenizer.GetStringValue() == ",") { tokenizer.NextToken(); } else { break; } } IProjection projection = new Projection(projectionName, paramList, projectionName, authority, authorityCode, String.Empty, String.Empty, string.Empty); return(projection); }
/// <summary> /// Returns a <see cref="AngularUnit"/> 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 IAngularUnit ReadAngularUnit(WktStreamTokenizer tokenizer) { tokenizer.ReadToken("["); string unitName = tokenizer.ReadDoubleQuotedWord(); tokenizer.ReadToken(","); tokenizer.NextToken(); double unitsPerUnit = tokenizer.GetNumericValue(); string authority = String.Empty; long authorityCode = -1; tokenizer.NextToken(); if (tokenizer.GetStringValue() == ",") { tokenizer.ReadAuthority(ref authority, ref authorityCode); tokenizer.ReadToken("]"); } return(new AngularUnit(unitsPerUnit, unitName, authority, authorityCode, String.Empty, String.Empty, String.Empty)); }
private static IPrimeMeridian ReadPrimeMeridian(WktStreamTokenizer tokenizer) { //PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]] tokenizer.ReadToken("["); string name = tokenizer.ReadDoubleQuotedWord(); tokenizer.ReadToken(","); tokenizer.NextToken(); double longitude = tokenizer.GetNumericValue(); tokenizer.NextToken(); string authority = String.Empty; long authorityCode = -1; if (tokenizer.GetStringValue() == ",") { tokenizer.ReadAuthority(ref authority, ref authorityCode); tokenizer.ReadToken("]"); } // make an assumption about the Angular units - degrees. IPrimeMeridian primeMeridian = new PrimeMeridian(longitude, AngularUnit.Degrees, name, authority, authorityCode, String.Empty, String.Empty, String.Empty); return(primeMeridian); }
private static IGeographicCoordinateSystem ReadGeographicCoordinateSystem(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"); IHorizontalDatum horizontalDatum = ReadHorizontalDatum(tokenizer); tokenizer.ReadToken(","); tokenizer.ReadToken("PRIMEM"); IPrimeMeridian primeMeridian = ReadPrimeMeridian(tokenizer); tokenizer.ReadToken(","); tokenizer.ReadToken("UNIT"); IAngularUnit angularUnit = ReadAngularUnit(tokenizer); string authority = String.Empty; long authorityCode = -1; tokenizer.NextToken(); List <AxisInfo> info = new List <AxisInfo>(2); if (tokenizer.GetStringValue() == ",") { tokenizer.NextToken(); while (tokenizer.GetStringValue() == "AXIS") { info.Add(ReadAxis(tokenizer)); tokenizer.NextToken(); if (tokenizer.GetStringValue() == ",") { tokenizer.NextToken(); } } if (tokenizer.GetStringValue() == ",") { tokenizer.NextToken(); } if (tokenizer.GetStringValue() == "AUTHORITY") { tokenizer.ReadAuthority(ref authority, ref authorityCode); tokenizer.ReadToken("]"); } } //This is default axis values if not specified. if (info.Count == 0) { info.Add(new AxisInfo("Lon", AxisOrientationEnum.East)); info.Add(new AxisInfo("Lat", AxisOrientationEnum.North)); } IGeographicCoordinateSystem geographicCS = new GeographicCoordinateSystem(angularUnit, horizontalDatum, primeMeridian, info, name, authority, authorityCode, String.Empty, String.Empty, String.Empty); return(geographicCS); }
private static IProjectedCoordinateSystem ReadProjectedCoordinateSystem(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"); IGeographicCoordinateSystem geographicCS = ReadGeographicCoordinateSystem(tokenizer); tokenizer.ReadToken(","); IProjection projection = null; IUnit unit = null; List <AxisInfo> axes = new List <AxisInfo>(2); string authority = String.Empty; long authorityCode = -1; TokenType ct = tokenizer.NextToken(); while (ct != TokenType.Eol && ct != TokenType.Eof) { switch (tokenizer.GetStringValue()) { case ",": case "]": break; case "PROJECTION": projection = ReadProjection(tokenizer); ct = tokenizer.GetTokenType(); continue; //break; case "UNIT": unit = ReadLinearUnit(tokenizer); break; case "AXIS": axes.Add(ReadAxis(tokenizer)); tokenizer.NextToken(); break; case "AUTHORITY": tokenizer.ReadAuthority(ref authority, ref authorityCode); //tokenizer.ReadToken("]"); break; } ct = tokenizer.NextToken(); } //This is default axis values if not specified. if (axes.Count == 0) { //修改为国内常见 axes.Add(new AxisInfo("X", AxisOrientationEnum.North)); axes.Add(new AxisInfo("Y", AxisOrientationEnum.East)); //axes.Add(new AxisInfo("X", AxisOrientationEnum.East)); //axes.Add(new AxisInfo("Y", AxisOrientationEnum.North)); } IProjectedCoordinateSystem projectedCS = new ProjectedCoordinateSystem(geographicCS.HorizontalDatum, geographicCS, unit as LinearUnit, projection, axes, name, authority, authorityCode, String.Empty, String.Empty, String.Empty); return(projectedCS); }