GeometryJSON geometryJSON = new GeometryJSON(); geometryJSON.write(gf.createMultiPoint(coords), sw); LOG.debug("done"); } else if (output.equals(SIsochrone.RESULT_TYPE_SHED)) { geometryJSON.write(circleShape, sw); } else { if (maxTime > shedCalcMethodSwitchTimeInSec) { // eg., walkshed > 20 min geometryJSON.write(outputHull, sw); LOG.debug("done"); geometryJSON.write(pathToStreet, sw); } else { mls = gf.createMultiLineString(edges); LOG.debug("write geom"); geometryJSON.write(mls, sw); LOG.debug("done"); geometryJSON.write(mls, sw); LOG.debug("done");
/** * Reads a Geometry instance from GeoJSON. * * <p>This method calls through to {@link #read(Object)} * * @param input The input stream. * @return The geometry instance. */ public Geometry read(InputStream input) throws IOException { return read((Object) input); }
/** * Reads a GeometryCollection from GeoJSON. * * <p>This method calls through to {@link #readGeometryCollection(Object)} * * @param input The input stream. * @return The geometry collection. * @throws IOException In the event of a parsing error or if the input json is invalid. */ public GeometryCollection readGeometryCollection(InputStream input) throws IOException { return readGeometryCollection((Object) input); }
@Override public Object decode(String input) throws Exception { return new GeometryJSON().read(input); } }
GeometryJSON geometryJSON = new GeometryJSON(); String json = geometryJSON.toString(geometry)
GeometryCollection g = new GeometryJSON().readGeometryCollection(geojsonstring); Geometry g = new GeometryJSON().read(geojsonstring);
/** * Get GeometryJSON point. * * @param longitude the longitude. * @param latitude the latitude. * @return the GeoJSON representation of the given point. */ public static Point getGeoJsonPoint( double longitude, double latitude ) throws IOException { Point point = null; GeometryJSON gtjson = new GeometryJSON(); point = gtjson.readPoint( new StringReader( "{\"type\":\"Point\", \"coordinates\":[" + longitude + "," + latitude + "]}" ) ); return point; }
GeometryJSON gtjson = new GeometryJSON(); Polygon polygon = gtjson.readPolygon( new StringReader( "{\"type\":\"Polygon\", \"coordinates\":" + multiPolygonJson + "}" ) ); MultiPolygon multiPolygon = gtjson.readMultiPolygon( new StringReader( "{\"type\":\"MultiPolygon\", \"coordinates\":" + multiPolygonJson + "}" ) );
public FeatureJSON() { this(new GeometryJSON()); }
/** * Writes a Geometry instance as GeoJSON returning the result as a string. * * @param geometry The geometry. * @return The geometry encoded as GeoJSON */ public String toString(Geometry geometry) { StringWriter w = new StringWriter(); try { write(geometry, w); return w.toString(); } catch (IOException e) { throw new RuntimeException(e); } }
BoundingBox bbox = feature.getBounds(); string("bbox", sb).append(":"); sb.append(gjson.toString(bbox)).append(","); string("geometry", sb) .append(":") .append(gjson.toString((Geometry) feature.getDefaultGeometry())); sb.append(","); array(ad.getLocalName(), gjson.toString((Envelope) value), sb); } else if (value instanceof BoundingBox) { array(ad.getLocalName(), gjson.toString((BoundingBox) value), sb); } else if (value instanceof Geometry) { string(ad.getLocalName(), sb) .append(":") .append(gjson.toString((Geometry) value)); } else { entry(ad.getLocalName(), value, sb);
/** * Reads a MultiPolygon from GeoJSON. * * <p>This method calls through to {@link #readMultiPolygon(Object)} * * @param input The input stream. * @return The multi polygon. * @throws IOException In the event of a parsing error or if the input json is invalid. */ public MultiPolygon readMultiPolygon(InputStream input) throws IOException { return readMultiPolygon((Object) input); }
@Override public Object decode(InputStream input) throws Exception { return new GeometryJSON().read(input); }
private String getGeoJSONGeometryForSubject(Subject subject) { // For millimeter (mm) precision represent lat/lon with 8 decimal places in decimal degrees format. return (new GeometryJSON(8)).toString(subject.getShape()); } }
public FeatureJSON() { this(new GeometryJSON()); }
public static void write(Object obj, Object output) throws IOException { if (obj instanceof Geometry) { gjson.write((Geometry) obj, output); } else if (obj instanceof Feature || obj instanceof FeatureCollection || obj instanceof CoordinateReferenceSystem) { if (obj instanceof SimpleFeature) { fjson.writeFeature((SimpleFeature) obj, output); } else if (obj instanceof FeatureCollection) { fjson.writeFeatureCollection((FeatureCollection) obj, output); } else if (obj instanceof CoordinateReferenceSystem) { fjson.writeCRS((CoordinateReferenceSystem) obj, output); } else { throw new IllegalArgumentException( "Unable able to encode object of type " + obj.getClass()); } } } }
BoundingBox bbox = feature.getBounds(); string("bbox", sb).append(":"); sb.append(gjson.toString(bbox)).append(","); .append(gjson.toString((Geometry) feature.getDefaultGeometry())); sb.append(","); array(ad.getLocalName(), gjson.toString((Envelope)value), sb); } else if (value instanceof BoundingBox) { array(ad.getLocalName(), gjson.toString((BoundingBox)value), sb); } else if (value instanceof Geometry) { string(ad.getLocalName(), sb).append(":") .append(gjson.toString((Geometry) value)); } else { entry(ad.getLocalName(), value, sb);
/** * Reads a MultiPolygon from GeoJSON. * <p> * This method calls through to {@link #readMultiPolygon(Object)} * </p> * @param input The input stream. * * @return The multi polygon. * * @throws IOException In the event of a parsing error or if the input json is invalid. */ public MultiPolygon readMultiPolygon(InputStream input) throws IOException { return readMultiPolygon((Object)input); }
public static Geometry getGeometryFromCoordinatesAndType( FeatureType featureType, String coordinates ) throws IOException { GeometryJSON geometryJSON = new GeometryJSON(); if ( featureType.equals( FeatureType.NONE ) || featureType.equals( FeatureType.SYMBOL ) ) { throw new IllegalArgumentException( "Invalid featureType '" + featureType.value() + "'" ); } return geometryJSON.read( String.format( "{\"type\": \"%s\", \"coordinates\": %s}", featureType.value(), coordinates) ); }
/** * Given a JTS Geometry in fixed-point latitude and longitude, log it as floating-point GeoJSON. */ public static void logFixedPointGeometry (String label, Geometry fixedPointGeometry) { if (fixedPointGeometry == null){ LOG.info("{} is null.", label); } else if (fixedPointGeometry.isEmpty()) { LOG.info("{} is empty.", label); } else { String geoJson = new GeometryJSON().toString(fixedDegreeGeometryToFloating(fixedPointGeometry)); if (geoJson == null) { LOG.info("Could not convert non-null geometry to GeoJSON"); } else { LOG.info("{} {}", label, geoJson); } } }