@Test(expected = JsonSyntaxException.class) public void parseGeometryIncorrectGeometryType() throws Exception { Geometry geom = (new GeoJSONParser( new ByteArrayInputStream( "{\"type\": \"POINT\", \"coordinates\": [1.0, 2.0]}" .getBytes()), this.fType, null)) .parseGeometry(); }
public Geometry parseGeometry() throws JsonSyntaxException, IOException, IllegalStateException { double[] coords; GeometryBuilder builder = new GeometryBuilder(); GeometryFactory geomFactory = new GeometryFactory(); try { if (this.reader.peek() == JsonToken.NULL) { this.reader.nextNull(); throw (new MalformedJsonException( "just here to avoid repeating the return statement")); } } catch (IllegalStateException | MalformedJsonException e) { return builder.point(); } this.reader.beginObject(); if (!reader.nextName().equals(FEATURE_TYPE)) { throw (new JsonSyntaxException("Geometry type expected")); } switch (reader.nextString()) { case GEOMETRY_POINT: this.checkPropertyName(FEATURE_GEOMETRY_COORDINATES); coords = this.parsePointCoordinates(); this.reader.endObject(); return (Geometry) builder.point(coords[0], coords[1]); case GEOMETRY_MULTIPOINT: this.checkPropertyName(FEATURE_GEOMETRY_COORDINATES); List<double[]> pointCoords = this.parseMultiPointCoordinates(); ; Point[] points = new Point[pointCoords.size()]; for (int i = 0; i < pointCoords.size(); i++) { points[i] = (Point) builder.point(pointCoords.get(i)[0], pointCoords.get(i)[1]); } this.reader.endObject(); return (Geometry) new MultiPoint(points, geomFactory); case GEOMETRY_LINE: this.checkPropertyName(FEATURE_GEOMETRY_COORDINATES); coords = this.parseLineStringCoordinates(); this.reader.endObject(); return (Geometry) builder.lineString(coords); case GEOMETRY_MULTILINE: this.checkPropertyName(FEATURE_GEOMETRY_COORDINATES); List<double[]> lineArrays = this.parseMultiLineStringCoordinates(); LineString[] lines = new LineString[lineArrays.size()]; int i = 0; for (double[] array : lineArrays) { lines[i++] = builder.lineString(array); } this.reader.endObject(); return (Geometry) builder.multiLineString(lines); case GEOMETRY_POLYGON: this.checkPropertyName(FEATURE_GEOMETRY_COORDINATES); List<double[]> rings = this.parsePolygonCoordinates(); this.reader.endObject(); return (Geometry) builder.polygon(rings.get(0)); case GEOMETRY_MULTIPOLYGON: this.checkPropertyName(FEATURE_GEOMETRY_COORDINATES); List<List<double[]>> polyArrays = this.parseMultiPolygonCoordinates(); Polygon[] polys = new Polygon[polyArrays.size()]; int j = 0; for (List<double[]> array : polyArrays) { polys[j++] = builder.polygon(array.get(0)); } this.reader.endObject(); return (Geometry) builder.multiPolygon(polys); default: throw (new JsonSyntaxException("Unrecognized geometry type")); } }
GeoJSONParser implements SimpleFeatureIterator { public Geometry parseGeometry() throws JsonSyntaxException, IOException, IllegalStateException { double[] coords; GeometryBuilder builder = new GeometryBuilder(); GeometryFactory geomFactory = new GeometryFactory(); try { if (this.reader.peek() == JsonToken.NULL) { this.reader.nextNull(); throw (new MalformedJsonException( "just here to avoid repeating the return statement")); } } catch (IllegalStateException | MalformedJsonException e) { return builder.point(); } this.reader.beginObject(); if (!reader.nextName().equals(FEATURE_TYPE)) { throw (new JsonSyntaxException("Geometry type expected")); } switch (reader.nextString()) { case GEOMETRY_POINT: this.checkPropertyName(FEATURE_GEOMETRY_COORDINATES); coords = this.parsePointCoordinates(); this.reader.endObject(); return (Geometry) builder.point(coords[0], coords[1]); case GEOMETRY_MULTIPOINT: this.checkPropertyName(FEATURE_GEOMETRY_COORDINATES); List<double[]> pointCoords = this.parseMultiPointCoordinates(); ; Point[] points = new Point[pointCoords.size()]; for (int i = 0; i < pointCoords.size(); i++) { points[i] = (Point) builder.point(pointCoords.get(i)[0], pointCoords.get(i)[1]); } this.reader.endObject(); return (Geometry) new MultiPoint(points, geomFactory); case GEOMETRY_LINE: this.checkPropertyName(FEATURE_GEOMETRY_COORDINATES); coords = this.parseLineStringCoordinates(); this.reader.endObject(); return (Geometry) builder.lineString(coords); case GEOMETRY_MULTILINE: this.checkPropertyName(FEATURE_GEOMETRY_COORDINATES); List<double[]> lineArrays = this.parseMultiLineStringCoordinates(); LineString[] lines = new LineString[lineArrays.size()]; int i = 0; for (double[] array : lineArrays) { lines[i++] = builder.lineString(array); } this.reader.endObject(); return (Geometry) builder.multiLineString(lines); case GEOMETRY_POLYGON: this.checkPropertyName(FEATURE_GEOMETRY_COORDINATES); List<double[]> rings = this.parsePolygonCoordinates(); this.reader.endObject(); return (Geometry) builder.polygon(rings.get(0)); case GEOMETRY_MULTIPOLYGON: this.checkPropertyName(FEATURE_GEOMETRY_COORDINATES); List<List<double[]>> polyArrays = this.parseMultiPolygonCoordinates(); Polygon[] polys = new Polygon[polyArrays.size()]; int j = 0; for (List<double[]> array : polyArrays) { polys[j++] = builder.polygon(array.get(0)); } this.reader.endObject(); return (Geometry) builder.multiPolygon(polys); default: throw (new JsonSyntaxException("Unrecognized geometry type")); } } }
GeoJSONParser implements SimpleFeatureIterator { public Geometry parseGeometry() throws JsonSyntaxException, IOException, IllegalStateException { double[] coords; GeometryBuilder builder = new GeometryBuilder(); GeometryFactory geomFactory = new GeometryFactory(); try { if (this.reader.peek() == JsonToken.NULL) { this.reader.nextNull(); throw (new MalformedJsonException( "just here to avoid repeating the return statement")); } } catch (IllegalStateException | MalformedJsonException e) { return builder.point(); } this.reader.beginObject(); if (!reader.nextName().equals(FEATURE_TYPE)) { throw (new JsonSyntaxException("Geometry type expected")); } switch (reader.nextString()) { case GEOMETRY_POINT: this.checkPropertyName(FEATURE_GEOMETRY_COORDINATES); coords = this.parsePointCoordinates(); this.reader.endObject(); return (Geometry) builder.point(coords[0], coords[1]); case GEOMETRY_MULTIPOINT: this.checkPropertyName(FEATURE_GEOMETRY_COORDINATES); List<double[]> pointCoords = this.parseMultiPointCoordinates(); ; Point[] points = new Point[pointCoords.size()]; for (int i = 0; i < pointCoords.size(); i++) { points[i] = (Point) builder.point(pointCoords.get(i)[0], pointCoords.get(i)[1]); } this.reader.endObject(); return (Geometry) new MultiPoint(points, geomFactory); case GEOMETRY_LINE: this.checkPropertyName(FEATURE_GEOMETRY_COORDINATES); coords = this.parseLineStringCoordinates(); this.reader.endObject(); return (Geometry) builder.lineString(coords); case GEOMETRY_MULTILINE: this.checkPropertyName(FEATURE_GEOMETRY_COORDINATES); List<double[]> lineArrays = this.parseMultiLineStringCoordinates(); LineString[] lines = new LineString[lineArrays.size()]; int i = 0; for (double[] array : lineArrays) { lines[i++] = builder.lineString(array); } this.reader.endObject(); return (Geometry) builder.multiLineString(lines); case GEOMETRY_POLYGON: this.checkPropertyName(FEATURE_GEOMETRY_COORDINATES); List<double[]> rings = this.parsePolygonCoordinates(); this.reader.endObject(); return (Geometry) builder.polygon(rings.get(0)); case GEOMETRY_MULTIPOLYGON: this.checkPropertyName(FEATURE_GEOMETRY_COORDINATES); List<List<double[]>> polyArrays = this.parseMultiPolygonCoordinates(); Polygon[] polys = new Polygon[polyArrays.size()]; int j = 0; for (List<double[]> array : polyArrays) { polys[j++] = builder.polygon(array.get(0)); } this.reader.endObject(); return (Geometry) builder.multiPolygon(polys); default: throw (new JsonSyntaxException("Unrecognized geometry type")); } } GeoJSONParser(InputStream iStream, SimpleFeatureType featureTypeIn, Logger loggerIn); }
GeoJSONParser implements SimpleFeatureIterator { public Geometry parseGeometry() throws JsonSyntaxException, IOException, IllegalStateException { double[] coords; GeometryBuilder builder = new GeometryBuilder(); GeometryFactory geomFactory = new GeometryFactory(); try { if (this.reader.peek() == JsonToken.NULL) { this.reader.nextNull(); throw (new MalformedJsonException( "just here to avoid repeating the return statement")); } } catch (IllegalStateException | MalformedJsonException e) { return builder.point(); } this.reader.beginObject(); if (!reader.nextName().equals(FEATURE_TYPE)) { throw (new JsonSyntaxException("Geometry type expected")); } switch (reader.nextString()) { case GEOMETRY_POINT: this.checkPropertyName(FEATURE_GEOMETRY_COORDINATES); coords = this.parsePointCoordinates(); this.reader.endObject(); return (Geometry) builder.point(coords[0], coords[1]); case GEOMETRY_MULTIPOINT: this.checkPropertyName(FEATURE_GEOMETRY_COORDINATES); List<double[]> pointCoords = this.parseMultiPointCoordinates(); ; Point[] points = new Point[pointCoords.size()]; for (int i = 0; i < pointCoords.size(); i++) { points[i] = (Point) builder.point(pointCoords.get(i)[0], pointCoords.get(i)[1]); } this.reader.endObject(); return (Geometry) new MultiPoint(points, geomFactory); case GEOMETRY_LINE: this.checkPropertyName(FEATURE_GEOMETRY_COORDINATES); coords = this.parseLineStringCoordinates(); this.reader.endObject(); return (Geometry) builder.lineString(coords); case GEOMETRY_MULTILINE: this.checkPropertyName(FEATURE_GEOMETRY_COORDINATES); List<double[]> lineArrays = this.parseMultiLineStringCoordinates(); LineString[] lines = new LineString[lineArrays.size()]; int i = 0; for (double[] array : lineArrays) { lines[i++] = builder.lineString(array); } this.reader.endObject(); return (Geometry) builder.multiLineString(lines); case GEOMETRY_POLYGON: this.checkPropertyName(FEATURE_GEOMETRY_COORDINATES); List<double[]> rings = this.parsePolygonCoordinates(); this.reader.endObject(); return (Geometry) builder.polygon(rings.get(0)); case GEOMETRY_MULTIPOLYGON: this.checkPropertyName(FEATURE_GEOMETRY_COORDINATES); List<List<double[]>> polyArrays = this.parseMultiPolygonCoordinates(); Polygon[] polys = new Polygon[polyArrays.size()]; int j = 0; for (List<double[]> array : polyArrays) { polys[j++] = builder.polygon(array.get(0)); } this.reader.endObject(); return (Geometry) builder.multiPolygon(polys); default: throw (new JsonSyntaxException("Unrecognized geometry type")); } } GeoJSONParser(InputStream iStream, SimpleFeatureType featureTypeIn, Logger loggerIn); @Override void close(); @Override boolean hasNext(); @Override SimpleFeature next(); void parseFeatureCollection(); static double[] listToArray(List<Double> coords); double[] parseCoordinateArray(); double[] parsePointCoordinates(); List<double[]> parseMultiPointCoordinates(); double[] parseLineStringCoordinates(); List<double[]> parseMultiLineStringCoordinates(); List<double[]> parsePolygonCoordinates(); List<List<double[]>> parseMultiPolygonCoordinates(); Geometry parseGeometry(); Map<String, Object> parseProperties(); SimpleFeature parseFeature(); IOException parseError(); }
GeoJSONParser implements SimpleFeatureIterator { public Geometry parseGeometry() throws JsonSyntaxException, IOException, IllegalStateException { double[] coords; GeometryBuilder builder = new GeometryBuilder(); GeometryFactory geomFactory = new GeometryFactory(); try { if (this.reader.peek() == JsonToken.NULL) { this.reader.nextNull(); throw (new MalformedJsonException( "just here to avoid repeating the return statement")); } } catch (IllegalStateException | MalformedJsonException e) { return builder.point(); } this.reader.beginObject(); if (!reader.nextName().equals(FEATURE_TYPE)) { throw (new JsonSyntaxException("Geometry type expected")); } switch (reader.nextString()) { case GEOMETRY_POINT: this.checkPropertyName(FEATURE_GEOMETRY_COORDINATES); coords = this.parsePointCoordinates(); this.reader.endObject(); return (Geometry) builder.point(coords[0], coords[1]); case GEOMETRY_MULTIPOINT: this.checkPropertyName(FEATURE_GEOMETRY_COORDINATES); List<double[]> pointCoords = this.parseMultiPointCoordinates(); ; Point[] points = new Point[pointCoords.size()]; for (int i = 0; i < pointCoords.size(); i++) { points[i] = (Point) builder.point(pointCoords.get(i)[0], pointCoords.get(i)[1]); } this.reader.endObject(); return (Geometry) new MultiPoint(points, geomFactory); case GEOMETRY_LINE: this.checkPropertyName(FEATURE_GEOMETRY_COORDINATES); coords = this.parseLineStringCoordinates(); this.reader.endObject(); return (Geometry) builder.lineString(coords); case GEOMETRY_MULTILINE: this.checkPropertyName(FEATURE_GEOMETRY_COORDINATES); List<double[]> lineArrays = this.parseMultiLineStringCoordinates(); LineString[] lines = new LineString[lineArrays.size()]; int i = 0; for (double[] array : lineArrays) { lines[i++] = builder.lineString(array); } this.reader.endObject(); return (Geometry) builder.multiLineString(lines); case GEOMETRY_POLYGON: this.checkPropertyName(FEATURE_GEOMETRY_COORDINATES); List<double[]> rings = this.parsePolygonCoordinates(); this.reader.endObject(); return (Geometry) builder.polygon(rings.get(0)); case GEOMETRY_MULTIPOLYGON: this.checkPropertyName(FEATURE_GEOMETRY_COORDINATES); List<List<double[]>> polyArrays = this.parseMultiPolygonCoordinates(); Polygon[] polys = new Polygon[polyArrays.size()]; int j = 0; for (List<double[]> array : polyArrays) { polys[j++] = builder.polygon(array.get(0)); } this.reader.endObject(); return (Geometry) builder.multiPolygon(polys); default: throw (new JsonSyntaxException("Unrecognized geometry type")); } } GeoJSONParser(InputStream iStream, SimpleFeatureType featureTypeIn, Logger loggerIn); @Override void close(); @Override boolean hasNext(); @Override SimpleFeature next(); void parseFeatureCollection(); static double[] listToArray(List<Double> coords); double[] parseCoordinateArray(); double[] parsePointCoordinates(); List<double[]> parseMultiPointCoordinates(); double[] parseLineStringCoordinates(); List<double[]> parseMultiLineStringCoordinates(); List<double[]> parsePolygonCoordinates(); List<List<double[]>> parseMultiPolygonCoordinates(); Geometry parseGeometry(); Map<String, Object> parseProperties(); SimpleFeature parseFeature(); IOException parseError(); static final String ENCODING; static final String DATETIME_FORMAT; static final String ERROR; static final String ERROR_CODE; static final String ERROR_MESSAGE; static final String ERROR_DETAILS; static final String GEOJSON_TYPE; static final String GEOJSON_TYPE_VALUE_FC; static final String GEOJSON_PROPERTIES; static final String GEOJSON_TOTALFEATURES; static final String FEATURES; static final String CRS; static final String CRS_TYPE; static final String CRS_TYPE_VALUE; static final String CRS_PROPERTIES; static final String CRS_PROPERTIES_NAME; static final String FEATURE_TYPE; static final String FEATURE_ID; static final String FEATURE_GEOMETRY; static final String FEATURE_GEOMETRY_TYPE; static final String FEATURE_TYPE_VALUE; static final String FEATURE_GEOMETRY_COORDINATES; static final String FEATURE_PROPERTIES; static final String GEOMETRY_POINT; static final String GEOMETRY_MULTIPOINT; static final String GEOMETRY_LINE; static final String GEOMETRY_MULTILINE; static final String GEOMETRY_POLYGON; static final String GEOMETRY_MULTIPOLYGON; }