Package org.openstreetmap.josm.io
Class GeoJSONReader
- java.lang.Object
-
- org.openstreetmap.josm.io.AbstractReader
-
- org.openstreetmap.josm.io.GeoJSONReader
-
public class GeoJSONReader extends AbstractReader
Reader that reads GeoJSON files. See RFC7946 for more information.- Since:
- 15424
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.openstreetmap.josm.io.AbstractReader
AbstractReader.BinaryParserWorker, AbstractReader.CommonReader, AbstractReader.NodeReader, AbstractReader.ParserWorker, AbstractReader.RelationReader, AbstractReader.WayReader
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
COORDINATES
private static java.lang.String
CRS
private static java.lang.String
CRS_GEOJSON
WGS 84 is the specified CRS for geojson -- alternate coordinate systems are considered to be deprecated from GJ2008.private static java.lang.String
FEATURES
private static java.lang.String
GEOMETRY
private static java.lang.String
LINK
private static java.lang.String
NAME
private Projection
projection
private static java.lang.String
PROPERTIES
private static byte
RECORD_SEPARATOR_BYTE
The record separator is 0x1E per RFC 7464private static java.lang.String
TYPE
-
Fields inherited from class org.openstreetmap.josm.io.AbstractReader
cancel, ds, externalIdMap, relations, uploadChangeset, ways
-
-
Constructor Summary
Constructors Constructor Description GeoJSONReader()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private Node
createNode(LatLon latlon)
private java.util.Optional<Way>
createWay(jakarta.json.JsonArray coordinates, boolean autoClose)
protected DataSet
doParseDataSet(java.io.InputStream source, ProgressMonitor progressMonitor)
private static <O extends OsmPrimitive>
OfillTagsFromFeature(jakarta.json.JsonObject feature, O primitive)
Merge existing tags in primitive (if any) with the values given in the GeoJSON feature.private LatLon
getLatLon(jakarta.json.JsonArray coordinates)
private static TagCollection
getTags(jakarta.json.JsonObject feature)
private static boolean
isLineDelimited(java.io.InputStream source)
Check if the inputstream follows RFC 7464private static TagCollection
mergeAllTagValues(OsmPrimitive primitive, TagCollection featureTags)
private void
mergeEqualMultipolygonWays()
Import may create duplicate ways were one is member of a multipolygon and untagged and the other is tagged.private void
parse(jakarta.json.stream.JsonParser parser)
private static double
parseCoordinate(jakarta.json.JsonValue coordinate)
private void
parseCrs(jakarta.json.JsonObject crs)
static DataSet
parseDataSet(java.io.InputStream source, ProgressMonitor progressMonitor)
Parse the given input source and return the dataset.private java.util.Optional<? extends OsmPrimitive>
parseFeature(jakarta.json.JsonObject feature)
private java.util.Optional<? extends OsmPrimitive>
parseFeatureCollection(jakarta.json.JsonArray features, boolean createRelation)
private java.util.Optional<? extends OsmPrimitive>
parseGeometry(jakarta.json.JsonObject feature, jakarta.json.JsonObject geometry)
private java.util.Optional<Relation>
parseGeometryCollection(jakarta.json.JsonObject feature, jakarta.json.JsonObject geometry, boolean createRelation)
private java.util.Optional<Way>
parseLineString(jakarta.json.JsonObject feature, jakarta.json.JsonArray coordinates)
private java.util.Optional<Relation>
parseMultiLineString(jakarta.json.JsonObject feature, jakarta.json.JsonObject geometry)
private java.util.Optional<Relation>
parseMultiPoint(jakarta.json.JsonObject feature, jakarta.json.JsonObject geometry)
private java.util.Optional<Relation>
parseMultiPolygon(jakarta.json.JsonObject feature, jakarta.json.JsonObject geometry)
private java.util.Optional<? extends OsmPrimitive>
parseNonGeometryFeature(jakarta.json.JsonObject feature, jakarta.json.JsonObject properties)
private static void
parseNullGeometry(jakarta.json.JsonObject feature)
private java.util.Optional<Node>
parsePoint(jakarta.json.JsonObject feature, jakarta.json.JsonArray coordinates)
private java.util.Optional<? extends OsmPrimitive>
parsePolygon(jakarta.json.JsonObject feature, jakarta.json.JsonArray coordinates)
private void
parseRoot(jakarta.json.JsonObject object)
private static void
parseUnknown(jakarta.json.JsonObject object)
-
Methods inherited from class org.openstreetmap.josm.io.AbstractReader
buildPrimitive, callPostProcessors, deregisterPostprocessor, doParseDataSet, doParseDataSet, getDataSet, getLong, parseAction, parseBounds, parseChangeset, parseChangeset, parseDownloadPolicy, parseId, parseLocked, parseNode, parseNode, parseRelation, parseRelationMember, parseRelationMember, parseTag, parseTimestamp, parseUploadPolicy, parseUser, parseUser, parseVersion, parseVersion, parseVersion, parseVisible, parseWay, prepareDataSet, processChangesetAfterParsing, processNodesAfterParsing, processRelationsAfterParsing, processWaysAfterParsing, registerPostprocessor
-
-
-
-
Field Detail
-
CRS
private static final java.lang.String CRS
- See Also:
- Constant Field Values
-
NAME
private static final java.lang.String NAME
- See Also:
- Constant Field Values
-
LINK
private static final java.lang.String LINK
- See Also:
- Constant Field Values
-
COORDINATES
private static final java.lang.String COORDINATES
- See Also:
- Constant Field Values
-
FEATURES
private static final java.lang.String FEATURES
- See Also:
- Constant Field Values
-
PROPERTIES
private static final java.lang.String PROPERTIES
- See Also:
- Constant Field Values
-
GEOMETRY
private static final java.lang.String GEOMETRY
- See Also:
- Constant Field Values
-
TYPE
private static final java.lang.String TYPE
- See Also:
- Constant Field Values
-
RECORD_SEPARATOR_BYTE
private static final byte RECORD_SEPARATOR_BYTE
The record separator is 0x1E per RFC 7464- See Also:
- Constant Field Values
-
CRS_GEOJSON
private static final java.lang.String CRS_GEOJSON
WGS 84 is the specified CRS for geojson -- alternate coordinate systems are considered to be deprecated from GJ2008.- See Also:
- Constant Field Values
-
projection
private Projection projection
-
-
Constructor Detail
-
GeoJSONReader
GeoJSONReader()
-
-
Method Detail
-
parse
private void parse(jakarta.json.stream.JsonParser parser) throws IllegalDataException
- Throws:
IllegalDataException
-
parseRoot
private void parseRoot(jakarta.json.JsonObject object) throws IllegalDataException
- Throws:
IllegalDataException
-
parseCrs
private void parseCrs(jakarta.json.JsonObject crs) throws IllegalDataException
Parse CRS as per https://geojson.org/geojson-spec.html#coordinate-reference-system-objects. CRS are obsolete in RFC7946 but still allowed for interoperability with older applications. Only named CRS are supported.- Parameters:
crs
- CRS JSON object- Throws:
IllegalDataException
- in case of error
-
parseFeatureCollection
private java.util.Optional<? extends OsmPrimitive> parseFeatureCollection(jakarta.json.JsonArray features, boolean createRelation)
-
parseFeature
private java.util.Optional<? extends OsmPrimitive> parseFeature(jakarta.json.JsonObject feature)
-
parseNonGeometryFeature
private java.util.Optional<? extends OsmPrimitive> parseNonGeometryFeature(jakarta.json.JsonObject feature, jakarta.json.JsonObject properties)
-
parseGeometryCollection
private java.util.Optional<Relation> parseGeometryCollection(jakarta.json.JsonObject feature, jakarta.json.JsonObject geometry, boolean createRelation)
-
parseGeometry
private java.util.Optional<? extends OsmPrimitive> parseGeometry(jakarta.json.JsonObject feature, jakarta.json.JsonObject geometry)
-
parseCoordinate
private static double parseCoordinate(jakarta.json.JsonValue coordinate)
-
parsePoint
private java.util.Optional<Node> parsePoint(jakarta.json.JsonObject feature, jakarta.json.JsonArray coordinates)
-
parseMultiPoint
private java.util.Optional<Relation> parseMultiPoint(jakarta.json.JsonObject feature, jakarta.json.JsonObject geometry)
-
parseLineString
private java.util.Optional<Way> parseLineString(jakarta.json.JsonObject feature, jakarta.json.JsonArray coordinates)
-
parseMultiLineString
private java.util.Optional<Relation> parseMultiLineString(jakarta.json.JsonObject feature, jakarta.json.JsonObject geometry)
-
parsePolygon
private java.util.Optional<? extends OsmPrimitive> parsePolygon(jakarta.json.JsonObject feature, jakarta.json.JsonArray coordinates)
-
parseMultiPolygon
private java.util.Optional<Relation> parseMultiPolygon(jakarta.json.JsonObject feature, jakarta.json.JsonObject geometry)
-
createNode
private Node createNode(LatLon latlon)
-
createWay
private java.util.Optional<Way> createWay(jakarta.json.JsonArray coordinates, boolean autoClose)
-
fillTagsFromFeature
private static <O extends OsmPrimitive> O fillTagsFromFeature(jakarta.json.JsonObject feature, O primitive)
Merge existing tags in primitive (if any) with the values given in the GeoJSON feature.- Type Parameters:
O
- The primitive type- Parameters:
feature
- the GeoJSON featureprimitive
- the OSM primitive- Returns:
- The primitive passed in as
primitive
for easier chaining
-
mergeAllTagValues
private static TagCollection mergeAllTagValues(OsmPrimitive primitive, TagCollection featureTags)
-
parseUnknown
private static void parseUnknown(jakarta.json.JsonObject object)
-
parseNullGeometry
private static void parseNullGeometry(jakarta.json.JsonObject feature)
-
getTags
private static TagCollection getTags(jakarta.json.JsonObject feature)
-
isLineDelimited
private static boolean isLineDelimited(java.io.InputStream source)
Check if the inputstream follows RFC 7464- Parameters:
source
- The source to check (should be at the beginning)- Returns:
true
if the initial character isRECORD_SEPARATOR_BYTE
.
-
doParseDataSet
protected DataSet doParseDataSet(java.io.InputStream source, ProgressMonitor progressMonitor) throws IllegalDataException
- Specified by:
doParseDataSet
in classAbstractReader
- Throws:
IllegalDataException
-
mergeEqualMultipolygonWays
private void mergeEqualMultipolygonWays()
Import may create duplicate ways were one is member of a multipolygon and untagged and the other is tagged. Try to merge them here.
-
parseDataSet
public static DataSet parseDataSet(java.io.InputStream source, ProgressMonitor progressMonitor) throws IllegalDataException
Parse the given input source and return the dataset.- Parameters:
source
- the source input stream. Must not be null.progressMonitor
- the progress monitor. If null,NullProgressMonitor.INSTANCE
is assumed- Returns:
- the dataset with the parsed data
- Throws:
IllegalDataException
- if an error was found while parsing the data from the sourcejava.lang.IllegalArgumentException
- if source is null
-
-