diff --git a/export_data.sh b/export_data.sh index 5154902..c915f7c 100755 --- a/export_data.sh +++ b/export_data.sh @@ -15,7 +15,7 @@ mkdir -p export # Export roads by city echo_time "Export roads to export/city_roads.csv ..." -psql -c "COPY (SELECT cr.road_name, oa.name city_name FROM import.city_roads cr LEFT JOIN import.osm_admin oa ON cr.city_osm_id=oa.osm_id GROUP BY cr.road_name, oa.name) TO STDOUT WITH (FORMAT CSV, HEADER, FORCE_QUOTE *);" > export/city_roads.csv +psql -c "COPY (SELECT cr.road_name, oa.name city_name, cr.postal_code_tags FROM import.city_roads cr LEFT JOIN import.osm_admin oa ON cr.city_osm_id=oa.osm_id GROUP BY cr.road_name, oa.name, cr.postal_code_tags) TO STDOUT WITH (FORMAT CSV, HEADER, FORCE_QUOTE *);" > export/city_roads.csv # Export postcode by city echo_time "Export postcodes to export/city_postcode.csv ..." diff --git a/mapping.json b/mapping.json index 43c8bd0..3163a3c 100644 --- a/mapping.json +++ b/mapping.json @@ -222,6 +222,11 @@ "name": "name", "key": "name" }, + { + "type": "string", + "name": "postal_code", + "key": "postal_code" + }, { "type": "string", "name": "addr:suburb", diff --git a/sql/copyTables.sql b/sql/copyTables.sql index 611d8b8..8c21d72 100644 --- a/sql/copyTables.sql +++ b/sql/copyTables.sql @@ -28,7 +28,7 @@ GROUP BY osm_id, class, name, type, population; -- osm_roads INSERT INTO import.osm_roads -SELECT osm_id, name, highway, "addr:suburb", geometry +SELECT osm_id, name, highway, postal_code, "addr:suburb", geometry FROM osm_roads WHERE osm_id IN (SELECT osm_id FROM update_roads WHERE update_type!='D'); UPDATE import.osm_roads SET geometry=ST_ExteriorRing(geometry) WHERE ST_geometrytype(geometry) = 'ST_Polygon'; diff --git a/sql/importCreateTables.sql b/sql/importCreateTables.sql index b058534..2785d3d 100644 --- a/sql/importCreateTables.sql +++ b/sql/importCreateTables.sql @@ -40,6 +40,7 @@ CREATE TABLE import.osm_roads osm_id bigint, name text, highway text, + postal_code text, "addr:suburb" text, geometry geometry ); diff --git a/sql/importCreateViews.sql b/sql/importCreateViews.sql index 1070080..328c6ad 100644 --- a/sql/importCreateViews.sql +++ b/sql/importCreateViews.sql @@ -75,6 +75,7 @@ road.name AS road_name, city.osm_id AS city_osm_id, "addr:suburb" as suburb, string_agg(road.osm_id::text, ',') as road_osm_ids, +string_agg(DISTINCT road.postal_code::text, ',') as postal_code_tags, string_agg(DISTINCT road.highway::text, ',') as highway_tags, ST_UNION(road.geometry) as roads_geom FROM import.osm_roads as road, diff --git a/sql/planetCreateViews.sql b/sql/planetCreateViews.sql index 65ac111..56666b3 100644 --- a/sql/planetCreateViews.sql +++ b/sql/planetCreateViews.sql @@ -57,7 +57,7 @@ CREATE OR REPLACE VIEW osm_associated AS -- osm_roads CREATE OR REPLACE VIEW osm_roads AS - SELECT osm_id, name, highway, NULLIF("addr:suburb",'') AS "addr:suburb", geometry + SELECT osm_id, name, highway, NULLIF(postal_code,'') AS postal_code, NULLIF("addr:suburb",'') AS "addr:suburb", geometry FROM imposm_roads WHERE name<>'' AND highway<>'' AND highway NOT IN('platform', 'bus_stop', 'proposed');