コード例 #1
0
        /// <summary>
        /// Constructs a coordinate system object from well-known text.
        /// </summary>
        /// <param name="wkt">Well-known text representation of object</param>
        /// <returns>An object constructed from well-known text</returns>
        /// <exception cref="System.ArgumentException">Raises when parsing of string fails.</exception>
        public static IInfo Parse(string wkt)
        {
            IInfo returnObject = null;
            StringReader reader = new StringReader(wkt);
            WktStreamTokenizer tokenizer = new WktStreamTokenizer(reader);
            tokenizer.NextToken();
            string objectName = tokenizer.GetStringValue();
            switch (objectName)
            {
                case "UNIT":
                    returnObject = ReadUnit(tokenizer);
                    break;
                //case "VERT_DATUM":
                //    IVerticalDatum verticalDatum = ReadVerticalDatum(tokenizer);
                //    returnObject = verticalDatum;
                //    break;
                case "SPHEROID":
                    returnObject = ReadEllipsoid(tokenizer);
                    break;
                case "DATUM":
                    returnObject = ReadHorizontalDatum(tokenizer); ;
                    break;
                case "PRIMEM":
                    returnObject = ReadPrimeMeridian(tokenizer);
                    break;
                case "VERT_CS":
                case "GEOGCS":
                case "PROJCS":
                case "COMPD_CS":
                case "GEOCCS":
                case "FITTED_CS":
                case "LOCAL_CS":
                    returnObject = ReadCoordinateSystem(wkt, tokenizer);
                    break;
                default:
                    throw new ArgumentException(String.Format("'{0}' is not recognized.", objectName));

            }
            reader.Close();
            return returnObject;
        }
コード例 #2
0
 private static ICoordinate readPointCoords(WktStreamTokenizer tokenizer)
 {
     ICoordinate point = PlanimetryEnvironment.NewCoordinate(0, 0);
     tokenizer.NextToken();
     point.X = tokenizer.GetNumericValue();
     tokenizer.NextToken();
     point.Y = tokenizer.GetNumericValue();
     return point;
 }
コード例 #3
0
        private static List<ICoordinate> readPointCoordsList(WktStreamTokenizer tokenizer)
        {
            List<ICoordinate> points = new List<ICoordinate>();
            bool comma = true;
            while(comma)
            {
                points.Add(readPointCoords(tokenizer));
                tokenizer.NextToken();
                comma = tokenizer.GetStringValue() == ",";
            }

            return points;
        }
コード例 #4
0
 private static List<List<ICoordinate>> readPointsCoordLists(WktStreamTokenizer tokenizer)
 {
     List<List<ICoordinate>> result = new List<List<ICoordinate>>();
     bool comma = true;
     while (comma)
     {
         tokenizer.ReadToken("(");
         result.Add(readPointCoordsList(tokenizer));
         if (tokenizer.GetStringValue() == ")")
         {
             tokenizer.NextToken();
             comma = tokenizer.GetStringValue() == ",";
         }
         else
             throwMissingCloseBracket(tokenizer);
     }
     return result;
 }
コード例 #5
0
        private static Polygon readMultiPolygon(WktStreamTokenizer tokenizer)
        {
            tokenizer.ReadToken("(");
            Polygon polygon = new Polygon();
            bool comma = true;
            while (comma)
            {
                tokenizer.ReadToken("(");
                List<List<ICoordinate>> lists = readPointsCoordLists(tokenizer);
                if (tokenizer.GetStringValue() == ")")
                {
                    foreach (List<ICoordinate> list in lists)
                    {
                        Contour contour = new Contour();
                        list.RemoveAt(list.Count - 1);
                        contour.Vertices = list;
                        polygon.Contours.Add(contour);
                    }
                }
                else
                    throwMissingCloseBracket(tokenizer);
                tokenizer.NextToken();
                comma = tokenizer.GetStringValue() == ",";
            }
            if (tokenizer.GetStringValue() != ")")
                throwMissingCloseBracket(tokenizer);

            return polygon;
        }
コード例 #6
0
        private static MultiPoint readMultiPoint(WktStreamTokenizer tokenizer)
        {
            tokenizer.ReadToken("(");
            List<ICoordinate> points = new List<ICoordinate>();

            while (true)
            {
                points.Add(readPoint(tokenizer).Coordinate);
                tokenizer.NextToken(true);
                if (tokenizer.GetStringValue() == ",")
                    continue;

                if (tokenizer.GetStringValue() == ")")
                    break;
            }

            if (tokenizer.GetStringValue() == ")")
            {
                MultiPoint multiPoint = new MultiPoint(points);
                return multiPoint;
            }
            else
                throwMissingCloseBracket(tokenizer);
            return null;
        }
