Package org.openstreetmap.josm.io
Class GeoJSONWriter
- java.lang.Object
-
- org.openstreetmap.josm.io.GeoJSONWriter
-
- Direct Known Subclasses:
GeoJSONMapRouletteWriter
public class GeoJSONWriter extends java.lang.Object
Writes OSM data as a GeoJSON string, using JSR 353: Java API for JSON Processing (JSON-P).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classGeoJSONWriter.GeometryPrimitiveVisitorConvert a primitive to a json object(package private) static classGeoJSONWriter.Options
-
Field Summary
Fields Modifier and Type Field Description private DataSetdataprotected static jakarta.json.spi.JsonProviderJSON_PROVIDERUsed to avoid many calls toJsonProvider.provider()ingetCoorArray(JsonArrayBuilder, EastNorth).(package private) static java.lang.StringJSON_VALUE_END_MARKERThis is used to determine that a tag should be interpreted as a json object or array.(package private) static java.lang.StringJSON_VALUE_START_MARKERThis is used to determine that a tag should be interpreted as a json object or array.private java.util.EnumSet<GeoJSONWriter.Options>optionsprivate static java.util.Set<Way>processedMultipolygonWaysprivate static Projectionprojectionprivate static BooleanPropertySKIP_EMPTY_NODESprivate static BooleanPropertyUNTAGGED_CLOSED_IS_POLYGON
-
Constructor Summary
Constructors Constructor Description GeoJSONWriter(DataSet ds)Constructs a newGeoJSONWriter.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidappendBounds(Bounds b, jakarta.json.JsonObjectBuilder object)protected voidappendLayerBounds(DataSet ds, jakarta.json.JsonObjectBuilder object)protected voidappendLayerFeatures(DataSet ds, jakarta.json.JsonObjectBuilder object)protected voidappendPrimitive(OsmPrimitive p, jakarta.json.JsonArrayBuilder array)private static jakarta.json.JsonValueconvertValueToJson(java.lang.String value)private static jakarta.json.JsonArrayBuildergetCoorArray(jakarta.json.JsonArrayBuilder builder, EastNorth c)private jakarta.json.JsonArrayBuildergetCoorArray(jakarta.json.JsonArrayBuilder builder, ILatLon c)(package private) voidsetOptions(GeoJSONWriter.Options... options)Set the options for this writer.java.lang.Stringwrite()Writes OSM data as a GeoJSON string (prettified).java.lang.Stringwrite(boolean pretty)Writes OSM data as a GeoJSON string (prettified or not).voidwrite(boolean pretty, java.io.Writer writer)Writes OSM data as a GeoJSON string (prettified or not).
-
-
-
Field Detail
-
projection
private static final Projection projection
-
SKIP_EMPTY_NODES
private static final BooleanProperty SKIP_EMPTY_NODES
-
UNTAGGED_CLOSED_IS_POLYGON
private static final BooleanProperty UNTAGGED_CLOSED_IS_POLYGON
-
JSON_PROVIDER
protected static final jakarta.json.spi.JsonProvider JSON_PROVIDER
Used to avoid many calls toJsonProvider.provider()ingetCoorArray(JsonArrayBuilder, EastNorth). For validating Mesa County, CO, this reduces CPU and memory usage ofwrite()by ~80%. By using this for otherJsoncalls,write()takes ~95% less resources than the original. And the entire process takes 1/4 of the time (38 minutes → <10 minutes).For more details, see JSONP #346.
-
processedMultipolygonWays
private static final java.util.Set<Way> processedMultipolygonWays
-
options
private final java.util.EnumSet<GeoJSONWriter.Options> options
-
JSON_VALUE_START_MARKER
static final java.lang.String JSON_VALUE_START_MARKER
This is used to determine that a tag should be interpreted as a json object or array. The tag should have bothJSON_VALUE_START_MARKERandJSON_VALUE_END_MARKER.- See Also:
- Constant Field Values
-
JSON_VALUE_END_MARKER
static final java.lang.String JSON_VALUE_END_MARKER
This is used to determine that a tag should be interpreted as a json object or array. The tag should have bothJSON_VALUE_START_MARKERandJSON_VALUE_END_MARKER.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
GeoJSONWriter
public GeoJSONWriter(DataSet ds)
Constructs a newGeoJSONWriter.- Parameters:
ds- The OSM data set to save- Since:
- 12806
-
-
Method Detail
-
setOptions
void setOptions(GeoJSONWriter.Options... options)
Set the options for this writer. SeeGeoJSONWriter.Options.- Parameters:
options- The options to set.
-
write
public java.lang.String write()
Writes OSM data as a GeoJSON string (prettified).- Returns:
- The GeoJSON data
-
write
public java.lang.String write(boolean pretty)
Writes OSM data as a GeoJSON string (prettified or not).- Parameters:
pretty-trueto have pretty output,falseotherwise- Returns:
- The GeoJSON data
- Since:
- 6756
-
write
public void write(boolean pretty, java.io.Writer writer)
Writes OSM data as a GeoJSON string (prettified or not).- Parameters:
pretty-trueto have pretty output,falseotherwisewriter- The writer used to write results
-
getCoorArray
private jakarta.json.JsonArrayBuilder getCoorArray(jakarta.json.JsonArrayBuilder builder, ILatLon c)
-
getCoorArray
private static jakarta.json.JsonArrayBuilder getCoorArray(jakarta.json.JsonArrayBuilder builder, EastNorth c)
-
appendPrimitive
protected void appendPrimitive(OsmPrimitive p, jakarta.json.JsonArrayBuilder array)
-
convertValueToJson
private static jakarta.json.JsonValue convertValueToJson(java.lang.String value)
-
appendLayerBounds
protected void appendLayerBounds(DataSet ds, jakarta.json.JsonObjectBuilder object)
-
appendBounds
protected void appendBounds(Bounds b, jakarta.json.JsonObjectBuilder object)
-
appendLayerFeatures
protected void appendLayerFeatures(DataSet ds, jakarta.json.JsonObjectBuilder object)
-
-