This is a static archive of our old OpenStreetMap Help Site. Please post any new questions and answers at community.osm.org.

How convert OSM relation to GeoJSON based on relation member’s roles

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.

asked 20 May '19, 12:16

jaye19's gravatar image

jaye19
21112
accept rate: 0%


One Answer:

0

Try using ogr2ogr command instead. You need to export different "layers" but it could work like:

ogr2ogr -f GeoJSON tmp_lines.geojson myosm.pbf lines
ogr2ogr -f GeoJSON tmp_mpoly.geojson myosm.pbf multipolygons

answered 29 Apr '20, 09:30

mcld's gravatar image

mcld
81349
accept rate: 0%

Source code available on GitHub .