private static Coordinate[] convertPath(List<LngLatAlt> path) { Coordinate[] coords = new Coordinate[path.size()]; int i = 0; for (LngLatAlt p : path) { coords[i++] = new Coordinate(p.getLatitude(), p.getLongitude()); } return coords; } }
if (geoJsonGeom instanceof org.geojson.Point) { org.geojson.Point geoJsonPoint = (org.geojson.Point) geoJsonGeom; return gf.createPoint(new Coordinate(geoJsonPoint.getCoordinates().getLongitude(), geoJsonPoint .getCoordinates().getLatitude())); LinearRing shell = gf.createLinearRing(convertPath(geoJsonPolygon.getExteriorRing())); LinearRing[] holes = new LinearRing[geoJsonPolygon.getInteriorRings().size()]; int i = 0; for (List<LngLatAlt> hole : geoJsonPolygon.getInteriorRings()) { holes[i++] = gf.createLinearRing(convertPath(hole)); Polygon[] jtsPolygons = new Polygon[geoJsonMultiPolygon.getCoordinates().size()]; int i = 0; for (List<List<LngLatAlt>> geoJsonRings : geoJsonMultiPolygon.getCoordinates()) { org.geojson.Polygon geoJsonPoly = new org.geojson.Polygon(); for (List<LngLatAlt> geoJsonRing : geoJsonRings) geoJsonPoly.add(geoJsonRing); jtsPolygons[i++] = (Polygon) convertGeoJsonToJtsGeometry(geoJsonPoly); return gf.createLineString(convertPath(geoJsonLineString.getCoordinates())); LineString[] jtsLineStrings = new LineString[geoJsonMultiLineString.getCoordinates().size()]; int i = 0; for (List<LngLatAlt> geoJsonPath : geoJsonMultiLineString.getCoordinates()) { org.geojson.LineString geoJsonLineString = new org.geojson.LineString( geoJsonPath.toArray(new LngLatAlt[geoJsonPath.size()])); jtsLineStrings[i++] = (LineString) convertGeoJsonToJtsGeometry(geoJsonLineString);
org.geojson.Polygon p = new org.geojson.Polygon(); List<LngLatAlt> shell = new ArrayList<LngLatAlt>(); for (Coordinate c : polygons[i].getExteriorRing().getCoordinates()) { shell.add(new LngLatAlt(c.x, c.y)); p.add(shell); geomSerializer.writeValue(jgen, p); } else { org.geojson.Point p = new org.geojson.Point(lons[i], lats[i]); geomSerializer.writeValue(jgen, p);
for (Feature feature : featureCollection.getFeatures()) { GeoJsonObject geom = feature.getGeometry(); if (geom instanceof Point) { Point p = (Point) geom; GeocoderResult res = new GeocoderResult(); res.setLat(p.getCoordinates().getLatitude()); res.setLng(p.getCoordinates().getLongitude()); res.setDescription(feature.getProperties().get("label").toString());
@SuppressWarnings("unchecked") public static PointFeature fromJsonNode(JsonNode feature) throws EmptyPolygonException, UnsupportedGeometryException { Feature geoJsonFeature; try { geoJsonFeature = deserializer.readValue(feature.traverse(), Feature.class); } catch (IOException e) { throw new UnsupportedGeometryException(e.getMessage()); } PointFeature ret = new PointFeature(geoJsonFeature.getId()); ret.setGeom(GeometryUtils.convertGeoJsonToJtsGeometry(geoJsonFeature.getGeometry())); Object structured = geoJsonFeature.getProperty("structured"); if (structured == null || !(structured instanceof Map)) return null; // The code below assume the structured map to have integers only ret.setAttributes((Map<String, Integer>)(structured)); return ret; }
/** * Build a bounding box feature. * In this case, it has a name but is empty. * * @param id the ID string * @return the Feature for the new bounds */ public static Feature createBounds(final String id) { final Feature feature = new Feature(); feature.setId(id); feature.setGeometry(new Polygon()); return feature; }
@SuppressWarnings("unchecked") protected static <V> V propertyOrDefault(Feature feature, String propertyName, V defaultValue) { return (feature.getProperty(propertyName) == null) ? defaultValue : (V)feature.getProperty(propertyName); } }
@Override public String toString() { return "Geometry{" + "coordinates=" + coordinates + "} " + super.toString(); } }
@Override public String toString() { return "MultiLineString{} " + super.toString(); } }
/** * Default constructor to use in serialization. */ public GeoServiceGeometry() { this.featureCollection = new FeatureCollection(); }
@Override public String toString() { return "LineString{} " + super.toString(); } }
@Override public String toString() { return "GeometryCollection{" + "geometries=" + geometries + "} " + super.toString(); } }
@Override public String toString() { return "MultiPolygon{} " + super.toString(); } }
/** * Default constructor used in serialization. */ public GeoServiceGeocodingResult() { this.addressComponents = new AddressComponent[0]; this.types = new AddressType[0]; this.geometry = new FeatureCollection(); }
@Override public String toString() { return "GeometryCollection{" + "geometries=" + geometries + "} " + super.toString(); } }
@Override public String toString() { return "MultiPolygon{} " + super.toString(); } }