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

(Non-multipolygon) relation support #360

Merged
merged 4 commits into from
Jan 8, 2022
Merged

(Non-multipolygon) relation support #360

merged 4 commits into from
Jan 8, 2022

Conversation

systemed
Copy link
Owner

@systemed systemed commented Jan 5, 2022

This PR enables tilemaker to take account of relations in Lua scripts. There are two new (but linked) pieces of functionality:

  • relation_scan_function reads relation tags and memberships into memory, so that they can be considered by member ways in way_function
  • relation_function constructs discrete geometries from entire relations, including as multilinestrings

This means tilemaker can now support route and boundary relations, among others. Support for boundary relations is added to the OMT-compatible Lua script in this PR. The new functions are documented in a separate RELATIONS.md file.

Each relation type is sui generis so I anticipate this won't be the end of the story! As this evolves we may need to change the Lua interface for relations (semver purists look away now ;) ). But this should cope with the majority of cases.

The following aren't supported in this PR and could be considered at a later date:

  • relation roles (moderately easy, may require changing the Lua interface)
  • nested relations (quite hard)
  • nodes in relations (moderately easy)

@systemed systemed mentioned this pull request Jan 5, 2022
4 tasks
@leonardehrenfried
Copy link
Contributor

Nice work!

Out of interest, where does FindInRelation search when the way is part of multiple relations?

@systemed
Copy link
Owner Author

systemed commented Jan 5, 2022

It searches the current relation in the iterator controlled by NextRelation. In this example:

while true do
  local rel = way:NextRelation()
  if not rel then break end
  print ("Part of route "..way:FindInRelation("ref"))
end

then it'll show each ref in turn - NextRelation advances the current relation each time.

The idea is that you use it as part of a loop scanning through all the relations. If you need to store all of them, then you can create a Lua table and populate it as part of this loop.

Copy link
Contributor

@leonardehrenfried leonardehrenfried left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just tested this code with one of my data sets and it works great - well done!

I need to work on some styling first before I can share a screenshot but I'm really pleased already!

@systemed systemed merged commit 965f6ae into master Jan 8, 2022
@systemed
Copy link
Owner Author

systemed commented Jan 8, 2022

Ok, good to go I think!

@leonardehrenfried
Copy link
Contributor

leonardehrenfried commented Jan 8, 2022

Because everybody loves a screenshot, here is what I built with this: national cycle routes in Norway.

Screenshot_20220108-122142~2

@systemed systemed deleted the relations branch March 13, 2022 19:12
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

Successfully merging this pull request may close these issues.

None yet

2 participants