Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relation parsing #3

Closed
karussell opened this issue Sep 17, 2013 · 6 comments
Closed

Relation parsing #3

karussell opened this issue Sep 17, 2013 · 6 comments

Comments

@karussell
Copy link

Hi,

sorry for my issue bombing, hope all will be clear in a few days ;)

I'm in the process of implementing relation parsing as I need the administration boundaries. Why would I need the members json array? Isn't this information already included in the 'ways' and 'nodes' key?

@jillesvangurp
Copy link
Owner

No problem; I don't mind a little code review and so far all you are
bringing up are valid issues/questions.

Relations are ugly and the reason I kept the members array is because it
has the exact order the member nodes, ways, and relations (relations can be
part of other relations) appear in the xml; unlike the merged ways and
nodes. The order for things with the same id is not deterministic in my
concurrent implementation of merge sort. So, the ways and nodes for a
relation may be in the wrong order.

You will need the correct order to reconstruct multi polygons correctly. To
do that, you will need to connect ways into polygons (large polygons
consist of several ways), distinguish between outer and inner (holes)
polygons, and deal with ways that are part of bus routes. It's quite easy
to get wrong. I recommend you read the wiki at osm on how to interpret
relations; it's hairy.

I had a go at this problem a few months ago and you can find some of that
code in the git history. It worked reasonably well for multi polygons. But
is not very portable to the new design and there are quite a few relations
that are not multi polygons but things like bus routes or associated ways
instead. I deleted the old implementation a few weeks ago:
jillesvangurp/osm2geojson@b725b08

Have a look at the processRelation in the now removed OsmBlobProcessor and
calculateMultiPolygonForRelation in the old OsmProcessor. Be sure to test
any shapes you reconstruct by drawing them on a map using e.g. leaflet. I
got it wrong a few times before coming up with the referenced
implementation.

I'd really appreciate a pull request for this one.

Jilles

On Tue, Sep 17, 2013 at 12:04 PM, Peter notifications@github.com wrote:

Hi,

sorry for my issue bombing, hope all will be clear in a few days ;)

I'm in the process of implementing relation parsing as I need the
administration boundaries. Why would I need the members json array? Isn't
this information already included in the 'ways' and 'nodes' key?


Reply to this email directly or view it on GitHubhttps://github.com//issues/3
.

@jillesvangurp
Copy link
Owner

Also, if you want admin boundaries, have a look at quatro shapes as well. OSM doesn't have good coverage for this.

@karussell
Copy link
Author

Thanks a lot for all the hints! Also for the quatro shapes one!

You will need the correct order to reconstruct multi polygons correctly.

Yeah, I can now see what you mean+describe ;), but I think I'll for now just try the admin boundaries ignoring the other relations. I'm closing here for now and will hopefully come up with a working version for it and create a PR.

admin-boundaries

@karussell
Copy link
Author

-> Ups, wrong project. Issue should be here https://github.com/jillesvangurp/osm2geojson

@jaye19
Copy link

jaye19 commented May 20, 2019

How convert OSM relation to GeoJSON -based on relation member's roles

`
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
                    // process 350K relations
                    // extract admin_levels (60K) multi_polygons
                    // extract public transport routes (62K)
                    // associated street (30K)
                    // TMC ??? some traffic meta data (17K)
                    // restriction on traffic (153K)
                    // rest 34K (mix of all kinds of uncategorized metadata)

                    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 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 am expecting the logic behind the conversion of the relation tags from OSM to GeoJSON and sample code for that.

@jillesvangurp
Copy link
Owner

I never figured out the relations and I've not worked on this for six years. Good luck figuring this out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants