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

WIP: Feature/aeroways #4346

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ osm2pgsql -G --hstore --style openstreetmap-carto.style --tag-transform-script o

You can find a more detailed guide to setting up a database and loading data with osm2pgsql at [switch2osm.org](https://switch2osm.org/manually-building-a-tile-server-16-04-2-lts/).

### Custom indexes
### Custom indexes and functions
Custom indexes are required for rendering performance and are essential on full planet databases.
`functions.sql` contains SQL functions used by the project.

```
psql -d gis -f indexes.sql
psql -d gis -f functions.sql
```

## Scripted download
Expand Down
13 changes: 13 additions & 0 deletions functions.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-- This SQL file contains custom PostgreSQL functions used by Carto.

-- Compute the scale factor to use when converting from metres to pixels.
-- This works by computing what the distance of a lateral translation of '1'
-- amounts to in WGS 84 coordinates for the specified object.
create or replace function scale_factor (geometry)
returns numeric
language sql
immutable
returns null on null input
as $func$
select ST_DistanceSphere(ST_Transform(ST_Translate(geom, 0, 1), 4326), ST_Transform(geom, 4326))::numeric from (select ST_Centroid($1) as geom) as p
$func$;
1 change: 1 addition & 0 deletions openstreetmap-carto.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ local polygon_keys = {
'allotments',
'amenity',
'area:highway',
'area:aeroway',
'craft',
'building',
'building:part',
Expand Down
103 changes: 90 additions & 13 deletions project.mml
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,32 @@ Layer:
properties:
cache-features: true
minzoom: 10
- id: aeroway-area-fill
<<: *extents
Datasource:
<<: *osm2pgsql
table: |-
(SELECT
way,
way_area/NULLIF(POW(!scale_denominator!*0.001*0.28,2),0) AS way_pixels,
CASE
WHEN surface IN ('paved', 'asphalt', 'concrete', 'concrete:lanes', 'concrete:plates', 'metal') THEN 'paved'
WHEN surface IN ('grass') THEN 'grass'
ELSE 'unpaved'
END AS int_surface,
COALESCE(
(('aeroway_' || CASE
WHEN aeroway IN ('helipad', 'apron') THEN aeroway
WHEN tags->'area:aeroway' IN ('runway', 'taxiway', 'stopway') THEN tags->'area:aeroway'
END))
) AS feature
FROM planet_osm_polygon
WHERE aeroway IN ('helipad', 'apron')
OR tags->'area:aeroway' IN ('runway', 'taxiway', 'stopway')
ORDER BY COALESCE(layer,0), way_area desc
) AS highway_area_fill
properties:
minzoom: 14
- id: highway-area-fill
# FIXME: No geometry?
<<: *extents
Expand All @@ -795,16 +821,14 @@ Layer:
AND (tags->'location' NOT IN ('underground') OR (tags->'location') IS NULL)
AND (tunnel NOT IN ('yes', 'building_passage') OR tunnel IS NULL)
AND (covered NOT IN ('yes') OR covered IS NULL))
THEN railway END)),
(('aeroway_' || CASE WHEN aeroway IN ('runway', 'taxiway', 'helipad') THEN aeroway END))
THEN railway END))
) AS feature
FROM planet_osm_polygon
WHERE highway IN ('pedestrian', 'footway', 'service', 'living_street', 'platform', 'services')
OR (railway IN ('platform')
AND (tags->'location' NOT IN ('underground') OR (tags->'location') IS NULL)
AND (tunnel NOT IN ('yes', 'building_passage') OR tunnel IS NULL)
AND (covered NOT IN ('yes') OR covered IS NULL))
OR aeroway IN ('runway', 'taxiway', 'helipad')
ORDER BY COALESCE(layer,0), way_area desc
) AS highway_area_fill
properties:
Expand Down Expand Up @@ -1035,11 +1059,55 @@ Layer:
(SELECT
way,
aeroway,
bridge IN ('yes', 'boardwalk', 'cantilever', 'covered', 'low_water_crossing', 'movable', 'trestle', 'viaduct') AS bridge
FROM planet_osm_line
WHERE aeroway IN ('runway', 'taxiway')
ORDER BY bridge NULLS FIRST,
CASE WHEN aeroway = 'runway' THEN 1 ELSE 0 END
runway,
bridge,
int_surface,
width,
GREATEST(width::real/sf, 2) AS area_width,
1/sf AS line_width
FROM
(SELECT
way,
aeroway,
tags->'runway' AS runway,
bridge IN ('yes', 'boardwalk', 'cantilever', 'covered', 'low_water_crossing', 'movable', 'trestle', 'viaduct') AS bridge,
CASE
WHEN surface IN ('paved', 'asphalt', 'concrete', 'concrete:lanes', 'concrete:plates', 'metal') THEN 'paved'
WHEN surface IN ('grass') THEN 'grass'
ELSE 'unpaved'
END AS int_surface,
-- Convert valid length units into metres. Fall back to a sensible default if no valid value was set.
GREATEST(
CASE
-- Metric:
WHEN tags->'width' ~ '^[0-9]*[.]?[0-9]+ m$' THEN LEFT(tags->'width', -2)::real
WHEN tags->'width' ~ '^[0-9]*[.]?[0-9]+$' THEN (tags->'width')::real
-- Feet:
WHEN tags->'width' ~ '^[0-9]+''$' THEN LEFT(tags->'width', -1)::real * 12 * 0.0254
-- The case-branches below work, but we assume that runway widths will always be
-- specified in metres or (rarely) feet, so for performance reasons these are left out:
-- Kilometres:
-- WHEN tags->'width' ~ '^[0-9]*[.]?[0-9]+ km$' THEN LEFT(tags->'width',-3)::real * 1000
-- Miles and nautical miles:
-- WHEN tags->'width' ~ '^[0-9]*[.]?[0-9]+ mi$' THEN LEFT(tags->'width', -3)::real * 1609.344
-- WHEN tags->'width' ~ '^[0-9]*[.]?[0-9]+ nmi$' THEN LEFT(tags->'width', -4)::real * 1852
-- Remaining feet and inches:
-- WHEN tags->'width' ~ '^[0-9]+''[0-9]+"$' THEN (SPLIT_PART(tags->'width', '''', 1)::real * 12 + LEFT(SPLIT_PART(tags->'width', '''', 2), -1)::real) * 0.0254
-- WHEN tags->'width' ~ '^[0-9]+"$' THEN LEFT(tags->'width', -1)::real * 0.0254
ELSE NULL
END,
-- Default to a small standard width for runways and a matching taxiway width.
CASE
WHEN aeroway IN ('runway') THEN 18
ELSE 7.5
END
) as width,
NULLIF(scale_factor(way)*!scale_denominator!*0.001*0.28, 0) AS sf
FROM planet_osm_line
WHERE aeroway IN ('runway', 'taxiway', 'taxilane', 'stopway', 'parking_position')
ORDER BY bridge NULLS FIRST,
CASE WHEN aeroway = 'runway' THEN 1 ELSE 0 END
) _
) AS aeroways
properties:
cache-features: true
Expand Down Expand Up @@ -1772,13 +1840,20 @@ Layer:
SELECT
osm_id,
way,
COALESCE(
CASE WHEN highway IN ('motorway', 'trunk', 'primary', 'secondary', 'tertiary') THEN highway END,
CASE WHEN aeroway IN ('runway', 'taxiway') THEN aeroway END
) AS highway,
highway,
string_to_array(ref, ';') AS refs
FROM planet_osm_line
WHERE highway IN ('motorway', 'trunk', 'primary', 'secondary', 'tertiary')
AND ref IS NOT NULL
UNION ALL
SELECT
osm_id,
way,
aeroway AS highway,
string_to_array(ref, ';') AS refs
FROM planet_osm_line
WHERE (highway IN ('motorway', 'trunk', 'primary', 'secondary', 'tertiary') OR aeroway IN ('runway', 'taxiway'))
WHERE aeroway IN ('runway', 'taxiway', 'taxilane', 'parking_position')
AND NOT tags @> '"runway"=>"displaced_threshold"'
AND ref IS NOT NULL
) AS p) AS q
WHERE height <= 4 AND width <= 11
Expand All @@ -1791,6 +1866,8 @@ Layer:
WHEN highway = 'tertiary' THEN 34
WHEN highway = 'runway' THEN 6
WHEN highway = 'taxiway' THEN 5
WHEN highway = 'parking_position' THEN 4
WHEN highway = 'taxilane' THEN 3
END DESC NULLS LAST,
height DESC,
width DESC,
Expand Down
1 change: 1 addition & 0 deletions scripts/docker-startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import)
psql -c "SELECT 1 FROM pg_database WHERE datname = 'gis';" | grep -q 1 || createdb gis && \
psql -d gis -c 'CREATE EXTENSION IF NOT EXISTS postgis;' && \
psql -d gis -c 'CREATE EXTENSION IF NOT EXISTS hstore;' && \
psql -d gis -f functions.sql && \

# Creating default import settings file editable by user and passing values for osm2pgsql
if [ ! -e ".env" ]; then
Expand Down
8 changes: 1 addition & 7 deletions style/landcover.mss
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
// --- Transport ----

@transportation-area: #e9e7e2;
@apron: #dadae0;
@apron: #cdcdda;
@garages: #dfddce;
@parking: #eeeeee;
@parking-outline: saturate(darken(@parking, 40%), 20%);
Expand Down Expand Up @@ -629,12 +629,6 @@
line-color: mix(@parking-outline, @parking, 50%);
}

[feature = 'aeroway_apron'][zoom >= 10] {
polygon-fill: @apron;
[way_pixels >= 4] { polygon-gamma: 0.75; }
[way_pixels >= 64] { polygon-gamma: 0.3; }
}

[feature = 'aeroway_aerodrome'][zoom >= 10],
[feature = 'amenity_ferry_terminal'][zoom >= 15],
[feature = 'amenity_bus_station'][zoom >= 15] {
Expand Down
Loading