private static GeographicCoordinateSystem ReadGeographicCoordinateSystem(string[] parameters)
        {
            //+proj=longlat +ellps=intl +pm=ferro +towgs84=145,-187,103,0,0,0,0 +no_defs

            WGS84ConversionInfo wgs84     = ReadWGS84ConversionInfo(ParameterValue(parameters, "+towgs84"));
            LinearUnit          unit      = ReadUnit(parameters) as LinearUnit;
            Ellipsoid           ellipsoid = ReadEllipsoid(parameters, unit);
            HorizontalDatum     datum     = new HorizontalDatum(
                "Unknown",
                DatumType.IHD_Classic,
                ellipsoid,
                wgs84);

            GeographicCoordinateSystem geogrCoordSystem =
                new GeographicCoordinateSystem(
                    "Unknown",
                    new AngularUnit(Math.PI / 180.0, String.Empty, String.Empty, String.Empty, "degree", String.Empty, String.Empty),
                    datum,
                    ReadPrimeMeridian(parameters),
                    new AxisInfo("Geodetic latitude", AxisOrientation.North),
                    new AxisInfo("Geodetic longitude", AxisOrientation.East));

            return(geogrCoordSystem);
        }
Beispiel #2
0
 internal Geotransformation(string name, string method, GeographicCoordinateSystem geoCoordSys1, GeographicCoordinateSystem geoCoordSys2, ParameterList Parameters, string classification, string remarks, string authority, string authorityCode)
     : base(remarks, authority, authorityCode, name, String.Empty, String.Empty)
 {
     _parameters   = Parameters;
     _method       = method;
     _classication = classification;
     _geographicCoordinateSystem1 = geoCoordSys1;
     _geographicCoordinateSystem2 = geoCoordSys2;
 }
        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 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);
        }
        public static object Create(string wkt)
        {
            object             returnObject     = null;
            bool               includeAuthority = (wkt.ToLower().IndexOf("authority") != -1);
            StringReader       reader           = new StringReader(wkt);
            WktStreamTokenizer tokenizer        = new WktStreamTokenizer(reader);

            tokenizer.NextToken();
            string objectName = tokenizer.GetStringValue();

            switch (objectName)
            {
            case "UNIT":
                Unit unit = ReadUnit(tokenizer, includeAuthority);
                returnObject = unit;
                break;

            case "VERT_DATUM":
                VerticalDatum verticalDatum = ReadVerticalDatum(tokenizer, includeAuthority);
                returnObject = verticalDatum;
                break;

            case "SPHEROID":
                Ellipsoid ellipsoid = ReadEllipsoid(tokenizer, includeAuthority);
                returnObject = ellipsoid;
                break;

            case "TOWGS84":
                WGS84ConversionInfo wgsInfo = ReadWGS84ConversionInfo(tokenizer, includeAuthority);
                returnObject = wgsInfo;
                break;

            case "DATUM":
                HorizontalDatum horizontalDatum = ReadHorizontalDatum(tokenizer, includeAuthority);
                returnObject = horizontalDatum;
                break;

            case "PRIMEM":
                PrimeMeridian primeMeridian = ReadPrimeMeridian(tokenizer, includeAuthority);
                returnObject = primeMeridian;
                break;

            case "VERT_CS":
                VerticalCoordinateSystem verticalCS = ReadVerticalCoordinateSystem(tokenizer, includeAuthority);
                returnObject = verticalCS;
                break;

            case "GEOGCS":
                GeographicCoordinateSystem geographicCS = ReadGeographicCoordinateSystem(tokenizer, includeAuthority);
                returnObject = geographicCS;
                break;

            case "PROJCS":
                ProjectedCoordinateSystem projectedCS = ReadProjectedCoordinateSystem(tokenizer, includeAuthority);
                returnObject = projectedCS;
                break;

            case "COMPD_CS":
                CompoundCoordinateSystem compoundCS = ReadCompoundCoordinateSystem(tokenizer, includeAuthority);
                returnObject = compoundCS;
                break;

            case "GEOCCS":
            case "FITTED_CS":
            case "LOCAL_CS":
                throw new NotSupportedException(String.Format("{0} is not implemented.", objectName));

            default:
                throw new ParseException(String.Format("'{0'} is not recongnized.", objectName));
            }
            reader.Close();
            return(returnObject);
        }