コード例 #7
0
        /// <summary>
        /// Constructs a geometry from its well-known text representation.
        /// </summary>
        /// <returns>A constructed geometry</returns>
        public static IGeometry GeometryFromWKT(string wkt)
        {
            StringReader sr = new StringReader(wkt);
            WktStreamTokenizer tokenizer = new WktStreamTokenizer(sr);
            tokenizer.NextToken();
            switch (tokenizer.GetStringValue().ToUpper())
            {
                case "POINT": return readPoint(tokenizer);
                case "LINESTRING": return readLineString(tokenizer);
                case "MULTILINESTRING": return readMultiLineString(tokenizer);
                case "POLYGON": return readPolygon(tokenizer);
                case "MULTIPOLYGON": return readMultiPolygon(tokenizer);
                case "MULTIPOINT": return readMultiPoint(tokenizer);
            }

            throw new ArgumentException(string.Format("Unknown geometry \"{0}\"", tokenizer.GetStringValue()));
        }
コード例 #8
0
 /// <summary>
 /// Reads a unit.
 /// </summary>
 private static IUnit ReadUnit(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);
         ReadAuthority(tokenizer, ref authority, ref authorityCode);
         tokenizer.ReadToken("]");
     }
     return new Unit(unitsPerUnit, unitName, authority, authorityCode, String.Empty, String.Empty, String.Empty);
 }
コード例 #9
0
        /// <summary>
        /// Reads a prime meridian.
        /// </summary>
        private static IPrimeMeridian ReadPrimeMeridian(WktStreamTokenizer tokenizer)
        {
            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() == ",")
            {
                ReadAuthority(tokenizer, ref authority, ref authorityCode);
                tokenizer.ReadToken("]");
            }

            IPrimeMeridian primeMeridian = new PrimeMeridian(longitude, AngularUnit.Degrees, name, authority, authorityCode, String.Empty, String.Empty, String.Empty);

            return primeMeridian;
        }
コード例 #10
0
        /// <summary>
        /// Reads a geographic coordinate system.
        /// </summary>
        private static IGeographicCoordinateSystem ReadGeographicCoordinateSystem(WktStreamTokenizer tokenizer)
        {
            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);
                    ReadAuthority(tokenizer, ref authority, ref authorityCode);
                    tokenizer.ReadToken("]");
                }
            }

            // значения по умолчанию для осей
            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;
        }
コード例 #11
0
        /// <summary>
        /// Reads a horizontal datum.
        /// </summary>
        private static IHorizontalDatum ReadHorizontalDatum(WktStreamTokenizer tokenizer)
        {
            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);
                    ReadAuthority(tokenizer, ref authority, ref authorityCode);
                    tokenizer.ReadToken("]");
                }
            }

            IHorizontalDatum horizontalDatum = new HorizontalDatum(ellipsoid, wgsInfo, DatumType.HD_Geocentric, name, authority, authorityCode, String.Empty, String.Empty, String.Empty);

            return horizontalDatum;
        }
コード例 #12
0
        /// <summary>
        /// Reads a projected coordinate system.
        /// </summary>
        private static IProjectedCoordinateSystem ReadProjectedCoordinateSystem(WktStreamTokenizer tokenizer)
        {
            tokenizer.ReadToken("[");
            string name = tokenizer.ReadDoubleQuotedWord();
            tokenizer.ReadToken(",");
            tokenizer.ReadToken("GEOGCS");
            IGeographicCoordinateSystem geographicCS = ReadGeographicCoordinateSystem(tokenizer);
            tokenizer.ReadToken(",");
            IProjection projection = ReadProjection(tokenizer);
            IUnit unit = ReadLinearUnit(tokenizer);

            string authority = String.Empty;
            long authorityCode = -1;
            tokenizer.NextToken();
            List<AxisInfo> axes = new List<AxisInfo>(2);
            if (tokenizer.GetStringValue() == ",")
            {
                tokenizer.NextToken();
                while (tokenizer.GetStringValue() == "AXIS")
                {
                    axes.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);
                    ReadAuthority(tokenizer, ref authority, ref authorityCode);
                    tokenizer.ReadToken("]");
                }
            }
            //This is default axis values if not specified.
            if (axes.Count == 0)
            {
                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;
        }
コード例 #13
0
 /// <summary>
 /// Reads a projection.
 /// </summary>
 private static IProjection ReadProjection(WktStreamTokenizer tokenizer)
 {
     tokenizer.ReadToken("PROJECTION");
     tokenizer.ReadToken("[");//[
     string projectionName = tokenizer.ReadDoubleQuotedWord();
     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("]");
         tokenizer.ReadToken(",");
         paramList.Add(new ProjectionParameter(paramName, paramValue));
         tokenizer.NextToken();
     }
     string authority = String.Empty;
     long authorityCode = -1;
     IProjection projection = new Projection(projectionName, paramList, projectionName, authority, authorityCode, String.Empty, String.Empty, string.Empty);
     return projection;
 }
