internal static GeographicCoordinateSystem ReadGeographicCoordinateSystem(WktStreamTokenizer tokenizer, bool includeAuthority) { //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"]] //UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]] //AXIS["Geodetic latitude","NORTH"] //AXIS["Geodetic longitude","EAST"] //AUTHORITY["EPSG","4277"] //] tokenizer.ReadToken("["); string name = tokenizer.ReadDoubleQuotedWord(); tokenizer.ReadToken(","); tokenizer.ReadToken("DATUM"); HorizontalDatum horizontalDatum = ReadHorizontalDatum(tokenizer, includeAuthority); tokenizer.ReadToken(","); tokenizer.ReadToken("PRIMEM"); PrimeMeridian primeMeridian = ReadPrimeMeridian(tokenizer, includeAuthority); tokenizer.ReadToken(","); tokenizer.ReadToken("UNIT"); Unit angularUnit = ReadUnit(tokenizer, includeAuthority); AxisInfo axisInfo1 = null, axisInfo2 = null; if (tokenizer.TryReadToken(",")) { if (tokenizer.TryReadToken("AXIS")) { axisInfo1 = ReadAxisInfo(tokenizer); } if (tokenizer.TryReadToken(",")) { if (tokenizer.TryReadToken("AXIS")) { axisInfo2 = ReadAxisInfo(tokenizer); } } } string authority = String.Empty; string authorityCode = String.Empty; if (includeAuthority) { tokenizer.ReadToken(","); tokenizer.ReadAuthority(ref authority, ref authorityCode); } tokenizer.ReadToken("]"); GeographicCoordinateSystem geographicCS = new GeographicCoordinateSystem(angularUnit as AngularUnit, horizontalDatum, primeMeridian, axisInfo1, axisInfo2, String.Empty, authority, authorityCode, name, String.Empty, String.Empty); return(geographicCS); }
private static Projection ReadProjection(WktStreamTokenizer tokenizer, bool includeAuthority) { //tokenizer.NextToken();// PROJECTION tokenizer.ReadToken("PROJECTION"); tokenizer.ReadToken("[");//[ string projectionName = tokenizer.ReadDoubleQuotedWord(); tokenizer.ReadToken("]"); //] tokenizer.ReadToken(","); //, tokenizer.ReadToken("PARAMETER"); ParameterList paramList = new ParameterList(); while (tokenizer.GetStringValue() == "PARAMETER") { tokenizer.ReadToken("["); string paramName = tokenizer.ReadDoubleQuotedWord(); //added by monoGIS team: parameters names may be capitalized, but the code works only with lower-case! paramName = paramName.ToLower(); tokenizer.ReadToken(","); tokenizer.NextToken(); double paramValue = tokenizer.GetNumericValue(); tokenizer.ReadToken("]"); paramList.Add(paramName, paramValue); if (!tokenizer.TryReadToken(",")) { break; } if (!tokenizer.TryReadToken("PARAMETER")) { break; } } ProjectionParameter[] paramArray = new ProjectionParameter[paramList.Count]; int i = 0; foreach (string key in paramList.Keys) { ProjectionParameter param = new ProjectionParameter(); param.Name = key; param.Value = (double)paramList[key]; paramArray[i] = param; i++; } string authority = String.Empty; string authorityCode = String.Empty; Projection projection = new Projection(projectionName, paramArray, String.Empty, String.Empty, authority, authorityCode); return(projection); }
private static HorizontalDatum ReadHorizontalDatum(WktStreamTokenizer tokenizer, bool includeAuthority) { //DATUM["OSGB 1936", // SPHEROID["Airy 1830",6377563.396,299.3249646,AUTHORITY["EPSG","7001"]], // TOWGS84[0,0,0,0,0,0,0],AUTHORITY["EPSG","6277"]] tokenizer.ReadToken("["); string name = tokenizer.ReadDoubleQuotedWord(); tokenizer.ReadToken(","); tokenizer.ReadToken("SPHEROID"); Ellipsoid ellipsoid = ReadEllipsoid(tokenizer, includeAuthority); string authority = String.Empty; string authorityCode = String.Empty; WGS84ConversionInfo wgsInfo = new WGS84ConversionInfo(); wgsInfo.IsInUse = false; if (tokenizer.TryReadToken(",")) { if (tokenizer.TryReadToken("TOWGS84")) { wgsInfo = ReadWGS84ConversionInfo(tokenizer, includeAuthority); } if (includeAuthority) { tokenizer.ReadToken(","); tokenizer.ReadAuthority(ref authority, ref authorityCode); } } tokenizer.ReadToken("]"); // make an assumption about the datum type. DatumType datumType = DatumType.IHD_Geocentric; HorizontalDatum horizontalDatum = new HorizontalDatum(name, datumType, ellipsoid, wgsInfo, String.Empty, authority, authorityCode, String.Empty, String.Empty); return(horizontalDatum); }
private static Geotransformation ReadGeotransformation(WktStreamTokenizer tokenizer, bool includeAuthority) { // GEOGTRAN[ // "MGI_To_WGS_1984_2", // GEOGCS[ // "GCS_MGI", // DATUM["D_MGI",SPHEROID["Bessel_1841",6377397.155,299.1528128]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]], // METHOD["Position_Vector"], // PARAMETER["X_Axis_Translation",577.326], // PARAMETER["Y_Axis_Translation",90.129], // PARAMETER["Z_Axis_Translation",463.919], // PARAMETER["X_Axis_Rotation",5.1365988], // PARAMETER["Y_Axis_Rotation",1.4742], // PARAMETER["Z_Axis_Rotation",5.2970436], // PARAMETER["Scale_Difference",2.4232] //] tokenizer.ReadToken("["); string name = tokenizer.ReadDoubleQuotedWord(); tokenizer.ReadToken(","); tokenizer.ReadToken("GEOGCS"); GeographicCoordinateSystem geographicCS1 = WktCoordinateSystemReader.ReadGeographicCoordinateSystem(tokenizer, includeAuthority); tokenizer.ReadToken(","); tokenizer.ReadToken("GEOGCS"); GeographicCoordinateSystem geographicCS2 = WktCoordinateSystemReader.ReadGeographicCoordinateSystem(tokenizer, includeAuthority); tokenizer.ReadToken(","); string method = String.Empty; ParameterList paramList = new ParameterList(); if (tokenizer.TryReadToken("METHOD")) { tokenizer.ReadToken("["); method = tokenizer.ReadDoubleQuotedWord(); tokenizer.ReadToken("]"); } if (tokenizer.TryReadToken(",")) { tokenizer.ReadToken("PARAMETER"); while (tokenizer.GetStringValue() == "PARAMETER") { tokenizer.ReadToken("["); string paramName = tokenizer.ReadDoubleQuotedWord(); paramName = paramName.ToLower(); tokenizer.ReadToken(","); tokenizer.NextToken(); double paramValue = tokenizer.GetNumericValue(); tokenizer.ReadToken("]"); paramList.Add(paramName, paramValue); if (!tokenizer.TryReadToken(",")) { break; } if (!tokenizer.TryReadToken("PARAMETER")) { break; } } } return(new Geotransformation(name, method, geographicCS1, geographicCS2, paramList, "", "", "", "")); }
private static ProjectedCoordinateSystem ReadProjectedCoordinateSystem(WktStreamTokenizer tokenizer, bool includeAuthority) { //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"); GeographicCoordinateSystem geographicCS = ReadGeographicCoordinateSystem(tokenizer, includeAuthority); tokenizer.ReadToken(","); Projection projection = ReadProjection(tokenizer, includeAuthority); tokenizer.ReadToken("UNIT"); Unit unit = ReadUnit(tokenizer, includeAuthority); AxisInfo axisInfo1 = null, axisInfo2 = null; if (tokenizer.TryReadToken(",")) { if (tokenizer.TryReadToken("AXIS")) { axisInfo1 = ReadAxisInfo(tokenizer); } if (tokenizer.TryReadToken(",")) { if (tokenizer.TryReadToken("AXIS")) { axisInfo2 = ReadAxisInfo(tokenizer); } } } string authority = String.Empty; string authorityCode = String.Empty; if (includeAuthority) { tokenizer.ReadToken(","); tokenizer.ReadAuthority(ref authority, ref authorityCode); } tokenizer.ReadToken("]"); int axisInfoDim = 0; if (axisInfo1 != null) { axisInfoDim = 1; } if (axisInfo2 != null) { axisInfoDim = 2; } AxisInfo[] axisArray = new AxisInfo[axisInfoDim]; if (axisInfo1 != null) { axisArray[0] = axisInfo1; } if (axisInfo2 != null) { axisArray[1] = axisInfo2; } ProjectedCoordinateSystem projectedCS = new ProjectedCoordinateSystem(geographicCS.HorizontalDatum, axisArray, geographicCS, unit as LinearUnit, projection, String.Empty, authority, authorityCode, name, String.Empty, String.Empty); return(projectedCS); }