Skip to content

Commit

Permalink
adding postal_code to roads, see #14
Browse files Browse the repository at this point in the history
  • Loading branch information
britiger committed Nov 25, 2017
1 parent bf349f5 commit bd4fb58
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion export_data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 ..."
Expand Down
5 changes: 5 additions & 0 deletions mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@
"name": "name",
"key": "name"
},
{
"type": "string",
"name": "postal_code",
"key": "postal_code"
},
{
"type": "string",
"name": "addr:suburb",
Expand Down
2 changes: 1 addition & 1 deletion sql/copyTables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
1 change: 1 addition & 0 deletions sql/importCreateTables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ CREATE TABLE import.osm_roads
osm_id bigint,
name text,
highway text,
postal_code text,
"addr:suburb" text,
geometry geometry
);
Expand Down
1 change: 1 addition & 0 deletions sql/importCreateViews.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion sql/planetCreateViews.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down

0 comments on commit bd4fb58

Please sign in to comment.