コード例 #1
0
        /// <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));
        }
コード例 #2
0
        /// <summary>
        /// Reads math transform from using current token from the specified tokenizer
        /// </summary>
        /// <param name="tokenizer"></param>
        /// <returns></returns>
        internal static IMathTransform ReadMathTransform(WktStreamTokenizer tokenizer)
        {
            if (tokenizer.GetStringValue() != "PARAM_MT")
            {
                tokenizer.ReadToken("PARAM_MT");
            }
            tokenizer.ReadToken("[");
            string transformName = tokenizer.ReadDoubleQuotedWord();

            tokenizer.ReadToken(",");

            switch (transformName.ToUpperInvariant())
            {
            case "AFFINE":
                return(ReadAffineTransform(tokenizer));

            default:
                throw new NotSupportedException("Transform not supported '" + transformName + "'");
            }
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }