コード例 #1
0
        /// <summary>
        /// Parses a GeometryCollection text.
        /// </summary>
        /// <param name="tokens">The list of tokens.</param>
        /// <param name="is3D">bool value indicating whether GeometryCollection being parsed has z-coordinate.</param>
        /// <param name="isMeasured">bool value indicating whether GeometryCollection being parsed has m-value.</param>
        /// <returns>A GeometryCollection specified by tokens.</returns>
        /// <remarks><![CDATA[<GeometryCollection text> ::= <empty set> | <left paren> <geometry tagged text> {<comma> <geometry tagged text>}* <right paren>]]></remarks>
        private static GeometryCollection <Geometry> ParseGeometryCollectionText(WktTokensBuffer tokens, bool is3D, bool isMeasured)
        {
            WktToken t = tokens.Peek(true);

            if (t.Type == TokenType.STRING && t.Value.ToUpperInvariant() == "EMPTY")
            {
                tokens.GetToken(true);
                return(new GeometryCollection <Geometry>());
            }

            WktReader.Expect(TokenType.LEFT_PARENTHESIS, tokens);

            GeometryCollection <Geometry> result = new GeometryCollection <Geometry>();

            result.Geometries.Add(WktReader.ParseGeometryTaggedText(tokens));

            t = tokens.Peek(true);
            while (t.Type == TokenType.COMMA)
            {
                tokens.GetToken(true);
                result.Geometries.Add(WktReader.ParseGeometryTaggedText(tokens));
                t = tokens.Peek(true);
            }

            WktReader.Expect(TokenType.RIGHT_PARENTHESIS, tokens);

            return(result);
        }
コード例 #2
0
        /// <summary>
        /// Parses series of polygons.
        /// </summary>
        /// <param name="tokens">The list of tokens.</param>
        /// <param name="is3D">bool value indicating whether polygon being parsed has z-coordinate.</param>
        /// <param name="isMeasured">bool value indicating whether polygon being parsed has m-value.</param>
        /// <returns>A list of polygons specified by tokens.</returns>
        private static IEnumerable <Polygon> ParsePolygons(WktTokensBuffer tokens, bool is3D, bool isMeasured)
        {
            List <Polygon> polygons = new List <Polygon>();

            polygons.Add(WktReader.ParsePolygonText(tokens, is3D, isMeasured));

            WktToken t = tokens.Peek(true);

            while (t.Type == TokenType.COMMA)
            {
                tokens.GetToken(true);
                polygons.Add(WktReader.ParsePolygonText(tokens, is3D, isMeasured));
                t = tokens.Peek(true);
            }

            return(polygons);
        }
コード例 #3
0
        /// <summary>
        /// Parses multiple LineStrings separated by comma.
        /// </summary>
        /// <param name="tokens">The list of tokens.</param>
        /// <param name="is3D">bool value indicating whether linestring being parsed had z-coordinate.</param>
        /// <param name="isMeasured">bool value indicating whether linestring being parsed has m-value.</param>
        /// <returns>A list of linestrings specified by tokens.</returns>
        private static List <LineString> ParseLineStrings(WktTokensBuffer tokens, bool is3D, bool isMeasured)
        {
            List <LineString> linestrigns = new List <LineString>();

            linestrigns.Add(WktReader.ParseLineStringText(tokens, is3D, isMeasured));

            WktToken t = tokens.Peek(true);

            while (t.Type == TokenType.COMMA)
            {
                tokens.GetToken(true);
                linestrigns.Add(WktReader.ParseLineStringText(tokens, is3D, isMeasured));
                t = tokens.Peek(true);
            }

            return(linestrigns);
        }
コード例 #4
0
        /// <summary>
        /// Parses multiple Points separated by comma.
        /// </summary>
        /// <param name="tokens">The list of tokens.</param>
        /// <param name="is3D">bool value indicating whether point being parsed had z-coordinate.</param>
        /// <param name="isMeasured">bool value indicating whether point being parsed has m-value.</param>
        /// <returns>A list of point specified by tokens.</returns>
        private static List <Point> ParsePoints(WktTokensBuffer tokens, bool is3D, bool isMeasured)
        {
            List <Point> points = new List <Point>();

            points.Add(WktReader.ParsePointText(tokens, is3D, isMeasured));

            WktToken t = tokens.Peek(true);

            while (t.Type == TokenType.COMMA)
            {
                tokens.GetToken(true);
                points.Add(WktReader.ParsePointText(tokens, is3D, isMeasured));
                t = tokens.Peek(true);
            }

            return(points);
        }
