Skip to content

Commit

Permalink
Refactor z12-14 transportation filter logic (openmaptiles#1207)
Browse files Browse the repository at this point in the history
This PR is a refactor.  The purpose of this PR is to refactor the logic in the z12-z14 transportation layer to increase readability and reduce code complexity.

In addition, this fixes bugs in the original filter code:
* Create filter parity between `service` and `service_construction` highway classes.
* Removal of unintended `class` values `minor_construction`, `path_construction`, `service_construction`, and `track_construction` from zoom 12 filter by explicitly listing the highway classes that are included.
  • Loading branch information
ZeLonewolf authored Sep 20, 2021
1 parent d19aa5b commit 849aca8
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 21 deletions.
34 changes: 34 additions & 0 deletions layers/transportation/class.sql
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,37 @@ SELECT CASE
$$ LANGUAGE SQL IMMUTABLE
STRICT
PARALLEL SAFE;

-- Determine which transportation features are shown at zoom 12
CREATE OR REPLACE FUNCTION transportation_filter_z12(highway text, construction text) RETURNS boolean AS
$$
SELECT CASE
WHEN highway IN ('unclassified', 'residential') THEN TRUE
WHEN highway_class(highway, '', construction) IN
(
'motorway', 'trunk', 'primary', 'secondary', 'tertiary', 'raceway',
'motorway_construction', 'trunk_construction', 'primary_construction',
'secondary_construction', 'tertiary_construction', 'raceway_construction'
) THEN TRUE --includes ramps
ELSE FALSE
END
$$ LANGUAGE SQL IMMUTABLE
STRICT
PARALLEL SAFE;

-- Determine which transportation features are shown at zoom 13
-- Assumes that piers have already been excluded
CREATE OR REPLACE FUNCTION transportation_filter_z13(highway text,
public_transport text,
construction text,
service text) RETURNS boolean AS
$$
SELECT CASE
WHEN transportation_filter_z12(highway, construction) THEN TRUE
WHEN highway = 'service' OR construction = 'service' THEN service NOT IN ('driveway', 'parking_aisle')
WHEN highway_class(highway, public_transport, construction) IN ('minor', 'minor_construction') THEN TRUE
ELSE FALSE
END
$$ LANGUAGE SQL IMMUTABLE
STRICT
PARALLEL SAFE;
31 changes: 11 additions & 20 deletions layers/transportation/transportation.sql
Original file line number Diff line number Diff line change
Expand Up @@ -358,26 +358,17 @@ FROM (
z_order
FROM osm_highway_linestring
WHERE NOT is_area
AND (
zoom_level = 12 AND (
highway_class(highway, public_transport, construction) NOT IN ('track', 'path', 'minor', 'service')
OR highway IN ('unclassified', 'residential')
) AND man_made <> 'pier'
OR zoom_level = 13
AND (
highway_class(highway, public_transport, construction) NOT IN ('track', 'path') AND
man_made <> 'pier'
OR
man_made = 'pier' AND NOT ST_IsClosed(geometry)
)
AND service NOT IN ('driveway', 'parking_aisle')
OR zoom_level >= 14
AND (
man_made <> 'pier'
OR
NOT ST_IsClosed(geometry)
)
)
AND
CASE WHEN zoom_level = 12 THEN transportation_filter_z12(highway, construction)
WHEN zoom_level = 13 THEN
CASE WHEN man_made='pier' THEN NOT ST_IsClosed(geometry)
ELSE transportation_filter_z13(highway, public_transport, construction, service)
END
WHEN zoom_level >= 14 THEN
CASE WHEN man_made='pier' THEN NOT ST_IsClosed(geometry)
ELSE TRUE
END
END
UNION ALL

-- etldoc: osm_railway_linestring_gen_z8 -> layer_transportation:z8
Expand Down
2 changes: 1 addition & 1 deletion layers/transportation/transportation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ layer:
[`aerialway`](http://wiki.openstreetmap.org/wiki/Key:aerialway),
[`route`](http://wiki.openstreetmap.org/wiki/Key:route) tag (for
shipping ways), or
[`man_made`](http://wiki.openstreetmap.org/wiki/Key:route).
[`man_made`](http://wiki.openstreetmap.org/wiki/Key:man_made).
values:
motorway:
highway: ['motorway', 'motorway_link']
Expand Down

0 comments on commit 849aca8

Please sign in to comment.