private void writeGeometry(JsonWriter out, Feature value) throws IOException { out.name(GEOMETRY_NAME); geometryAdapter.write(out, value.geometry()); }
/** * Build a {@link Feature} with the given {@link Geometry}. * * @param geometry The Geometry to build Feature from * * @return An instance of Feature */ public static Feature of(Geometry<?> geometry) { return builder().withGeometry(geometry).build(); }
@Override public void write(JsonWriter out, Feature value) throws IOException { if (value == null) { out.nullValue(); } else { out.beginObject(); if(value.id().isPresent()) { out.name(ID_NAME).value(value.id().get()); } out.name(TYPE_NAME).value(FEATURE_TYPE); writeProperties(out, value); writeGeometry(out, value); out.endObject(); } }
private void writeProperties(JsonWriter out, Feature value) throws IOException { out.name(PROPERTIES_NAME); out.beginObject(); for(String key : value.properties().keySet()) { out.name(key); JsonElement propertyValue = gson.toJsonTree(value.properties().get(key)); gson.toJson(propertyValue, out); } out.endObject(); }
public Feature build() { if(geometry == null) { throw new IllegalStateException("geometry is required to build a Feature"); } return new Feature(geometry, properties, id); }
private void writeProperties(JsonWriter out, Feature value) throws IOException { out.name(PROPERTIES_NAME); out.beginObject(); for(String key : value.properties().keySet()) { out.name(key); JsonElement propertyValue = gson.toJsonTree(value.properties().get(key)); gson.toJson(propertyValue, out); } out.endObject(); }
public Feature build() { if(geometry == null) { throw new IllegalStateException("geometry is required to build a Feature"); } return new Feature(geometry, properties, id); }
private void writeGeometry(JsonWriter out, Feature value) throws IOException { out.name(GEOMETRY_NAME); geometryAdapter.write(out, value.geometry()); }
/** * Build a {@link Feature} with the given {@link Geometry}. * * @param geometry The Geometry to build Feature from * * @return An instance of Feature */ public static Feature of(Geometry<?> geometry) { return builder().withGeometry(geometry).build(); }
@Test public void shouldHandleGeometryAsProperty() { Point point = Point.from(12.3, 45.3); Map<String, JsonElement> properties = new HashMap<>(); properties.put("test", toTest.toJsonTree(point)); Feature feature = FeatureUtils.featureWithProperties(properties); Feature parsed = toTest.fromJson(toTest.toJson(feature), Feature.class); assertThat(toTest.fromJson(parsed.properties().get("test"), Point.class), equalTo(point)); }
@Override public void write(JsonWriter out, Feature value) throws IOException { if (value == null) { out.nullValue(); } else { out.beginObject(); if(value.id().isPresent()) { out.name(ID_NAME).value(value.id().get()); } out.name(TYPE_NAME).value(FEATURE_TYPE); writeProperties(out, value); writeGeometry(out, value); out.endObject(); } }
private void fetchLineStrings() { for (Feature feature : fc.features()) { if (debug) { // LOGGER.log(Level.INFO,feature.toString()); } Geometry<?> geometry = feature.geometry(); if (geometry instanceof MultiPolygon) { MultiPolygon mpolygon = (MultiPolygon) geometry; for (Polygon polygon : mpolygon.polygons()) { addLineString(polygon); } } if (geometry instanceof Polygon) { Polygon polygon = (Polygon) geometry; addLineString(polygon); } } }
@Override public Feature read(JsonReader in) throws IOException { Feature.Builder builder = Feature.builder(); if (in.peek() == JsonToken.NULL) { in.nextNull();
@Test public void shouldHandleNullProperties() { String nullPropertiesJson = "{" + "\"type\": \"Feature\", " + "\"geometry\": " + JsonUtils.givenPointJson(10,10) + ", " + "\"properties\": null" + "}"; Feature parsed = toTest.fromJson(nullPropertiesJson, Feature.class); assertThat(parsed.properties(), emptyMap()); }
@Test public void shouldHandleFeatureCollectionWithFeatures() { List<Feature> features = Arrays.asList( FeatureUtils.featureWithId("test1"), FeatureUtils.featureWithId("test2") ); FeatureCollection collection = new FeatureCollection(features); FeatureCollection parsed = toTest.fromJson(toTest.toJson(collection), FeatureCollection.class); assertThat(parsed.features(), hasSize(2)); assertThat(parsed.features().get(0).id().get(), equalTo("test1")); assertThat(parsed.features().get(1).id().get(), equalTo("test2")); }
private static Boolean isPointInside(Feature feature, Coordinates location) { Polygon polygon = (Polygon) feature.geometry(); List<SinglePosition> positions = Lists.newArrayList(polygon.perimeter().positions().children()); if ((positions == null) || (location == null)) { return false; } int wn = 0; for (int i = 0; i < positions.size() - 1; i++) { if (positions.get(i).coordinates().getLat() <= location.getLat()) { if (positions.get(i + 1).coordinates().getLat() > location.getLat()) { if (isLeft(positions.get(i).coordinates(), positions.get(i + 1).coordinates(), location) > 0.0) { ++wn; } } } else { if (positions.get(i + 1).coordinates().getLat() <= location.getLat()) { if (isLeft(positions.get(i).coordinates(), positions.get(i + 1).coordinates(), location) < 0.0) { --wn; } } } } return (wn != 0); }
@Override public Feature read(JsonReader in) throws IOException { Feature.Builder builder = Feature.builder(); if (in.peek() == JsonToken.NULL) { in.nextNull();
public static Builder builder(Feature feature) { return builder().withGeometry(feature.geometry).withProperties(feature.properties).withId(feature.id); }
public static Builder builder(Feature feature) { return builder().withGeometry(feature.geometry).withProperties(feature.properties).withId(feature.id); }
public static Feature featureWithGeometry(Geometry<?> geometry) { return Feature.builder().withGeometry(Point.from(12.3, 45.3)).build(); }