0

I just want to convert OSM data to GeoJSON where it is pretty simple with node and way tags of OSM data, but relation which is giving complex can't find the logic to convert OSM relation to GeoJSON format, especially how to form coordinates parameter of GeoJSON based on their relation member roles (ex. Inner, outer,admin_centre,riverbank,side_stream,main_stream,from,via,to,forward,backward,stop_entry_only,stop_exit_only and platform_exit_only).

I have tried many documentation but no logics or code found in Java and Python.

In Python https://pypi.org/project/osm2geojson/ osm Official https://wiki.openstreetmap.org geojson Official https://geojson.org/ sample data: https://download.geofabrik.de/asia/maldives-latest.osm.bz2 https://download.geofabrik.de/asia/bhutan-latest.osm.pbf

As simple, how to form relation member's latitude and longitude in coordinates parameter of GeoJSON based on their roles?

EXample code

public void processRelations() {
    try {
        LineIterable lineIterable = LineIterable.openGzipFile(dir + OsmJoin.REL_ID_COMPLETE_JSON);
        try (JsonWriter writer = createJsonWriter(OsmType.RELATION)) {
            Processor<String, JsonObject> p = compose(entryParsingProcessor, jsonParsingProcessor, new Processor<JsonObject, JsonObject>() {
                @Override
                public JsonObject process(JsonObject input) {
                    // FIXME see if we can extract some useful things from relations                       
                    return null;
                }
            });
            try (ConcurrentProcessingIterable<String, JsonObject> concIt = processConcurrently(lineIterable, p, 10, 9, 100)) {
                for (JsonObject o : concIt) {
                    if (o != null) {
                        writer.add(o);
                    }
                }
            } catch (IOException e) {
                throw new IllegalStateException(e);
            }
        }
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
}

I have tried in Java and Python but reason is I could not find the logic behind the conversion of the relation tags from OSM to GeoJSON

I am expecting the logic behind the conversion of the relation tags from OSM to GeoJSON and sample code for that.

  • What have you tried and where are you getting stuck? It's unclear from your post what your question is. – lambertj May 17 at 13:52
  • i just edit my question relatively ur question – jayendran S May 17 at 15:14
  • Maybe this Overpass turbo example helps: overpass-turbo.eu/s/Jcl. Click run, then export, save as GeoJSON. Take a look at the result. You can change the original query to see how other OSM relations are exported to GeoJSON. Or Take a look at wiki.openstreetmap.org/wiki/GeoJSON which lists various tools for converting OSM data to GeoJSON. Note that there is not just one "correct" way for converting OSM data to GeoJSON. – scai May 22 at 8:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.