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

Add turn restriction layer / data #400

Open
6 tasks
rustprooflabs opened this issue Aug 7, 2024 · 0 comments
Open
6 tasks

Add turn restriction layer / data #400

rustprooflabs opened this issue Aug 7, 2024 · 0 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@rustprooflabs
Copy link
Owner

rustprooflabs commented Aug 7, 2024

Details

A discussion about turn restrictions on the main osm2pgsql project (osm2pgsql-dev/osm2pgsql#2215) caught my eye. The idea seems worth exploring to attempt to add a turn restriction layer to PgOSM Flex.

I think this could be implemented similarly to the nested place polygon data set. Some data will be loaded to Postgres via osm2pgsql, and custom functions are developed to handle loading data from that data set into a structure that is usable for common use cases.

What needs to be done?

While I fully intend to work forward on this idea as I have time.... Help is appreciated! Everything from ideas shared in comments, reviewing PRs, and submitting PRs is welcome (see the contributing page). I'll keep this issue updated as progress is made.

  • The Lua example below doesn't appear to consider restriction:conditional. Research what tags all need to be included
  • Start implementing code to load initial data into Postgres
  • Work out how to merge data (assuming points, ways and relations all need to relate to restrictions)
  • Data tests - Queries and expected output
  • Update Routing example to use turn restrictions https://pgosm-flex.com/routing.html
  • What else?

Example Starting Point

This file was shared in the original discussion: https://raw.githubusercontent.com/Andreas4242/Andreas_file_tools/main/compatible.lua

The relevant bits to integrate into PgOSM Flex are below. This site seems to be a good place to verify what is expected in the data. https://ahorn.lima-city.de/tr/

turn_restrictions = osm2pgsql.define_table{
    name = prefix .. 'turn_restrictions',
    ids = { type = 'relation', id_column = 'relation_id' },
    columns = {
        { column = 'restriction', type = 'text' },
        { column = 'from_way', type = 'bigint' },
        { column = 'via_node', type = 'bigint', null = true },
        { column = 'to_way', type = 'bigint' },
        { column = 'members', type = 'jsonb' },
        { column = 'tags', type = 'jsonb' }
    }
}


function osm2pgsql.process_relation(object)
    if clean_tags(object.tags) then
        return
    end

     if object.tags.type == 'restriction' then
        local restriction = {
            restriction = object.tags.restriction or 'no_turn',
            from_way = -1,
            via_node = nil,
            to_way = -1,
            members = object.members,
            tags = object.tags
        }

        for _, member in ipairs(object.members) do
            if member.role == 'from' and member.type == 'w' then
                restriction.from_way = member.ref
            elseif member.role == 'to' and member.type == 'w' then
                restriction.to_way = member.ref
            elseif member.role == 'via' and member.type == 'n' then
                restriction.via_node = member.ref
            end
        end

        -- Debugging: Print the restriction data before inserting
        -- print("Restriction Data: ", table_to_string(restriction))

        turn_restrictions:insert(restriction)
    end


...
...
...
@rustprooflabs rustprooflabs added enhancement New feature or request help wanted Extra attention is needed labels Aug 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant