private static ProjectedCoordinateSystem ReadProjectedCoordinateSystem(string[] parameters) { // +proj=tmerc +lat_0=0 +lon_0=-62 +k=0.999500 +x_0=400000 +y_0=0 +ellps=clrk80 +towgs84=725,685,536,0,0,0,0 +units=m +no_defs string projParam = ParameterValue(parameters, "+proj"); string projName = ProjDB.ProjectionNameByP4(projParam); List <ProjectionParameter> projParameters = new List <ProjectionParameter>(); if (projParam.ToLower() == "utm" && projName.ToLower() == "transverse_mercator") { projParameters.Add(new ProjectionParameter("scale_factor", 0.9996)); projParameters.Add(new ProjectionParameter("false_easting", 500000.0)); } foreach (string p4param in parameters) { string val; string p4 = Parameter(p4param, out val); double v; if (!double.TryParse(val, NumberStyles.Number, _nhi, out v)) { continue; } switch (p4) { case "+lat_0": projParameters.Add(new ProjectionParameter("latitude_of_origin", v)); break; case "+lon_0": projParameters.Add(new ProjectionParameter("longitude_of_origin", v)); projParameters.Add(new ProjectionParameter("central_meridian", v)); break; case "+k": projParameters.Add(new ProjectionParameter("scale_factor", v)); break; case "+x_0": projParameters.Add(new ProjectionParameter("false_easting", v)); break; case "+y_0": projParameters.Add(new ProjectionParameter("false_northing", v)); break; case "+alpha": projParameters.Add(new ProjectionParameter("azimuth", v)); break; case "+lat_1": projParameters.Add(new ProjectionParameter("standard_parallel_1", v)); break; case "+lat_2": projParameters.Add(new ProjectionParameter("standard_parallel_2", v)); break; case "+zone": projParameters.Add(new ProjectionParameter("Central_Meridian", -177.0 + 6 * (v - 1))); break; } } Projection proj = new Projection(projName, projParameters.ToArray(), "", "", "", ""); GeographicCoordinateSystem geogrCoordSystem = ReadGeographicCoordinateSystem(parameters); AxisInfo[] axis = { new AxisInfo("Easting", AxisOrientation.East), new AxisInfo("Northing", AxisOrientation.North) }; ProjectedCoordinateSystem projCoordSystem = new ProjectedCoordinateSystem( geogrCoordSystem.HorizontalDatum, axis, geogrCoordSystem, new LinearUnit(1.0, String.Empty, String.Empty, String.Empty, "metre", String.Empty, String.Empty), proj); projCoordSystem.Name = "Unknown"; return(projCoordSystem); }
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); }