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

Render type=restriction and restriction:bicycle=give_way #4

Closed
Phyks opened this issue Jan 26, 2019 · 6 comments · Fixed by #420
Closed

Render type=restriction and restriction:bicycle=give_way #4

Phyks opened this issue Jan 26, 2019 · 6 comments · Fixed by #420
Assignees
Labels
new feature Render a new feature

Comments

@Phyks
Copy link
Member

Phyks commented Jan 26, 2019

No description provided.

@Phyks Phyks added the new feature Render a new feature label Jan 26, 2019
@Phyks
Copy link
Member Author

Phyks commented Feb 9, 2019

Quick overview of such relations:

  • 1264 in total (worldwide, according to taginfo)
  • 584 in Paris
  • On the 584 in Paris, 516 are missing members and therefore not really usable :/

@Florimondable
Copy link
Member

La France pays du fromage et des CLPC

@Phyks Phyks added this to the SOTM milestone Jun 19, 2019
@Phyks Phyks removed this from the SOTM milestone Sep 16, 2019
@Florimondable
Copy link
Member

Propositions:
we draw two arrows next to ways from and to near the via node and on the inside of the corner
image

@patman37
Copy link

patman37 commented Dec 5, 2019

I am not sure the "to" arrow is important as it can be mostly deduced from the street layout. I would just mark the "from" location to reduce clutter

@Florimondable
Copy link
Member

example in JOSM with turn restrictions :
The icon next to the end of the via way
Capture du 2020-03-05 19-12-02

@Phyks
Copy link
Member Author

Phyks commented Aug 7, 2020

For the record, osm2pgsql does not consider type=restriction relations when parsing OpenStreetMap data (see https://github.com/openstreetmap/osm2pgsql/blob/a05209aa602d1af806ccda4b72dde577dec95dec/src/tagtransform-c.cpp#L225-L234). These are not accessible directly from the regular planet_osm_point / planet_osm_line / planet_osm_polygon tables and tags are not projected under members ways :/

They can however be recovered from the raw planet_osm_rels table, which contains raw relations. Here is a SQL snippet to fetch data from this table and recursively add data about the relation members (geometry etc):

-- Fetches completely a restriction:bicycle=give_wau relation from osm2pgsql
-- tables layout. Read comment from innermost to outermost.


-- Fill in details for the "via" node using dedicated table
-- planet_osm_point
SELECT
    data.from_original_id,
    data.from_id,
    data.from_way,
    data.to_original_id,
    data.to_id,
    data.to_way,
    data.via AS via_original_id,
    planet_osm_point.osm_id AS via_id,
    planet_osm_point.way AS via_way
FROM
    planet_osm_point,
    (
        -- Fill in details for the "to" way using dedicated table
        -- planet_osm_line
        SELECT
            data.from_original_id,
            data.from_id,
            data.from_way,
            data.to AS to_original_id,
            planet_osm_line.osm_id AS to_id,
            planet_osm_line.way AS to_way,
            data.via
        FROM
            planet_osm_line,
            (
                -- Fill in details for the "from" way using dedicated table
                -- planet_osm_line
                SELECT
                    data.from AS from_original_id,
                    planet_osm_line.osm_id AS from_id,
                    planet_osm_line.way AS from_way,
                    data.to,
                    data.via
                FROM
                    planet_osm_line,
                    (
                        -- Ensure the restriction:bicycle=give_way relation is
                        -- correct with both from and to as ways and via as
                        -- node.
                        SELECT
                            id,
                            LTRIM("from", 'w') AS from,
                            LTRIM("via", 'n') AS via,
                            LTRIM("to", 'w') AS to
                        FROM (
                            -- Select restriction:bicycle=give_way relations from relations table
                            -- This table only includes nodes and ways ids, not
                            -- the geometry nor references to the objects in
                            -- the dedicated tables.
                            SELECT
                                id,
                                members[array_position(members, 'from') - 1] AS from,
                                members[array_position(members, 'via') - 1] AS via,
                                members[array_position(members, 'to') - 1] AS to
                            FROM planet_osm_rels
                            WHERE
                                tags @> ARRAY['type', 'restriction', 'restriction:bicycle', 'give_way']
                        ) AS data
                        WHERE
                            data.from IS NULL OR data.from LIKE 'w%'
                            AND data.via IS NULL OR data.via LIKE 'n%'
                            AND data.to IS NULL OR data.to LIKE 'w%'
                        ORDER BY id  -- TODO
                        LIMIT 10  -- TODO
                    ) AS data
                WHERE
                    planet_osm_line.osm_id = data.from::integer
            ) AS data
        WHERE
            planet_osm_line.osm_id = data.to::integer
    ) AS data
WHERE
    planet_osm_point.osm_id = data.via::integer
;

Styling this is not a big deal then. The main issue is that the innermost SQL lookup (SELECT ... FROM planet_osm_rels WHERE tags @> ARRAY['type', 'restriction', 'restriction:bicycle', 'give_way']) is fetching *all such restrictions in the world and not using any kind of spatial index (there is not parsed geometry data here) to lookup only within the tile area. So this should be refined and thought carefully before considering pushing anything into production.

@Phyks Phyks mentioned this issue Aug 8, 2020
2 tasks
@Phyks Phyks self-assigned this Aug 8, 2020
@brainwad brainwad mentioned this issue Aug 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature Render a new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants