Removing, Modifying, and Adding layers to OpenMapTiles

Dockerfile

1
2
3
4
5
6
7
8
9
10
11
12
FROM ubuntu:18.04

ENV IMPORT_DATA_DIR=/import \
BUILDINGS=/import/Buildings.shp \
PARCELS=/import/Parcel_NoData.shp

WORKDIR /usr/src/app
COPY . /usr/src/app

RUN apt-get -y update && apt-get -y --no-install-recommends install wget unzip gdal-bin

CMD ["./import-mecklenburg.sh"]

import-mecklenburg.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
set -o errexit
set -o pipefail
set -o nounset

readonly PGCONN="dbname=$POSTGRES_DB user=$POSTGRES_USER host=$POSTGRES_HOST password=$POSTGRES_PASSWORD port=$POSTGRES_PORT"

# Parcels
echo "Fetching parcels..."
wget --quiet http://maps.co.mecklenburg.nc.us/opendata/parcel_nodata.zip
unzip -oj parcel_nodata.zip -d /import
rm parcel_nodata.zip

echo "Importing parcels..."
ogr2ogr \
-progress \
-f Postgresql \
-s_srs EPSG:2264 \
-t_srs EPSG:3857 \
PG:"$PGCONN" \
-lco GEOMETRY_NAME=geometry \
-lco DIM=2 \
-lco SPATIAL_INDEX=YES \
-nlt GEOMETRY \
-nln "meck_parcels" \
-doo PRELUDE_STATEMENTS="DROP TABLE IF EXISTS meck_parcels;" \
-overwrite \
"$PARCELS"

# Buildings
echo "Fetching buildings..."
wget --quiet http://maps.co.mecklenburg.nc.us/opendata/buildings.zip
unzip -oj buildings.zip -d /import
rm buildings.zip

echo "Importing buildings..."
ogr2ogr \
-progress \
-f Postgresql \
-s_srs EPSG:2264 \
-t_srs EPSG:3857 \
PG:"$PGCONN" \
-lco GEOMETRY_NAME=geometry \
-lco DIM=2 \
-lco SPATIAL_INDEX=YES \
-nlt GEOMETRY \
-nln "meck_buildings" \
-doo PRELUDE_STATEMENTS="DROP TABLE IF EXISTS meck_buildings;" \
-overwrite \
"$BUILDINGS"

parcel.yaml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
layer:
id: "parcel"
description: |
Mecklenburg County tax parcels.
buffer_size: 4
fields:
datasource:
geometry_field: geometry
query: (SELECT geometry FROM layer_parcel(!bbox!, z(!scale_denominator!))) AS t
schema:
- ./layer.sql
datasources:
- type: imposm3
mapping_file: ./mapping.yaml

parcel layer.sql

1
2
3
4
5
6
7
8
9
10
11
12
13
14
-- etldoc: layer_parcel[shape=record fillcolor=lightpink, style="rounded,filled",
-- etldoc: label="layer_parcel <z14> z14+" ] ;

CREATE OR REPLACE FUNCTION layer_parcel(bbox geometry, zoom_level int)
RETURNS TABLE(osm_id bigint, geometry geometry) AS $$
SELECT osm_id, geometry
FROM (
-- etldoc: meck_parcels -> layer_park:z14
SELECT ogc_fid::bigint as osm_id, geometry
FROM meck_parcels
WHERE zoom_level >= 14
) AS zoom_levels
WHERE geometry && bbox;
$$ LANGUAGE SQL IMMUTABLE;

Resources