feat(db): add taxi stations to update-db.sh
This commit is contained in:
parent
2eaa603448
commit
7bef39db9e
|
@ -0,0 +1,37 @@
|
|||
-- colon before variable: for a prepared statement using named placeholders, this will be a parameter name of the form :name
|
||||
CREATE SCHEMA IF NOT EXISTS :schema;
|
||||
SET search_path to :schema, public;
|
||||
|
||||
DROP TABLE IF EXISTS :schema.tbl_taxi;
|
||||
DROP VIEW IF EXISTS :schema.vw_taxi;
|
||||
|
||||
CREATE OR REPLACE VIEW :schema.vw_taxi AS
|
||||
SELECT entity.osm_id, entity.amenity, entity.name, entity.st_x, entity.st_y
|
||||
FROM (
|
||||
--planet_osm_point/node
|
||||
SELECT osmNode.osm_id, osmNode.amenity, osmNode.name,
|
||||
st_x(st_transform(osmNode.way, 4326)) AS st_x,
|
||||
st_y(st_transform(osmNode.way, 4326)) AS st_y
|
||||
FROM planet_osm_point AS osmNode
|
||||
WHERE
|
||||
osmNode.amenity = 'taxi'
|
||||
AND osmNode.proposed IS NULL
|
||||
UNION
|
||||
--planet_osm_polygone/way
|
||||
SELECT osmWay.osm_id, osmWay.amenity, osmWay.name,
|
||||
st_x(st_centroid(st_transform(osmWay.way, 4326))) AS st_x,
|
||||
st_y(st_centroid(st_transform(osmWay.way, 4326))) AS st_y
|
||||
FROM planet_osm_polygon AS osmWay
|
||||
WHERE
|
||||
osmWay.amenity = 'taxi'
|
||||
AND osmWay.proposed IS NULL
|
||||
) AS entity
|
||||
--consider coordinates inside rvb only
|
||||
LEFT JOIN vw_counties vwc ON st_contains(vwc.way, st_transform(st_geomfromtext('POINT(' || entity.st_x || ' ' || entity.st_y ||')',4326),3857))
|
||||
--consider coordinates inside rvb only
|
||||
LEFT JOIN vw_municipalities vwm ON st_contains(vwm.way, st_transform(st_geomfromtext('POINT(' || entity.st_x || ' ' || entity.st_y ||')',4326),3857))
|
||||
--consider counties of rvb only
|
||||
WHERE (vwc.name = ANY (ARRAY['Braunschweig','Salzgitter','Wolfsburg','Gifhorn','Landkreis Goslar','Landkreis Helmstedt','Landkreis Peine','Landkreis Wolfenbüttel']))
|
||||
ORDER BY vwc.name, vwm.name, entity.name;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS :schema.tbl_taxi AS SELECT * FROM :schema.vw_taxi;
|
Loading…
Reference in New Issue