Skip to content

Commit

Permalink
Updated SQL queries as well
Browse files Browse the repository at this point in the history
  • Loading branch information
jenningsanderson committed Dec 17, 2024
1 parent 8f86743 commit 7083d67
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ CASE
--Outbuilding
'allotment_house',
'carport',
'roof',
'outbuilding',
'shed',

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ CASE
WHEN lower(trim(element_at(tags, 'building'))) IN (
'allotment_house',
'carport',
'roof',
'outbuilding',
'shed'
) THEN 'outbuilding'
Expand Down
30 changes: 21 additions & 9 deletions src/queries/partials/osm_conversion_logic/infrastructure.sql
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
CASE
-- Railways / Subways
-- Railway stations / Subway stations
WHEN element_at(tags,'railway') IN ('station','halt') THEN CASE

-- Railway Specific
WHEN element_at(tags,'station') <> 'subway' AND element_at(tags, 'subway') <> 'yes' THEN ROW('transit', 'railway_station')

-- Multimodal stations
WHEN element_at(tags,'station') = 'subway' THEN ROW('transit', 'subway_station')
ELSE ROW('transit', 'railway_' || element_at(tags,'railway'))
END

Expand All @@ -24,7 +20,8 @@ CASE
WHEN element_at(tags,'amenity') IN (
'parking',
'parking_space',
'bicycle_parking'
'bicycle_parking',
'motorcycle_parking'
) THEN ROW('transit', element_at(tags,'amenity'))

-- Aerialways (Linestrings)
Expand All @@ -33,8 +30,14 @@ CASE
'chair_lift',
'drag_lift',
'gondola',
'j-bar',
'magic_carpet',
'goods',
'mixed_lift',
't-bar'
'platter',
'rope_tow',
't-bar',
'zip_line'
) THEN ROW('aerialway', element_at(tags,'aerialway'))

-- Pylons are points
Expand All @@ -46,13 +49,19 @@ CASE
-- Airports (Polygons)
WHEN ST_GEOMETRYTYPE(ST_GeomFromBinary(geometry)) IN ('ST_Polygon', 'ST_MultiPolygon') AND element_at(tags,'aeroway') IN (
'airstrip',
'apron',
'helipad',
'heliport'
'heliport',
'launchpad',
'runway',
'taxiway'
) THEN ROW('airport', element_at(tags,'aeroway'))

-- Airports (LineStrings)
WHEN ST_GEOMETRYTYPE(ST_GeomFromBinary(geometry)) = 'ST_LineString' AND element_at(tags, 'aeroway') IN (
'runway',
'stopway',
'taxilane',
'taxiway'
) THEN ROW('airport', element_at(tags,'aeroway'))

Expand Down Expand Up @@ -159,7 +168,9 @@ CASE

-- Utility / human made made containers
WHEN element_at(tags,'man_made') IN (
'gasometer',
'pipeline',
'reservoir_covered',
'silo',
'storage_tank',
'utility_pole',
Expand All @@ -180,6 +191,7 @@ CASE
(element_at(tags,'drinking_water') IS NULL OR element_at(tags,'drinking_water') <> 'no') AND
(element_at(tags,'access') IS NULL OR element_at(tags,'access') <> 'private')
THEN ROW('water', 'drinking_water')
WHEN element_at(tags,'amenity') IN ('fountain') THEN ROW('water', 'fountain')


-- Standalone piers
Expand Down
7 changes: 7 additions & 0 deletions src/queries/partials/osm_conversion_logic/land.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
CASE
-- Craters
WHEN element_at(tags,'geological') IN ('meteor_crater', 'volcanic_caldera_rim')
AND (element_at(tags, 'water') IS NULL OR element_at(tags, 'water') <> 'lake')
AND (element_at(tags, 'natural') IS NULL OR element_at(tags, 'natural') <> 'water')
THEN ROW('crater', element_at(tags,'geological'))

-- Desert
WHEN element_at(tags,'natural') IN ('desert') THEN ROW('desert', element_at(tags,'natural'))

Expand Down Expand Up @@ -59,6 +65,7 @@ CASE
'mountain_range',
'peak',
'peninsula',
'plateau',
'ridge',
'saddle',
'valley'
Expand Down
89 changes: 48 additions & 41 deletions src/queries/partials/osm_conversion_logic/land_use.sql
Original file line number Diff line number Diff line change
@@ -1,13 +1,33 @@
CASE
-- Piste types
WHEN ST_GeometryType(ST_GeomFromBinary(geometry)) <> 'ST_Point' AND element_at(tags,'piste:type') IN (
'playground'
'connection',
'downhill',
'fatbike',
'hike',
'ice_skate',
'nordic',
'playground',
'ski_jump',
'skitour',
'sled',
'sleigh',
'snow_park'
) THEN ROW ('winter_sports', element_at(tags,'piste:type'))

-- Polygons
WHEN ST_GeometryType(ST_GeomFromBinary(geometry)) IN ('ST_Polygon', 'ST_MultiPolygon') THEN CASE

-- Military Specific Landuses

WHEN ( element_at(tags,'landuse') = 'military' OR element_at(tags,'military') <> 'no')
AND element_at(tags,'amenity') IN ('hospital', 'clinic')
THEN ROW('military', 'military_hospital')

WHEN ( element_at(tags,'landuse') = 'military' OR element_at(tags,'military') <> 'no')
AND element_at(tags,'amenity') IN ('school','university','college')
THEN ROW('military', 'military_school')

WHEN element_at(tags,'military') IN (
'airfield',
'barracks',
Expand Down Expand Up @@ -36,54 +56,32 @@ CASE
'water_park'
) THEN ROW('entertainment', element_at(tags,'leisure'))

-- Give National Parks top priority since it might have other tags.
WHEN element_at(tags,'boundary') = 'national_park' THEN ROW('protected','national_park')

-- Aboriginal Lands & Reservations
WHEN element_at(tags, 'boundary') IN ('aboriginal_lands') OR (
element_at(tags, 'boundary') = 'protected_area' AND element_at(tags, 'protect_class') = '24'
) THEN ROW('protected', 'aboriginal_land')

-- Pedestrian land use, such as plazas
WHEN element_at(tags, 'place') = 'square' THEN ROW('pedestrian', 'plaza')
WHEN element_at(tags, 'highway') = 'pedestrian' THEN ROW('pedestrian', 'pedestrian')
-- National Parks & Aboriginal Lands based on boundary
WHEN element_at(tags, 'boundary') = 'national_park' THEN ROW('protected','national_park')
WHEN element_at(tags, 'boundary') = 'aboriginal_lands' THEN ROW('protected', 'aboriginal_land')

-- Is there is an official Protect Class Designation (wiki.openstreetmap.org/wiki/Key:protect_class)?
-- Protected areas based on protect_class
WHEN element_at(tags, 'protect_class') = '1a' THEN ROW('protected', 'strict_nature_reserve')
WHEN element_at(tags, 'protect_class') IN ('1b', '1') THEN ROW('protected', 'wilderness_area')
WHEN element_at(tags, 'protect_class') = '2' THEN ROW('protected', 'national_park')
WHEN element_at(tags, 'protect_class') = '3' THEN ROW('protected', 'natural_monument')
WHEN element_at(tags, 'protect_class') = '4' THEN ROW('protected', 'species_management_area')
WHEN element_at(tags, 'protect_class') = '5' THEN ROW('protected', 'protected_landscape_seascape')
WHEN element_at(tags, 'protect_class') = '6' THEN ROW('protected', 'nature_reserve')

WHEN element_at(tags, 'boundary') = 'protected_area' THEN CASE
WHEN LOWER(element_at(tags, 'protection_title')) IN ('national forest', 'state forest')
THEN ROW('protected', 'forest')
WHEN LOWER(element_at(tags, 'protection_title')) IN ('national park', 'parque nacional', 'national_park')
THEN ROW('protected', 'national_park')
WHEN LOWER(element_at(tags, 'protection_title')) IN ('state park') THEN ROW('protected','state_park')
WHEN LOWER(element_at(tags, 'protection_title')) IN (
'wilderness area',
'wilderness study area'
) THEN ROW('protected', 'wilderness_area')
WHEN LOWER(element_at(tags, 'protection_title')) IN ('nature reserve', 'nature refuge', 'reserva nacional')
THEN ROW('protected', 'nature_reserve')
WHEN LOWER(element_at(tags, 'protection_title')) IN ('environmental use')
THEN ROW('protected', 'environmental')
WHEN element_at(tags,'leisure') IN ('nature_reserve')
THEN ROW('protected', element_at(tags,'leisure'))
WHEN element_at(tags,'landuse') IS NOT NULL
THEN ROW('protected', 'protected')
END

WHEN element_at(tags,'leisure') IN ('nature_reserve') THEN ROW('protected','nature_reserve')

-- National & State Parks
WHEN LOWER(element_at(tags, 'protection_title')) = 'national park' THEN ROW('protected', 'national_park')
WHEN LOWER(element_at(tags, 'protection_title')) = 'state park' THEN ROW('protected', 'state_park')
WHEN element_at(tags, 'protected_area') = 'national_park' THEN ROW('protected', 'national_park')

WHEN element_at(tags, 'protect_class') = '24' THEN ROW('protected', 'aboriginal_land')

-- Protected areas based on protection_title
WHEN element_at(tags, 'boundary') = 'protected_area' AND LOWER(element_at(tags, 'protection_title')) IN ('national forest', 'state forest') THEN ROW('protected', 'forest')
WHEN element_at(tags, 'boundary') = 'protected_area' AND LOWER(element_at(tags, 'protection_title')) IN ('national park', 'parque nacional', 'national_park') THEN ROW('protected', 'national_park')
WHEN element_at(tags, 'boundary') = 'protected_area' AND LOWER(element_at(tags, 'protection_title')) IN ('state park') THEN ROW('protected','state_park')
WHEN element_at(tags, 'boundary') = 'protected_area' AND LOWER(element_at(tags, 'protection_title')) IN ('wilderness area', 'wilderness study area') THEN ROW('protected', 'wilderness_area')
WHEN element_at(tags, 'boundary') = 'protected_area' AND LOWER(element_at(tags, 'protection_title')) IN ('nature reserve', 'nature refuge', 'reserva nacional') THEN ROW('protected', 'nature_reserve')
WHEN element_at(tags, 'boundary') = 'protected_area' AND LOWER(element_at(tags, 'protection_title')) IN ('environmental use') THEN ROW('protected', 'environmental')

-- Protected areas based on leisure or landuse
WHEN element_at(tags, 'leisure') = 'nature_reserve' THEN ROW('protected','nature_reserve')
WHEN element_at(tags, 'boundary') = 'protected_area' AND element_at(tags,'landuse') IS NOT NULL THEN ROW('protected', 'protected')

-- Golf
WHEN element_at(tags,'golf') IN (
'bunker',
Expand Down Expand Up @@ -122,6 +120,9 @@ CASE
-- Education / Schoolyards
WHEN element_at(tags, 'amenity') IN (
'college',
'driving_school',
'kindergarten',
'music_school',
'school',
'university'
) THEN ROW('education', element_at(tags, 'amenity'))
Expand All @@ -144,6 +145,10 @@ CASE
) THEN ROW('park', element_at(tags,'leisure'))
WHEN element_at(tags,'landuse') IN ('village_green') THEN ROW('park', element_at(tags,'landuse'))

-- Pedestrian land use, such as plazas
WHEN element_at(tags, 'place') = 'square' THEN ROW('pedestrian', 'plaza')
WHEN element_at(tags, 'highway') = 'pedestrian' THEN ROW('pedestrian', 'pedestrian')

-- Agriculture
WHEN element_at(tags,'landuse') IN ('animal_keeping', 'farmland', 'farmyard', 'meadow')
THEN ROW('agriculture', element_at(tags,'landuse'))
Expand Down Expand Up @@ -178,6 +183,7 @@ CASE
'pitch',
'playground',
'recreation_ground',
'resort',
'stadium',
'track'
) THEN ROW('recreation', element_at(tags,'leisure'))
Expand All @@ -194,6 +200,7 @@ CASE
'institutional',
'retail'
) THEN ROW('developed', element_at(tags,'landuse'))
WHEN element_at(tags,'shop') = 'mall' THEN ROW('developed', 'retail')
WHEN element_at(tags,'man_made') = 'works' THEN ROW('developed', 'works')

-- Construction
Expand Down
2 changes: 1 addition & 1 deletion src/queries/partials/osm_conversion_logic/water.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ CASE
WHEN element_at(tags, 'water') IN ('lake', 'oxbow','lagoon') THEN ROW('lake', element_at(tags, 'water'))

-- Springs
WHEN element_at(tags, 'natural') IN ('spring','hot_spring','geyser') THEN ROW('spring', element_at(tags, 'natural'))
WHEN element_at(tags, 'natural') IN ('spring','hot_spring','geyser','blowhole') THEN ROW('spring', element_at(tags, 'natural'))

-- Tidal Channels / Fairways
WHEN element_at(tags, 'waterway') IN ('tidal_channel', 'fairway') THEN ROW('water', element_at(tags, 'waterway'))
Expand Down

0 comments on commit 7083d67

Please sign in to comment.