Skip to content
Merged
Show file tree
Hide file tree
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
63 changes: 56 additions & 7 deletions misc/scripts/mapcreation/brouter.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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;

Expand Down Expand Up @@ -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..
Expand Down Expand Up @@ -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();
Expand All @@ -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,
Expand Down
55 changes: 48 additions & 7 deletions misc/scripts/mapcreation/brouter_cfg.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}

Expand All @@ -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 },
})

Expand Down Expand Up @@ -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)
Expand All @@ -87,7 +120,6 @@ function osm2pgsql.process_node(object)
population = object.tags.population,
way = object:as_point()
})

end

if (object.tags.natural == 'peak') then
Expand Down Expand Up @@ -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
Expand All @@ -131,7 +168,6 @@ function osm2pgsql.process_way(object)
})
end


end

function osm2pgsql.process_relation(object)
Expand All @@ -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()
})

Expand All @@ -166,4 +207,4 @@ function osm2pgsql.process_relation(object)
})
end

end
end