コード例 #14
0
        /*
        /// <summary>
        /// 
        /// </summary>
        /// <param name="tokenizer"></param>
        /// <returns></returns>
        private static ICompoundCoordinateSystem ReadCompoundCoordinateSystem(WktStreamTokenizer tokenizer)
        {
			
            //COMPD_CS[
            //"OSGB36 / British National Grid + ODN",
            //PROJCS[]
            //VERT_CS[]
            //AUTHORITY["EPSG","7405"]
            //]

            tokenizer.ReadToken("[");
            string name=tokenizer.ReadDoubleQuotedWord();
            tokenizer.ReadToken(",");
            tokenizer.NextToken();
            string headCSCode =  tokenizer.GetStringValue();
            ICoordinateSystem headCS = ReadCoordinateSystem(headCSCode,tokenizer);
            tokenizer.ReadToken(",");
            tokenizer.NextToken();
            string tailCSCode =  tokenizer.GetStringValue();
            ICoordinateSystem tailCS = ReadCoordinateSystem(tailCSCode,tokenizer);
            tokenizer.ReadToken(",");
            string authority=String.Empty;
            string authorityCode=String.Empty; 
            tokenizer.ReadAuthority(ref authority, ref authorityCode);
            tokenizer.ReadToken("]");
            ICompoundCoordinateSystem compoundCS = new CompoundCoordinateSystem(headCS,tailCS,String.Empty,authority,authorityCode,name,String.Empty,String.Empty); 
            return compoundCS;
			
        }*/

        /// <summary>
        /// Reads an ellipsiod.
        /// </summary>
        private static IEllipsoid ReadEllipsoid(WktStreamTokenizer tokenizer)
        {
            tokenizer.ReadToken("[");
            string name = tokenizer.ReadDoubleQuotedWord();
            tokenizer.ReadToken(",");
            tokenizer.NextToken();
            double majorAxis = tokenizer.GetNumericValue();
            tokenizer.ReadToken(",");
            tokenizer.NextToken();
            double e = tokenizer.GetNumericValue();

            //tokenizer.ReadToken(",");
            tokenizer.NextToken();
            string authority = String.Empty;
            long authorityCode = -1;
            if (tokenizer.GetStringValue() == ",") //Read authority
            {
                //tokenizer.ReadAuthority(ref authority, ref authorityCode);
                ReadAuthority(tokenizer, 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;
        }
コード例 #15
0
        /// <summary>
        /// Reads a WGS84 conversion info.
        /// </summary>
        private static Wgs84ConversionInfo ReadWGS84ConversionInfo(WktStreamTokenizer tokenizer)
        {
            //TOWGS84[0,0,0,0,0,0,0]
            tokenizer.ReadToken("[");
            Wgs84ConversionInfo info = new Wgs84ConversionInfo();
            tokenizer.NextToken();
            info.Dx = tokenizer.GetNumericValue();
            tokenizer.ReadToken(",");

            tokenizer.NextToken();
            info.Dy = tokenizer.GetNumericValue();
            tokenizer.ReadToken(",");

            tokenizer.NextToken();
            info.Dz = tokenizer.GetNumericValue();
            tokenizer.NextToken();
            if (tokenizer.GetStringValue() == ",")
            {
                tokenizer.NextToken();
                info.Ex = tokenizer.GetNumericValue();

                tokenizer.ReadToken(",");
                tokenizer.NextToken();
                info.Ey = tokenizer.GetNumericValue();

                tokenizer.ReadToken(",");
                tokenizer.NextToken();
                info.Ez = tokenizer.GetNumericValue();

                tokenizer.NextToken();
                if (tokenizer.GetStringValue() == ",")
                {
                    tokenizer.NextToken();
                    info.Ppm = tokenizer.GetNumericValue();
                }
            }
            if (tokenizer.GetStringValue() != "]")
                tokenizer.ReadToken("]");
            return info;
        }
コード例 #16
0
 /// <summary>
 /// Reads an axis info.
 /// </summary>
 private static AxisInfo ReadAxis(WktStreamTokenizer tokenizer)
 {
     if (tokenizer.GetStringValue() != "AXIS")
         tokenizer.ReadToken("AXIS");
     tokenizer.ReadToken("[");
     string axisName = tokenizer.ReadDoubleQuotedWord();
     tokenizer.ReadToken(",");
     tokenizer.NextToken();
     string unitname = tokenizer.GetStringValue();
     tokenizer.ReadToken("]");
     switch (unitname.ToUpper(CultureInfo.InvariantCulture))
     {
         case "DOWN": return new AxisInfo(axisName, AxisOrientationEnum.Down);
         case "EAST": return new AxisInfo(axisName, AxisOrientationEnum.East);
         case "NORTH": return new AxisInfo(axisName, AxisOrientationEnum.North);
         case "OTHER": return new AxisInfo(axisName, AxisOrientationEnum.Other);
         case "SOUTH": return new AxisInfo(axisName, AxisOrientationEnum.South);
         case "UP": return new AxisInfo(axisName, AxisOrientationEnum.Up);
         case "WEST": return new AxisInfo(axisName, AxisOrientationEnum.West);
         default:
             throw new ArgumentException("Invalid axis name '" + unitname + "' in WKT");
     }
 }