From 76265e7713ad203ee6679a810121d2bd22f78074 Mon Sep 17 00:00:00 2001 From: afischerdev Date: Wed, 2 Aug 2023 13:27:21 +0200 Subject: [PATCH] latest scripts for db generation --- misc/scripts/mapcreation/brouter.sql | 63 +++++++++++++++++++++--- misc/scripts/mapcreation/brouter_cfg.lua | 55 ++++++++++++++++++--- 2 files changed, 104 insertions(+), 14 deletions(-) diff --git a/misc/scripts/mapcreation/brouter.sql b/misc/scripts/mapcreation/brouter.sql index 14aa658..43a4c29 100644 --- a/misc/scripts/mapcreation/brouter.sql +++ b/misc/scripts/mapcreation/brouter.sql @@ -44,7 +44,6 @@ SELECT -- "buffer radius" was initially created with 50 meters at a lat 50 degrees.... ==> ST_Buffer(way,50) -- but, using geometry "projection", to get same results by a calculation of the planet (latitude between -80, +85) this value should be adapted to the latitude of the highways... , - -- ST_Buffer (way, 32.15 * st_length (ST_Transform (way, 3857)) / st_length (ST_Transform (way, 4326)::geography)) AS way INTO TABLE osm_line_buf_50 FROM lines @@ -361,7 +360,7 @@ SELECT now(); -- create tags for noise --- create raw data +-- create raw data for noise coming from cars -- when several highways-segments are producing noise, aggregate the noises using the "ST_Union" of the segments! -- (better as using "sum" or "max" that do not deliver good factors) SELECT @@ -418,6 +417,47 @@ GROUP BY ORDER BY sum_noise_factor DESC; +-- noise coming from airports +SELECT + name, + st_buffer (way, (643 * st_length (ST_Transform (st_makeline (st_startpoint (way), st_centroid (way)), 3857)) / st_length (ST_Transform (st_makeline (st_startpoint (way), st_centroid (way)), 4326)::geography))) AS way INTO TABLE poly_airport +FROM + polygons +WHERE + aeroway = 'aerodrome' + AND aerodrome = 'international'; + +SELECT + m.osm_id losmid, + st_area (st_intersection (m.way, q.way)) / (st_area (m.way) * 1.5) AS dist_factor INTO TABLE noise_airport +FROM + osm_line_buf_50 AS m + INNER JOIN poly_airport AS q ON ST_intersects (m.way, q.way) +WHERE + m.highway IS NOT NULL + --GROUP BY losmid, m.way +ORDER BY + dist_factor DESC; + +-- add car & airport noises +SELECT + losmid, + sum(noise_factor) AS sum_noise_factor INTO TABLE noise_tmp3 +FROM (( + SELECT + losmid, + sum_noise_factor AS noise_factor + FROM + noise_tmp2 AS nois1) + UNION ( + SELECT + losmid, + dist_factor AS noise_factor + FROM + noise_airport AS nois2)) AS nois_sum +GROUP BY + losmid; + -- create the noise classes SELECT losmid, @@ -435,7 +475,7 @@ SELECT '6' END AS noise_class INTO TABLE noise_tags FROM - noise_tmp2 y + noise_tmp3 y WHERE y.sum_noise_factor > 0.01; @@ -707,7 +747,8 @@ SELECT ----------------------------------------- -- OSM data used to calculate/estimate the traffic: -- population of towns (+ distance from position to the towns) --- industrial areas (landuse=industrial) (+ surface of the areas and distance from position) +-- industrial& retail areas (landuse=industrial/retail) (consider surface of the areas and distance from position) +-- airports international -- motorway density (traffic on motorways decreases traffic on primary/secondary/tertiary) calculated on grid -- highway density (traffic decreases when more primary/secondary/tertiary highways are available) calculated on grid -- exceptions: near junctions between motorways and primary/secondary/tertiary the traffic increases on the primary/secondary/tertiary.. @@ -841,7 +882,8 @@ SELECT now(); -- --- traffic due to industrial parcs ... +-- traffic due to industrial or retail areas ... (exceptions/not considered: solar & wind parks!) +-- traffic due to aerodromes -- SELECT now(); @@ -852,8 +894,15 @@ SELECT st_length (ST_Transform (st_makeline (st_startpoint (way), st_centroid (way)), 3857)) / st_length (ST_Transform (st_makeline (st_startpoint (way), st_centroid (way)), 4326)::geography) AS merca_coef INTO TABLE poly_industri FROM polygons -WHERE - landuse = 'industrial'; +WHERE (landuse IN ('industrial', 'retail')) + OR (aeroway = 'aerodrome' + AND aerodrome = 'international') + --where landuse in ('industrial', 'retail') + --where landuse in ('industrial') + AND (plant_method IS NULL + OR plant_method NOT IN ('photovoltaic')) + AND (plant_source IS NULL + OR plant_source NOT IN ('solar', 'wind')); SELECT name, diff --git a/misc/scripts/mapcreation/brouter_cfg.lua b/misc/scripts/mapcreation/brouter_cfg.lua index 5ed6d53..b1a7979 100644 --- a/misc/scripts/mapcreation/brouter_cfg.lua +++ b/misc/scripts/mapcreation/brouter_cfg.lua @@ -2,8 +2,9 @@ local srid = 3857 --- 3857 SHOULD BE USED here for distance calculation ... (not srid = 4326 !) --- https://gis.stackexchange.com/questions/48949/epsg-3857-or-4326-for-web-mapping + +-- 3857 (projection) SHOULD BE USED here for distance calculation ... (not srid = 4326 !) +-- https://gis.stackexchange.com/questions/48949/epsg-3857-or-4326-for-web-mapping local tables = {} @@ -28,6 +29,11 @@ tables.polygons = osm2pgsql.define_area_table('polygons', { { column = 'leisure', type = 'text' }, { column = 'natural', type = 'text' }, { column = 'water', type = 'text' }, + { column = 'power', type = 'text' }, + { column = 'plant_method', type = 'text' }, + { column = 'plant_source', type = 'text' }, + { column = 'aeroway', type = 'text' }, + { column = 'aerodrome', type = 'text' }, { column = 'way', type = 'geometry', projection = srid, not_null = true }, }) @@ -73,7 +79,34 @@ function has_area_tags(tags) end return tags.place - or tags.population + or tags.population +end + +function get_plant_source(tags) + local source = nil + + for _, key in ipairs({'source'}) do + local a = tags['plant:' .. key] + if a then + source = a + end + end + + return source +end + + +function get_plant_method(tags) + local method = nil + + for _, key in ipairs({'method'}) do + local a = tags['plant:' .. key] + if a then + method = a + end + end + + return method end function osm2pgsql.process_node(object) @@ -87,7 +120,6 @@ function osm2pgsql.process_node(object) population = object.tags.population, way = object:as_point() }) - end if (object.tags.natural == 'peak') then @@ -115,8 +147,13 @@ function osm2pgsql.process_way(object) leisure = object.tags.leisure, natural = object.tags.natural, water = object.tags.water, + power = object.tags.power, + plant_source = get_plant_source(object.tags), + plant_method = get_plant_method(object.tags), + aeroway = object.tags.aeroway, + aerodrome = object.tags.aerodrome, way = object:as_polygon() - }) + }) end if ( object.tags.highway ~= nil) or ( object.tags.waterway ~= nil) then @@ -131,7 +168,6 @@ function osm2pgsql.process_way(object) }) end - end function osm2pgsql.process_relation(object) @@ -149,6 +185,11 @@ function osm2pgsql.process_relation(object) leisure = object.tags.leisure, natural = object.tags.natural, water = object.tags.water, + power = object.tags.power, + plant_source = get_plant_source(object.tags), + plant_method = get_plant_method(object.tags), + aeroway = object.tags.aeroway, + aerodrome = object.tags.aerodrome, way = object:as_multipolygon() }) @@ -166,4 +207,4 @@ function osm2pgsql.process_relation(object) }) end -end \ No newline at end of file +end