NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum

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%


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
permanent link

answered 29 Apr '20, 09:30

mcld's gravatar image

mcld
81349
accept rate: 0%

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×710
×252
×36
×22
×4

question asked: 20 May '19, 12:16

question was seen: 2,919 times

last updated: 29 Apr '20, 09:30

NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum