@Test public void parseFeature() throws Exception { SimpleFeature feat = (new GeoJSONParser( new ByteArrayInputStream( "{\"type\":\"Feature\", \"geometry\": {\"type\": \"Point\", \"coordinates\": [1.0, 2.0]}, \"properties\":{\"vstring\": \"value0\", \"vint\": 12, \"vboolean\": true}}" .getBytes()), this.fType, null)) .parseFeature(); assertEquals(1.0f, ((Point) (feat.getDefaultGeometry())).getX(), 0.1f); assertEquals(2.0f, ((Point) (feat.getDefaultGeometry())).getY(), 0.1f); assertEquals("value0", feat.getAttribute("vstring")); assertTrue((Boolean) (feat.getAttribute("vboolean"))); assertEquals(12, feat.getAttribute("vint")); }
public SimpleFeature parseFeature() { Geometry geom = null; String id = SimpleFeatureBuilder.createDefaultFeatureIdentifier(FEATURES).getID(); Map<String, Object> props = new HashMap<String, Object>(); SimpleFeatureBuilder builder = new SimpleFeatureBuilder(this.featureType); try { this.reader.beginObject(); while (this.reader.hasNext()) { switch (this.reader.nextName()) { case FEATURE_TYPE: this.checkPropertyValue(FEATURE_TYPE_VALUE); break; case FEATURE_GEOMETRY: geom = this.parseGeometry(); break; case FEATURE_PROPERTIES: props = this.parseProperties(); break; case FEATURE_ID: id = this.reader.nextString(); break; default: this.LOGGER.log(Level.WARNING, "Unrecognized feature format"); this.reader.skipValue(); } } this.reader.endObject(); } catch (IOException | IllegalStateException e) { throw (new NoSuchElementException(e.getMessage())); } for (AttributeDescriptor attr : this.featureType.getAttributeDescriptors()) { if (this.featureType .getGeometryDescriptor() .getLocalName() .equals(attr.getLocalName())) { builder.set(attr.getLocalName(), geom); } else { if (props.get(attr.getLocalName()) != null) { try { builder.set(attr.getLocalName(), props.get(attr.getLocalName())); } catch (java.lang.AbstractMethodError e) { this.LOGGER.log( Level.SEVERE, String.format( "Error reading attribute %s with value %s", attr.getLocalName(), props.get(attr.getLocalName()))); } } } } return builder.buildFeature(id); }
GeoJSONParser implements SimpleFeatureIterator { public SimpleFeature parseFeature() { Geometry geom = null; String id = SimpleFeatureBuilder.createDefaultFeatureIdentifier(FEATURES).getID(); Map<String, Object> props = new HashMap<String, Object>(); SimpleFeatureBuilder builder = new SimpleFeatureBuilder(this.featureType); try { this.reader.beginObject(); while (this.reader.hasNext()) { switch (this.reader.nextName()) { case FEATURE_TYPE: this.checkPropertyValue(FEATURE_TYPE_VALUE); break; case FEATURE_GEOMETRY: geom = this.parseGeometry(); break; case FEATURE_PROPERTIES: props = this.parseProperties(); break; case FEATURE_ID: id = this.reader.nextString(); break; default: this.LOGGER.log(Level.WARNING, "Unrecognized feature format"); this.reader.skipValue(); } } this.reader.endObject(); } catch (IOException | IllegalStateException e) { throw (new NoSuchElementException(e.getMessage())); } for (AttributeDescriptor attr : this.featureType.getAttributeDescriptors()) { if (this.featureType .getGeometryDescriptor() .getLocalName() .equals(attr.getLocalName())) { builder.set(attr.getLocalName(), geom); } else { if (props.get(attr.getLocalName()) != null) { try { builder.set(attr.getLocalName(), props.get(attr.getLocalName())); } catch (java.lang.AbstractMethodError e) { this.LOGGER.log( Level.SEVERE, String.format( "Error reading attribute %s with value %s", attr.getLocalName(), props.get(attr.getLocalName()))); } } } } return builder.buildFeature(id); } }
GeoJSONParser implements SimpleFeatureIterator { public SimpleFeature parseFeature() { Geometry geom = null; String id = SimpleFeatureBuilder.createDefaultFeatureIdentifier(FEATURES).getID(); Map<String, Object> props = new HashMap<String, Object>(); SimpleFeatureBuilder builder = new SimpleFeatureBuilder(this.featureType); try { this.reader.beginObject(); while (this.reader.hasNext()) { switch (this.reader.nextName()) { case FEATURE_TYPE: this.checkPropertyValue(FEATURE_TYPE_VALUE); break; case FEATURE_GEOMETRY: geom = this.parseGeometry(); break; case FEATURE_PROPERTIES: props = this.parseProperties(); break; case FEATURE_ID: id = this.reader.nextString(); break; default: this.LOGGER.log(Level.WARNING, "Unrecognized feature format"); this.reader.skipValue(); } } this.reader.endObject(); } catch (IOException | IllegalStateException e) { throw (new NoSuchElementException(e.getMessage())); } for (AttributeDescriptor attr : this.featureType.getAttributeDescriptors()) { if (this.featureType .getGeometryDescriptor() .getLocalName() .equals(attr.getLocalName())) { builder.set(attr.getLocalName(), geom); } else { if (props.get(attr.getLocalName()) != null) { try { builder.set(attr.getLocalName(), props.get(attr.getLocalName())); } catch (java.lang.AbstractMethodError e) { this.LOGGER.log( Level.SEVERE, String.format( "Error reading attribute %s with value %s", attr.getLocalName(), props.get(attr.getLocalName()))); } } } } return builder.buildFeature(id); } GeoJSONParser(InputStream iStream, SimpleFeatureType featureTypeIn, Logger loggerIn); }
GeoJSONParser implements SimpleFeatureIterator { public SimpleFeature parseFeature() { Geometry geom = null; String id = SimpleFeatureBuilder.createDefaultFeatureIdentifier(FEATURES).getID(); Map<String, Object> props = new HashMap<String, Object>(); SimpleFeatureBuilder builder = new SimpleFeatureBuilder(this.featureType); try { this.reader.beginObject(); while (this.reader.hasNext()) { switch (this.reader.nextName()) { case FEATURE_TYPE: this.checkPropertyValue(FEATURE_TYPE_VALUE); break; case FEATURE_GEOMETRY: geom = this.parseGeometry(); break; case FEATURE_PROPERTIES: props = this.parseProperties(); break; case FEATURE_ID: id = this.reader.nextString(); break; default: this.LOGGER.log(Level.WARNING, "Unrecognized feature format"); this.reader.skipValue(); } } this.reader.endObject(); } catch (IOException | IllegalStateException e) { throw (new NoSuchElementException(e.getMessage())); } for (AttributeDescriptor attr : this.featureType.getAttributeDescriptors()) { if (this.featureType .getGeometryDescriptor() .getLocalName() .equals(attr.getLocalName())) { builder.set(attr.getLocalName(), geom); } else { if (props.get(attr.getLocalName()) != null) { try { builder.set(attr.getLocalName(), props.get(attr.getLocalName())); } catch (java.lang.AbstractMethodError e) { this.LOGGER.log( Level.SEVERE, String.format( "Error reading attribute %s with value %s", attr.getLocalName(), props.get(attr.getLocalName()))); } } } } return builder.buildFeature(id); } 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 SimpleFeature parseFeature() { Geometry geom = null; String id = SimpleFeatureBuilder.createDefaultFeatureIdentifier(FEATURES).getID(); Map<String, Object> props = new HashMap<String, Object>(); SimpleFeatureBuilder builder = new SimpleFeatureBuilder(this.featureType); try { this.reader.beginObject(); while (this.reader.hasNext()) { switch (this.reader.nextName()) { case FEATURE_TYPE: this.checkPropertyValue(FEATURE_TYPE_VALUE); break; case FEATURE_GEOMETRY: geom = this.parseGeometry(); break; case FEATURE_PROPERTIES: props = this.parseProperties(); break; case FEATURE_ID: id = this.reader.nextString(); break; default: this.LOGGER.log(Level.WARNING, "Unrecognized feature format"); this.reader.skipValue(); } } this.reader.endObject(); } catch (IOException | IllegalStateException e) { throw (new NoSuchElementException(e.getMessage())); } for (AttributeDescriptor attr : this.featureType.getAttributeDescriptors()) { if (this.featureType .getGeometryDescriptor() .getLocalName() .equals(attr.getLocalName())) { builder.set(attr.getLocalName(), geom); } else { if (props.get(attr.getLocalName()) != null) { try { builder.set(attr.getLocalName(), props.get(attr.getLocalName())); } catch (java.lang.AbstractMethodError e) { this.LOGGER.log( Level.SEVERE, String.format( "Error reading attribute %s with value %s", attr.getLocalName(), props.get(attr.getLocalName()))); } } } } return builder.buildFeature(id); } 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; }