Skip to content

Commit

Permalink
Add leisure and improve low level zooms
Browse files Browse the repository at this point in the history
  • Loading branch information
bchapuis committed Nov 8, 2023
1 parent 1405103 commit 3a83312
Show file tree
Hide file tree
Showing 10 changed files with 497 additions and 11 deletions.
2 changes: 1 addition & 1 deletion basemap/layers/landuse/prepare.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ SELECT
FROM osm_polygon
WHERE geom IS NOT NULL
AND st_area(geom) > 78270 / power(2, 12) * 100
AND tags ->> 'landuse' IN ('residential', 'farmland', 'forest', 'meadow', 'orchard', 'vineyard', 'salt_pond', 'water');
AND tags ->> 'landuse' IN ('commercial', 'construction', 'industrial', 'residential', 'retail', 'farmland', 'forest', 'meadow', 'greenhouse_horticulture', 'meadow', 'orchard', 'plant_nursery','vineyard', 'basin', 'salt_pond', 'brownfield', 'cemetery', 'grass', 'greenfield', 'landfill', 'military', 'quarry', 'railway');
CREATE INDEX IF NOT EXISTS osm_landuse_filtered_geom_idx ON osm_landuse_filtered USING GIST (geom);
CREATE INDEX IF NOT EXISTS osm_landuse_filtered_tags_idx ON osm_landuse_filtered (landuse);

Expand Down
8 changes: 1 addition & 7 deletions basemap/layers/landuse/tileset.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,9 @@ export default {
queries: [
{
minzoom: 1,
maxzoom: 8,
sql:
"SELECT id, tags, geom FROM osm_landuse_z$zoom WHERE tags ->> 'landuse' IN ('farmland', 'forest', 'meadow')",
},
{
minzoom: 8,
maxzoom: 13,
sql:
"SELECT id, tags, geom FROM osm_landuse_z$zoom WHERE tags ->> 'landuse' IN ('farmland', 'forest', 'meadow', 'residential', 'vineyard')",
"SELECT id, tags, geom FROM osm_landuse_z$zoom WHERE tags ? 'landuse'",
},
{
minzoom: 13,
Expand Down
71 changes: 71 additions & 0 deletions basemap/layers/leisure/clean.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
-- Licensed to the Apache Software Foundation (ASF) under one or more
-- contributor license agreements. See the NOTICE file distributed with
-- this work for additional information regarding copyright ownership.
-- The ASF licenses this file to you under the Apache License, Version 2.0
-- (the "License"); you may not use this file except in compliance with
-- the License. You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
DROP MATERIALIZED VIEW IF EXISTS osm_leisure_filtered CASCADE;
DROP MATERIALIZED VIEW IF EXISTS osm_leisure_clustered CASCADE;
DROP MATERIALIZED VIEW IF EXISTS osm_leisure_grouped CASCADE;
DROP MATERIALIZED VIEW IF EXISTS osm_leisure_buffered CASCADE;
DROP MATERIALIZED VIEW IF EXISTS osm_leisure_exploded CASCADE;
DROP MATERIALIZED VIEW IF EXISTS osm_leisure CASCADE;

DROP MATERIALIZED VIEW IF EXISTS osm_leisure_xl_filtered CASCADE;
DROP MATERIALIZED VIEW IF EXISTS osm_leisure_xl_clustered CASCADE;
DROP MATERIALIZED VIEW IF EXISTS osm_leisure_xl_grouped CASCADE;
DROP MATERIALIZED VIEW IF EXISTS osm_leisure_xl_buffered CASCADE;
DROP MATERIALIZED VIEW IF EXISTS osm_leisure_xl_exploded CASCADE;
DROP MATERIALIZED VIEW IF EXISTS osm_leisure_xl CASCADE;

DROP MATERIALIZED VIEW IF EXISTS osm_leisure_l_filtered CASCADE;
DROP MATERIALIZED VIEW IF EXISTS osm_leisure_l_clustered CASCADE;
DROP MATERIALIZED VIEW IF EXISTS osm_leisure_l_grouped CASCADE;
DROP MATERIALIZED VIEW IF EXISTS osm_leisure_l_buffered CASCADE;
DROP MATERIALIZED VIEW IF EXISTS osm_leisure_l_exploded CASCADE;
DROP MATERIALIZED VIEW IF EXISTS osm_leisure_l CASCADE;

DROP MATERIALIZED VIEW IF EXISTS osm_leisure_m_filtered CASCADE;
DROP MATERIALIZED VIEW IF EXISTS osm_leisure_m_clustered CASCADE;
DROP MATERIALIZED VIEW IF EXISTS osm_leisure_m_grouped CASCADE;
DROP MATERIALIZED VIEW IF EXISTS osm_leisure_m_buffered CASCADE;
DROP MATERIALIZED VIEW IF EXISTS osm_leisure_m_exploded CASCADE;
DROP MATERIALIZED VIEW IF EXISTS osm_leisure_m CASCADE;

DROP MATERIALIZED VIEW IF EXISTS osm_leisure_s_filtered CASCADE;
DROP MATERIALIZED VIEW IF EXISTS osm_leisure_s_clustered CASCADE;
DROP MATERIALIZED VIEW IF EXISTS osm_leisure_s_grouped CASCADE;
DROP MATERIALIZED VIEW IF EXISTS osm_leisure_s_buffered CASCADE;
DROP MATERIALIZED VIEW IF EXISTS osm_leisure_s_exploded CASCADE;
DROP MATERIALIZED VIEW IF EXISTS osm_leisure_s CASCADE;

DROP VIEW IF EXISTS osm_leisure_z20 CASCADE;
DROP VIEW IF EXISTS osm_leisure_z19 CASCADE;
DROP VIEW IF EXISTS osm_leisure_z18 CASCADE;
DROP VIEW IF EXISTS osm_leisure_z17 CASCADE;
DROP VIEW IF EXISTS osm_leisure_z16 CASCADE;
DROP VIEW IF EXISTS osm_leisure_z15 CASCADE;
DROP VIEW IF EXISTS osm_leisure_z14 CASCADE;
DROP VIEW IF EXISTS osm_leisure_z13 CASCADE;

DROP MATERIALIZED VIEW IF EXISTS osm_leisure_z12 CASCADE;
DROP MATERIALIZED VIEW IF EXISTS osm_leisure_z11 CASCADE;
DROP MATERIALIZED VIEW IF EXISTS osm_leisure_z10 CASCADE;
DROP MATERIALIZED VIEW IF EXISTS osm_leisure_z9 CASCADE;
DROP MATERIALIZED VIEW IF EXISTS osm_leisure_z8 CASCADE;
DROP MATERIALIZED VIEW IF EXISTS osm_leisure_z7 CASCADE;
DROP MATERIALIZED VIEW IF EXISTS osm_leisure_z6 CASCADE;
DROP MATERIALIZED VIEW IF EXISTS osm_leisure_z5 CASCADE;
DROP MATERIALIZED VIEW IF EXISTS osm_leisure_z4 CASCADE;
DROP MATERIALIZED VIEW IF EXISTS osm_leisure_z3 CASCADE;
DROP MATERIALIZED VIEW IF EXISTS osm_leisure_z2 CASCADE;
DROP MATERIALIZED VIEW IF EXISTS osm_leisure_z1 CASCADE;

26 changes: 26 additions & 0 deletions basemap/layers/leisure/index.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
-- Licensed to the Apache Software Foundation (ASF) under one or more
-- contributor license agreements. See the NOTICE file distributed with
-- this work for additional information regarding copyright ownership.
-- The ASF licenses this file to you under the Apache License, Version 2.0
-- (the "License"); you may not use this file except in compliance with
-- the License. You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
CREATE INDEX IF NOT EXISTS osm_leisure_geom_z1_index ON osm_leisure_z1 USING SPGIST (geom);
CREATE INDEX IF NOT EXISTS osm_leisure_geom_z2_index ON osm_leisure_z2 USING SPGIST (geom);
CREATE INDEX IF NOT EXISTS osm_leisure_geom_z3_index ON osm_leisure_z3 USING SPGIST (geom);
CREATE INDEX IF NOT EXISTS osm_leisure_geom_z4_index ON osm_leisure_z4 USING SPGIST (geom);
CREATE INDEX IF NOT EXISTS osm_leisure_geom_z5_index ON osm_leisure_z5 USING SPGIST (geom);
CREATE INDEX IF NOT EXISTS osm_leisure_geom_z6_index ON osm_leisure_z6 USING SPGIST (geom);
CREATE INDEX IF NOT EXISTS osm_leisure_geom_z7_index ON osm_leisure_z7 USING SPGIST (geom);
CREATE INDEX IF NOT EXISTS osm_leisure_geom_z8_index ON osm_leisure_z8 USING SPGIST (geom);
CREATE INDEX IF NOT EXISTS osm_leisure_geom_z9_index ON osm_leisure_z9 USING SPGIST (geom);
CREATE INDEX IF NOT EXISTS osm_leisure_geom_z10_index ON osm_leisure_z10 USING SPGIST (geom);
CREATE INDEX IF NOT EXISTS osm_leisure_geom_z11_index ON osm_leisure_z11 USING SPGIST (geom);
CREATE INDEX IF NOT EXISTS osm_leisure_geom_z12_index ON osm_leisure_z12 USING SPGIST (geom);
232 changes: 232 additions & 0 deletions basemap/layers/leisure/prepare.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
-- Licensed to the Apache Software Foundation (ASF) under one or more
-- contributor license agreements. See the NOTICE file distributed with
-- this work for additional information regarding copyright ownership.
-- The ASF licenses this file to you under the Apache License, Version 2.0
-- (the "License"); you may not use this file except in compliance with
-- the License. You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
CREATE MATERIALIZED VIEW osm_leisure_filtered AS
SELECT
tags -> 'leisure' AS leisure,
st_simplifypreservetopology(geom, 78270 / power(2, 12)) AS geom
FROM osm_polygon
WHERE geom IS NOT NULL
AND st_area(geom) > 78270 / power(2, 12) * 100
AND tags ->> 'leisure' IN ('garden', 'golf_course', 'marina', 'nature_reserve', 'park', 'pitch', 'sport_center', 'stadium', 'swimming_pool', 'track');
CREATE INDEX IF NOT EXISTS osm_leisure_filtered_geom_idx ON osm_leisure_filtered USING GIST (geom);
CREATE INDEX IF NOT EXISTS osm_leisure_filtered_tags_idx ON osm_leisure_filtered (leisure);

CREATE MATERIALIZED VIEW osm_leisure_clustered AS
SELECT
leisure,
geom,
st_clusterdbscan(geom, 0, 0) OVER(PARTITION BY leisure) AS cluster
FROM osm_leisure_filtered
WHERE geom IS NOT NULL;
CREATE INDEX IF NOT EXISTS osm_leisure_clustered_geom_idx ON osm_leisure_clustered USING GIST (geom);
CREATE INDEX IF NOT EXISTS osm_leisure_clustered_tags_idx ON osm_leisure_clustered (leisure);

CREATE MATERIALIZED VIEW osm_leisure_grouped AS
SELECT
leisure,
st_collect(geom) AS geom
FROM osm_leisure_clustered
GROUP BY leisure, cluster;

CREATE MATERIALIZED VIEW osm_leisure_buffered AS
SELECT
leisure,
st_buffer(geom, 0, 'join=mitre') AS geom
FROM osm_leisure_grouped;

CREATE MATERIALIZED VIEW osm_leisure_exploded AS
SELECT
leisure,
(st_dump(geom)).geom AS geom
FROM osm_leisure_buffered;

CREATE MATERIALIZED VIEW osm_leisure AS
SELECT
row_number() OVER () AS id,
jsonb_build_object('leisure', leisure) AS tags,
geom
FROM osm_leisure_exploded;

-- XTRA LARGE
CREATE MATERIALIZED VIEW osm_leisure_xl_filtered AS
SELECT
id,
tags -> 'leisure' as leisure,
st_buffer(st_simplifypreservetopology(geom, 78270 / power(2, 8)), 78270 / power(2, 8), 'join=mitre') AS geom
FROM osm_leisure
WHERE st_area(st_envelope(geom)) > 25 * power(78270 / power(2, 8), 2);

CREATE MATERIALIZED VIEW osm_leisure_xl_clustered AS
SELECT
leisure,
geom,
st_clusterdbscan(geom, 0, 0) OVER(PARTITION BY leisure) AS cluster
FROM osm_leisure_xl_filtered;

CREATE MATERIALIZED VIEW osm_leisure_xl_grouped AS
SELECT
leisure,
cluster,
st_collect(geom) AS geom
FROM osm_leisure_xl_clustered
GROUP BY leisure, cluster;

CREATE MATERIALIZED VIEW osm_leisure_xl_buffered AS
SELECT
leisure,
st_buffer(geom, -78270 / power(2, 8), 'join=mitre') AS geom
FROM osm_leisure_xl_grouped;

CREATE MATERIALIZED VIEW osm_leisure_xl_exploded AS
SELECT
leisure,
(st_dump(geom)).geom AS geom
FROM osm_leisure_xl_buffered;

CREATE MATERIALIZED VIEW osm_leisure_xl AS
SELECT
row_number() OVER () AS id,
jsonb_build_object('leisure', leisure) AS tags,
geom AS geom
FROM osm_leisure_xl_buffered;

-- LARGE
CREATE MATERIALIZED VIEW osm_leisure_l_filtered AS
SELECT
id,
tags -> 'leisure' as leisure,
st_buffer(st_simplifypreservetopology(geom, 78270 / power(2, 6)), 78270 / power(2, 7), 'join=mitre') AS geom
FROM osm_leisure
WHERE st_area(st_envelope(geom)) > 5 * power(78270 / power(2, 7), 2);

CREATE MATERIALIZED VIEW osm_leisure_l_clustered AS
SELECT
leisure,
geom,
st_clusterdbscan(geom, 0, 0) OVER(PARTITION BY leisure) AS cluster
FROM osm_leisure_l_filtered;

CREATE MATERIALIZED VIEW osm_leisure_l_grouped AS
SELECT
leisure,
cluster,
st_collect(geom) AS geom
FROM osm_leisure_l_clustered
GROUP BY leisure, cluster;

CREATE MATERIALIZED VIEW osm_leisure_l_buffered AS
SELECT
leisure,
st_buffer(geom, 0.5 * -78270 / power(2, 7), 'join=mitre') AS geom
FROM osm_leisure_l_grouped;

CREATE MATERIALIZED VIEW osm_leisure_l_exploded AS
SELECT
leisure,
(st_dump(geom)).geom AS geom
FROM osm_leisure_l_buffered;

CREATE MATERIALIZED VIEW osm_leisure_l AS
SELECT
row_number() OVER () AS id,
jsonb_build_object('leisure', leisure) AS tags,
geom AS geom
FROM osm_leisure_l_buffered;

-- MEDIUM
CREATE MATERIALIZED VIEW osm_leisure_m_filtered AS
SELECT
id,
tags -> 'leisure' as leisure,
st_buffer(st_simplifypreservetopology(geom, 78270 / power(2, 5)), 78270 / power(2, 6), 'join=mitre') AS geom
FROM osm_leisure
WHERE st_area(st_envelope(geom)) > 10 * power(78270 / power(2, 6), 2);

CREATE MATERIALIZED VIEW osm_leisure_m_clustered AS
SELECT
leisure,
geom,
st_clusterdbscan(geom, 0, 0) OVER(PARTITION BY leisure) AS cluster
FROM osm_leisure_m_filtered;

CREATE MATERIALIZED VIEW osm_leisure_m_grouped AS
SELECT
leisure,
cluster,
st_collect(geom) AS geom
FROM osm_leisure_m_clustered
GROUP BY leisure, cluster;

CREATE MATERIALIZED VIEW osm_leisure_m_buffered AS
SELECT
leisure,
st_buffer(geom, 0.1 * -78270 / power(2, 6), 'join=mitre') AS geom
FROM osm_leisure_m_grouped;

CREATE MATERIALIZED VIEW osm_leisure_m_exploded AS
SELECT
leisure,
(st_dump(geom)).geom AS geom
FROM osm_leisure_m_buffered;

CREATE MATERIALIZED VIEW osm_leisure_m AS
SELECT
row_number() OVER () AS id,
jsonb_build_object('leisure', leisure) AS tags,
geom AS geom
FROM osm_leisure_m_buffered;

-- SMALL
CREATE MATERIALIZED VIEW osm_leisure_s_filtered AS
SELECT
id,
tags -> 'leisure' as leisure,
st_buffer(st_simplifypreservetopology(geom, 78270 / power(2, 4)), 78270 / power(2, 5), 'join=mitre') AS geom
FROM osm_leisure
WHERE st_area(st_envelope(geom)) > 15 * power(78270 / power(2, 5), 2);

CREATE MATERIALIZED VIEW osm_leisure_s_clustered AS
SELECT
leisure,
geom,
st_clusterdbscan(geom, 0, 0) OVER(PARTITION BY leisure) AS cluster
FROM osm_leisure_s_filtered;

CREATE MATERIALIZED VIEW osm_leisure_s_grouped AS
SELECT
leisure,
cluster,
st_collect(geom) AS geom
FROM osm_leisure_s_clustered
GROUP BY leisure, cluster;

CREATE MATERIALIZED VIEW osm_leisure_s_buffered AS
SELECT
leisure,
st_buffer(geom, 0, 'join=mitre') AS geom
FROM osm_leisure_s_grouped;

CREATE MATERIALIZED VIEW osm_leisure_s_exploded AS
SELECT
leisure,
(st_dump(geom)).geom AS geom
FROM osm_leisure_s_buffered;

CREATE MATERIALIZED VIEW osm_leisure_s AS
SELECT
row_number() OVER () AS id,
jsonb_build_object('leisure', leisure) AS tags,
geom AS geom
FROM osm_leisure_s_buffered;
Loading

0 comments on commit 3a83312

Please sign in to comment.