コード例 #5
0
        /// <summary>
        /// Parses a series of coordinate.
        /// </summary>
        /// <param name="tokens">The list of tokens.</param>
        /// <param name="is3D">bool value indicating whether coordinate being parsed had z-coordinate.</param>
        /// <param name="isMeasured">bool value indicating whether coordinate beeing parsed has m-value.</param>
        /// <returns>A list of coordinates specified by tokens.</returns>
        private static IEnumerable <Coordinate> ParseCoordinates(WktTokensBuffer tokens, bool is3D, bool isMeasured)
        {
            List <Coordinate> coordinates = new List <Coordinate>();

            coordinates.Add(WktReader.ParseCoordinate(tokens, is3D, isMeasured));

            WktToken t = tokens.Peek(true);

            while (t.Type == TokenType.COMMA)
            {
                tokens.GetToken(true);
                WktReader.Expect(TokenType.WHITESPACE, tokens);
                coordinates.Add(WktReader.ParseCoordinate(tokens, is3D, isMeasured));
                t = tokens.Peek(true);
            }

            return(coordinates);
        }
コード例 #6
0
        /// <summary>
        /// Parses a multipolygon text.
        /// </summary>
        /// <param name="tokens">The list of tokens.</param>
        /// <param name="is3D">bool value indicating whether multipolygon being parsed has z-coordinate.</param>
        /// <param name="isMeasured">bool value indicating whether multipolygon being parsed has m-value.</param>
        /// <returns>A multipolygon specified by tokens.</returns>
        /// <remarks><![CDATA[<multipolygon text> ::= <empty set> | <left paren> <polygon text> {<comma> <polygon text>}* <right paren>]]></remarks>
        private static MultiPolygon ParseMultiPolygonText(WktTokensBuffer tokens, bool is3D, bool isMeasured)
        {
            WktToken t = tokens.Peek(true);

            if (t.Type == TokenType.STRING && t.Value.ToUpperInvariant() == "EMPTY")
            {
                tokens.GetToken(true);
                return(new MultiPolygon());
            }

            WktReader.Expect(TokenType.LEFT_PARENTHESIS, tokens);
            MultiPolygon result = new MultiPolygon(WktReader.ParsePolygons(tokens, is3D, isMeasured));

            WktReader.Expect(TokenType.RIGHT_PARENTHESIS, tokens);

            return(result);
        }
コード例 #7
0
        /// <summary>
        /// Parses a linestring text.
        /// </summary>
        /// <param name="tokens">The list of tokens.</param>
        /// <param name="is3D">bool value indicating whether linestring being parsed has z-coordinate.</param>
        /// <param name="isMeasured">bool value indicating whether linestring being parsed has m-value.</param>
        /// <returns>A linestring specified by tokens.</returns>
        /// <remarks><![CDATA[<empty set> | <left paren> <point> {<comma> <point>}* <right paren>]]></remarks>
        private static LineString ParseLineStringText(WktTokensBuffer tokens, bool is3D, bool isMeasured)
        {
            WktToken t = tokens.Peek(true);

            if (t.Type == TokenType.STRING && t.Value.ToUpperInvariant() == "EMPTY")
            {
                tokens.GetToken(true);
                return(new LineString());
            }

            WktReader.Expect(TokenType.LEFT_PARENTHESIS, tokens);
            IEnumerable <Coordinate> coords = WktReader.ParseCoordinates(tokens, is3D, isMeasured);

            WktReader.Expect(TokenType.RIGHT_PARENTHESIS, tokens);

            return(new LineString(coords));
        }
コード例 #8
0
        /// <summary>
        /// Parses a multipolyugon tagged text.
        /// </summary>
        /// <param name="tokens">The list of tokens.</param>
        /// <returns>A GeometryCollection specified by tokens.</returns>
        /// <remarks><![CDATA[<GeometryCollection tagged text> ::=  GeometryCollection {z}{m} <GeometryCollection text>]]></remarks>
        private static GeometryCollection <Geometry> ParseGeometryCollectionTaggedText(WktTokensBuffer tokens)
        {
            WktReader.Expect("geometrycollection", tokens);
            WktReader.Expect(TokenType.WHITESPACE, tokens);

            bool is3D       = false;
            bool isMeasured = false;

            WktToken t = tokens.Peek(true);

            if (WktReader.TryParseDimensions(t, out is3D, out isMeasured))
            {
                tokens.GetToken(true);
                WktReader.Expect(TokenType.WHITESPACE, tokens);
            }

            return(WktReader.ParseGeometryCollectionText(tokens, is3D, isMeasured));
        }
