Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve town, forest and river tags #614

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 75 additions & 31 deletions misc/scripts/mapcreation/brouter.sql
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,8 @@ FROM
polygons p
WHERE
-- do not consider small surfaces
st_area (p.way) > 1000
AND p.natural IN ('water')
OR (p.landuse IN ('forest', 'allotments', 'flowerbed', 'orchard', 'vineyard', 'recreation_ground', 'village_green')
OR p.leisure IN ('garden', 'park', 'nature_reserve'));
st_area (st_transform (p.way, 4326)::geography) > 10000
AND p.natural IN ('water');

SELECT
osm_id::bigint,
Expand All @@ -92,10 +90,9 @@ FROM
polygons p
WHERE
-- do not consider small surfaces
st_area (p.way) > 1000
AND p.natural IN ('water')
OR (p.landuse IN ('forest', 'allotments', 'flowerbed', 'orchard', 'vineyard', 'recreation_ground', 'village_green')
OR p.leisure IN ('garden', 'park', 'nature_reserve'));
st_area (st_transform (p.way, 4326)::geography) > 1000
AND (p.leisure IN ('garden', 'park', 'nature_reserve')
OR p.landuse IN ('forest', 'allotments', 'orchard', 'vineyard', 'village_green', 'farmland', 'meadow', 'grass'));

SELECT
osm_id::bigint,
Expand Down Expand Up @@ -575,17 +572,17 @@ ORDER BY
SELECT
now();

-- create tags for forest
-- create tags for green
SELECT
m.osm_id,
m.highway,
st_area (st_intersection (m.way, ST_Union (q.way))) / st_area (m.way) AS green_factor INTO TABLE forest_tmp
st_area (st_intersection (m.way, ST_Union (q.way))) / st_area (m.way) AS green_factor INTO TABLE green_tmp
FROM
osm_line_buf_50 AS m
INNER JOIN osm_poly_no_buf AS q ON ST_Intersects (m.way, q.way)
WHERE
m.highway IS NOT NULL
AND ((q.landuse IN ('forest', 'allotments', 'flowerbed', 'orchard', 'vineyard', 'recreation_ground', 'village_green'))
AND ((q.landuse IN ('forest', 'allotments', 'orchard', 'vineyard', 'village_green', 'farmland', 'meadow', 'grass'))
OR q.leisure IN ('garden', 'park', 'nature_reserve'))
AND (st_area (ST_Transform (q.way, 4326)::geography) / 1000000) < 5000
GROUP BY
Expand All @@ -598,25 +595,84 @@ ORDER BY
--
SELECT
y.osm_id losmid,
CASE WHEN y.green_factor < 0.1 THEN
CASE WHEN y.green_factor < 0.5 THEN
NULL
WHEN y.green_factor < 0.2 THEN
WHEN y.green_factor < 0.6 THEN
'1'
WHEN y.green_factor < 0.4 THEN
WHEN y.green_factor < 0.7 THEN
'2'
WHEN y.green_factor < 0.6 THEN
'3'
WHEN y.green_factor < 0.8 THEN
'3'
WHEN y.green_factor < 0.9 THEN
'4'
WHEN y.green_factor < 0.98 THEN
'5'
ELSE
'6'
END AS green_class INTO TABLE green_tags
FROM
green_tmp y
WHERE
y.green_factor > 0.5;

SELECT
count(*)
FROM
green_tags;

SELECT
green_class,
count(*)
FROM
green_tags
GROUP BY
green_class
ORDER BY
green_class;

SELECT
now();

-- create tags for forest
SELECT
m.osm_id,
m.highway,
st_area (st_intersection (m.way, ST_Union (q.way))) / st_area (m.way) AS forest_factor INTO TABLE forest_tmp
FROM
osm_line_buf_50 AS m
INNER JOIN osm_poly_no_buf AS q ON ST_Intersects (m.way, q.way)
WHERE
m.highway IS NOT NULL
AND q.landuse IN ('forest')
GROUP BY
m.osm_id,
m.highway,
m.way
ORDER BY
forest_factor DESC;

--
SELECT
y.osm_id losmid,
CASE WHEN y.forest_factor < 0.5 THEN
NULL
quaelnix marked this conversation as resolved.
Show resolved Hide resolved
WHEN y.forest_factor < 0.6 THEN
'1'
WHEN y.forest_factor < 0.7 THEN
'2'
WHEN y.forest_factor < 0.8 THEN
'3'
WHEN y.forest_factor < 0.9 THEN
'4'
WHEN y.forest_factor < 0.98 THEN
'5'
ELSE
'6'
END AS forest_class INTO TABLE forest_tags
FROM
forest_tmp y
WHERE
y.green_factor > 0.1;
y.forest_factor > 0.5;

SELECT
count(*)
Expand Down Expand Up @@ -659,7 +715,7 @@ FROM
INNER JOIN cities_all AS q ON ST_Intersects (m.way, q.way)
WHERE
m.highway IS NOT NULL
AND q.population > '50000'
AND q.population > '1000'
ORDER BY
town_factor DESC;

Expand Down Expand Up @@ -711,18 +767,7 @@ WHERE losmid IN (
SELECT
losmid
FROM
forest_tags
WHERE
forest_class NOT IN ('1'));

DELETE FROM town_tags
WHERE losmid IN (
SELECT
losmid
FROM
river_tags
WHERE
river_class NOT IN ('1'));
green_tags);

SELECT
count(*)
Expand Down Expand Up @@ -1189,4 +1234,3 @@ ANALYSE;

SELECT
now();