This is a Kotlin / Java / Android implementation of the Javascript/Node.js library osmtogeojson.
All features from the original library are available, including command-line interface.
As the implementation relies heavily on org.json
, the JAR library is unfortunately incompatible with Android. Thus, a version with minor adaptions for Android is supplied as well.
Usage:
$ java -jar osmtogeojson.jar file.osm > file.geojson
Supported command line options are shown with:
$ java -jar osmtogeojson-3.0.0-beta.5.jar --help
Usage: For plain Java projects add the .jar file to your project as a library. For Android projects, use the .aar file instead.
import de.jonaswolf.osmtogeojson.OsmToGeoJson
String osmDataJson = /* ... */;
String geoJsonFromJson = new OsmToGeoJson().convertOverpassJsonToGeoJson(osmDataJson, null);
// or
String osmDataXml = /* ... */;
String geoJsonFromXml = new OsmToGeoJson().convertOsmXmlToGeoJson(osmDataXml, null);
new OsmToGeoJson(verbose, flatProperties, uninterestingTags, uninterestingTagsValidator, polygonFeaturesValidator, deduplicator)
Creates a new OSM data to GeoJSON converter. You can use some optional arguments to configure the converter.
verbose
: If true, the converter will print conversion details to stdout during execution. default: falseflatProperties
: If true, the resulting GeoJSON feature's properties will be a simple key-value list instead of a structured json object (with separate tags and metadata). default: falseuninterestingTags
(non-nullable): A blacklist of tag keys. Will be used to decide if a feature is interesting enough for its own GeoJSON feature.uninterestingTagsValidator
(nullable): A callback function object. Will be used to decide if a feature is interesting enough for its own GeoJSON feature. Callback function has preference over blacklist.additionalPolygonFeatures
(nullable): A json object that is merged with the default json object and is used to determine if a closed way should be treated as a Polygon or LineString. read morepolygonFeaturesValidator
(nullable): A callback function object. Will be used to determine if a closed way should be treated as a Polygon or LineString. Callback function has preference over feature list.deduplicator
: A deduplicator function object. Can be used to override default deduplication rules.
data
: the OSM data in OSM JSON.featureCallback
: Optional/nullable. A callback function that will be called for every feature that is created during conversion.
data
: the OSM data as a XML DOM.featureCallback
: Optional/nullable. A callback function that will be called for every feature that is created during conversion.
For more information on the produced GeoJSON and the way this library works, check out the documentation at tyrasd/osmtogeojson.