for (Feature feature : featureCollection.getFeatures()) { GeoJsonObject geom = feature.getGeometry(); if (geom instanceof Point) {
/** * Default constructor used in serialization. */ public GeoServiceGeocodingResult() { this.addressComponents = new AddressComponent[0]; this.types = new AddressType[0]; this.geometry = new FeatureCollection(); }
/** * Constructor. * @param location the location of the center of the region * @param bounds the actual bounding box of the region * @param viewport the bounding box of the recommended view of the region */ private GeoServiceGeometry(final Feature location, final Feature bounds, final Feature viewport) { this(); this.featureCollection.add(location); this.featureCollection.add(bounds); this.featureCollection.add(viewport); }
/** * Default constructor to use in serialization. */ public GeoServiceGeometry() { this.featureCollection = new FeatureCollection(); }
public static List<POI> toPoiList(FeatureCollection featureCollection) { List<POI> pois = new ArrayList<>(); for (Feature feature : featureCollection.getFeatures()) { pois.add(toPoi(feature)); } return pois; } }
/** * Return the location. It is in the form of a GeoJSON feature. * Much of the descriptive data from Google is in the properties * of that feature. * * @return the location feature */ @Transient private Feature getLocation() { if (geometry == null) { return null; } final List<Feature> features = geometry.getFeatures(); if (features == null || features.isEmpty()) { return null; } return features.get(0); } }
/** * @param geometry the geometry to populate * @param featureCollection the feature collection to get bounds from * @return the populated location */ private Feature populateBoundaries(final Geometry geometry, final FeatureCollection featureCollection) { Feature location; if (featureCollection.getFeatures().isEmpty()) { location = null; geometry.bounds = toBounds(null); geometry.viewport = toBounds(null); } else { location = featureCollection.getFeatures().get(0); geometry.bounds = toBounds(featureCollection.getFeatures().get(1)); geometry.viewport = toBounds(featureCollection.getFeatures().get(2)); } return location; }
public static GeoPlaces toGeoPlaces(FeatureCollection featureCollection) { List<GeoPlace> places = new ArrayList<>(); for (Feature feature : featureCollection.getFeatures()) { places.add(toGeoPlace(feature)); } return new GeoPlaces(places); }
public static Photos toPhotos(FeatureCollection featureCollection) { List<Photo> photos = new ArrayList<>(); for (Feature feature : featureCollection.getFeatures()) { Photo photo = toPhoto(feature); if (!photo.isPlaceholder()) { photos.add(photo); } } return new Photos(photos); }
public String getAddressFor(NavigationPosition position) throws IOException { FeatureCollection collection = getResultFor("/reverse/?lon=" + position.getLongitude() + "&lat=" + position.getLatitude()); if (collection == null) return null; List<Feature> features = collection.getFeatures(); if (features.size() == 0) return null; Feature feature = features.get(0); GeoJsonObject geometry = feature.getGeometry(); if (!(geometry instanceof Point)) return null; return getDisplayName(feature); }
public List<NavigationPosition> getPositionsFor(String address) throws IOException { FeatureCollection collection = getResultFor("/api/?q=" + encodeUri(address) + "&limit=10"); if (collection == null) return null; return extractPositions(collection.getFeatures()); }
this.geometry = geometry; if (geometry != null && geometry.getFeatures() != null && !geometry.getFeatures().isEmpty()) { final Feature fg = geometry.getFeatures().get(0); fg.setProperty("formattedAddress", formattedAddress); fg.setProperty("partialMatch", Boolean.valueOf(partialMatch));
final GeoServiceGeocodingResult result = item.getResult(); final FeatureCollection featureCollection = result.getGeometry(); final List<Feature> features = featureCollection.getFeatures(); final Feature locationFeature = features.get(0); final Point locationPoint = (Point) locationFeature.getGeometry();
@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"))); }