@Test public void testGetFeatures() throws IOException, ParseException { URL url = TestData.url(GeoJSONDataStore.class, "locations.json"); try (GeoJSONReader reader = new GeoJSONReader(url)) { FeatureCollection features = reader.getFeatures(); assertNotNull(features); assertEquals("wrong number of features read", 9, features.size()); } }
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; }