@SuppressWarnings("unchecked") @Test public void testFeatureCollectionWithRegularGeometryAttributeReadAndGeometryAfterProperties() throws Exception { String geojson1 = "{" + "'type': 'FeatureCollection'," + "'features': " + "[{" + " 'type': 'Feature'," + " 'id': 'feature.0'," + " 'properties': {" + " 'otherGeometry': {" + " 'type': 'LineString'," + " 'coordinates': [[1.1, 1.2], [1.3, 1.4]]" + " }" + " }," + " 'geometry': {" + " 'type': 'Point'," + " 'coordinates': [0.1, 0.1]" + " }" + "}" + "]" + "}"; geojson1 = geojson1.replace('\'', '"'); SimpleFeature f = null; try (GeoJSONReader reader = new GeoJSONReader(new ByteArrayInputStream(geojson1.getBytes()))) { FeatureCollection features = reader.getFeatures(); assertNotNull(features); assertFalse(features.isEmpty()); f = (SimpleFeature) DataUtilities.first(features); } catch (IOException e) { e.printStackTrace(); } assertNotNull(f); assertEquals("features.0", f.getID()); WKTReader wkt = new WKTReader(); assertEquals(wkt.read("POINT (0.1 0.1)"), f.getDefaultGeometry()); assertEquals(wkt.read("LINESTRING (1.1 1.2, 1.3 1.4)"), f.getAttribute("otherGeometry")); }
public FeatureCollection getFeatures() throws IOException { if (!isConnected()) { throw new IOException("not connected to " + url.toExternalForm()); } ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new JtsModule()); List<SimpleFeature> features = new ArrayList<>(); builder = null; while (!parser.isClosed()) { JsonToken token = parser.nextToken(); if (token == null) { break; } if (JsonToken.FIELD_NAME.equals(token) && "features".equalsIgnoreCase(parser.currentName())) { token = parser.nextToken(); if (!JsonToken.START_ARRAY.equals(token) || token == null) { break; } while (parser.nextToken() == JsonToken.START_OBJECT) { ObjectNode node = mapper.readTree(parser); SimpleFeature feature = getNextFeature(node); features.add(feature); } } } if (isSchemaChanged()) { List<SimpleFeature> nFeatures = new ArrayList<>(features.size()); for (SimpleFeature feature : features) { if (feature.getFeatureType() != schema) { SimpleFeature nFeature = DataUtilities.reType(schema, feature); nFeatures.add(nFeature); } else { nFeatures.add(feature); } } return DataUtilities.collection(nFeatures); } return DataUtilities.collection(features); }
GeoJSONReader implements AutoCloseable { public FeatureCollection getFeatures() throws IOException { if (!isConnected()) { throw new IOException("not connected to " + url.toExternalForm()); } ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new JtsModule()); List<SimpleFeature> features = new ArrayList<>(); builder = null; while (!parser.isClosed()) { JsonToken token = parser.nextToken(); if (token == null) { break; } if (JsonToken.FIELD_NAME.equals(token) && "features".equalsIgnoreCase(parser.currentName())) { token = parser.nextToken(); if (!JsonToken.START_ARRAY.equals(token) || token == null) { break; } while (parser.nextToken() == JsonToken.START_OBJECT) { ObjectNode node = mapper.readTree(parser); SimpleFeature feature = getNextFeature(node); features.add(feature); } } } if (isSchemaChanged()) { List<SimpleFeature> nFeatures = new ArrayList<>(features.size()); for (SimpleFeature feature : features) { if (feature.getFeatureType() != schema) { SimpleFeature nFeature = DataUtilities.reType(schema, feature); nFeatures.add(nFeature); } else { nFeatures.add(feature); } } return DataUtilities.collection(nFeatures); } return DataUtilities.collection(features); } }
GeoJSONReader implements AutoCloseable { public FeatureCollection getFeatures() throws IOException { if (!isConnected()) { throw new IOException("not connected to " + url.toExternalForm()); } ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new JtsModule()); List<SimpleFeature> features = new ArrayList<>(); builder = null; while (!parser.isClosed()) { JsonToken token = parser.nextToken(); if (token == null) { break; } if (JsonToken.FIELD_NAME.equals(token) && "features".equalsIgnoreCase(parser.currentName())) { token = parser.nextToken(); if (!JsonToken.START_ARRAY.equals(token) || token == null) { break; } while (parser.nextToken() == JsonToken.START_OBJECT) { ObjectNode node = mapper.readTree(parser); SimpleFeature feature = getNextFeature(node); features.add(feature); } } } if (isSchemaChanged()) { List<SimpleFeature> nFeatures = new ArrayList<>(features.size()); for (SimpleFeature feature : features) { if (feature.getFeatureType() != schema) { SimpleFeature nFeature = DataUtilities.reType(schema, feature); nFeatures.add(nFeature); } else { nFeatures.add(feature); } } return DataUtilities.collection(nFeatures); } return DataUtilities.collection(features); } GeoJSONReader(URL url);  GeoJSONReader(InputStream is); }
GeoJSONReader implements AutoCloseable { public FeatureCollection getFeatures() throws IOException { if (!isConnected()) { throw new IOException("not connected to " + url.toExternalForm()); } ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new JtsModule()); List<SimpleFeature> features = new ArrayList<>(); builder = null; while (!parser.isClosed()) { JsonToken token = parser.nextToken(); if (token == null) { break; } if (JsonToken.FIELD_NAME.equals(token) && "features".equalsIgnoreCase(parser.currentName())) { token = parser.nextToken(); if (!JsonToken.START_ARRAY.equals(token) || token == null) { break; } while (parser.nextToken() == JsonToken.START_OBJECT) { ObjectNode node = mapper.readTree(parser); SimpleFeature feature = getNextFeature(node); features.add(feature); } } } if (isSchemaChanged()) { List<SimpleFeature> nFeatures = new ArrayList<>(features.size()); for (SimpleFeature feature : features) { if (feature.getFeatureType() != schema) { SimpleFeature nFeature = DataUtilities.reType(schema, feature); nFeatures.add(nFeature); } else { nFeatures.add(feature); } } return DataUtilities.collection(nFeatures); } return DataUtilities.collection(features); } GeoJSONReader(URL url);  GeoJSONReader(InputStream is); boolean isConnected(); static SimpleFeature parseFeature(String json); FeatureCollection getFeatures(); FeatureIterator<SimpleFeature> getIterator(); FeatureType getSchema(); void setSchema(SimpleFeatureType schema); boolean isSchemaChanged(); void setSchemaChanged(boolean schemaChanged); @Override void close(); }
GeoJSONReader implements AutoCloseable { public FeatureCollection getFeatures() throws IOException { if (!isConnected()) { throw new IOException("not connected to " + url.toExternalForm()); } ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new JtsModule()); List<SimpleFeature> features = new ArrayList<>(); builder = null; while (!parser.isClosed()) { JsonToken token = parser.nextToken(); if (token == null) { break; } if (JsonToken.FIELD_NAME.equals(token) && "features".equalsIgnoreCase(parser.currentName())) { token = parser.nextToken(); if (!JsonToken.START_ARRAY.equals(token) || token == null) { break; } while (parser.nextToken() == JsonToken.START_OBJECT) { ObjectNode node = mapper.readTree(parser); SimpleFeature feature = getNextFeature(node); features.add(feature); } } } if (isSchemaChanged()) { List<SimpleFeature> nFeatures = new ArrayList<>(features.size()); for (SimpleFeature feature : features) { if (feature.getFeatureType() != schema) { SimpleFeature nFeature = DataUtilities.reType(schema, feature); nFeatures.add(nFeature); } else { nFeatures.add(feature); } } return DataUtilities.collection(nFeatures); } return DataUtilities.collection(features); } GeoJSONReader(URL url);  GeoJSONReader(InputStream is); boolean isConnected(); static SimpleFeature parseFeature(String json); FeatureCollection getFeatures(); FeatureIterator<SimpleFeature> getIterator(); FeatureType getSchema(); void setSchema(SimpleFeatureType schema); boolean isSchemaChanged(); void setSchemaChanged(boolean schemaChanged); @Override void close(); static final String GEOMETRY_NAME; }