-
Notifications
You must be signed in to change notification settings - Fork 821
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rendering specific access tags (#4952)
* Interpret additional access tags mode specific access tags relevant to primary mode of highway interpreted to determine access marking for: Road types (motorcar > motor_vehicle > vehicle) Footway (foot) Cycleway (bicycle) Bridleway (horse) * Function load in CI * Add carto_path_primary_path * Moving customers, permit Following discussion moving: access=customers -> "restricted" marking access=permit -> "no" marking * Major changes in response to comments Functions renamed for clarity Changed logic for mode-specific tags, only ignoring 'unknown' values unknown access type return for unknown/uninterpretable path promoted to cycleway/bridleway in SQL rather than MSS * Use foot primary mode for highway=pedestrian * Typo fix * Remove incorrect END statements * Fix regression on introducing explicit unknown * Fix regression for highway=path * Alter 'destination' outcome for 2-state access 'destination' on path / footway etc. interpreted as 'yes' (matching current behaviour) * Simplify functions.sql Reduce number of functions Tidy comments * Tidy access functions Consistent formatting of CASE/WHEN Use more idiomatic COALESCE(NULLIF(...),) * Update functions.sql Change argument name accesstag -> accessvalue Improve documentation Simplify logic for promoted paths * Remove obsolete comment from MML * Avoid unknown overload Return "unrecognised" rather than "unknown" if access restriction is not one of recognised values * Extend code comments Note on short-circuiting logic in carto_highway_int_access * Fix broken bridge on path Bridge not being rendered on highway=path
- Loading branch information
Showing
5 changed files
with
147 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* Additional database functions for openstreetmap-carto */ | ||
|
||
/* Access functions below adapted from https://github.com/imagico/osm-carto-alternative-colors/tree/591c861112b4e5d44badd108f4cd1409146bca0b/sql/roads.sql */ | ||
|
||
/* Simplified 'yes', 'destination', 'no', 'unrecognised', NULL scale for access restriction | ||
'no' is returned if the rendering for highway category does not support 'restricted'. | ||
NULL is functionally equivalent to 'yes', but indicates the absence of a restriction | ||
rather than a positive access = yes. 'unrecognised' corresponds to an uninterpretable | ||
access restriction e.g. access=unknown or motorcar=occasionally */ | ||
CREATE OR REPLACE FUNCTION carto_int_access(accessvalue text, allow_restricted boolean) | ||
RETURNS text | ||
LANGUAGE SQL | ||
IMMUTABLE PARALLEL SAFE | ||
AS $$ | ||
SELECT | ||
CASE | ||
WHEN accessvalue IN ('yes', 'designated', 'permissive') THEN 'yes' | ||
WHEN accessvalue IN ('destination', 'delivery', 'customers') THEN | ||
CASE WHEN allow_restricted = TRUE THEN 'restricted' ELSE 'yes' END | ||
WHEN accessvalue IN ('no', 'permit', 'private', 'agricultural', 'forestry', 'agricultural;forestry') THEN 'no' | ||
WHEN accessvalue IS NULL THEN NULL | ||
ELSE 'unrecognised' | ||
END | ||
$$; | ||
|
||
/* Try to promote path to cycleway (if bicycle allowed), then bridleway (if horse) | ||
This duplicates existing behaviour where designated access is required */ | ||
CREATE OR REPLACE FUNCTION carto_path_type(bicycle text, horse text) | ||
RETURNS text | ||
LANGUAGE SQL | ||
IMMUTABLE PARALLEL SAFE | ||
AS $$ | ||
SELECT | ||
CASE | ||
WHEN bicycle IN ('designated') THEN 'cycleway' | ||
WHEN horse IN ('designated') THEN 'bridleway' | ||
ELSE 'path' | ||
END | ||
$$; | ||
|
||
/* Return int_access value which will be used to determine access marking. | ||
Return values are documented above for carto_int_access function. | ||
Note that the code handling the promotion of highway=path assumes that | ||
promotion to cycleway or bridleway is based on the value of bicycle or | ||
horse respectively. A more general formulation would be, for example, | ||
WHEN 'cycleway' THEN carto_int_access(COALESCE(NULLIF(bicycle, 'unknown'), "access"), FALSE) */ | ||
CREATE OR REPLACE FUNCTION carto_highway_int_access(highway text, "access" text, foot text, bicycle text, horse text, motorcar text, motor_vehicle text, vehicle text) | ||
RETURNS text | ||
LANGUAGE SQL | ||
IMMUTABLE PARALLEL SAFE | ||
AS $$ | ||
SELECT | ||
CASE | ||
WHEN highway IN ('motorway', 'motorway_link', 'trunk', 'trunk_link', 'primary', 'primary_link', 'secondary', | ||
'secondary_link', 'tertiary', 'tertiary_link', 'residential', 'unclassified', 'living_street', 'service', 'road') THEN | ||
carto_int_access( | ||
COALESCE( | ||
NULLIF(motorcar, 'unknown'), | ||
NULLIF(motor_vehicle, 'unknown'), | ||
NULLIF(vehicle, 'unknown'), | ||
"access"), TRUE) | ||
WHEN highway = 'path' THEN | ||
CASE carto_path_type(bicycle, horse) | ||
WHEN 'cycleway' THEN carto_int_access(bicycle, FALSE) | ||
WHEN 'bridleway' THEN carto_int_access(horse, FALSE) | ||
ELSE carto_int_access(COALESCE(NULLIF(foot, 'unknown'), "access"), FALSE) | ||
END | ||
WHEN highway IN ('pedestrian', 'footway', 'steps') THEN carto_int_access(COALESCE(NULLIF(foot, 'unknown'), "access"), FALSE) | ||
WHEN highway = 'cycleway' THEN carto_int_access(COALESCE(NULLIF(bicycle, 'unknown'), "access"), FALSE) | ||
WHEN highway = 'bridleway' THEN carto_int_access(COALESCE(NULLIF(horse, 'unknown'), "access"), FALSE) | ||
ELSE carto_int_access("access", TRUE) | ||
END | ||
$$; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.