res.setLat(p.getCoordinates().getLatitude()); res.setLng(p.getCoordinates().getLongitude()); res.setDescription(feature.getProperties().get("label").toString());
private boolean isFeatureEmpty(org.geojson.Feature feature) { return feature == null || (feature.getGeometry() == null && feature.getProperties().isEmpty()); } }
@Override public EventSchema getEventSchema(List<byte[]> oneEvent) { EventSchema resultSchema = new EventSchema(); Feature geoFeature = null; try { geoFeature = new ObjectMapper().readValue(oneEvent.get(0), Feature.class); } catch (IOException e) { logger.error(e.toString()); } for (Map.Entry<String, Object> entry : geoFeature.getProperties().entrySet()) { EventProperty p = JsonEventProperty.getEventProperty(entry.getKey(), entry.getValue()); resultSchema.addEventProperty(p); } List<EventProperty> eventProperties = parseGeometryField(geoFeature); eventProperties.forEach(eventProperty -> resultSchema.addEventProperty(eventProperty)); return resultSchema; }
@Override public EventSchema getEventSchema(List<byte[]> oneEvent) { EventSchema resultSchema = new EventSchema(); Feature geoFeature = null; try { geoFeature = new ObjectMapper().readValue(oneEvent.get(0), Feature.class); } catch (IOException e) { logger.error(e.toString()); } for (Map.Entry<String, Object> entry : geoFeature.getProperties().entrySet()) { EventProperty p = JsonEventProperty.getEventProperty(entry.getKey(), entry.getValue()); resultSchema.addEventProperty(p); } List<EventProperty> eventProperties = parseGeometryField(geoFeature); eventProperties.forEach(eventProperty -> resultSchema.addEventProperty(eventProperty)); return resultSchema; }
@Test public void writes_the_GeoJSON_file() throws IOException { List<Feature> outputFeatures = IntStream.range(0, 1000).mapToObj(i -> buildFeature()).collect(Collectors.toList()); GeoJson.write(output, outputFeatures.stream()); FeatureCollection parsedFeatureCollection = new ObjectMapper().readValue(Files.newInputStream(output), FeatureCollection.class); List<Feature> actualFeatures = parsedFeatureCollection.getFeatures(); assertThat(actualFeatures, hasSize(1000)); assertThat(actualFeatures, allMatch(feature -> feature.getGeometry() instanceof Point)); assertThat(actualFeatures, allMatch(feature -> ((Point) feature.getGeometry()).getCoordinates() != null)); assertThat(actualFeatures, allMatch(feature -> feature.getProperties().containsKey("key") && feature.getProperty("key") != null)); assertThat(actualFeatures, allMatch(feature -> feature.getProperties().containsKey("field") && feature.getProperty("field").equals("some-field"))); assertThat(actualFeatures, allMatch(feature -> feature.getProperties().containsKey("empty") && feature.getProperty("empty").equals("no"))); assertThat(actualFeatures, allMatch(feature -> feature.getProperties().containsKey("valid") && feature.getProperty("valid").equals("yes"))); }