Class SimpleWKTShapeParser


  • public class SimpleWKTShapeParser
    extends java.lang.Object
    Parses shape geometry represented in WKT format complies with OGC® document: 12-063r5 and ISO/IEC 13249-3:2016 standard located at http://docs.opengeospatial.org/is/12-063r5/12-063r5.html
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String COMMA  
      static java.lang.String EMPTY  
      private static java.lang.String EOF  
      private static java.lang.String EOL  
      static java.lang.String LPAREN  
      static java.lang.String NAN  
      private static java.lang.String NUMBER  
      static java.lang.String RPAREN  
      static java.lang.String SPACE  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      private static void checkEOF​(java.io.StreamTokenizer stream)
      next word in the stream
      private static boolean isNumberNext​(java.io.StreamTokenizer stream)
      checks if the next token is a number
      private static java.lang.String nextCloser​(java.io.StreamTokenizer stream)
      checks if next token is a closing paren
      private static java.lang.String nextCloserOrComma​(java.io.StreamTokenizer stream)
      expects either a closing LPAREN or comma as the next token
      private static java.lang.String nextComma​(java.io.StreamTokenizer stream)
      expects a comma as next token
      private static java.lang.String nextEmptyOrOpen​(java.io.StreamTokenizer stream)
      checks if next token is an EMPTY or open paren
      private static double nextNumber​(java.io.StreamTokenizer stream)
      next number in the stream
      private static java.lang.String nextOpener​(java.io.StreamTokenizer stream)
      expects an open RPAREN as the next toke
      private static java.lang.String nextWord​(java.io.StreamTokenizer stream)
      next word in the stream
      static java.lang.Object parse​(java.lang.String wkt)  
      private static Rectangle parseBBox​(java.io.StreamTokenizer stream)
      parses an ENVELOPE
      private static void parseCoordinate​(java.io.StreamTokenizer stream, java.util.ArrayList<java.lang.Double> lats, java.util.ArrayList<java.lang.Double> lons)
      parses a single coordinate, w/ optional 3rd dimension
      private static void parseCoordinates​(java.io.StreamTokenizer stream, java.util.ArrayList<java.lang.Double> lats, java.util.ArrayList<java.lang.Double> lons)
      Parses a list of points into latitude and longitude arraylists
      static java.lang.Object parseExpectedType​(java.lang.String wkt, SimpleWKTShapeParser.ShapeType shapeType)  
      private static java.lang.Object parseGeometry​(java.io.StreamTokenizer stream, SimpleWKTShapeParser.ShapeType shapeType)
      parse geometry from the stream tokenizer
      private static java.lang.Object[] parseGeometryCollection​(java.io.StreamTokenizer stream)
      parses a GEOMETRYCOLLECTION
      private static Line parseLine​(java.io.StreamTokenizer stream)
      parses a LINESTRING
      private static Line[] parseMultiLine​(java.io.StreamTokenizer stream)
      parses a MULTILINESTRING
      private static double[][] parseMultiPoint​(java.io.StreamTokenizer stream)
      parses a MULTIPOINT type
      private static Polygon[] parseMultiPolygon​(java.io.StreamTokenizer stream)
      parses a MULTIPOLYGON
      private static double[] parsePoint​(java.io.StreamTokenizer stream)
      Parses a point as a double array
      private static Polygon parsePolygon​(java.io.StreamTokenizer stream)
      parses a POLYGON
      private static Polygon parsePolygonHole​(java.io.StreamTokenizer stream)
      parses the hole of a polygon
      private static java.lang.String tokenString​(java.io.StreamTokenizer stream)
      next token in the stream
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SimpleWKTShapeParser

        private SimpleWKTShapeParser()
    • Method Detail

      • parse

        public static java.lang.Object parse​(java.lang.String wkt)
                                      throws java.io.IOException,
                                             java.text.ParseException
        Throws:
        java.io.IOException
        java.text.ParseException
      • parseExpectedType

        public static java.lang.Object parseExpectedType​(java.lang.String wkt,
                                                         SimpleWKTShapeParser.ShapeType shapeType)
                                                  throws java.io.IOException,
                                                         java.text.ParseException
        Throws:
        java.io.IOException
        java.text.ParseException
      • parseGeometry

        private static java.lang.Object parseGeometry​(java.io.StreamTokenizer stream,
                                                      SimpleWKTShapeParser.ShapeType shapeType)
                                               throws java.io.IOException,
                                                      java.text.ParseException
        parse geometry from the stream tokenizer
        Throws:
        java.io.IOException
        java.text.ParseException
      • parsePoint

        private static double[] parsePoint​(java.io.StreamTokenizer stream)
                                    throws java.io.IOException,
                                           java.text.ParseException
        Parses a point as a double array
        Throws:
        java.io.IOException
        java.text.ParseException
      • parseCoordinates

        private static void parseCoordinates​(java.io.StreamTokenizer stream,
                                             java.util.ArrayList<java.lang.Double> lats,
                                             java.util.ArrayList<java.lang.Double> lons)
                                      throws java.io.IOException,
                                             java.text.ParseException
        Parses a list of points into latitude and longitude arraylists
        Throws:
        java.io.IOException
        java.text.ParseException
      • parseCoordinate

        private static void parseCoordinate​(java.io.StreamTokenizer stream,
                                            java.util.ArrayList<java.lang.Double> lats,
                                            java.util.ArrayList<java.lang.Double> lons)
                                     throws java.io.IOException,
                                            java.text.ParseException
        parses a single coordinate, w/ optional 3rd dimension
        Throws:
        java.io.IOException
        java.text.ParseException
      • parseMultiPoint

        private static double[][] parseMultiPoint​(java.io.StreamTokenizer stream)
                                           throws java.io.IOException,
                                                  java.text.ParseException
        parses a MULTIPOINT type
        Throws:
        java.io.IOException
        java.text.ParseException
      • parseLine

        private static Line parseLine​(java.io.StreamTokenizer stream)
                               throws java.io.IOException,
                                      java.text.ParseException
        parses a LINESTRING
        Throws:
        java.io.IOException
        java.text.ParseException
      • parseMultiLine

        private static Line[] parseMultiLine​(java.io.StreamTokenizer stream)
                                      throws java.io.IOException,
                                             java.text.ParseException
        parses a MULTILINESTRING
        Throws:
        java.io.IOException
        java.text.ParseException
      • parsePolygonHole

        private static Polygon parsePolygonHole​(java.io.StreamTokenizer stream)
                                         throws java.io.IOException,
                                                java.text.ParseException
        parses the hole of a polygon
        Throws:
        java.io.IOException
        java.text.ParseException
      • parsePolygon

        private static Polygon parsePolygon​(java.io.StreamTokenizer stream)
                                     throws java.io.IOException,
                                            java.text.ParseException
        parses a POLYGON
        Throws:
        java.io.IOException
        java.text.ParseException
      • parseMultiPolygon

        private static Polygon[] parseMultiPolygon​(java.io.StreamTokenizer stream)
                                            throws java.io.IOException,
                                                   java.text.ParseException
        parses a MULTIPOLYGON
        Throws:
        java.io.IOException
        java.text.ParseException
      • parseBBox

        private static Rectangle parseBBox​(java.io.StreamTokenizer stream)
                                    throws java.io.IOException,
                                           java.text.ParseException
        parses an ENVELOPE
        Throws:
        java.io.IOException
        java.text.ParseException
      • parseGeometryCollection

        private static java.lang.Object[] parseGeometryCollection​(java.io.StreamTokenizer stream)
                                                           throws java.io.IOException,
                                                                  java.text.ParseException
        parses a GEOMETRYCOLLECTION
        Throws:
        java.io.IOException
        java.text.ParseException
      • nextWord

        private static java.lang.String nextWord​(java.io.StreamTokenizer stream)
                                          throws java.text.ParseException,
                                                 java.io.IOException
        next word in the stream
        Throws:
        java.text.ParseException
        java.io.IOException
      • nextNumber

        private static double nextNumber​(java.io.StreamTokenizer stream)
                                  throws java.io.IOException,
                                         java.text.ParseException
        next number in the stream
        Throws:
        java.io.IOException
        java.text.ParseException
      • tokenString

        private static java.lang.String tokenString​(java.io.StreamTokenizer stream)
        next token in the stream
      • isNumberNext

        private static boolean isNumberNext​(java.io.StreamTokenizer stream)
                                     throws java.io.IOException
        checks if the next token is a number
        Throws:
        java.io.IOException
      • nextEmptyOrOpen

        private static java.lang.String nextEmptyOrOpen​(java.io.StreamTokenizer stream)
                                                 throws java.io.IOException,
                                                        java.text.ParseException
        checks if next token is an EMPTY or open paren
        Throws:
        java.io.IOException
        java.text.ParseException
      • nextCloser

        private static java.lang.String nextCloser​(java.io.StreamTokenizer stream)
                                            throws java.io.IOException,
                                                   java.text.ParseException
        checks if next token is a closing paren
        Throws:
        java.io.IOException
        java.text.ParseException
      • nextComma

        private static java.lang.String nextComma​(java.io.StreamTokenizer stream)
                                           throws java.io.IOException,
                                                  java.text.ParseException
        expects a comma as next token
        Throws:
        java.io.IOException
        java.text.ParseException
      • nextOpener

        private static java.lang.String nextOpener​(java.io.StreamTokenizer stream)
                                            throws java.io.IOException,
                                                   java.text.ParseException
        expects an open RPAREN as the next toke
        Throws:
        java.io.IOException
        java.text.ParseException
      • nextCloserOrComma

        private static java.lang.String nextCloserOrComma​(java.io.StreamTokenizer stream)
                                                   throws java.io.IOException,
                                                          java.text.ParseException
        expects either a closing LPAREN or comma as the next token
        Throws:
        java.io.IOException
        java.text.ParseException
      • checkEOF

        private static void checkEOF​(java.io.StreamTokenizer stream)
                              throws java.text.ParseException,
                                     java.io.IOException
        next word in the stream
        Throws:
        java.text.ParseException
        java.io.IOException