Beispiel #1
0
        private static string GetNextEmptyOrOpener(WktStreamTokenizer tokenizer)
        {
            tokenizer.NextToken();
            string nextWord = tokenizer.GetStringValue();

            if (nextWord == "EMPTY" || nextWord == "(")
            {
                return(nextWord);
            }

            throw new Exception("Expected 'EMPTY' or '(' but encountered '" + nextWord + "'");
        }
Beispiel #2
0
        private static Point ReadPointText(WktStreamTokenizer tokenizer)
        {
            Point  p         = new Point();
            string nextToken = GetNextEmptyOrOpener(tokenizer);

            if (nextToken == "EMPTY")
            {
                return(p);
            }
            p.X = GetNextNumber(tokenizer);
            p.Y = GetNextNumber(tokenizer);
            GetNextCloser(tokenizer);
            return(p);
        }
Beispiel #3
0
        private static GeometryCollection ReadGeometryCollectionText(WktStreamTokenizer tokenizer)
        {
            GeometryCollection geometries = new GeometryCollection();
            string             nextToken  = GetNextEmptyOrOpener(tokenizer);

            if (nextToken.Equals("EMPTY"))
            {
                return(geometries);
            }
            geometries.Collection.Add(ReadGeometryTaggedText(tokenizer));
            nextToken = GetNextCloserOrComma(tokenizer);
            while (nextToken.Equals(","))
            {
                geometries.Collection.Add(ReadGeometryTaggedText(tokenizer));
                nextToken = GetNextCloserOrComma(tokenizer);
            }
            return(geometries);
        }
Beispiel #4
0
        private static MultiPoint ReadMultiPointText(WktStreamTokenizer tokenizer)
        {
            MultiPoint mp        = new MultiPoint();
            string     nextToken = GetNextEmptyOrOpener(tokenizer);

            if (nextToken == "EMPTY")
            {
                return(mp);
            }
            mp.Points.Add(new Point(GetNextNumber(tokenizer), GetNextNumber(tokenizer)));
            nextToken = GetNextCloserOrComma(tokenizer);
            while (nextToken == ",")
            {
                mp.Points.Add(new Point(GetNextNumber(tokenizer), GetNextNumber(tokenizer)));
                nextToken = GetNextCloserOrComma(tokenizer);
            }
            return(mp);
        }
Beispiel #5
0
        private static MultiLineString ReadMultiLineStringText(WktStreamTokenizer tokenizer)
        {
            MultiLineString lines     = new MultiLineString();
            string          nextToken = GetNextEmptyOrOpener(tokenizer);

            if (nextToken == "EMPTY")
            {
                return(lines);
            }

            lines.LineStrings.Add(ReadLineStringText(tokenizer));
            nextToken = GetNextCloserOrComma(tokenizer);
            while (nextToken == ",")
            {
                lines.LineStrings.Add(ReadLineStringText(tokenizer));
                nextToken = GetNextCloserOrComma(tokenizer);
            }
            return(lines);
        }
Beispiel #6
0
        private static Geometry ReadGeometryTaggedText(WktStreamTokenizer tokenizer)
        {
            tokenizer.NextToken();
            string   type     = tokenizer.GetStringValue().ToUpper();
            Geometry geometry = null;

            switch (type)
            {
            case "POINT":
                geometry = ReadPointText(tokenizer);
                break;

            case "LINESTRING":
                geometry = ReadLineStringText(tokenizer);
                break;

            case "MULTIPOINT":
                geometry = ReadMultiPointText(tokenizer);
                break;

            case "MULTILINESTRING":
                geometry = ReadMultiLineStringText(tokenizer);
                break;

            case "POLYGON":
                geometry = ReadPolygonText(tokenizer);
                break;

            case "MULTIPOLYGON":
                geometry = ReadMultiPolygonText(tokenizer);
                break;

            case "GEOMETRYCOLLECTION":
                geometry = ReadGeometryCollectionText(tokenizer);
                break;

            default:
                throw new Exception(String.Format(Map.NumberFormatEnUs, "Geometrytype '{0}' is not supported.",
                                                  type));
            }
            return(geometry);
        }
Beispiel #7
0
        /// <summary>
        /// 取得多边形区域文字
        /// </summary>
        /// <param name="tokenizer"></param>
        /// <returns></returns>
        private static Polygon ReadPolygonText(WktStreamTokenizer tokenizer)
        {
            Polygon pol       = new Polygon();
            string  nextToken = GetNextEmptyOrOpener(tokenizer);

            if (nextToken == "EMPTY")
            {
                return(pol);
            }

            pol.ExteriorRing = new LinearRing(GetCoordinates(tokenizer));
            nextToken        = GetNextCloserOrComma(tokenizer);
            while (nextToken == ",")
            {
                //Add holes
                pol.InteriorRings.Add(new LinearRing(GetCoordinates(tokenizer)));
                nextToken = GetNextCloserOrComma(tokenizer);
            }
            return(pol);
        }
Beispiel #8
0
        private static MultiPolygon ReadMultiPolygonText(WktStreamTokenizer tokenizer)
        {
            MultiPolygon polygons  = new MultiPolygon();
            string       nextToken = GetNextEmptyOrOpener(tokenizer);

            if (nextToken == "EMPTY")
            {
                return(polygons);
            }

            Polygon polygon = ReadPolygonText(tokenizer);

            polygons.Polygons.Add(polygon);
            nextToken = GetNextCloserOrComma(tokenizer);
            while (nextToken == ",")
            {
                polygon = ReadPolygonText(tokenizer);
                polygons.Polygons.Add(polygon);
                nextToken = GetNextCloserOrComma(tokenizer);
            }
            return(polygons);
        }
Beispiel #9
0
 private static double GetNextNumber(WktStreamTokenizer tokenizer)
 {
     tokenizer.NextToken();
     return(tokenizer.GetNumericValue());
 }
Beispiel #10
0
 private static LineString ReadLineStringText(WktStreamTokenizer tokenizer)
 {
     return(new LineString(GetCoordinates(tokenizer)));
 }
Beispiel #11
0
        public static Geometry Parse(TextReader reader)
        {
            WktStreamTokenizer tokenizer = new WktStreamTokenizer(reader);

            return(ReadGeometryTaggedText(tokenizer));
        }