Class SimpleGeoJSONPolygonParser


  • class SimpleGeoJSONPolygonParser
    extends java.lang.Object
    Does minimal parsing of a GeoJSON object, to extract either Polygon or MultiPolygon, either directly as the top-level type, or if the top-level type is Feature, as the geometry of that feature.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.List<java.lang.Object> coordinates  
      (package private) java.lang.String input  
      private java.lang.String polyType  
      private int upto  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private static boolean isJSONWhitespace​(char ch)  
      private boolean isValidGeometryPath​(java.lang.String path)
      Returns true if the object path is a valid location to see a Multi/Polygon geometry
      private java.text.ParseException newParseException​(java.lang.String details)
      When calling this, upto should be at the position of the incorrect character!
      Polygon[] parse()  
      private java.util.List<java.lang.Object> parseArray​(java.lang.String path)  
      private java.lang.Number parseNumber()  
      private void parseObject​(java.lang.String path)
      path is the "address" by keys of where we are, e.g.
      private double[][] parsePoints​(java.util.List<java.lang.Object> o)
      Parses [[lat, lon], [lat, lon] ...] into 2d double array
      private Polygon parsePolygon​(java.util.List<java.lang.Object> coordinates)  
      private java.lang.String parseString()  
      private char peek()  
      private void readEnd()  
      private void scan​(char expected)
      Scans across whitespace and consumes the expected character, or throws ParseException if the character is wrong
      private void scan​(java.lang.String expected)
      Scans the expected string, or throws ParseException
      • Methods inherited from class java.lang.Object

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

      • input

        final java.lang.String input
      • upto

        private int upto
      • polyType

        private java.lang.String polyType
      • coordinates

        private java.util.List<java.lang.Object> coordinates
    • Constructor Detail

      • SimpleGeoJSONPolygonParser

        public SimpleGeoJSONPolygonParser​(java.lang.String input)
    • Method Detail

      • parse

        public Polygon[] parse()
                        throws java.text.ParseException
        Throws:
        java.text.ParseException
      • parseObject

        private void parseObject​(java.lang.String path)
                          throws java.text.ParseException
        path is the "address" by keys of where we are, e.g. geometry.coordinates
        Throws:
        java.text.ParseException
      • isValidGeometryPath

        private boolean isValidGeometryPath​(java.lang.String path)
        Returns true if the object path is a valid location to see a Multi/Polygon geometry
      • parsePolygon

        private Polygon parsePolygon​(java.util.List<java.lang.Object> coordinates)
                              throws java.text.ParseException
        Throws:
        java.text.ParseException
      • parsePoints

        private double[][] parsePoints​(java.util.List<java.lang.Object> o)
                                throws java.text.ParseException
        Parses [[lat, lon], [lat, lon] ...] into 2d double array
        Throws:
        java.text.ParseException
      • parseArray

        private java.util.List<java.lang.Object> parseArray​(java.lang.String path)
                                                     throws java.text.ParseException
        Throws:
        java.text.ParseException
      • parseNumber

        private java.lang.Number parseNumber()
                                      throws java.text.ParseException
        Throws:
        java.text.ParseException
      • parseString

        private java.lang.String parseString()
                                      throws java.text.ParseException
        Throws:
        java.text.ParseException
      • peek

        private char peek()
                   throws java.text.ParseException
        Throws:
        java.text.ParseException
      • scan

        private void scan​(char expected)
                   throws java.text.ParseException
        Scans across whitespace and consumes the expected character, or throws ParseException if the character is wrong
        Throws:
        java.text.ParseException
      • readEnd

        private void readEnd()
                      throws java.text.ParseException
        Throws:
        java.text.ParseException
      • scan

        private void scan​(java.lang.String expected)
                   throws java.text.ParseException
        Scans the expected string, or throws ParseException
        Throws:
        java.text.ParseException
      • isJSONWhitespace

        private static boolean isJSONWhitespace​(char ch)
      • newParseException

        private java.text.ParseException newParseException​(java.lang.String details)
                                                    throws java.text.ParseException
        When calling this, upto should be at the position of the incorrect character!
        Throws:
        java.text.ParseException