Skip to content

jwtue/osmtogeojson-java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

osmtogeojson-java

Converts OSM data to GeoJSON.

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

command line tool

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

java/android library

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);

API

new OsmToGeoJson()

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: false
  • flatProperties: 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: false
  • uninterestingTags (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 more
  • polygonFeaturesValidator (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.

osmToGeoJson.convertOverpassJsonToGeoJson(data, featureCallback)

  • 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.

osmToGeoJson.convertOsmXmlToGeoJson(data, featureCallback)

  • 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.

More information

For more information on the produced GeoJSON and the way this library works, check out the documentation at tyrasd/osmtogeojson.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages