kopia lustrzana https://github.com/openmaptiles/openmaptiles
Merge branch 'master' into power_facilities
commit
868f0a8328
2
.env
2
.env
|
@ -4,7 +4,7 @@
|
|||
TILESET_FILE=openmaptiles.yaml
|
||||
|
||||
# Use 3-part patch version to ignore patch updates, e.g. 5.0.0
|
||||
TOOLS_VERSION=6.1
|
||||
TOOLS_VERSION=6.2
|
||||
|
||||
# Make sure these values are in sync with the ones in .env-postgres file
|
||||
PGDATABASE=openmaptiles
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
# This file defines environment variables for the PostgreSQL image.
|
||||
# The main docker PostgreSQL image requires these vars rather than
|
||||
# the standard PG* ones that all PostgreSQL tools use.
|
||||
|
||||
# Make sure these values are in sync with the ones in .env file
|
||||
POSTGRES_DB=openmaptiles
|
||||
POSTGRES_USER=openmaptiles
|
||||
POSTGRES_PASSWORD=openmaptiles
|
71
Makefile
71
Makefile
|
@ -6,11 +6,8 @@
|
|||
SHELL = /bin/bash
|
||||
.SHELLFLAGS = -o pipefail -c
|
||||
|
||||
# Make all .env variables available for make targets
|
||||
include .env
|
||||
|
||||
# Layers definition and meta data
|
||||
TILESET_FILE ?= openmaptiles.yaml
|
||||
TILESET_FILE := $(or $(TILESET_FILE),$(shell (. .env; echo $${TILESET_FILE})),openmaptiles.yaml)
|
||||
|
||||
# Options to run with docker and docker-compose - ensure the container is destroyed on exit
|
||||
# Containers run as the current user rather than root (so that created files are not root-owned)
|
||||
|
@ -27,7 +24,8 @@ TPORT ?= 8080
|
|||
export TPORT
|
||||
|
||||
# Allow a custom docker-compose project name
|
||||
ifeq ($(strip $(DC_PROJECT)),)
|
||||
DC_PROJECT := $(or $(DC_PROJECT),$(shell (. .env; echo $${DC_PROJECT})))
|
||||
ifeq ($(DC_PROJECT),)
|
||||
DC_PROJECT := $(notdir $(shell pwd))
|
||||
DOCKER_COMPOSE := docker-compose
|
||||
else
|
||||
|
@ -35,7 +33,7 @@ else
|
|||
endif
|
||||
|
||||
# Make some operations quieter (e.g. inside the test script)
|
||||
ifeq ($(strip $(QUIET)),)
|
||||
ifeq ($(or $(QUIET),$(shell (. .env; echo $${QUIET})))),)
|
||||
QUIET_FLAG :=
|
||||
else
|
||||
QUIET_FLAG := --quiet
|
||||
|
@ -55,8 +53,7 @@ else
|
|||
endif
|
||||
|
||||
# Set OpenMapTiles host
|
||||
OMT_HOST := http://$(firstword $(subst :, ,$(subst tcp://,,$(DOCKER_HOST))) localhost)
|
||||
export OMT_HOST
|
||||
export OMT_HOST := http://$(firstword $(subst :, ,$(subst tcp://,,$(DOCKER_HOST))) localhost)
|
||||
|
||||
# This defines an easy $(newline) value to act as a "\n". Make sure to keep exactly two empty lines after newline.
|
||||
define newline
|
||||
|
@ -64,12 +61,12 @@ define newline
|
|||
|
||||
endef
|
||||
|
||||
# use the old postgres connection values if they are existing
|
||||
PGHOST := $(or $(POSTGRES_HOST),$(PGHOST))
|
||||
PGPORT := $(or $(POSTGRES_PORT),$(PGPORT))
|
||||
PGDATABASE := $(or $(POSTGRES_DB),$(PGDATABASE))
|
||||
PGUSER := $(or $(POSTGRES_USER),$(PGUSER))
|
||||
PGPASSWORD := $(or $(POSTGRES_PASSWORD),$(PGPASSWORD))
|
||||
# Use the old Postgres connection values as a fallback
|
||||
PGHOST := $(or $(PGHOST),$(shell (. .env; echo $${PGHOST})),$(POSTGRES_HOST),$(shell (. .env; echo $${POSTGRES_HOST})),postgres)
|
||||
PGPORT := $(or $(PGPORT),$(shell (. .env; echo $${PGPORT})),$(POSTGRES_PORT),$(shell (. .env; echo $${POSTGRES_PORT})),postgres)
|
||||
PGDATABASE := $(or $(PGDATABASE),$(shell (. .env; echo $${PGDATABASE})),$(POSTGRES_DB),$(shell (. .env; echo $${POSTGRES_DB})),postgres)
|
||||
PGUSER := $(or $(PGUSER),$(shell (. .env; echo $${PGUSER})),$(POSTGRES_USER),$(shell (. .env; echo $${POSTGRES_USER})),postgres)
|
||||
PGPASSWORD := $(or $(PGPASSWORD),$(shell (. .env; echo $${PGPASSWORD})),$(POSTGRES_PASSWORD),$(shell (. .env; echo $${POSTGRES_PASSWORD})),postgres)
|
||||
|
||||
#
|
||||
# Determine area to work on
|
||||
|
@ -82,7 +79,7 @@ PGPASSWORD := $(or $(POSTGRES_PASSWORD),$(PGPASSWORD))
|
|||
# historically we have been using $(area) rather than $(AREA), so make both work
|
||||
area ?= $(AREA)
|
||||
# Ensure the $(area) param is set, or try to automatically determine it based on available data files
|
||||
ifeq ($(strip $(area)),)
|
||||
ifeq ($(area),)
|
||||
# An $(area) parameter is not set. If only one *.osm.pbf file is found in ./data, use it as $(area).
|
||||
data_files := $(shell find data -name '*.osm.pbf' 2>/dev/null)
|
||||
ifneq ($(word 2,$(data_files)),)
|
||||
|
@ -127,7 +124,7 @@ ifeq ($(strip $(area)),)
|
|||
endif
|
||||
endif
|
||||
|
||||
ifneq ($(strip $(AREA_INFO)),)
|
||||
ifneq ($(AREA_INFO),)
|
||||
define assert_area_is_given
|
||||
@echo "$(AREA_INFO)"
|
||||
endef
|
||||
|
@ -137,20 +134,17 @@ endif
|
|||
PBF_FILE ?= data/$(area).osm.pbf
|
||||
|
||||
# For download-osm, allow URL parameter to download file from a given URL. Area param must still be provided.
|
||||
ifneq ($(strip $(url)),)
|
||||
DOWNLOAD_AREA := $(url)
|
||||
else
|
||||
DOWNLOAD_AREA := $(area)
|
||||
endif
|
||||
DOWNLOAD_AREA := $(or $(url), $(area))
|
||||
|
||||
# The file is placed into the $EXPORT_DIR=/export (mapped to ./data)
|
||||
export MBTILES_FILE ?= $(area).mbtiles
|
||||
# The mbtiles file is placed into the $EXPORT_DIR=/export (mapped to ./data)
|
||||
MBTILES_FILE := $(or $(MBTILES_FILE),$(shell (. .env; echo $${MBTILES_FILE})),$(area).mbtiles)
|
||||
MBTILES_LOCAL_FILE = data/$(MBTILES_FILE)
|
||||
|
||||
ifeq ($(strip $(DIFF_MODE)),true)
|
||||
DIFF_MODE := $(or $(DIFF_MODE),$(shell (. .env; echo $${DIFF_MODE})))
|
||||
ifeq ($(DIFF_MODE),true)
|
||||
# import-osm implementation requires IMPOSM_CONFIG_FILE to be set to a valid file
|
||||
# For static (no-updates) import, we don't need to override the default value
|
||||
# For the update mode, set location of the dynamically-generated area-based config file
|
||||
# For one-time only imports, the default value is fine.
|
||||
# For diff mode updates, use the dynamically-generated area-based config file
|
||||
export IMPOSM_CONFIG_FILE = data/$(area).repl.json
|
||||
endif
|
||||
|
||||
|
@ -162,6 +156,12 @@ ifneq (,$(wildcard $(AREA_BBOX_FILE)))
|
|||
export BBOX
|
||||
endif
|
||||
|
||||
# Consult .env if needed
|
||||
MIN_ZOOM := $(or $(MIN_ZOOM),$(shell (. .env; echo $${MIN_ZOOM})),0)
|
||||
MAX_ZOOM := $(or $(MAX_ZOOM),$(shell (. .env; echo $${MAX_ZOOM})),7)
|
||||
PPORT := $(or $(PPORT),$(shell (. .env; echo $${PPORT})),7)
|
||||
TPORT := $(or $(TPORT),$(shell (. .env; echo $${TPORT})),7)
|
||||
|
||||
define HELP_MESSAGE
|
||||
==============================================================================
|
||||
OpenMapTiles https://github.com/openmaptiles/openmaptiles
|
||||
|
@ -258,7 +258,7 @@ init-dirs:
|
|||
build/openmaptiles.tm2source/data.yml: init-dirs
|
||||
ifeq (,$(wildcard build/openmaptiles.tm2source/data.yml))
|
||||
$(DOCKER_COMPOSE) run $(DC_OPTS) openmaptiles-tools bash -c \
|
||||
'generate-tm2source $(TILESET_FILE) --host="$(PGHOST)" --port=$(PGPORT) --database="$(PGDATABASE)" --user="$(PGUSER)" --password="$(PGPASSWORD)" > $@'
|
||||
'generate-tm2source $(TILESET_FILE) > $@'
|
||||
endif
|
||||
|
||||
build/mapping.yaml: init-dirs
|
||||
|
@ -288,12 +288,11 @@ clean-test-data:
|
|||
rm -rf data/changes.repl.json
|
||||
|
||||
.PHONY: destroy-db
|
||||
# TODO: Use https://stackoverflow.com/a/27852388/177275
|
||||
destroy-db: DC_PROJECT := $(shell echo $(DC_PROJECT) | tr A-Z a-z)
|
||||
DOCKER_PROJECT = $(shell echo $(DC_PROJECT) | tr A-Z a-z | tr -cd '[:alnum:]')
|
||||
destroy-db:
|
||||
$(DOCKER_COMPOSE) down -v --remove-orphans
|
||||
$(DOCKER_COMPOSE) rm -fv
|
||||
docker volume ls -q -f "name=^$(DC_PROJECT)_" | $(XARGS) docker volume rm
|
||||
docker volume ls -q -f "name=^$(DOCKER_PROJECT)_" | $(XARGS) docker volume rm
|
||||
rm -rf cache
|
||||
mkdir cache
|
||||
|
||||
|
@ -336,11 +335,11 @@ OSM_SERVER=$(patsubst download,,$(patsubst download-%,%,$@))
|
|||
.PHONY: $(ALL_DOWNLOADS)
|
||||
$(ALL_DOWNLOADS): init-dirs
|
||||
@$(assert_area_is_given)
|
||||
ifneq ($(strip $(url)),)
|
||||
ifneq ($(url),)
|
||||
$(if $(OSM_SERVER),$(error url parameter can only be used with non-specific download target:$(newline) make download area=$(area) url="$(url)"$(newline)))
|
||||
endif
|
||||
ifeq (,$(wildcard $(PBF_FILE)))
|
||||
ifeq ($(strip $(DIFF_MODE)),true)
|
||||
ifeq ($(DIFF_MODE),true)
|
||||
@echo "Downloading $(DOWNLOAD_AREA) with replication support into $(PBF_FILE) and $(IMPOSM_CONFIG_FILE) from $(if $(OSM_SERVER),$(OSM_SERVER),any source)"
|
||||
@$(DOCKER_COMPOSE) run $(DC_OPTS) openmaptiles-tools download-osm $(OSM_SERVER) "$(DOWNLOAD_AREA)" \
|
||||
--imposm-cfg "$(IMPOSM_CONFIG_FILE)" \
|
||||
|
@ -354,7 +353,7 @@ ifeq (,$(wildcard $(PBF_FILE)))
|
|||
endif
|
||||
@echo ""
|
||||
else
|
||||
ifeq ($(strip $(DIFF_MODE)),true)
|
||||
ifeq ($(DIFF_MODE),true)
|
||||
ifeq (,$(wildcard $(IMPOSM_CONFIG_FILE)))
|
||||
$(error \
|
||||
$(newline) Data files $(PBF_FILE) already exists, but $(IMPOSM_CONFIG_FILE) does not. \
|
||||
|
@ -387,7 +386,7 @@ psql: start-db-nowait
|
|||
# Special cache handling for Docker Toolbox on Windows
|
||||
ifeq ($(MSYSTEM),MINGW64)
|
||||
DC_CONFIG_CACHE := -f docker-compose.yml -f docker-compose-$(MSYSTEM).yml
|
||||
DC_OPTS_CACHE := $(strip $(filter-out --user=%,$(DC_OPTS)))
|
||||
DC_OPTS_CACHE := $(filter-out --user=%,$(DC_OPTS))
|
||||
else
|
||||
DC_OPTS_CACHE := $(DC_OPTS)
|
||||
endif
|
||||
|
@ -561,12 +560,12 @@ list-docker-images:
|
|||
|
||||
.PHONY: refresh-docker-images
|
||||
refresh-docker-images: init-dirs
|
||||
ifneq ($(strip $(NO_REFRESH)),)
|
||||
ifneq ($(NO_REFRESH),)
|
||||
@echo "Skipping docker image refresh"
|
||||
else
|
||||
@echo ""
|
||||
@echo "Refreshing docker images... Use NO_REFRESH=1 to skip."
|
||||
ifneq ($(strip $(USE_PRELOADED_IMAGE)),)
|
||||
ifneq ($(USE_PRELOADED_IMAGE),)
|
||||
POSTGIS_IMAGE=openmaptiles/postgis-preloaded \
|
||||
docker-compose pull --ignore-pull-failures $(QUIET_FLAG) openmaptiles-tools generate-vectortiles postgres
|
||||
else
|
||||
|
|
|
@ -18,8 +18,14 @@ services:
|
|||
networks:
|
||||
- postgres
|
||||
ports:
|
||||
- "5432"
|
||||
env_file: .env-postgres
|
||||
- "${PGPORT:-5432}:${PGPORT:-5432}"
|
||||
env_file: .env
|
||||
environment:
|
||||
# postgress container uses old variable names
|
||||
POSTGRES_DB: ${PGDATABASE:-openmaptiles}
|
||||
POSTGRES_USER: ${PGUSER:-openmaptiles}
|
||||
POSTGRES_PASSWORD: ${PGPASSWORD:-openmaptiles}
|
||||
PGPORT: ${PGPORT:-5432}
|
||||
|
||||
import-data:
|
||||
image: "openmaptiles/import-data:${TOOLS_VERSION}"
|
||||
|
@ -44,6 +50,11 @@ services:
|
|||
IMPOSM_CONFIG_FILE: ${IMPOSM_CONFIG_FILE}
|
||||
# Control import-sql processes
|
||||
MAX_PARALLEL_PSQL: ${MAX_PARALLEL_PSQL}
|
||||
PGDATABASE: ${PGDATABASE:-openmaptiles}
|
||||
PGUSER: ${PGUSER:-openmaptiles}
|
||||
PGPASSWORD: ${PGPASSWORD:-openmaptiles}
|
||||
PGPORT: ${PGPORT:-5432}
|
||||
MBTILES_FILE: ${MBTILES_FILE}
|
||||
networks:
|
||||
- postgres
|
||||
volumes:
|
||||
|
@ -71,6 +82,10 @@ services:
|
|||
MBTILES_NAME: ${MBTILES_FILE}
|
||||
# Control tilelive-copy threads
|
||||
COPY_CONCURRENCY: ${COPY_CONCURRENCY}
|
||||
PGDATABASE: ${PGDATABASE:-openmaptiles}
|
||||
PGUSER: ${PGUSER:-openmaptiles}
|
||||
PGPASSWORD: ${PGPASSWORD:-openmaptiles}
|
||||
PGPORT: ${PGPORT:-5432}
|
||||
|
||||
generate-vectortiles:
|
||||
image: "openmaptiles/generate-vectortiles:${TOOLS_VERSION}"
|
||||
|
@ -88,6 +103,10 @@ services:
|
|||
# Control tilelive-copy threads
|
||||
COPY_CONCURRENCY: ${COPY_CONCURRENCY}
|
||||
#
|
||||
PGDATABASE: ${PGDATABASE:-openmaptiles}
|
||||
PGUSER: ${PGUSER:-openmaptiles}
|
||||
PGPASSWORD: ${PGPASSWORD:-openmaptiles}
|
||||
PGPORT: ${PGPORT:-5432}
|
||||
|
||||
postserve:
|
||||
image: "openmaptiles/openmaptiles-tools:${TOOLS_VERSION}"
|
||||
|
@ -112,6 +131,8 @@ services:
|
|||
command:
|
||||
- --port
|
||||
- "${TPORT:-8080}"
|
||||
- --mbtiles
|
||||
- "${MBTILES_FILE}"
|
||||
ports:
|
||||
- "${TPORT:-8080}:${TPORT:-8080}"
|
||||
volumes:
|
||||
|
|
|
@ -8,12 +8,6 @@ CREATE INDEX IF NOT EXISTS osm_aerodrome_label_point_type_partial_idx
|
|||
WHERE aerodrome_type = 'international'
|
||||
AND iata <> '';
|
||||
|
||||
UPDATE osm_aerodrome_label_point SET aerodrome_type=(
|
||||
CASE
|
||||
%%FIELD_MAPPING: class %%
|
||||
ELSE 'other' END
|
||||
);
|
||||
|
||||
CREATE SCHEMA IF NOT EXISTS aerodrome_label;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS aerodrome_label.osm_ids
|
||||
|
@ -34,6 +28,17 @@ $$
|
|||
WHERE (full_update OR osm_id IN (SELECT osm_id FROM aerodrome_label.osm_ids))
|
||||
AND COALESCE(tags->'name:latin', tags->'name:nonlatin', tags->'name_int') IS NULL
|
||||
AND tags != update_tags(tags, geometry);
|
||||
|
||||
UPDATE osm_aerodrome_label_point
|
||||
SET aerodrome_type=
|
||||
CASE
|
||||
%%FIELD_MAPPING: class %%
|
||||
ELSE 'other' END
|
||||
WHERE (full_update OR osm_id IN (SELECT osm_id FROM aerodrome_label.osm_ids))
|
||||
AND aerodrome_type !=
|
||||
CASE
|
||||
%%FIELD_MAPPING: class %%
|
||||
ELSE 'other' END;
|
||||
$$ LANGUAGE SQL;
|
||||
|
||||
SELECT update_aerodrome_label_point(true);
|
||||
|
|
|
@ -9,6 +9,7 @@ def_poi_mapping_aerialway: &poi_mapping_aerialway
|
|||
# amenity values , see http://taginfo.openstreetmap.org/keys/amenity#values
|
||||
def_poi_mapping_amenity: &poi_mapping_amenity
|
||||
- arts_centre
|
||||
- atm
|
||||
- bank
|
||||
- bar
|
||||
- bbq
|
||||
|
@ -367,6 +368,12 @@ def_poi_fields: &poi_fields
|
|||
- name: sport
|
||||
key: sport
|
||||
type: string
|
||||
- name: operator
|
||||
key: operator
|
||||
type: string
|
||||
- name: network
|
||||
key: network
|
||||
type: string
|
||||
|
||||
def_poi_mapping: &poi_mapping
|
||||
aerialway: *poi_mapping_aerialway
|
||||
|
|
Plik binarny nie jest wyświetlany.
Przed Szerokość: | Wysokość: | Rozmiar: 1.4 MiB Po Szerokość: | Wysokość: | Rozmiar: 1.4 MiB |
|
@ -94,6 +94,8 @@ layer:
|
|||
subclass: ['swimming_area', 'swimming']
|
||||
castle:
|
||||
subclass: ['castle', 'ruins']
|
||||
atm:
|
||||
subclass: ['atm']
|
||||
subclass:
|
||||
description: |
|
||||
Original value of either the
|
||||
|
|
|
@ -15,6 +15,18 @@ BEGIN
|
|||
WHERE funicular = 'yes'
|
||||
AND subclass = 'station';
|
||||
|
||||
-- ATM without name
|
||||
-- use either operator or network
|
||||
-- (using name for ATM is discouraged, see osm wiki)
|
||||
UPDATE osm_poi_point
|
||||
SET (name, tags) = (
|
||||
COALESCE(tags -> 'operator', tags -> 'network'),
|
||||
tags || hstore('name', COALESCE(tags -> 'operator', tags -> 'network'))
|
||||
)
|
||||
WHERE subclass = 'atm'
|
||||
AND name = ''
|
||||
AND COALESCE(tags -> 'operator', tags -> 'network') IS NOT NULL;
|
||||
|
||||
UPDATE osm_poi_point
|
||||
SET tags = update_tags(tags, geometry)
|
||||
WHERE COALESCE(tags->'name:latin', tags->'name:nonlatin', tags->'name_int') IS NULL
|
||||
|
|
|
@ -75,7 +75,8 @@ BEGIN
|
|||
WHERE rm.member IN
|
||||
(SELECT DISTINCT osm_id FROM transportation_name.network_changes)
|
||||
ON CONFLICT (id, osm_id) DO UPDATE SET concurrency_index = EXCLUDED.concurrency_index,
|
||||
rank = EXCLUDED.rank;
|
||||
rank = EXCLUDED.rank,
|
||||
network_type = EXCLUDED.network_type;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
|
@ -87,7 +88,7 @@ CREATE INDEX IF NOT EXISTS osm_route_member_ref_idx ON osm_route_member ("ref");
|
|||
CREATE INDEX IF NOT EXISTS osm_route_member_network_type_idx ON osm_route_member ("network_type");
|
||||
|
||||
CREATE INDEX IF NOT EXISTS osm_highway_linestring_osm_id_idx ON osm_highway_linestring ("osm_id");
|
||||
CREATE INDEX IF NOT EXISTS osm_highway_linestring_gen_z11_osm_id_idx ON osm_highway_linestring_gen_z11 ("osm_id");
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS osm_highway_linestring_gen_z11_osm_id_idx ON osm_highway_linestring_gen_z11 ("osm_id");
|
||||
|
||||
ALTER TABLE osm_route_member ADD COLUMN IF NOT EXISTS concurrency_index int,
|
||||
ADD COLUMN IF NOT EXISTS rank int;
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
DROP TRIGGER IF EXISTS trigger_flag_transportation ON osm_highway_linestring;
|
||||
DROP TRIGGER IF EXISTS trigger_refresh ON transportation.updates;
|
||||
DROP TRIGGER IF EXISTS trigger_osm_transportation_merge_linestring_gen_z8 ON osm_transportation_merge_linestring_gen_z8;
|
||||
DROP TRIGGER IF EXISTS trigger_store_transportation_highway_linestring_gen_z9 ON osm_transportation_merge_linestring_gen_z9;
|
||||
DROP TRIGGER IF EXISTS trigger_flag_transportation_z9 ON osm_transportation_merge_linestring_gen_z9;
|
||||
DROP TRIGGER IF EXISTS trigger_refresh_z8 ON transportation.updates_z9;
|
||||
DROP TRIGGER IF EXISTS trigger_osm_transportation_merge_linestring_gen_z11 ON osm_transportation_merge_linestring_gen_z11;
|
||||
DROP TRIGGER IF EXISTS trigger_store_transportation_highway_linestring_gen_z11 ON osm_highway_linestring_gen_z11;
|
||||
DROP TRIGGER IF EXISTS trigger_flag_transportation_z11 ON osm_highway_linestring_gen_z11;
|
||||
DROP TRIGGER IF EXISTS trigger_refresh_z11 ON transportation.updates_z11;
|
||||
|
||||
-- Instead of using relations to find out the road names we
|
||||
-- stitch together the touching ways with the same name
|
||||
|
@ -70,10 +76,31 @@ CREATE INDEX IF NOT EXISTS osm_highway_linestring_highway_partial_idx
|
|||
ON osm_highway_linestring (highway)
|
||||
WHERE highway IN ('motorway', 'trunk');
|
||||
|
||||
|
||||
-- etldoc: osm_highway_linestring_gen_z11 -> osm_transportation_merge_linestring_gen_z11
|
||||
DROP MATERIALIZED VIEW IF EXISTS osm_transportation_merge_linestring_gen_z11 CASCADE;
|
||||
CREATE MATERIALIZED VIEW osm_transportation_merge_linestring_gen_z11 AS
|
||||
(
|
||||
CREATE TABLE IF NOT EXISTS osm_transportation_merge_linestring_gen_z11(
|
||||
geometry geometry,
|
||||
id SERIAL PRIMARY KEY,
|
||||
osm_id bigint,
|
||||
highway character varying,
|
||||
network character varying,
|
||||
construction character varying,
|
||||
is_bridge boolean,
|
||||
is_tunnel boolean,
|
||||
is_ford boolean,
|
||||
expressway boolean,
|
||||
z_order integer,
|
||||
bicycle character varying,
|
||||
foot character varying,
|
||||
horse character varying,
|
||||
mtb_scale character varying,
|
||||
sac_scale character varying,
|
||||
access text,
|
||||
toll boolean,
|
||||
layer integer
|
||||
);
|
||||
|
||||
INSERT INTO osm_transportation_merge_linestring_gen_z11(geometry, osm_id, highway, network, construction, is_bridge, is_tunnel, is_ford, expressway, z_order, bicycle, foot, horse, mtb_scale, sac_scale, access, toll, layer)
|
||||
SELECT (ST_Dump(ST_LineMerge(ST_Collect(geometry)))).geom AS geometry,
|
||||
NULL::bigint AS osm_id,
|
||||
highway,
|
||||
|
@ -97,68 +124,110 @@ SELECT (ST_Dump(ST_LineMerge(ST_Collect(geometry)))).geom AS geometry,
|
|||
FROM osm_highway_linestring_gen_z11
|
||||
-- mapping.yaml pre-filter: motorway/trunk/primary/secondary/tertiary, with _link variants, construction, ST_IsValid()
|
||||
GROUP BY highway, network, construction, is_bridge, is_tunnel, is_ford, expressway, bicycle, foot, horse, mtb_scale, sac_scale, access, toll, layer
|
||||
) /* DELAY_MATERIALIZED_VIEW_CREATION */;
|
||||
;
|
||||
CREATE INDEX IF NOT EXISTS osm_transportation_merge_linestring_gen_z11_geometry_idx
|
||||
ON osm_transportation_merge_linestring_gen_z11 USING gist (geometry);
|
||||
|
||||
-- etldoc: osm_transportation_merge_linestring_gen_z11 -> osm_transportation_merge_linestring_gen_z10
|
||||
CREATE MATERIALIZED VIEW osm_transportation_merge_linestring_gen_z10 AS
|
||||
(
|
||||
SELECT ST_Simplify(geometry, ZRes(12)) AS geometry,
|
||||
osm_id,
|
||||
highway,
|
||||
network,
|
||||
construction,
|
||||
is_bridge,
|
||||
is_tunnel,
|
||||
is_ford,
|
||||
expressway,
|
||||
z_order,
|
||||
bicycle,
|
||||
foot,
|
||||
horse,
|
||||
mtb_scale,
|
||||
sac_scale,
|
||||
access,
|
||||
toll,
|
||||
layer
|
||||
FROM osm_transportation_merge_linestring_gen_z11
|
||||
WHERE highway NOT IN ('tertiary', 'tertiary_link', 'busway')
|
||||
AND construction NOT IN ('tertiary', 'tertiary_link', 'busway')
|
||||
) /* DELAY_MATERIALIZED_VIEW_CREATION */;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS osm_transportation_merge_linestring_gen_z10
|
||||
(LIKE osm_transportation_merge_linestring_gen_z11);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS osm_transportation_merge_linestring_gen_z9
|
||||
(LIKE osm_transportation_merge_linestring_gen_z10);
|
||||
|
||||
|
||||
CREATE OR REPLACE FUNCTION insert_transportation_merge_linestring_gen_z10(update_id bigint) RETURNS void AS
|
||||
$$
|
||||
BEGIN
|
||||
DELETE FROM osm_transportation_merge_linestring_gen_z10
|
||||
WHERE update_id IS NULL OR id = update_id;
|
||||
|
||||
-- etldoc: osm_transportation_merge_linestring_gen_z11 -> osm_transportation_merge_linestring_gen_z10
|
||||
INSERT INTO osm_transportation_merge_linestring_gen_z10
|
||||
SELECT ST_Simplify(geometry, ZRes(12)) AS geometry,
|
||||
id,
|
||||
osm_id,
|
||||
highway,
|
||||
network,
|
||||
construction,
|
||||
is_bridge,
|
||||
is_tunnel,
|
||||
is_ford,
|
||||
expressway,
|
||||
z_order,
|
||||
bicycle,
|
||||
foot,
|
||||
horse,
|
||||
mtb_scale,
|
||||
sac_scale,
|
||||
access,
|
||||
toll,
|
||||
layer
|
||||
FROM osm_transportation_merge_linestring_gen_z11
|
||||
WHERE (update_id IS NULL OR id = update_id)
|
||||
AND highway NOT IN ('tertiary', 'tertiary_link', 'busway')
|
||||
AND construction NOT IN ('tertiary', 'tertiary_link', 'busway')
|
||||
;
|
||||
|
||||
DELETE FROM osm_transportation_merge_linestring_gen_z9
|
||||
WHERE update_id IS NULL OR id = update_id;
|
||||
|
||||
-- etldoc: osm_transportation_merge_linestring_gen_z10 -> osm_transportation_merge_linestring_gen_z9
|
||||
INSERT INTO osm_transportation_merge_linestring_gen_z9
|
||||
SELECT ST_Simplify(geometry, ZRes(11)) AS geometry,
|
||||
id,
|
||||
osm_id,
|
||||
highway,
|
||||
network,
|
||||
construction,
|
||||
is_bridge,
|
||||
is_tunnel,
|
||||
is_ford,
|
||||
expressway,
|
||||
z_order,
|
||||
bicycle,
|
||||
foot,
|
||||
horse,
|
||||
mtb_scale,
|
||||
sac_scale,
|
||||
access,
|
||||
toll,
|
||||
layer
|
||||
FROM osm_transportation_merge_linestring_gen_z10
|
||||
WHERE (update_id IS NULL OR id = update_id)
|
||||
;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
SELECT insert_transportation_merge_linestring_gen_z10(NULL);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS osm_transportation_merge_linestring_gen_z10_geometry_idx
|
||||
ON osm_transportation_merge_linestring_gen_z10 USING gist (geometry);
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS osm_transportation_merge_linestring_gen_z10_id_idx
|
||||
ON osm_transportation_merge_linestring_gen_z10(id);
|
||||
|
||||
-- etldoc: osm_transportation_merge_linestring_gen_z10 -> osm_transportation_merge_linestring_gen_z9
|
||||
CREATE MATERIALIZED VIEW osm_transportation_merge_linestring_gen_z9 AS
|
||||
(
|
||||
SELECT ST_Simplify(geometry, ZRes(11)) AS geometry,
|
||||
osm_id,
|
||||
highway,
|
||||
network,
|
||||
construction,
|
||||
is_bridge,
|
||||
is_tunnel,
|
||||
is_ford,
|
||||
expressway,
|
||||
z_order,
|
||||
bicycle,
|
||||
foot,
|
||||
horse,
|
||||
mtb_scale,
|
||||
sac_scale,
|
||||
access,
|
||||
toll,
|
||||
layer
|
||||
FROM osm_transportation_merge_linestring_gen_z10
|
||||
-- Current view: motorway/primary/secondary, with _link variants and construction
|
||||
) /* DELAY_MATERIALIZED_VIEW_CREATION */;
|
||||
CREATE INDEX IF NOT EXISTS osm_transportation_merge_linestring_gen_z9_geometry_idx
|
||||
ON osm_transportation_merge_linestring_gen_z9 USING gist (geometry);
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS osm_transportation_merge_linestring_gen_z9_id_idx
|
||||
ON osm_transportation_merge_linestring_gen_z9(id);
|
||||
|
||||
-- etldoc: osm_transportation_merge_linestring_gen_z9 -> osm_transportation_merge_linestring_gen_z8
|
||||
CREATE MATERIALIZED VIEW osm_transportation_merge_linestring_gen_z8 AS
|
||||
(
|
||||
|
||||
-- etldoc: osm_transportation_merge_linestring_gen_z9 -> osm_transportation_merge_linestring_gen_z8
|
||||
CREATE TABLE IF NOT EXISTS osm_transportation_merge_linestring_gen_z8(
|
||||
geometry geometry,
|
||||
id SERIAL PRIMARY KEY,
|
||||
osm_id bigint,
|
||||
highway character varying,
|
||||
network character varying,
|
||||
construction character varying,
|
||||
is_bridge boolean,
|
||||
is_tunnel boolean,
|
||||
is_ford boolean,
|
||||
expressway boolean,
|
||||
z_order integer
|
||||
);
|
||||
|
||||
INSERT INTO osm_transportation_merge_linestring_gen_z8(geometry, osm_id, highway, network, construction, is_bridge, is_tunnel, is_ford, expressway, z_order)
|
||||
SELECT ST_Simplify(ST_LineMerge(ST_Collect(geometry)), ZRes(10)) AS geometry,
|
||||
NULL::bigint AS osm_id,
|
||||
highway,
|
||||
|
@ -175,137 +244,628 @@ WHERE (highway IN ('motorway', 'trunk', 'primary') OR
|
|||
AND ST_IsValid(geometry)
|
||||
AND access IS NULL
|
||||
GROUP BY highway, network, construction, is_bridge, is_tunnel, is_ford, expressway
|
||||
) /* DELAY_MATERIALIZED_VIEW_CREATION */;
|
||||
;
|
||||
CREATE INDEX IF NOT EXISTS osm_transportation_merge_linestring_gen_z8_geometry_idx
|
||||
ON osm_transportation_merge_linestring_gen_z8 USING gist (geometry);
|
||||
|
||||
-- etldoc: osm_transportation_merge_linestring_gen_z8 -> osm_transportation_merge_linestring_gen_z7
|
||||
CREATE MATERIALIZED VIEW osm_transportation_merge_linestring_gen_z7 AS
|
||||
(
|
||||
SELECT ST_Simplify(geometry, ZRes(9)) AS geometry,
|
||||
osm_id,
|
||||
highway,
|
||||
network,
|
||||
construction,
|
||||
is_bridge,
|
||||
is_tunnel,
|
||||
is_ford,
|
||||
expressway,
|
||||
z_order
|
||||
FROM osm_transportation_merge_linestring_gen_z8
|
||||
-- Current view: motorway/trunk/primary
|
||||
WHERE ST_Length(geometry) > 50
|
||||
) /* DELAY_MATERIALIZED_VIEW_CREATION */;
|
||||
CREATE TABLE IF NOT EXISTS osm_transportation_merge_linestring_gen_z7
|
||||
(LIKE osm_transportation_merge_linestring_gen_z8);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS osm_transportation_merge_linestring_gen_z6
|
||||
(LIKE osm_transportation_merge_linestring_gen_z7);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS osm_transportation_merge_linestring_gen_z5
|
||||
(LIKE osm_transportation_merge_linestring_gen_z6);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS osm_transportation_merge_linestring_gen_z4
|
||||
(LIKE osm_transportation_merge_linestring_gen_z5);
|
||||
|
||||
|
||||
CREATE OR REPLACE FUNCTION insert_transportation_merge_linestring_gen_z7(update_id bigint) RETURNS void AS
|
||||
$$
|
||||
BEGIN
|
||||
DELETE FROM osm_transportation_merge_linestring_gen_z7
|
||||
WHERE update_id IS NULL OR id = update_id;
|
||||
|
||||
-- etldoc: osm_transportation_merge_linestring_gen_z8 -> osm_transportation_merge_linestring_gen_z7
|
||||
INSERT INTO osm_transportation_merge_linestring_gen_z7
|
||||
SELECT ST_Simplify(geometry, ZRes(9)) AS geometry,
|
||||
id,
|
||||
osm_id,
|
||||
highway,
|
||||
network,
|
||||
construction,
|
||||
is_bridge,
|
||||
is_tunnel,
|
||||
is_ford,
|
||||
expressway,
|
||||
z_order
|
||||
FROM osm_transportation_merge_linestring_gen_z8
|
||||
-- Current view: motorway/trunk/primary
|
||||
WHERE
|
||||
(update_id IS NULL OR id = update_id) AND
|
||||
ST_Length(geometry) > 50;
|
||||
|
||||
DELETE FROM osm_transportation_merge_linestring_gen_z6
|
||||
WHERE update_id IS NULL OR id = update_id;
|
||||
|
||||
-- etldoc: osm_transportation_merge_linestring_gen_z7 -> osm_transportation_merge_linestring_gen_z6
|
||||
INSERT INTO osm_transportation_merge_linestring_gen_z6
|
||||
SELECT ST_Simplify(geometry, ZRes(8)) AS geometry,
|
||||
id,
|
||||
osm_id,
|
||||
highway,
|
||||
network,
|
||||
construction,
|
||||
is_bridge,
|
||||
is_tunnel,
|
||||
is_ford,
|
||||
expressway,
|
||||
z_order
|
||||
FROM osm_transportation_merge_linestring_gen_z7
|
||||
WHERE
|
||||
(update_id IS NULL OR id = update_id) AND
|
||||
(highway IN ('motorway', 'trunk') OR construction IN ('motorway', 'trunk')) AND
|
||||
ST_Length(geometry) > 100;
|
||||
|
||||
DELETE FROM osm_transportation_merge_linestring_gen_z5
|
||||
WHERE update_id IS NULL OR id = update_id;
|
||||
|
||||
-- etldoc: osm_transportation_merge_linestring_gen_z6 -> osm_transportation_merge_linestring_gen_z5
|
||||
INSERT INTO osm_transportation_merge_linestring_gen_z5
|
||||
SELECT ST_Simplify(geometry, ZRes(7)) AS geometry,
|
||||
id,
|
||||
osm_id,
|
||||
highway,
|
||||
network,
|
||||
construction,
|
||||
is_bridge,
|
||||
is_tunnel,
|
||||
is_ford,
|
||||
expressway,
|
||||
z_order
|
||||
FROM osm_transportation_merge_linestring_gen_z6
|
||||
WHERE
|
||||
(update_id IS NULL OR id = update_id) AND
|
||||
-- Current view: motorway/trunk
|
||||
ST_Length(geometry) > 500;
|
||||
|
||||
DELETE FROM osm_transportation_merge_linestring_gen_z4
|
||||
WHERE update_id IS NULL OR id = update_id;
|
||||
|
||||
-- etldoc: osm_transportation_merge_linestring_gen_z5 -> osm_transportation_merge_linestring_gen_z4
|
||||
INSERT INTO osm_transportation_merge_linestring_gen_z4
|
||||
SELECT ST_Simplify(geometry, ZRes(6)) AS geometry,
|
||||
id,
|
||||
osm_id,
|
||||
highway,
|
||||
network,
|
||||
construction,
|
||||
is_bridge,
|
||||
is_tunnel,
|
||||
is_ford,
|
||||
expressway,
|
||||
z_order
|
||||
FROM osm_transportation_merge_linestring_gen_z5
|
||||
WHERE
|
||||
(update_id IS NULL OR id = update_id) AND
|
||||
(highway = 'motorway' OR construction = 'motorway') AND
|
||||
ST_Length(geometry) > 1000;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
SELECT insert_transportation_merge_linestring_gen_z7(NULL);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS osm_transportation_merge_linestring_gen_z7_geometry_idx
|
||||
ON osm_transportation_merge_linestring_gen_z7 USING gist (geometry);
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS osm_transportation_merge_linestring_gen_z7_id_idx
|
||||
ON osm_transportation_merge_linestring_gen_z7(id);
|
||||
|
||||
-- etldoc: osm_transportation_merge_linestring_gen_z7 -> osm_transportation_merge_linestring_gen_z6
|
||||
CREATE MATERIALIZED VIEW osm_transportation_merge_linestring_gen_z6 AS
|
||||
(
|
||||
SELECT ST_Simplify(geometry, ZRes(8)) AS geometry,
|
||||
osm_id,
|
||||
highway,
|
||||
network,
|
||||
construction,
|
||||
is_bridge,
|
||||
is_tunnel,
|
||||
is_ford,
|
||||
z_order
|
||||
FROM osm_transportation_merge_linestring_gen_z7
|
||||
WHERE (highway IN ('motorway', 'trunk') OR construction IN ('motorway', 'trunk'))
|
||||
AND ST_Length(geometry) > 100
|
||||
) /* DELAY_MATERIALIZED_VIEW_CREATION */;
|
||||
CREATE INDEX IF NOT EXISTS osm_transportation_merge_linestring_gen_z6_geometry_idx
|
||||
ON osm_transportation_merge_linestring_gen_z6 USING gist (geometry);
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS osm_transportation_merge_linestring_gen_z6_id_idx
|
||||
ON osm_transportation_merge_linestring_gen_z6(id);
|
||||
|
||||
-- etldoc: osm_transportation_merge_linestring_gen_z6 -> osm_transportation_merge_linestring_gen_z5
|
||||
CREATE MATERIALIZED VIEW osm_transportation_merge_linestring_gen_z5 AS
|
||||
(
|
||||
SELECT ST_Simplify(geometry, ZRes(7)) AS geometry,
|
||||
osm_id,
|
||||
highway,
|
||||
network,
|
||||
construction,
|
||||
is_bridge,
|
||||
is_tunnel,
|
||||
is_ford,
|
||||
z_order
|
||||
FROM osm_transportation_merge_linestring_gen_z6
|
||||
WHERE ST_Length(geometry) > 500
|
||||
-- Current view: motorway/trunk
|
||||
) /* DELAY_MATERIALIZED_VIEW_CREATION */;
|
||||
CREATE INDEX IF NOT EXISTS osm_transportation_merge_linestring_gen_z5_geometry_idx
|
||||
ON osm_transportation_merge_linestring_gen_z5 USING gist (geometry);
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS osm_transportation_merge_linestring_gen_z5_id_idx
|
||||
ON osm_transportation_merge_linestring_gen_z5(id);
|
||||
|
||||
-- etldoc: osm_transportation_merge_linestring_gen_z5 -> osm_transportation_merge_linestring_gen_z4
|
||||
CREATE MATERIALIZED VIEW osm_transportation_merge_linestring_gen_z4 AS
|
||||
(
|
||||
SELECT ST_Simplify(geometry, ZRes(6)) AS geometry,
|
||||
osm_id,
|
||||
highway,
|
||||
network,
|
||||
construction,
|
||||
is_bridge,
|
||||
is_tunnel,
|
||||
is_ford,
|
||||
z_order
|
||||
FROM osm_transportation_merge_linestring_gen_z5
|
||||
WHERE (highway = 'motorway' OR construction = 'motorway')
|
||||
AND ST_Length(geometry) > 1000
|
||||
) /* DELAY_MATERIALIZED_VIEW_CREATION */;
|
||||
CREATE INDEX IF NOT EXISTS osm_transportation_merge_linestring_gen_z4_geometry_idx
|
||||
ON osm_transportation_merge_linestring_gen_z4 USING gist (geometry);
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS osm_transportation_merge_linestring_gen_z4_id_idx
|
||||
ON osm_transportation_merge_linestring_gen_z4(id);
|
||||
|
||||
|
||||
-- Handle updates
|
||||
-- Handle updates on
|
||||
-- osm_highway_linestring_gen_z11 -> osm_transportation_merge_linestring_gen_z11
|
||||
|
||||
CREATE SCHEMA IF NOT EXISTS transportation;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS transportation.updates
|
||||
CREATE TABLE IF NOT EXISTS transportation.changes_z11
|
||||
(
|
||||
id serial PRIMARY KEY,
|
||||
is_old boolean,
|
||||
geometry geometry,
|
||||
osm_id bigint,
|
||||
highway character varying,
|
||||
network character varying,
|
||||
construction character varying,
|
||||
is_bridge boolean,
|
||||
is_tunnel boolean,
|
||||
is_ford boolean,
|
||||
expressway boolean,
|
||||
z_order integer,
|
||||
bicycle character varying,
|
||||
foot character varying,
|
||||
horse character varying,
|
||||
mtb_scale character varying,
|
||||
sac_scale character varying,
|
||||
access character varying,
|
||||
toll boolean,
|
||||
layer integer
|
||||
);
|
||||
|
||||
CREATE OR REPLACE FUNCTION transportation.store_z11() RETURNS trigger AS
|
||||
$$
|
||||
BEGIN
|
||||
IF (tg_op = 'DELETE' OR tg_op = 'UPDATE') THEN
|
||||
INSERT INTO transportation.changes_z11(is_old, geometry, osm_id, highway, network, construction, is_bridge, is_tunnel, is_ford, expressway, z_order, bicycle, foot, horse, mtb_scale, sac_scale, access, toll, layer)
|
||||
VALUES (true, old.geometry, old.osm_id, old.highway, old.network, old.construction, old.is_bridge, old.is_tunnel, old.is_ford, old.expressway, old.z_order, old.bicycle, old.foot, old.horse, old.mtb_scale, old.sac_scale,
|
||||
CASE
|
||||
WHEN old.access IN ('private', 'no') THEN 'no'
|
||||
ELSE NULL::text END,
|
||||
old.toll, old.layer);
|
||||
END IF;
|
||||
IF (tg_op = 'UPDATE' OR tg_op = 'INSERT') THEN
|
||||
INSERT INTO transportation.changes_z11(is_old, geometry, osm_id, highway, network, construction, is_bridge, is_tunnel, is_ford, expressway, z_order, bicycle, foot, horse, mtb_scale, sac_scale, access, toll, layer)
|
||||
VALUES (false, new.geometry, new.osm_id, new.highway, new.network, new.construction, new.is_bridge, new.is_tunnel, new.is_ford, new.expressway, new.z_order, new.bicycle, new.foot, new.horse, new.mtb_scale, new.sac_scale,
|
||||
CASE
|
||||
WHEN new.access IN ('private', 'no') THEN 'no'
|
||||
ELSE NULL::text END,
|
||||
new.toll, new.layer);
|
||||
END IF;
|
||||
RETURN NULL;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS transportation.updates_z11
|
||||
(
|
||||
id serial PRIMARY KEY,
|
||||
t text,
|
||||
UNIQUE (t)
|
||||
);
|
||||
CREATE OR REPLACE FUNCTION transportation.flag() RETURNS trigger AS
|
||||
CREATE OR REPLACE FUNCTION transportation.flag_z11() RETURNS trigger AS
|
||||
$$
|
||||
BEGIN
|
||||
INSERT INTO transportation.updates(t) VALUES ('y') ON CONFLICT(t) DO NOTHING;
|
||||
INSERT INTO transportation.updates_z11(t) VALUES ('y') ON CONFLICT(t) DO NOTHING;
|
||||
RETURN NULL;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE OR REPLACE FUNCTION transportation.refresh() RETURNS trigger AS
|
||||
CREATE OR REPLACE FUNCTION transportation.refresh_z11() RETURNS trigger AS
|
||||
$$
|
||||
DECLARE
|
||||
t TIMESTAMP WITH TIME ZONE := clock_timestamp();
|
||||
BEGIN
|
||||
RAISE LOG 'Refresh transportation';
|
||||
REFRESH MATERIALIZED VIEW osm_transportation_merge_linestring_gen_z11;
|
||||
REFRESH MATERIALIZED VIEW osm_transportation_merge_linestring_gen_z10;
|
||||
REFRESH MATERIALIZED VIEW osm_transportation_merge_linestring_gen_z9;
|
||||
REFRESH MATERIALIZED VIEW osm_transportation_merge_linestring_gen_z8;
|
||||
REFRESH MATERIALIZED VIEW osm_transportation_merge_linestring_gen_z7;
|
||||
REFRESH MATERIALIZED VIEW osm_transportation_merge_linestring_gen_z6;
|
||||
REFRESH MATERIALIZED VIEW osm_transportation_merge_linestring_gen_z5;
|
||||
REFRESH MATERIALIZED VIEW osm_transportation_merge_linestring_gen_z4;
|
||||
-- noinspection SqlWithoutWhere
|
||||
DELETE FROM transportation.updates;
|
||||
RAISE LOG 'Refresh transportation z11';
|
||||
|
||||
RAISE LOG 'Refresh transportation done in %', age(clock_timestamp(), t);
|
||||
-- Compact the change history to keep only the first and last version
|
||||
CREATE TEMP TABLE changes_compact AS
|
||||
SELECT
|
||||
*
|
||||
FROM ((
|
||||
SELECT DISTINCT ON (osm_id) *
|
||||
FROM transportation.changes_z11
|
||||
WHERE is_old
|
||||
ORDER BY osm_id,
|
||||
id ASC
|
||||
) UNION ALL (
|
||||
SELECT DISTINCT ON (osm_id) *
|
||||
FROM transportation.changes_z11
|
||||
WHERE NOT is_old
|
||||
ORDER BY osm_id,
|
||||
id DESC
|
||||
)) AS t;
|
||||
|
||||
-- Collect all original existing ways from impacted mmerge
|
||||
CREATE TEMP TABLE osm_highway_linestring_original AS
|
||||
SELECT DISTINCT ON (h.osm_id)
|
||||
NULL::integer AS id,
|
||||
NULL::boolean AS is_old,
|
||||
h.geometry,
|
||||
h.osm_id,
|
||||
h.highway,
|
||||
h.network,
|
||||
h.construction,
|
||||
h.is_bridge,
|
||||
h.is_tunnel,
|
||||
h.is_ford,
|
||||
h.expressway,
|
||||
h.z_order,
|
||||
h.bicycle,
|
||||
h.foot,
|
||||
h.horse,
|
||||
h.mtb_scale,
|
||||
h.sac_scale,
|
||||
h.access,
|
||||
h.toll,
|
||||
h.layer
|
||||
FROM
|
||||
changes_compact AS c
|
||||
JOIN osm_transportation_merge_linestring_gen_z11 AS m ON
|
||||
m.geometry && c.geometry
|
||||
AND m.highway IS NOT DISTINCT FROM c.highway
|
||||
AND m.network IS NOT DISTINCT FROM c.network
|
||||
AND m.construction IS NOT DISTINCT FROM c.construction
|
||||
AND m.is_bridge IS NOT DISTINCT FROM c.is_bridge
|
||||
AND m.is_tunnel IS NOT DISTINCT FROM c.is_tunnel
|
||||
AND m.is_ford IS NOT DISTINCT FROM c.is_ford
|
||||
AND m.expressway IS NOT DISTINCT FROM c.expressway
|
||||
AND m.bicycle IS NOT DISTINCT FROM c.bicycle
|
||||
AND m.foot IS NOT DISTINCT FROM c.foot
|
||||
AND m.horse IS NOT DISTINCT FROM c.horse
|
||||
AND m.mtb_scale IS NOT DISTINCT FROM c.mtb_scale
|
||||
AND m.sac_scale IS NOT DISTINCT FROM c.sac_scale
|
||||
AND m.access IS NOT DISTINCT FROM c.access
|
||||
AND m.toll IS NOT DISTINCT FROM c.toll
|
||||
AND m.layer IS NOT DISTINCT FROM c.layer
|
||||
JOIN osm_highway_linestring_gen_z11 AS h ON
|
||||
h.geometry && c.geometry
|
||||
AND h.osm_id NOT IN (SELECT osm_id FROM changes_compact)
|
||||
AND ST_Contains(m.geometry, h.geometry)
|
||||
AND h.highway IS NOT DISTINCT FROM m.highway
|
||||
AND h.network IS NOT DISTINCT FROM m.network
|
||||
AND h.construction IS NOT DISTINCT FROM m.construction
|
||||
AND h.is_bridge IS NOT DISTINCT FROM m.is_bridge
|
||||
AND h.is_tunnel IS NOT DISTINCT FROM m.is_tunnel
|
||||
AND h.is_ford IS NOT DISTINCT FROM m.is_ford
|
||||
AND h.expressway IS NOT DISTINCT FROM m.expressway
|
||||
AND h.bicycle IS NOT DISTINCT FROM m.bicycle
|
||||
AND h.foot IS NOT DISTINCT FROM m.foot
|
||||
AND h.horse IS NOT DISTINCT FROM m.horse
|
||||
AND h.mtb_scale IS NOT DISTINCT FROM m.mtb_scale
|
||||
AND h.sac_scale IS NOT DISTINCT FROM m.sac_scale
|
||||
AND CASE
|
||||
WHEN h.access IN ('private', 'no') THEN 'no'
|
||||
ELSE NULL::text END IS NOT DISTINCT FROM m.access
|
||||
AND h.toll IS NOT DISTINCT FROM m.toll
|
||||
AND h.layer IS NOT DISTINCT FROM m.layer
|
||||
ORDER BY
|
||||
h.osm_id
|
||||
;
|
||||
|
||||
DELETE
|
||||
FROM osm_transportation_merge_linestring_gen_z11 AS m
|
||||
USING changes_compact AS c
|
||||
WHERE
|
||||
m.geometry && c.geometry
|
||||
AND m.highway IS NOT DISTINCT FROM c.highway
|
||||
AND m.network IS NOT DISTINCT FROM c.network
|
||||
AND m.construction IS NOT DISTINCT FROM c.construction
|
||||
AND m.is_bridge IS NOT DISTINCT FROM c.is_bridge
|
||||
AND m.is_tunnel IS NOT DISTINCT FROM c.is_tunnel
|
||||
AND m.is_ford IS NOT DISTINCT FROM c.is_ford
|
||||
AND m.expressway IS NOT DISTINCT FROM c.expressway
|
||||
AND m.bicycle IS NOT DISTINCT FROM c.bicycle
|
||||
AND m.foot IS NOT DISTINCT FROM c.foot
|
||||
AND m.horse IS NOT DISTINCT FROM c.horse
|
||||
AND m.mtb_scale IS NOT DISTINCT FROM c.mtb_scale
|
||||
AND m.sac_scale IS NOT DISTINCT FROM c.sac_scale
|
||||
AND m.access IS NOT DISTINCT FROM c.access
|
||||
AND m.toll IS NOT DISTINCT FROM c.toll
|
||||
AND m.layer IS NOT DISTINCT FROM c.layer
|
||||
;
|
||||
|
||||
INSERT INTO osm_transportation_merge_linestring_gen_z11(geometry, osm_id, highway, network, construction, is_bridge, is_tunnel, is_ford, expressway, z_order, bicycle, foot, horse, mtb_scale, sac_scale, access, toll, layer)
|
||||
SELECT (ST_Dump(ST_LineMerge(ST_Collect(geometry)))).geom AS geometry,
|
||||
NULL::bigint AS osm_id,
|
||||
highway,
|
||||
network,
|
||||
construction,
|
||||
is_bridge,
|
||||
is_tunnel,
|
||||
is_ford,
|
||||
expressway,
|
||||
min(z_order) as z_order,
|
||||
bicycle,
|
||||
foot,
|
||||
horse,
|
||||
mtb_scale,
|
||||
sac_scale,
|
||||
CASE
|
||||
WHEN access IN ('private', 'no') THEN 'no'
|
||||
ELSE NULL::text END AS access,
|
||||
toll,
|
||||
layer
|
||||
FROM ((
|
||||
SELECT * FROM osm_highway_linestring_original
|
||||
) UNION ALL (
|
||||
-- New or updated ways
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
changes_compact
|
||||
WHERE
|
||||
NOT is_old
|
||||
)) AS t
|
||||
GROUP BY highway, network, construction, is_bridge, is_tunnel, is_ford, expressway, bicycle, foot, horse, mtb_scale, sac_scale, access, toll, layer
|
||||
;
|
||||
|
||||
DROP TABLE osm_highway_linestring_original;
|
||||
DROP TABLE changes_compact;
|
||||
-- noinspection SqlWithoutWhere
|
||||
DELETE FROM transportation.changes_z11;
|
||||
-- noinspection SqlWithoutWhere
|
||||
DELETE FROM transportation.updates_z11;
|
||||
|
||||
RAISE LOG 'Refresh transportation z11 done in %', age(clock_timestamp(), t);
|
||||
RETURN NULL;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE TRIGGER trigger_flag_transportation
|
||||
AFTER INSERT OR UPDATE OR DELETE
|
||||
ON osm_highway_linestring
|
||||
FOR EACH STATEMENT
|
||||
EXECUTE PROCEDURE transportation.flag();
|
||||
|
||||
CREATE CONSTRAINT TRIGGER trigger_refresh
|
||||
CREATE TRIGGER trigger_store_transportation_highway_linestring_gen_z11
|
||||
AFTER INSERT OR UPDATE OR DELETE
|
||||
ON osm_highway_linestring_gen_z11
|
||||
FOR EACH ROW
|
||||
EXECUTE PROCEDURE transportation.store_z11();
|
||||
|
||||
CREATE TRIGGER trigger_flag_transportation_z11
|
||||
AFTER INSERT OR UPDATE OR DELETE
|
||||
ON osm_highway_linestring_gen_z11
|
||||
FOR EACH STATEMENT
|
||||
EXECUTE PROCEDURE transportation.flag_z11();
|
||||
|
||||
CREATE CONSTRAINT TRIGGER trigger_refresh_z11
|
||||
AFTER INSERT
|
||||
ON transportation.updates
|
||||
ON transportation.updates_z11
|
||||
INITIALLY DEFERRED
|
||||
FOR EACH ROW
|
||||
EXECUTE PROCEDURE transportation.refresh();
|
||||
EXECUTE PROCEDURE transportation.refresh_z11();
|
||||
|
||||
|
||||
-- Handle updates on
|
||||
-- osm_transportation_merge_linestring_gen_z11 -> osm_transportation_merge_linestring_gen_z10
|
||||
-- osm_transportation_merge_linestring_gen_z11 -> osm_transportation_merge_linestring_gen_z9
|
||||
|
||||
|
||||
CREATE OR REPLACE FUNCTION transportation.merge_linestring_gen_refresh_z10() RETURNS trigger AS
|
||||
$$
|
||||
BEGIN
|
||||
IF (tg_op = 'DELETE') THEN
|
||||
DELETE FROM osm_transportation_merge_linestring_gen_z10 WHERE id = old.id;
|
||||
DELETE FROM osm_transportation_merge_linestring_gen_z9 WHERE id = old.id;
|
||||
END IF;
|
||||
|
||||
IF (tg_op = 'UPDATE' OR tg_op = 'INSERT') THEN
|
||||
PERFORM insert_transportation_merge_linestring_gen_z10(new.id);
|
||||
END IF;
|
||||
|
||||
RETURN NULL;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
|
||||
CREATE TRIGGER trigger_osm_transportation_merge_linestring_gen_z11
|
||||
AFTER INSERT OR UPDATE OR DELETE
|
||||
ON osm_transportation_merge_linestring_gen_z11
|
||||
FOR EACH ROW
|
||||
EXECUTE PROCEDURE transportation.merge_linestring_gen_refresh_z10();
|
||||
|
||||
|
||||
-- Handle updates on
|
||||
-- osm_transportation_merge_linestring_gen_z9 -> osm_transportation_merge_linestring_gen_z8
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS transportation.changes_z9
|
||||
(
|
||||
is_old boolean,
|
||||
geometry geometry,
|
||||
id bigint,
|
||||
highway character varying,
|
||||
network character varying,
|
||||
construction character varying,
|
||||
is_bridge boolean,
|
||||
is_tunnel boolean,
|
||||
is_ford boolean,
|
||||
expressway boolean,
|
||||
z_order integer
|
||||
);
|
||||
|
||||
CREATE OR REPLACE FUNCTION transportation.store_z9() RETURNS trigger AS
|
||||
$$
|
||||
BEGIN
|
||||
IF (tg_op = 'DELETE' OR tg_op = 'UPDATE') THEN
|
||||
INSERT INTO transportation.changes_z9(is_old, geometry, id, highway, network, construction, is_bridge, is_tunnel, is_ford, expressway, z_order)
|
||||
VALUES (true, old.geometry, old.id, old.highway, old.network, old.construction, old.is_bridge, old.is_tunnel, old.is_ford, old.expressway, old.z_order);
|
||||
END IF;
|
||||
IF (tg_op = 'UPDATE' OR tg_op = 'INSERT') THEN
|
||||
INSERT INTO transportation.changes_z9(is_old, geometry, id, highway, network, construction, is_bridge, is_tunnel, is_ford, expressway, z_order)
|
||||
VALUES (false, new.geometry, new.id, new.highway, new.network, new.construction, new.is_bridge, new.is_tunnel, new.is_ford, new.expressway, new.z_order);
|
||||
END IF;
|
||||
RETURN NULL;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS transportation.updates_z9
|
||||
(
|
||||
id serial PRIMARY KEY,
|
||||
t text,
|
||||
UNIQUE (t)
|
||||
);
|
||||
CREATE OR REPLACE FUNCTION transportation.flag_z9() RETURNS trigger AS
|
||||
$$
|
||||
BEGIN
|
||||
INSERT INTO transportation.updates_z9(t) VALUES ('y') ON CONFLICT(t) DO NOTHING;
|
||||
RETURN NULL;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE OR REPLACE FUNCTION transportation.refresh_z8() RETURNS trigger AS
|
||||
$$
|
||||
DECLARE
|
||||
t TIMESTAMP WITH TIME ZONE := clock_timestamp();
|
||||
BEGIN
|
||||
RAISE LOG 'Refresh transportation z9';
|
||||
|
||||
-- Compact the change history to keep only the first and last version
|
||||
CREATE TEMP TABLE changes_compact AS
|
||||
SELECT
|
||||
*
|
||||
FROM ((
|
||||
SELECT DISTINCT ON (id) *
|
||||
FROM transportation.changes_z9
|
||||
WHERE is_old
|
||||
ORDER BY id,
|
||||
id ASC
|
||||
) UNION ALL (
|
||||
SELECT DISTINCT ON (id) *
|
||||
FROM transportation.changes_z9
|
||||
WHERE NOT is_old
|
||||
ORDER BY id,
|
||||
id DESC
|
||||
)) AS t;
|
||||
|
||||
-- Collect all original existing ways from impacted mmerge
|
||||
CREATE TEMP TABLE osm_highway_linestring_original AS
|
||||
SELECT DISTINCT ON (h.id)
|
||||
NULL::boolean AS is_old,
|
||||
h.geometry,
|
||||
h.id,
|
||||
h.highway,
|
||||
h.network,
|
||||
h.construction,
|
||||
h.is_bridge,
|
||||
h.is_tunnel,
|
||||
h.is_ford,
|
||||
h.expressway,
|
||||
h.z_order
|
||||
FROM
|
||||
changes_compact AS c
|
||||
JOIN osm_transportation_merge_linestring_gen_z8 AS m ON
|
||||
m.geometry && c.geometry
|
||||
AND m.highway IS NOT DISTINCT FROM c.highway
|
||||
AND m.network IS NOT DISTINCT FROM c.network
|
||||
AND m.construction IS NOT DISTINCT FROM c.construction
|
||||
AND m.is_bridge IS NOT DISTINCT FROM c.is_bridge
|
||||
AND m.is_tunnel IS NOT DISTINCT FROM c.is_tunnel
|
||||
AND m.is_ford IS NOT DISTINCT FROM c.is_ford
|
||||
AND m.expressway IS NOT DISTINCT FROM c.expressway
|
||||
JOIN osm_transportation_merge_linestring_gen_z9 AS h ON
|
||||
h.geometry && c.geometry
|
||||
AND h.id NOT IN (SELECT id FROM changes_compact)
|
||||
AND ST_Contains(m.geometry, h.geometry)
|
||||
AND h.highway IS NOT DISTINCT FROM m.highway
|
||||
AND h.network IS NOT DISTINCT FROM m.network
|
||||
AND h.construction IS NOT DISTINCT FROM m.construction
|
||||
AND h.is_bridge IS NOT DISTINCT FROM m.is_bridge
|
||||
AND h.is_tunnel IS NOT DISTINCT FROM m.is_tunnel
|
||||
AND h.is_ford IS NOT DISTINCT FROM m.is_ford
|
||||
AND h.expressway IS NOT DISTINCT FROM m.expressway
|
||||
ORDER BY
|
||||
h.id
|
||||
;
|
||||
|
||||
DELETE
|
||||
FROM osm_transportation_merge_linestring_gen_z8 AS m
|
||||
USING changes_compact AS c
|
||||
WHERE
|
||||
m.geometry && c.geometry
|
||||
AND m.highway IS NOT DISTINCT FROM c.highway
|
||||
AND m.network IS NOT DISTINCT FROM c.network
|
||||
AND m.construction IS NOT DISTINCT FROM c.construction
|
||||
AND m.is_bridge IS NOT DISTINCT FROM c.is_bridge
|
||||
AND m.is_tunnel IS NOT DISTINCT FROM c.is_tunnel
|
||||
AND m.is_ford IS NOT DISTINCT FROM c.is_ford
|
||||
AND m.expressway IS NOT DISTINCT FROM c.expressway
|
||||
;
|
||||
|
||||
INSERT INTO osm_transportation_merge_linestring_gen_z8(geometry, osm_id, highway, network, construction, is_bridge, is_tunnel, is_ford, expressway, z_order)
|
||||
SELECT (ST_Dump(ST_LineMerge(ST_Collect(geometry)))).geom AS geometry,
|
||||
NULL::bigint AS osm_id,
|
||||
highway,
|
||||
network,
|
||||
construction,
|
||||
is_bridge,
|
||||
is_tunnel,
|
||||
is_ford,
|
||||
expressway,
|
||||
min(z_order) as z_order
|
||||
FROM ((
|
||||
SELECT * FROM osm_highway_linestring_original
|
||||
) UNION ALL (
|
||||
-- New or updated ways
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
changes_compact
|
||||
WHERE
|
||||
NOT is_old
|
||||
)) AS t
|
||||
GROUP BY highway, network, construction, is_bridge, is_tunnel, is_ford, expressway
|
||||
;
|
||||
|
||||
DROP TABLE osm_highway_linestring_original;
|
||||
DROP TABLE changes_compact;
|
||||
-- noinspection SqlWithoutWhere
|
||||
DELETE FROM transportation.changes_z9;
|
||||
-- noinspection SqlWithoutWhere
|
||||
DELETE FROM transportation.updates_z9;
|
||||
|
||||
RAISE LOG 'Refresh transportation z9 done in %', age(clock_timestamp(), t);
|
||||
RETURN NULL;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
|
||||
CREATE TRIGGER trigger_store_transportation_highway_linestring_gen_z9
|
||||
AFTER INSERT OR UPDATE OR DELETE
|
||||
ON osm_transportation_merge_linestring_gen_z9
|
||||
FOR EACH ROW
|
||||
EXECUTE PROCEDURE transportation.store_z9();
|
||||
|
||||
CREATE TRIGGER trigger_flag_transportation_z9
|
||||
AFTER INSERT OR UPDATE OR DELETE
|
||||
ON osm_transportation_merge_linestring_gen_z9
|
||||
FOR EACH STATEMENT
|
||||
EXECUTE PROCEDURE transportation.flag_z9();
|
||||
|
||||
CREATE CONSTRAINT TRIGGER trigger_refresh_z8
|
||||
AFTER INSERT
|
||||
ON transportation.updates_z9
|
||||
INITIALLY DEFERRED
|
||||
FOR EACH ROW
|
||||
EXECUTE PROCEDURE transportation.refresh_z8();
|
||||
|
||||
|
||||
-- Handle updates on
|
||||
-- osm_transportation_merge_linestring_gen_z8 -> osm_transportation_merge_linestring_gen_z7
|
||||
-- osm_transportation_merge_linestring_gen_z8 -> osm_transportation_merge_linestring_gen_z6
|
||||
-- osm_transportation_merge_linestring_gen_z8 -> osm_transportation_merge_linestring_gen_z5
|
||||
-- osm_transportation_merge_linestring_gen_z8 -> osm_transportation_merge_linestring_gen_z4
|
||||
|
||||
|
||||
CREATE OR REPLACE FUNCTION transportation.merge_linestring_gen_refresh_z7() RETURNS trigger AS
|
||||
$$
|
||||
BEGIN
|
||||
IF (tg_op = 'DELETE') THEN
|
||||
DELETE FROM osm_transportation_merge_linestring_gen_z7 WHERE id = old.id;
|
||||
DELETE FROM osm_transportation_merge_linestring_gen_z6 WHERE id = old.id;
|
||||
DELETE FROM osm_transportation_merge_linestring_gen_z5 WHERE id = old.id;
|
||||
DELETE FROM osm_transportation_merge_linestring_gen_z4 WHERE id = old.id;
|
||||
END IF;
|
||||
|
||||
IF (tg_op = 'UPDATE' OR tg_op = 'INSERT') THEN
|
||||
PERFORM insert_transportation_merge_linestring_gen_z7(new.id);
|
||||
END IF;
|
||||
|
||||
RETURN NULL;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE TRIGGER trigger_osm_transportation_merge_linestring_gen_z8
|
||||
AFTER INSERT OR UPDATE OR DELETE
|
||||
ON osm_transportation_merge_linestring_gen_z8
|
||||
FOR EACH ROW
|
||||
EXECUTE PROCEDURE transportation.merge_linestring_gen_refresh_z7();
|
||||
|
|
|
@ -75,6 +75,9 @@ tables:
|
|||
- name: waterway
|
||||
key: waterway
|
||||
type: string
|
||||
- name: leisure
|
||||
key: leisure
|
||||
type: string
|
||||
- name: water
|
||||
key: water
|
||||
type: string
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
CREATE OR REPLACE FUNCTION water_class(waterway text, water text) RETURNS text AS
|
||||
CREATE OR REPLACE FUNCTION water_class(waterway text, water text, leisure text) RETURNS text AS
|
||||
$$
|
||||
SELECT CASE
|
||||
WHEN waterway='riverbank' THEN 'river'
|
||||
|
@ -19,12 +19,71 @@ $$ LANGUAGE SQL IMMUTABLE
|
|||
STRICT
|
||||
PARALLEL SAFE;
|
||||
|
||||
-- Add ne_id for missing ne_50m_lakes.
|
||||
UPDATE ne_50m_lakes SET ne_id = ne_10m_lakes.ne_id
|
||||
FROM ne_50m_lakes lakes
|
||||
LEFT JOIN ne_10m_lakes USING (wikidataid)
|
||||
WHERE ne_50m_lakes.wikidataid = ne_10m_lakes.wikidataid
|
||||
AND ne_50m_lakes.ne_id = 0;
|
||||
|
||||
-- Update ne_110_lakes ne_id where two lakes (Lake Onega) have identical attributes.
|
||||
-- New ne_id is taken from ne_50m_lakes
|
||||
UPDATE ne_110m_lakes SET ne_id = 1159126421
|
||||
WHERE ne_id = 1159113251
|
||||
AND ST_Area(geometry) < 10000000000;
|
||||
|
||||
-- Get matching osm id for natural earth id.
|
||||
DROP MATERIALIZED VIEW IF EXISTS match_osm_ne_id CASCADE;
|
||||
CREATE MATERIALIZED VIEW match_osm_ne_id AS
|
||||
(
|
||||
WITH name_match AS
|
||||
(
|
||||
-- Distinct on keeps just the first occurence -> order by 'area_ratio DESC'.
|
||||
SELECT DISTINCT ON (ne.ne_id)
|
||||
ne.ne_id,
|
||||
osm.osm_id,
|
||||
(ST_Area(ST_Intersection(ne.geometry, osm.geometry))/ST_Area(ne.geometry)) AS area_ratio
|
||||
FROM ne_10m_lakes ne, osm_water_polygon_gen_z6 osm
|
||||
WHERE ne.name = osm.name
|
||||
AND ST_Intersects(ne.geometry, osm.geometry)
|
||||
ORDER BY ne_id,
|
||||
area_ratio DESC
|
||||
),
|
||||
-- Add lakes which are not match by name, but intersects.
|
||||
-- Duplicity solves 'DISTICT ON' with 'area_ratio'.
|
||||
geom_match AS
|
||||
(SELECT DISTINCT ON (ne.ne_id)
|
||||
ne.ne_id,
|
||||
osm.osm_id,
|
||||
(ST_Area(ST_Intersection(ne.geometry, osm.geometry))/ST_Area(ne.geometry)) AS area_ratio
|
||||
FROM ne_10m_lakes ne, osm_water_polygon_gen_z6 osm
|
||||
WHERE ST_Intersects(ne.geometry, osm.geometry)
|
||||
AND ne.ne_id NOT IN
|
||||
( SELECT ne_id
|
||||
FROM name_match
|
||||
)
|
||||
ORDER BY ne_id,
|
||||
area_ratio DESC
|
||||
)
|
||||
|
||||
SELECT ne_id,
|
||||
osm_id
|
||||
FROM name_match
|
||||
|
||||
UNION
|
||||
|
||||
SELECT ne_id,
|
||||
osm_id
|
||||
FROM geom_match
|
||||
);
|
||||
|
||||
-- ne_10m_ocean
|
||||
-- etldoc: ne_10m_ocean -> ne_10m_ocean_gen_z5
|
||||
DROP MATERIALIZED VIEW IF EXISTS ne_10m_ocean_gen_z5 CASCADE;
|
||||
CREATE MATERIALIZED VIEW ne_10m_ocean_gen_z5 AS
|
||||
(
|
||||
SELECT ST_Simplify(geometry, ZRes(7)) AS geometry,
|
||||
SELECT NULL::integer AS id,
|
||||
(ST_Dump(ST_Simplify(geometry, ZRes(7)))).geom AS geometry,
|
||||
'ocean'::text AS class,
|
||||
NULL::boolean AS is_intermittent,
|
||||
NULL::boolean AS is_bridge,
|
||||
|
@ -38,13 +97,16 @@ CREATE INDEX IF NOT EXISTS ne_10m_ocean_gen_z5_idx ON ne_10m_ocean_gen_z5 USING
|
|||
DROP MATERIALIZED VIEW IF EXISTS ne_10m_lakes_gen_z5 CASCADE;
|
||||
CREATE MATERIALIZED VIEW ne_10m_lakes_gen_z5 AS
|
||||
(
|
||||
SELECT ogc_fid,
|
||||
ST_MakeValid(ST_Simplify(geometry, ZRes(7))) AS geometry,
|
||||
SELECT COALESCE(osm.osm_id, ne_id) AS id,
|
||||
-- Union fixing e.g. Lake Huron and Georgian Bay duplicity
|
||||
(ST_Dump(ST_MakeValid(ST_Simplify(ST_Union(geometry), ZRes(7))))).geom AS geometry,
|
||||
'lake'::text AS class,
|
||||
NULL::boolean AS is_intermittent,
|
||||
NULL::boolean AS is_bridge,
|
||||
NULL::boolean AS is_tunnel
|
||||
FROM ne_10m_lakes
|
||||
LEFT JOIN match_osm_ne_id osm USING (ne_id)
|
||||
GROUP BY COALESCE(osm.osm_id, ne_id), is_intermittent, is_bridge, is_tunnel
|
||||
) /* DELAY_MATERIALIZED_VIEW_CREATION */ ;
|
||||
CREATE INDEX IF NOT EXISTS ne_10m_lakes_gen_z5_idx ON ne_10m_lakes_gen_z5 USING gist (geometry);
|
||||
|
||||
|
@ -52,8 +114,8 @@ CREATE INDEX IF NOT EXISTS ne_10m_lakes_gen_z5_idx ON ne_10m_lakes_gen_z5 USING
|
|||
DROP MATERIALIZED VIEW IF EXISTS ne_10m_lakes_gen_z4 CASCADE;
|
||||
CREATE MATERIALIZED VIEW ne_10m_lakes_gen_z4 AS
|
||||
(
|
||||
SELECT ogc_fid,
|
||||
ST_MakeValid(ST_Simplify(geometry, ZRes(6))) AS geometry,
|
||||
SELECT id,
|
||||
(ST_Dump(ST_MakeValid(ST_Simplify(geometry, ZRes(6))))).geom AS geometry,
|
||||
class,
|
||||
is_intermittent,
|
||||
is_bridge,
|
||||
|
@ -67,7 +129,8 @@ CREATE INDEX IF NOT EXISTS ne_10m_lakes_gen_z4_idx ON ne_10m_lakes_gen_z4 USING
|
|||
DROP MATERIALIZED VIEW IF EXISTS ne_50m_ocean_gen_z4 CASCADE;
|
||||
CREATE MATERIALIZED VIEW ne_50m_ocean_gen_z4 AS
|
||||
(
|
||||
SELECT ST_Simplify(geometry, ZRes(6)) AS geometry,
|
||||
SELECT NULL::integer AS id,
|
||||
(ST_Dump(ST_Simplify(geometry, ZRes(6)))).geom AS geometry,
|
||||
'ocean'::text AS class,
|
||||
NULL::boolean AS is_intermittent,
|
||||
NULL::boolean AS is_bridge,
|
||||
|
@ -80,7 +143,8 @@ CREATE INDEX IF NOT EXISTS ne_50m_ocean_gen_z4_idx ON ne_50m_ocean_gen_z4 USING
|
|||
DROP MATERIALIZED VIEW IF EXISTS ne_50m_ocean_gen_z3 CASCADE;
|
||||
CREATE MATERIALIZED VIEW ne_50m_ocean_gen_z3 AS
|
||||
(
|
||||
SELECT ST_Simplify(geometry, ZRes(5)) AS geometry,
|
||||
SELECT id,
|
||||
ST_Simplify(geometry, ZRes(5)) AS geometry,
|
||||
class,
|
||||
is_intermittent,
|
||||
is_bridge,
|
||||
|
@ -93,7 +157,8 @@ CREATE INDEX IF NOT EXISTS ne_50m_ocean_gen_z3_idx ON ne_50m_ocean_gen_z3 USING
|
|||
DROP MATERIALIZED VIEW IF EXISTS ne_50m_ocean_gen_z2 CASCADE;
|
||||
CREATE MATERIALIZED VIEW ne_50m_ocean_gen_z2 AS
|
||||
(
|
||||
SELECT ST_Simplify(geometry, ZRes(4)) AS geometry,
|
||||
SELECT id,
|
||||
ST_Simplify(geometry, ZRes(4)) AS geometry,
|
||||
class,
|
||||
is_intermittent,
|
||||
is_bridge,
|
||||
|
@ -107,13 +172,14 @@ CREATE INDEX IF NOT EXISTS ne_50m_ocean_gen_z2_idx ON ne_50m_ocean_gen_z2 USING
|
|||
DROP MATERIALIZED VIEW IF EXISTS ne_50m_lakes_gen_z3 CASCADE;
|
||||
CREATE MATERIALIZED VIEW ne_50m_lakes_gen_z3 AS
|
||||
(
|
||||
SELECT ogc_fid,
|
||||
ST_MakeValid(ST_Simplify(geometry, ZRes(5))) AS geometry,
|
||||
'lakes'::text AS class,
|
||||
SELECT COALESCE(osm.osm_id, ne_id) AS id,
|
||||
(ST_Dump(ST_MakeValid(ST_Simplify(geometry, ZRes(5))))).geom AS geometry,
|
||||
'lake'::text AS class,
|
||||
NULL::boolean AS is_intermittent,
|
||||
NULL::boolean AS is_bridge,
|
||||
NULL::boolean AS is_tunnel
|
||||
FROM ne_50m_lakes
|
||||
LEFT JOIN match_osm_ne_id osm USING (ne_id)
|
||||
) /* DELAY_MATERIALIZED_VIEW_CREATION */ ;
|
||||
CREATE INDEX IF NOT EXISTS ne_50m_lakes_gen_z3_idx ON ne_50m_lakes_gen_z3 USING gist (geometry);
|
||||
|
||||
|
@ -121,8 +187,8 @@ CREATE INDEX IF NOT EXISTS ne_50m_lakes_gen_z3_idx ON ne_50m_lakes_gen_z3 USING
|
|||
DROP MATERIALIZED VIEW IF EXISTS ne_50m_lakes_gen_z2 CASCADE;
|
||||
CREATE MATERIALIZED VIEW ne_50m_lakes_gen_z2 AS
|
||||
(
|
||||
SELECT ogc_fid,
|
||||
ST_MakeValid(ST_Simplify(geometry, ZRes(4))) AS geometry,
|
||||
SELECT id,
|
||||
(ST_Dump(ST_MakeValid(ST_Simplify(geometry, ZRes(4))))).geom AS geometry,
|
||||
class,
|
||||
is_intermittent,
|
||||
is_bridge,
|
||||
|
@ -136,7 +202,8 @@ CREATE INDEX IF NOT EXISTS ne_50m_lakes_gen_z2_idx ON ne_50m_lakes_gen_z2 USING
|
|||
DROP MATERIALIZED VIEW IF EXISTS ne_110m_ocean_gen_z1 CASCADE;
|
||||
CREATE MATERIALIZED VIEW ne_110m_ocean_gen_z1 AS
|
||||
(
|
||||
SELECT ST_Simplify(geometry, ZRes(3)) AS geometry,
|
||||
SELECT NULL::integer AS id,
|
||||
ST_Simplify(geometry, ZRes(3)) AS geometry,
|
||||
'ocean'::text AS class,
|
||||
NULL::boolean AS is_intermittent,
|
||||
NULL::boolean AS is_bridge,
|
||||
|
@ -149,7 +216,8 @@ CREATE INDEX IF NOT EXISTS ne_110m_ocean_gen_z1_idx ON ne_110m_ocean_gen_z1 USIN
|
|||
DROP MATERIALIZED VIEW IF EXISTS ne_110m_ocean_gen_z0 CASCADE;
|
||||
CREATE MATERIALIZED VIEW ne_110m_ocean_gen_z0 AS
|
||||
(
|
||||
SELECT ST_Simplify(geometry, ZRes(2)) AS geometry,
|
||||
SELECT id,
|
||||
ST_Simplify(geometry, ZRes(2)) AS geometry,
|
||||
class,
|
||||
is_intermittent,
|
||||
is_bridge,
|
||||
|
@ -164,13 +232,14 @@ CREATE INDEX IF NOT EXISTS ne_110m_ocean_gen_z0_idx ON ne_110m_ocean_gen_z0 USIN
|
|||
DROP MATERIALIZED VIEW IF EXISTS ne_110m_lakes_gen_z1 CASCADE;
|
||||
CREATE MATERIALIZED VIEW ne_110m_lakes_gen_z1 AS
|
||||
(
|
||||
SELECT ogc_fid,
|
||||
ST_Simplify(geometry, ZRes(3)) AS geometry,
|
||||
'lakes'::text AS class,
|
||||
SELECT COALESCE(osm.osm_id, ne_id) AS id,
|
||||
(ST_Dump(ST_Simplify(geometry, ZRes(3)))).geom AS geometry,
|
||||
'lake'::text AS class,
|
||||
NULL::boolean AS is_intermittent,
|
||||
NULL::boolean AS is_bridge,
|
||||
NULL::boolean AS is_tunnel
|
||||
FROM ne_110m_lakes
|
||||
LEFT JOIN match_osm_ne_id osm USING (ne_id)
|
||||
) /* DELAY_MATERIALIZED_VIEW_CREATION */ ;
|
||||
CREATE INDEX IF NOT EXISTS ne_110m_lakes_gen_z1_idx ON ne_110m_lakes_gen_z1 USING gist (geometry);
|
||||
|
||||
|
@ -178,8 +247,8 @@ CREATE INDEX IF NOT EXISTS ne_110m_lakes_gen_z1_idx ON ne_110m_lakes_gen_z1 USIN
|
|||
DROP MATERIALIZED VIEW IF EXISTS ne_110m_lakes_gen_z0 CASCADE;
|
||||
CREATE MATERIALIZED VIEW ne_110m_lakes_gen_z0 AS
|
||||
(
|
||||
SELECT ogc_fid,
|
||||
ST_Simplify(geometry, ZRes(2)) AS geometry,
|
||||
SELECT id,
|
||||
(ST_Dump(ST_Simplify(geometry, ZRes(2)))).geom AS geometry,
|
||||
class,
|
||||
is_intermittent,
|
||||
is_bridge,
|
||||
|
@ -188,11 +257,19 @@ FROM ne_110m_lakes_gen_z1
|
|||
) /* DELAY_MATERIALIZED_VIEW_CREATION */ ;
|
||||
CREATE INDEX IF NOT EXISTS ne_110m_lakes_gen_z0_idx ON ne_110m_lakes_gen_z0 USING gist (geometry);
|
||||
|
||||
DROP MATERIALIZED VIEW IF EXISTS water_z6;
|
||||
DROP MATERIALIZED VIEW IF EXISTS water_z7;
|
||||
DROP MATERIALIZED VIEW IF EXISTS water_z8;
|
||||
DROP MATERIALIZED VIEW IF EXISTS water_z9;
|
||||
DROP MATERIALIZED VIEW IF EXISTS water_z10;
|
||||
DROP MATERIALIZED VIEW IF EXISTS water_z11;
|
||||
DROP MATERIALIZED VIEW IF EXISTS water_z12;
|
||||
|
||||
CREATE OR REPLACE VIEW water_z0 AS
|
||||
(
|
||||
-- etldoc: ne_110m_ocean_gen_z0 -> water_z0
|
||||
SELECT geometry,
|
||||
SELECT id,
|
||||
geometry,
|
||||
class,
|
||||
is_intermittent,
|
||||
is_bridge,
|
||||
|
@ -200,7 +277,8 @@ SELECT geometry,
|
|||
FROM ne_110m_ocean_gen_z0
|
||||
UNION ALL
|
||||
-- etldoc: ne_110m_lakes_gen_z0 -> water_z0
|
||||
SELECT geometry,
|
||||
SELECT id,
|
||||
geometry,
|
||||
class,
|
||||
is_intermittent,
|
||||
is_bridge,
|
||||
|
@ -211,7 +289,8 @@ FROM ne_110m_lakes_gen_z0
|
|||
CREATE OR REPLACE VIEW water_z1 AS
|
||||
(
|
||||
-- etldoc: ne_110m_ocean_gen_z1 -> water_z1
|
||||
SELECT geometry,
|
||||
SELECT id,
|
||||
geometry,
|
||||
class,
|
||||
is_intermittent,
|
||||
is_bridge,
|
||||
|
@ -219,7 +298,8 @@ SELECT geometry,
|
|||
FROM ne_110m_ocean_gen_z1
|
||||
UNION ALL
|
||||
-- etldoc: ne_110m_lakes_gen_z1 -> water_z1
|
||||
SELECT geometry,
|
||||
SELECT id,
|
||||
geometry,
|
||||
class,
|
||||
is_intermittent,
|
||||
is_bridge,
|
||||
|
@ -230,7 +310,8 @@ FROM ne_110m_lakes_gen_z1
|
|||
CREATE OR REPLACE VIEW water_z2 AS
|
||||
(
|
||||
-- etldoc: ne_50m_ocean_gen_z2 -> water_z2
|
||||
SELECT geometry,
|
||||
SELECT id,
|
||||
geometry,
|
||||
class,
|
||||
is_intermittent,
|
||||
is_bridge,
|
||||
|
@ -238,7 +319,8 @@ SELECT geometry,
|
|||
FROM ne_50m_ocean_gen_z2
|
||||
UNION ALL
|
||||
-- etldoc: ne_50m_lakes_gen_z2 -> water_z2
|
||||
SELECT geometry,
|
||||
SELECT id,
|
||||
geometry,
|
||||
class,
|
||||
is_intermittent,
|
||||
is_bridge,
|
||||
|
@ -249,7 +331,8 @@ FROM ne_50m_lakes_gen_z2
|
|||
CREATE OR REPLACE VIEW water_z3 AS
|
||||
(
|
||||
-- etldoc: ne_50m_ocean_gen_z3 -> water_z3
|
||||
SELECT geometry,
|
||||
SELECT id,
|
||||
geometry,
|
||||
class,
|
||||
is_intermittent,
|
||||
is_bridge,
|
||||
|
@ -257,7 +340,8 @@ SELECT geometry,
|
|||
FROM ne_50m_ocean_gen_z3
|
||||
UNION ALL
|
||||
-- etldoc: ne_50m_lakes_gen_z3 -> water_z3
|
||||
SELECT geometry,
|
||||
SELECT id,
|
||||
geometry,
|
||||
class,
|
||||
is_intermittent,
|
||||
is_bridge,
|
||||
|
@ -268,7 +352,8 @@ FROM ne_50m_lakes_gen_z3
|
|||
CREATE OR REPLACE VIEW water_z4 AS
|
||||
(
|
||||
-- etldoc: ne_50m_ocean_gen_z4 -> water_z4
|
||||
SELECT geometry,
|
||||
SELECT id,
|
||||
geometry,
|
||||
class,
|
||||
is_intermittent,
|
||||
is_bridge,
|
||||
|
@ -276,7 +361,8 @@ SELECT geometry,
|
|||
FROM ne_50m_ocean_gen_z4
|
||||
UNION ALL
|
||||
-- etldoc: ne_10m_lakes_gen_z4 -> water_z4
|
||||
SELECT geometry,
|
||||
SELECT id,
|
||||
geometry,
|
||||
class,
|
||||
is_intermittent,
|
||||
is_bridge,
|
||||
|
@ -284,10 +370,12 @@ SELECT geometry,
|
|||
FROM ne_10m_lakes_gen_z4
|
||||
);
|
||||
|
||||
|
||||
CREATE OR REPLACE VIEW water_z5 AS
|
||||
(
|
||||
-- etldoc: ne_10m_ocean_gen_z5 -> water_z5
|
||||
SELECT geometry,
|
||||
SELECT id,
|
||||
geometry,
|
||||
class,
|
||||
is_intermittent,
|
||||
is_bridge,
|
||||
|
@ -295,7 +383,8 @@ SELECT geometry,
|
|||
FROM ne_10m_ocean_gen_z5
|
||||
UNION ALL
|
||||
-- etldoc: ne_10m_lakes_gen_z5 -> water_z5
|
||||
SELECT geometry,
|
||||
SELECT id,
|
||||
geometry,
|
||||
class,
|
||||
is_intermittent,
|
||||
is_bridge,
|
||||
|
@ -303,10 +392,11 @@ SELECT geometry,
|
|||
FROM ne_10m_lakes_gen_z5
|
||||
);
|
||||
|
||||
CREATE OR REPLACE VIEW water_z6 AS
|
||||
CREATE MATERIALIZED VIEW water_z6 AS
|
||||
(
|
||||
-- etldoc: osm_ocean_polygon_gen_z6 -> water_z6
|
||||
SELECT geometry,
|
||||
SELECT NULL::integer AS id,
|
||||
(ST_Dump(geometry)).geom AS geometry,
|
||||
'ocean'::text AS class,
|
||||
NULL::boolean AS is_intermittent,
|
||||
NULL::boolean AS is_bridge,
|
||||
|
@ -314,19 +404,22 @@ SELECT geometry,
|
|||
FROM osm_ocean_polygon_gen_z6
|
||||
UNION ALL
|
||||
-- etldoc: osm_water_polygon_gen_z6 -> water_z6
|
||||
SELECT geometry,
|
||||
water_class(waterway, water) AS class,
|
||||
SELECT osm_id AS id,
|
||||
(ST_Dump(geometry)).geom AS geometry,
|
||||
water_class(waterway, water, leisure) AS class,
|
||||
is_intermittent,
|
||||
NULL::boolean AS is_bridge,
|
||||
NULL::boolean AS is_tunnel
|
||||
FROM osm_water_polygon_gen_z6
|
||||
WHERE "natural" != 'bay'
|
||||
);
|
||||
CREATE INDEX ON water_z6 USING gist(geometry);
|
||||
|
||||
CREATE OR REPLACE VIEW water_z7 AS
|
||||
CREATE MATERIALIZED VIEW water_z7 AS
|
||||
(
|
||||
-- etldoc: osm_ocean_polygon_gen_z7 -> water_z7
|
||||
SELECT geometry,
|
||||
SELECT NULL::integer AS id,
|
||||
(ST_Dump(geometry)).geom AS geometry,
|
||||
'ocean'::text AS class,
|
||||
NULL::boolean AS is_intermittent,
|
||||
NULL::boolean AS is_bridge,
|
||||
|
@ -334,19 +427,22 @@ SELECT geometry,
|
|||
FROM osm_ocean_polygon_gen_z7
|
||||
UNION ALL
|
||||
-- etldoc: osm_water_polygon_gen_z7 -> water_z7
|
||||
SELECT geometry,
|
||||
water_class(waterway, water) AS class,
|
||||
SELECT osm_id AS id,
|
||||
(ST_Dump(geometry)).geom AS geometry,
|
||||
water_class(waterway, water, leisure) AS class,
|
||||
is_intermittent,
|
||||
NULL::boolean AS is_bridge,
|
||||
NULL::boolean AS is_tunnel
|
||||
FROM osm_water_polygon_gen_z7
|
||||
WHERE "natural" != 'bay'
|
||||
);
|
||||
CREATE INDEX ON water_z7 USING gist(geometry);
|
||||
|
||||
CREATE OR REPLACE VIEW water_z8 AS
|
||||
CREATE MATERIALIZED VIEW water_z8 AS
|
||||
(
|
||||
-- etldoc: osm_ocean_polygon_gen_z8 -> water_z8
|
||||
SELECT geometry,
|
||||
SELECT NULL::integer AS id,
|
||||
(ST_Dump(geometry)).geom AS geometry,
|
||||
'ocean'::text AS class,
|
||||
NULL::boolean AS is_intermittent,
|
||||
NULL::boolean AS is_bridge,
|
||||
|
@ -354,19 +450,22 @@ SELECT geometry,
|
|||
FROM osm_ocean_polygon_gen_z8
|
||||
UNION ALL
|
||||
-- etldoc: osm_water_polygon_gen_z8 -> water_z8
|
||||
SELECT geometry,
|
||||
water_class(waterway, water) AS class,
|
||||
SELECT osm_id AS id,
|
||||
(ST_Dump(geometry)).geom AS geometry,
|
||||
water_class(waterway, water, leisure) AS class,
|
||||
is_intermittent,
|
||||
NULL::boolean AS is_bridge,
|
||||
NULL::boolean AS is_tunnel
|
||||
FROM osm_water_polygon_gen_z8
|
||||
WHERE "natural" != 'bay'
|
||||
);
|
||||
CREATE INDEX ON water_z8 USING gist(geometry);
|
||||
|
||||
CREATE OR REPLACE VIEW water_z9 AS
|
||||
CREATE MATERIALIZED VIEW water_z9 AS
|
||||
(
|
||||
-- etldoc: osm_ocean_polygon_gen_z9 -> water_z9
|
||||
SELECT geometry,
|
||||
SELECT NULL::integer AS id,
|
||||
(ST_Dump(geometry)).geom AS geometry,
|
||||
'ocean'::text AS class,
|
||||
NULL::boolean AS is_intermittent,
|
||||
NULL::boolean AS is_bridge,
|
||||
|
@ -374,19 +473,22 @@ SELECT geometry,
|
|||
FROM osm_ocean_polygon_gen_z9
|
||||
UNION ALL
|
||||
-- etldoc: osm_water_polygon_gen_z9 -> water_z9
|
||||
SELECT geometry,
|
||||
water_class(waterway, water) AS class,
|
||||
SELECT osm_id AS id,
|
||||
(ST_Dump(geometry)).geom AS geometry,
|
||||
water_class(waterway, water, leisure) AS class,
|
||||
is_intermittent,
|
||||
NULL::boolean AS is_bridge,
|
||||
NULL::boolean AS is_tunnel
|
||||
FROM osm_water_polygon_gen_z9
|
||||
WHERE "natural" != 'bay'
|
||||
);
|
||||
CREATE INDEX ON water_z9 USING gist(geometry);
|
||||
|
||||
CREATE OR REPLACE VIEW water_z10 AS
|
||||
CREATE MATERIALIZED VIEW water_z10 AS
|
||||
(
|
||||
-- etldoc: osm_ocean_polygon_gen_z10 -> water_z10
|
||||
SELECT geometry,
|
||||
SELECT NULL::integer AS id,
|
||||
(ST_Dump(geometry)).geom AS geometry,
|
||||
'ocean'::text AS class,
|
||||
NULL::boolean AS is_intermittent,
|
||||
NULL::boolean AS is_bridge,
|
||||
|
@ -394,19 +496,22 @@ SELECT geometry,
|
|||
FROM osm_ocean_polygon_gen_z10
|
||||
UNION ALL
|
||||
-- etldoc: osm_water_polygon_gen_z10 -> water_z10
|
||||
SELECT geometry,
|
||||
water_class(waterway, water) AS class,
|
||||
SELECT osm_id AS id,
|
||||
(ST_Dump(geometry)).geom AS geometry,
|
||||
water_class(waterway, water, leisure) AS class,
|
||||
is_intermittent,
|
||||
NULL::boolean AS is_bridge,
|
||||
NULL::boolean AS is_tunnel
|
||||
FROM osm_water_polygon_gen_z10
|
||||
WHERE "natural" != 'bay'
|
||||
);
|
||||
CREATE INDEX ON water_z10 USING gist(geometry);
|
||||
|
||||
CREATE OR REPLACE VIEW water_z11 AS
|
||||
CREATE MATERIALIZED VIEW water_z11 AS
|
||||
(
|
||||
-- etldoc: osm_ocean_polygon_gen_z11 -> water_z11
|
||||
SELECT geometry,
|
||||
SELECT NULL::integer AS id,
|
||||
(ST_Dump(geometry)).geom AS geometry,
|
||||
'ocean'::text AS class,
|
||||
NULL::boolean AS is_intermittent,
|
||||
NULL::boolean AS is_bridge,
|
||||
|
@ -414,19 +519,22 @@ SELECT geometry,
|
|||
FROM osm_ocean_polygon_gen_z11
|
||||
UNION ALL
|
||||
-- etldoc: osm_water_polygon_gen_z11 -> water_z11
|
||||
SELECT geometry,
|
||||
water_class(waterway, water) AS class,
|
||||
SELECT osm_id AS id,
|
||||
(ST_Dump(geometry)).geom AS geometry,
|
||||
water_class(waterway, water, leisure) AS class,
|
||||
is_intermittent,
|
||||
NULL::boolean AS is_bridge,
|
||||
NULL::boolean AS is_tunnel
|
||||
FROM osm_water_polygon_gen_z11
|
||||
WHERE "natural" != 'bay'
|
||||
);
|
||||
CREATE INDEX ON water_z11 USING gist(geometry);
|
||||
|
||||
CREATE OR REPLACE VIEW water_z12 AS
|
||||
CREATE MATERIALIZED VIEW water_z12 AS
|
||||
(
|
||||
-- etldoc: osm_ocean_polygon_union -> water_z12
|
||||
SELECT geometry,
|
||||
SELECT NULL::integer AS id,
|
||||
(ST_Dump(geometry)).geom AS geometry,
|
||||
'ocean'::text AS class,
|
||||
NULL::boolean AS is_intermittent,
|
||||
NULL::boolean AS is_bridge,
|
||||
|
@ -434,14 +542,16 @@ SELECT geometry,
|
|||
FROM osm_ocean_polygon_union
|
||||
UNION ALL
|
||||
-- etldoc: osm_water_polygon -> water_z12
|
||||
SELECT geometry,
|
||||
water_class(waterway, water) AS class,
|
||||
SELECT osm_id AS id,
|
||||
(ST_Dump(geometry)).geom AS geometry,
|
||||
water_class(waterway, water, leisure) AS class,
|
||||
is_intermittent,
|
||||
is_bridge,
|
||||
is_tunnel
|
||||
FROM osm_water_polygon
|
||||
WHERE "natural" != 'bay'
|
||||
);
|
||||
CREATE INDEX ON water_z12 USING gist(geometry);
|
||||
|
||||
-- etldoc: layer_water [shape=record fillcolor=lightpink, style="rounded,filled",
|
||||
-- etldoc: label="layer_water |<z0> z0|<z1>z1|<z2>z2|<z3>z3 |<z4> z4|<z5>z5|<z6>z6|<z7>z7| <z8> z8 |<z9> z9 |<z10> z10 |<z11> z11 |<z12> z12+" ] ;
|
||||
|
@ -449,6 +559,7 @@ WHERE "natural" != 'bay'
|
|||
CREATE OR REPLACE FUNCTION layer_water(bbox geometry, zoom_level int)
|
||||
RETURNS TABLE
|
||||
(
|
||||
id bigint,
|
||||
geometry geometry,
|
||||
class text,
|
||||
brunnel text,
|
||||
|
@ -456,7 +567,8 @@ CREATE OR REPLACE FUNCTION layer_water(bbox geometry, zoom_level int)
|
|||
)
|
||||
AS
|
||||
$$
|
||||
SELECT geometry,
|
||||
SELECT id,
|
||||
geometry,
|
||||
class::text,
|
||||
waterway_brunnel(is_bridge, is_tunnel) AS brunnel,
|
||||
is_intermittent::int AS intermittent
|
||||
|
|
|
@ -12,12 +12,17 @@ layer:
|
|||
This however can lead to less rendering options in clients since these boundaries show up. So you might not be
|
||||
able to use border styling for ocean water features.
|
||||
fields:
|
||||
id:
|
||||
description: |
|
||||
From zoom 6 are taken OSM IDs. Up to zoom 5 there are used Natural Earth lakes, where are propagated the OSM IDs insted of Natural Earth IDs.
|
||||
For smaller area then planet, NE lakes keep their Natural Earth IDs.
|
||||
class:
|
||||
description: |
|
||||
All water polygons from [OpenStreetMapData](http://osmdata.openstreetmap.de/) have the class `ocean`.
|
||||
Water bodies with the [`waterway=riverbank`](http://wiki.openstreetmap.org/wiki/Tag:waterway=riverbank)
|
||||
or [`water=river`](http://wiki.openstreetmap.org/wiki/Tag:water=river) tag are classified as river. Wet and dry docks
|
||||
tagged [`waterway=dock`](http://wiki.openstreetmap.org/wiki/Tag:waterway=dock) are classified as a `dock`.
|
||||
tagged [`waterway=dock`](http://wiki.openstreetmap.org/wiki/Tag:waterway=dock) are classified as a `dock`.
|
||||
Swimming pools tagged [`leisure=swimming_pool`](https://wiki.openstreetmap.org/wiki/Tag:leisure=swimming_pool) are classified as a `swimming_pool`
|
||||
All other water bodies are classified as `lake`.
|
||||
values:
|
||||
dock:
|
||||
|
@ -26,8 +31,9 @@ layer:
|
|||
water: 'river'
|
||||
waterway: 'riverbank'
|
||||
lake:
|
||||
waterway: ''
|
||||
ocean:
|
||||
swimming_pool:
|
||||
leisure: 'swimming_pool'
|
||||
intermittent:
|
||||
description: |
|
||||
Mark with `1` if it is an [intermittent](http://wiki.openstreetmap.org/wiki/Key:intermittent) water polygon.
|
||||
|
@ -40,7 +46,7 @@ layer:
|
|||
- tunnel
|
||||
buffer_size: 4
|
||||
datasource:
|
||||
query: (SELECT geometry, class, intermittent, brunnel FROM layer_water(!bbox!, z(!scale_denominator!))) AS t
|
||||
query: (SELECT id, geometry, class, intermittent, brunnel FROM layer_water(!bbox!, z(!scale_denominator!))) AS t
|
||||
schema:
|
||||
- ./update_water.sql
|
||||
- ./water.sql
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
DROP TRIGGER IF EXISTS trigger_important_waterway_linestring ON osm_important_waterway_linestring;
|
||||
DROP TRIGGER IF EXISTS trigger_store ON osm_waterway_linestring;
|
||||
DROP TRIGGER IF EXISTS trigger_flag ON osm_waterway_linestring;
|
||||
DROP TRIGGER IF EXISTS trigger_refresh ON waterway_important.updates;
|
||||
|
@ -12,8 +13,17 @@ CREATE INDEX IF NOT EXISTS osm_waterway_linestring_waterway_partial_idx
|
|||
AND waterway = 'river'
|
||||
AND ST_IsValid(geometry);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS osm_important_waterway_linestring (
|
||||
id SERIAL PRIMARY KEY,
|
||||
geometry geometry,
|
||||
name varchar,
|
||||
name_en varchar,
|
||||
name_de varchar,
|
||||
tags hstore
|
||||
);
|
||||
|
||||
-- etldoc: osm_waterway_linestring -> osm_important_waterway_linestring
|
||||
CREATE TABLE IF NOT EXISTS osm_important_waterway_linestring AS
|
||||
INSERT INTO osm_important_waterway_linestring (geometry, name, name_en, name_de, tags)
|
||||
SELECT (ST_Dump(geometry)).geom AS geometry,
|
||||
name,
|
||||
name_en,
|
||||
|
@ -33,47 +43,71 @@ FROM (
|
|||
) AS waterway_union;
|
||||
CREATE INDEX IF NOT EXISTS osm_important_waterway_linestring_geometry_idx ON osm_important_waterway_linestring USING gist (geometry);
|
||||
|
||||
-- etldoc: osm_important_waterway_linestring -> osm_important_waterway_linestring_gen_z11
|
||||
DROP MATERIALIZED VIEW IF EXISTS osm_important_waterway_linestring_gen_z11 CASCADE;
|
||||
CREATE MATERIALIZED VIEW osm_important_waterway_linestring_gen_z11 AS
|
||||
(
|
||||
SELECT ST_Simplify(geometry, ZRes(12)) AS geometry,
|
||||
name,
|
||||
name_en,
|
||||
name_de,
|
||||
tags
|
||||
FROM osm_important_waterway_linestring
|
||||
WHERE ST_Length(geometry) > 1000
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS osm_important_waterway_linestring_gen_z11_geometry_idx ON osm_important_waterway_linestring_gen_z11 USING gist (geometry);
|
||||
CREATE TABLE IF NOT EXISTS osm_important_waterway_linestring_gen_z11
|
||||
(LIKE osm_important_waterway_linestring);
|
||||
|
||||
-- etldoc: osm_important_waterway_linestring_gen_z11 -> osm_important_waterway_linestring_gen_z10
|
||||
DROP MATERIALIZED VIEW IF EXISTS osm_important_waterway_linestring_gen_z10 CASCADE;
|
||||
CREATE MATERIALIZED VIEW osm_important_waterway_linestring_gen_z10 AS
|
||||
(
|
||||
SELECT ST_Simplify(geometry, ZRes(11)) AS geometry,
|
||||
name,
|
||||
name_en,
|
||||
name_de,
|
||||
tags
|
||||
FROM osm_important_waterway_linestring_gen_z11
|
||||
WHERE ST_Length(geometry) > 4000
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS osm_important_waterway_linestring_gen_z10_geometry_idx ON osm_important_waterway_linestring_gen_z10 USING gist (geometry);
|
||||
CREATE TABLE IF NOT EXISTS osm_important_waterway_linestring_gen_z10
|
||||
(LIKE osm_important_waterway_linestring_gen_z11);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS osm_important_waterway_linestring_gen_z9
|
||||
(LIKE osm_important_waterway_linestring_gen_z10);
|
||||
|
||||
CREATE OR REPLACE FUNCTION insert_important_waterway_linestring_gen(update_id bigint) RETURNS void AS
|
||||
$$
|
||||
BEGIN
|
||||
-- etldoc: osm_important_waterway_linestring -> osm_important_waterway_linestring_gen_z11
|
||||
INSERT INTO osm_important_waterway_linestring_gen_z11 (geometry, id, name, name_en, name_de, tags)
|
||||
SELECT ST_Simplify(geometry, ZRes(12)) AS geometry,
|
||||
id,
|
||||
name,
|
||||
name_en,
|
||||
name_de,
|
||||
tags
|
||||
FROM osm_important_waterway_linestring
|
||||
WHERE
|
||||
(update_id IS NULL OR id = update_id) AND
|
||||
ST_Length(geometry) > 1000;
|
||||
|
||||
-- etldoc: osm_important_waterway_linestring_gen_z11 -> osm_important_waterway_linestring_gen_z10
|
||||
INSERT INTO osm_important_waterway_linestring_gen_z10 (geometry, id, name, name_en, name_de, tags)
|
||||
SELECT ST_Simplify(geometry, ZRes(11)) AS geometry,
|
||||
id,
|
||||
name,
|
||||
name_en,
|
||||
name_de,
|
||||
tags
|
||||
FROM osm_important_waterway_linestring_gen_z11
|
||||
WHERE
|
||||
(update_id IS NULL OR id = update_id) AND
|
||||
ST_Length(geometry) > 4000;
|
||||
|
||||
-- etldoc: osm_important_waterway_linestring_gen_z10 -> osm_important_waterway_linestring_gen_z9
|
||||
INSERT INTO osm_important_waterway_linestring_gen_z9 (geometry, id, name, name_en, name_de, tags)
|
||||
SELECT ST_Simplify(geometry, ZRes(10)) AS geometry,
|
||||
id,
|
||||
name,
|
||||
name_en,
|
||||
name_de,
|
||||
tags
|
||||
FROM osm_important_waterway_linestring_gen_z10
|
||||
WHERE
|
||||
(update_id IS NULL OR id = update_id) AND
|
||||
ST_Length(geometry) > 8000;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
TRUNCATE osm_important_waterway_linestring_gen_z11;
|
||||
TRUNCATE osm_important_waterway_linestring_gen_z10;
|
||||
TRUNCATE osm_important_waterway_linestring_gen_z9;
|
||||
SELECT insert_important_waterway_linestring_gen(NULL);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS osm_important_waterway_linestring_gen_z11_geometry_idx
|
||||
ON osm_important_waterway_linestring_gen_z11 USING gist (geometry);
|
||||
CREATE INDEX IF NOT EXISTS osm_important_waterway_linestring_gen_z10_geometry_idx
|
||||
ON osm_important_waterway_linestring_gen_z10 USING gist (geometry);
|
||||
CREATE INDEX IF NOT EXISTS osm_important_waterway_linestring_gen_z9_geometry_idx
|
||||
ON osm_important_waterway_linestring_gen_z9 USING gist (geometry);
|
||||
|
||||
-- etldoc: osm_important_waterway_linestring_gen_z10 -> osm_important_waterway_linestring_gen_z9
|
||||
DROP MATERIALIZED VIEW IF EXISTS osm_important_waterway_linestring_gen_z9 CASCADE;
|
||||
CREATE MATERIALIZED VIEW osm_important_waterway_linestring_gen_z9 AS
|
||||
(
|
||||
SELECT ST_Simplify(geometry, ZRes(10)) AS geometry,
|
||||
name,
|
||||
name_en,
|
||||
name_de,
|
||||
tags
|
||||
FROM osm_important_waterway_linestring_gen_z10
|
||||
WHERE ST_Length(geometry) > 8000
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS osm_important_waterway_linestring_gen_z9_geometry_idx ON osm_important_waterway_linestring_gen_z9 USING gist (geometry);
|
||||
|
||||
-- Handle updates
|
||||
|
||||
|
@ -158,7 +192,7 @@ BEGIN
|
|||
AND w.name_de IS NOT DISTINCT FROM c.name_de
|
||||
AND w.tags IS NOT DISTINCT FROM c.tags;
|
||||
|
||||
INSERT INTO osm_important_waterway_linestring
|
||||
INSERT INTO osm_important_waterway_linestring (geometry, name, name_en, name_de, tags)
|
||||
SELECT (ST_Dump(geometry)).geom AS geometry,
|
||||
name,
|
||||
name_en,
|
||||
|
@ -181,15 +215,6 @@ BEGIN
|
|||
GROUP BY w.name, w.name_en, w.name_de, slice_language_tags(w.tags)
|
||||
) AS waterway_union;
|
||||
|
||||
-- REFRESH osm_important_waterway_linestring_gen_z11
|
||||
REFRESH MATERIALIZED VIEW osm_important_waterway_linestring_gen_z11;
|
||||
|
||||
-- REFRESH osm_important_waterway_linestring_gen_z10
|
||||
REFRESH MATERIALIZED VIEW osm_important_waterway_linestring_gen_z10;
|
||||
|
||||
-- REFRESH osm_important_waterway_linestring_gen_z9
|
||||
REFRESH MATERIALIZED VIEW osm_important_waterway_linestring_gen_z9;
|
||||
|
||||
DROP TABLE changes_compact;
|
||||
-- noinspection SqlWithoutWhere
|
||||
DELETE FROM waterway_important.changes;
|
||||
|
@ -201,6 +226,29 @@ BEGIN
|
|||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE OR REPLACE FUNCTION waterway_important.important_waterway_linestring_gen_refresh() RETURNS trigger AS
|
||||
$$
|
||||
BEGIN
|
||||
IF (tg_op = 'DELETE' OR tg_op = 'UPDATE') THEN
|
||||
DELETE FROM osm_important_waterway_linestring_gen_z11 WHERE id = old.id;
|
||||
DELETE FROM osm_important_waterway_linestring_gen_z10 WHERE id = old.id;
|
||||
DELETE FROM osm_important_waterway_linestring_gen_z9 WHERE id = old.id;
|
||||
END IF;
|
||||
|
||||
IF (tg_op = 'UPDATE' OR tg_op = 'INSERT') THEN
|
||||
PERFORM insert_important_waterway_linestring_gen(new.id);
|
||||
END IF;
|
||||
|
||||
RETURN NULL;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE TRIGGER trigger_important_waterway_linestring
|
||||
AFTER INSERT OR UPDATE OR DELETE
|
||||
ON osm_important_waterway_linestring
|
||||
FOR EACH ROW
|
||||
EXECUTE PROCEDURE waterway_important.important_waterway_linestring_gen_refresh();
|
||||
|
||||
CREATE TRIGGER trigger_store
|
||||
AFTER INSERT OR UPDATE OR DELETE
|
||||
ON osm_waterway_linestring
|
||||
|
|
|
@ -18,7 +18,7 @@ tileset:
|
|||
- layers/poi/poi.yaml
|
||||
- layers/aerodrome_label/aerodrome_label.yaml
|
||||
name: OpenMapTiles
|
||||
version: 3.13.0
|
||||
version: 3.13.1
|
||||
id: openmaptiles
|
||||
description: "A tileset showcasing all layers in OpenMapTiles. https://openmaptiles.org"
|
||||
attribution: '<a href="https://www.openmaptiles.org/" target="_blank">© OpenMapTiles</a> <a href="https://www.openstreetmap.org/copyright" target="_blank">© OpenStreetMap contributors</a>'
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<osm version="0.6" generator="Manual">
|
||||
<node id="600001" visible="true" timestamp="2019-01-01T00:00:00Z" version="1" lat="35.2" lon="-80.2">
|
||||
<tag k="amenity" v="atm"/>
|
||||
<tag k="name" v="OpenMapTiles ATM"/>
|
||||
<tag k="operator" v="Different operator"/>
|
||||
</node>
|
||||
<node id="600002" visible="true" timestamp="2019-01-01T00:00:00Z" version="1" lat="35.3" lon="-80.3">
|
||||
<tag k="amenity" v="atm"/>
|
||||
<tag k="operator" v="OpenMapTiles ATM"/>
|
||||
</node>
|
||||
<node id="600003" visible="true" timestamp="2019-01-01T00:00:00Z" version="1" lat="35.4" lon="-80.4">
|
||||
<tag k="amenity" v="atm"/>
|
||||
<tag k="network" v="OpenMapTiles ATM"/>
|
||||
</node>
|
||||
</osm>
|
|
@ -160,6 +160,16 @@ BEGIN
|
|||
INSERT INTO omt_test_failures VALUES(500, 'import', 'osm_transportation_name_linestring z12 route_rank expected 1, got ' || cnt);
|
||||
END IF;
|
||||
|
||||
-- Test 600
|
||||
|
||||
-- verify that atms are imported with correct name which can come from tags like operator or network
|
||||
SELECT COUNT(*) INTO cnt FROM osm_poi_point
|
||||
WHERE subclass = 'atm'
|
||||
AND tags->'name' = 'OpenMapTiles ATM';
|
||||
IF cnt <> 3 THEN
|
||||
INSERT INTO omt_test_failures VALUES(600, 'import', 'osm_poi_point atm with name "OpenMapTiles ATM" expected 3, got ' || cnt);
|
||||
END IF;
|
||||
|
||||
END;
|
||||
|
||||
$$
|
||||
|
|
|
@ -76,6 +76,22 @@ BEGIN
|
|||
INSERT INTO omt_test_failures VALUES(500, 'update', 'osm_transportation_linestring z9 update tags expected 1, got ' || cnt);
|
||||
END IF;
|
||||
|
||||
-- Test 600
|
||||
|
||||
-- check if name was applied correctly
|
||||
SELECT COUNT(*) INTO cnt FROM osm_poi_point
|
||||
WHERE subclass = 'atm'
|
||||
AND tags->'name' = 'OpenMapTiles ATM';
|
||||
IF cnt <> 2 THEN
|
||||
INSERT INTO omt_test_failures VALUES(600, 'update', 'osm_poi_point atm with name "OpenMapTiles ATM" expected 2, got ' || cnt);
|
||||
END IF;
|
||||
SELECT COUNT(*) INTO cnt FROM osm_poi_point
|
||||
WHERE subclass = 'atm'
|
||||
AND tags->'name' = 'New name';
|
||||
IF cnt <> 1 THEN
|
||||
INSERT INTO omt_test_failures VALUES(600, 'update', 'osm_poi_point atm with name "New name" expected 1, got ' || cnt);
|
||||
END IF;
|
||||
|
||||
END;
|
||||
|
||||
$$;
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<osmChange version="0.6" generator="Manual" timestamp="2020-01-02T00:00:00Z">
|
||||
<!--
|
||||
Test 600: POIs
|
||||
Change atm's network
|
||||
-->
|
||||
<modify>
|
||||
<node id="600003" visible="true" timestamp="2020-01-02T00:00:00Z" version="1" lat="35.4" lon="-80.4">
|
||||
<tag k="amenity" v="atm"/>
|
||||
<tag k="network" v="New name"/>
|
||||
</node>
|
||||
</modify>
|
||||
</osmChange>
|
Ładowanie…
Reference in New Issue