コード例 #9
0
        /// <summary>
        /// Parses a multipolyugon tagged text.
        /// </summary>
        /// <param name="tokens">The list of tokens.</param>
        /// <returns>A multipolygon specified by tokens.</returns>
        /// <remarks><![CDATA[<multipolygon tagged text> ::=  multipolygon {z}{m} <multipolygon text>]]></remarks>
        private static MultiPolygon ParseMultiPolygonTaggedText(WktTokensBuffer tokens)
        {
            WktReader.Expect("multipolygon", tokens);
            WktReader.Expect(TokenType.WHITESPACE, tokens);

            bool is3D       = false;
            bool isMeasured = false;

            WktToken t = tokens.Peek(true);

            if (WktReader.TryParseDimensions(t, out is3D, out isMeasured))
            {
                tokens.GetToken(true);
                WktReader.Expect(TokenType.WHITESPACE, tokens);
            }

            return(WktReader.ParseMultiPolygonText(tokens, is3D, isMeasured));
        }
コード例 #10
0
        /// <summary>
        /// Parses a linestring tagged text.
        /// </summary>
        /// <param name="tokens">The list of tokens.</param>
        /// <returns>A linestring specified by tokens.</returns>
        /// <remarks><![CDATA[<linestring tagged text> ::=  linestring {z}{m} <linestring text>]]></remarks>
        private static LineString ParseLineStringTaggedText(WktTokensBuffer tokens)
        {
            WktReader.Expect("linestring", tokens);
            WktReader.Expect(TokenType.WHITESPACE, tokens);

            bool is3D       = false;
            bool isMeasured = false;

            WktToken t = tokens.Peek(true);

            if (WktReader.TryParseDimensions(t, out is3D, out isMeasured))
            {
                tokens.GetToken(true);
                WktReader.Expect(TokenType.WHITESPACE, tokens);
            }

            return(WktReader.ParseLineStringText(tokens, is3D, isMeasured));
        }
コード例 #11
0
        /// <summary>
        /// Parses a geometry tagged text.
        /// </summary>
        /// <param name="tokens">The list of tokens.</param>
        /// <returns>A geometry specified by tokens.</returns>
        private static Geometry ParseGeometryTaggedText(WktTokensBuffer tokens)
        {
            WktToken t = tokens.Peek(true);

            if (t.Type == TokenType.STRING)
            {
                if (t.Value.ToUpperInvariant() == "POINT")
                {
                    return(WktReader.ParsePointTaggedText(tokens));
                }
                else if (t.Value.ToUpperInvariant() == "LINESTRING")
                {
                    return(WktReader.ParseLineStringTaggedText(tokens));
                }
                else if (t.Value.ToUpperInvariant() == "POLYGON")
                {
                    return(WktReader.ParsePolygonTaggedText(tokens));
                }
                else if (t.Value.ToUpperInvariant() == "MULTIPOINT")
                {
                    return(WktReader.ParseMultiPointTaggedText(tokens));
                }
                else if (t.Value.ToUpperInvariant() == "MULTILINESTRING")
                {
                    return(WktReader.ParseMultiLineStringTaggedText(tokens));
                }
                else if (t.Value.ToUpperInvariant() == "MULTIPOLYGON")
                {
                    return(WktReader.ParseMultiPolygonTaggedText(tokens));
                }
                else if (t.Value.ToUpperInvariant() == "GEOMETRYCOLLECTION")
                {
                    return(WktReader.ParseGeometryCollectionTaggedText(tokens));
                }
            }

            if (t.Type == TokenType.END_OF_DATA)
            {
                return(null);
            }

            throw new WktParseException(string.Format("Invalid geometry type '{0}'", t.Value));
        }
コード例 #12
0
        /// <summary>
        /// Parses a polygon text.
        /// </summary>
        /// <param name="tokens">The list of tokens.</param>
        /// <param name="is3D">bool value indicating whether polygon being parsed has z-coordinate.</param>
        /// <param name="isMeasured">bool value indicating whether polygon being parsed has m-value.</param>
        /// <returns>A polygon specified by tokens.</returns>
        /// <remarks><![CDATA[<empty set> | <left paren> <linestring text> {<comma> <linestring text>}* <right paren>]]></remarks>
        private static Polygon ParsePolygonText(WktTokensBuffer tokens, bool is3D, bool isMeasured)
        {
            WktToken t = tokens.Peek(true);

            if (t.Type == TokenType.STRING && t.Value.ToUpperInvariant() == "EMPTY")
            {
                tokens.GetToken(true);
                return(new Polygon());
            }

            WktReader.Expect(TokenType.LEFT_PARENTHESIS, tokens);

            IEnumerable <LineString> linestrings = WktReader.ParseLineStrings(tokens, is3D, isMeasured);
            Polygon result = new Polygon(linestrings.First().Coordinates);

            foreach (var inner in linestrings.Skip(1))
            {
                result.InteriorRings.Add(inner.Coordinates);
            }

            WktReader.Expect(TokenType.RIGHT_PARENTHESIS, tokens);

            return(result);
        }