From 5bb5ae7a516f11573e17a7f76027ca3f3a55b952 Mon Sep 17 00:00:00 2001 From: Spencer Gardner Date: Sat, 27 Aug 2016 15:38:41 -0500 Subject: [PATCH 01/94] Initial commit --- README.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 00000000..c3531769 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# pfb \ No newline at end of file From 01ad2b23627ab27320b42814954bcc466d7d5c61 Mon Sep 17 00:00:00 2001 From: Spencer Gardner Date: Sat, 27 Aug 2016 16:43:33 -0500 Subject: [PATCH 02/94] initial commit --- README.md | 3 ++- mapconfig_pfb.xml | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 mapconfig_pfb.xml diff --git a/README.md b/README.md index c3531769..6df70deb 100644 --- a/README.md +++ b/README.md @@ -1 +1,2 @@ -# pfb \ No newline at end of file +# pfb +osm2pgrouting mapconfig file diff --git a/mapconfig_pfb.xml b/mapconfig_pfb.xml new file mode 100644 index 00000000..8a78ca13 --- /dev/null +++ b/mapconfig_pfb.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From c36c1d7d7e435e9dfd8eeffee857cef7872fdd55 Mon Sep 17 00:00:00 2001 From: Spencer Gardner Date: Sat, 27 Aug 2016 23:08:07 -0500 Subject: [PATCH 03/94] stress --- stress.sql | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 stress.sql diff --git a/stress.sql b/stress.sql new file mode 100644 index 00000000..f1236958 --- /dev/null +++ b/stress.sql @@ -0,0 +1,2 @@ +ALTER TABLE ways ADD COLUMN stress INT; +ALTER TABLE ways ADD COLUMN reverse_stress INT; From da30aeef9532a7f7a1c4beec70d5e8bab6b1efaa Mon Sep 17 00:00:00 2001 From: Spencer Date: Mon, 29 Aug 2016 16:29:01 -0500 Subject: [PATCH 04/94] validation --- stress validation.sql | 494 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 494 insertions(+) create mode 100644 stress validation.sql diff --git a/stress validation.sql b/stress validation.sql new file mode 100644 index 00000000..b34d156f --- /dev/null +++ b/stress validation.sql @@ -0,0 +1,494 @@ +-- remove non-highways and unbikeable links +DELETE FROM boston_massachusetts_osm_line WHERE highway IS NULL; +DELETE FROM boston_massachusetts_osm_line WHERE highway IN ( + 'proposed','steps','track','construction','corridor','crossing','elevator', + 'platform','unsurfaced' +); + +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = NULL, + seg_stress_tf = NULL; + +-- paths +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 1, + seg_stress_tf = 1 +WHERE highway IN ('cycleway','path','living_street') +OR (highway = 'pedestrian' AND bicycle IN ('designated','destination','yes')) +OR (highway = 'footway' AND bicycle IN ('designated','destination','yes')); + +-- motorways +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 4, + seg_stress_tf = 4 +WHERE highway IN ('motorway','motorway_link'); + +-- residential +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 1, + seg_stress_tf = 1 +WHERE highway = 'residential'; + +------------------------------------------------------ +-- handle cases where speed limit and lanes present +------------------------------------------------------ +-- bike lanes +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 1, + seg_stress_tf = 1 +WHERE lanes::INT IN (2,3) +AND speed::INT = 25 +AND (bicycle='lane' OR cycleway='lane') +AND seg_stress_ft IS NULL; +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 2, + seg_stress_tf = 2 +WHERE lanes::INT IN (4,5) +AND speed::INT = 25 +AND (bicycle='lane' OR cycleway='lane') +AND seg_stress_ft IS NULL; +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 2, + seg_stress_tf = 2 +WHERE lanes::INT IN (2,3) +AND speed::INT = 30 +AND (bicycle='lane' OR cycleway='lane') +AND seg_stress_ft IS NULL; +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 3, + seg_stress_tf = 3 +WHERE lanes::INT > 5 +AND speed::INT = 25 +AND (bicycle='lane' OR cycleway='lane') +AND seg_stress_ft IS NULL; +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 3, + seg_stress_tf = 3 +WHERE lanes::INT IN (4,5) +AND speed::INT = 30 +AND (bicycle='lane' OR cycleway='lane') +AND seg_stress_ft IS NULL; +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 3, + seg_stress_tf = 3 +WHERE lanes::INT > 5 +AND speed::INT = 30 +AND (bicycle='lane' OR cycleway='lane') +AND seg_stress_ft IS NULL; +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 3, + seg_stress_tf = 3 +WHERE lanes::INT IN (2,3) +AND speed::INT >= 35 +AND (bicycle='lane' OR cycleway='lane') +AND seg_stress_ft IS NULL; +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 3, + seg_stress_tf = 3 +WHERE lanes::INT IN (4,5) +AND speed::INT >= 35 +AND (bicycle='lane' OR cycleway='lane') +AND seg_stress_ft IS NULL; +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 4, + seg_stress_tf = 4 +WHERE lanes::INT > 5 +AND speed::INT >= 35 +AND (bicycle='lane' OR cycleway='lane') +AND seg_stress_ft IS NULL; + +-- buffered bike lanes +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 1, + seg_stress_tf = 1 +WHERE lanes::INT IN (2,3) +AND speed::INT = 25 +AND cycleway='buffered_lane' +AND seg_stress_ft IS NULL; +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 2, + seg_stress_tf = 2 +WHERE lanes::INT IN (4,5) +AND speed::INT = 25 +AND cycleway='buffered_lane' +AND seg_stress_ft IS NULL; +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 2, + seg_stress_tf = 2 +WHERE lanes::INT IN (2,3) +AND speed::INT = 30 +AND cycleway='buffered_lane' +AND seg_stress_ft IS NULL; +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 2, + seg_stress_tf = 2 +WHERE lanes::INT > 5 +AND speed::INT = 25 +AND cycleway='buffered_lane' +AND seg_stress_ft IS NULL; +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 2, + seg_stress_tf = 2 +WHERE lanes::INT IN (4,5) +AND speed::INT = 30 +AND cycleway='buffered_lane' +AND seg_stress_ft IS NULL; +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 2, + seg_stress_tf = 2 +WHERE lanes::INT > 5 +AND speed::INT = 30 +AND cycleway='buffered_lane' +AND seg_stress_ft IS NULL; +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 3, + seg_stress_tf = 3 +WHERE lanes::INT IN (2,3) +AND speed::INT >= 35 +AND cycleway='buffered_lane' +AND seg_stress_ft IS NULL; +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 3, + seg_stress_tf = 3 +WHERE lanes::INT IN (4,5) +AND speed::INT >= 35 +AND cycleway='buffered_lane' +AND seg_stress_ft IS NULL; +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 3, + seg_stress_tf = 3 +WHERE lanes::INT > 5 +AND speed::INT >= 35 +AND cycleway='buffered_lane' +AND seg_stress_ft IS NULL; + +-- protected bike lanes +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 1, + seg_stress_tf = 1 +WHERE lanes::INT IN (2,3) +AND speed::INT = 25 +AND cycleway='track' +AND seg_stress_ft IS NULL; +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 1, + seg_stress_tf = 1 +WHERE lanes::INT IN (4,5) +AND speed::INT = 25 +AND cycleway='track' +AND seg_stress_ft IS NULL; +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 1, + seg_stress_tf = 1 +WHERE lanes::INT IN (2,3) +AND speed::INT = 30 +AND cycleway='track' +AND seg_stress_ft IS NULL; +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 2, + seg_stress_tf = 2 +WHERE lanes::INT > 5 +AND speed::INT = 25 +AND cycleway='track' +AND seg_stress_ft IS NULL; +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 2, + seg_stress_tf = 2 +WHERE lanes::INT IN (4,5) +AND speed::INT = 30 +AND cycleway='track' +AND seg_stress_ft IS NULL; +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 2, + seg_stress_tf = 2 +WHERE lanes::INT > 5 +AND speed::INT = 30 +AND cycleway='track' +AND seg_stress_ft IS NULL; +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 2, + seg_stress_tf = 2 +WHERE lanes::INT IN (2,3) +AND speed::INT >= 35 +AND cycleway='track' +AND seg_stress_ft IS NULL; +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 2, + seg_stress_tf = 2 +WHERE lanes::INT IN (4,5) +AND speed::INT >= 35 +AND cycleway='track' +AND seg_stress_ft IS NULL; +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 3, + seg_stress_tf = 3 +WHERE lanes::INT > 5 +AND speed::INT >= 35 +AND cycleway='track' +AND seg_stress_ft IS NULL; + +-- shared +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 2, + seg_stress_tf = 2 +WHERE lanes::INT IN (2,3) +AND speed::INT = 25 +AND seg_stress_ft IS NULL; +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 3, + seg_stress_tf = 3 +WHERE lanes::INT IN (4,5) +AND speed::INT = 25 +AND seg_stress_ft IS NULL; +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 3, + seg_stress_tf = 3 +WHERE lanes::INT IN (2,3) +AND speed::INT = 30 +AND seg_stress_ft IS NULL; +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 4, + seg_stress_tf = 4 +WHERE lanes::INT > 5 +AND speed::INT = 25 +AND seg_stress_ft IS NULL; +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 4, + seg_stress_tf = 4 +WHERE lanes::INT IN (4,5) +AND speed::INT = 30 +AND seg_stress_ft IS NULL; +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 4, + seg_stress_tf = 4 +WHERE lanes::INT > 5 +AND speed::INT = 30 +AND seg_stress_ft IS NULL; +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 4, + seg_stress_tf = 4 +WHERE lanes::INT IN (2,3) +AND speed::INT >= 35 +AND seg_stress_ft IS NULL; +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 4, + seg_stress_tf = 4 +WHERE lanes::INT IN (4,5) +AND speed::INT >= 35 +AND seg_stress_ft IS NULL; +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 4, + seg_stress_tf = 4 +WHERE lanes::INT > 5 +AND speed::INT >= 35 +AND seg_stress_ft IS NULL; + + +------------------------------------------------------ +-- handle speeds but no lane data +------------------------------------------------------ +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 4, + seg_stress_tf = 4 +WHERE speed::INT >= 35 +AND seg_stress_ft IS NULL; + +-- 25 +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 2, + seg_stress_tf = 2 +WHERE speed::INT = 25 +AND highway IN ('primary','primary_link','trunk','trunk_link') +AND cycleway = 'track' +AND seg_stress_ft IS NULL; +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 3, + seg_stress_tf = 3 +WHERE speed::INT = 25 +AND highway IN ('primary','primary_link','trunk','trunk_link') +AND (bicycle='lane' OR cycleway IN ('lane','buffered_lane')) +AND seg_stress_ft IS NULL; +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 1, + seg_stress_tf = 1 +WHERE speed::INT = 25 +AND highway IN ('tertiary','tertiary_link','secondary','secondary_link') +AND cycleway IN ('buffered_lane','track') +AND seg_stress_ft IS NULL; +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 2, + seg_stress_tf = 2 +WHERE speed::INT = 25 +AND highway IN ('tertiary','tertiary_link','secondary','secondary_link') +AND (bicycle='lane' OR cycleway IN ('lane')) +AND seg_stress_ft IS NULL; + +-- 30 +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 2, + seg_stress_tf = 2 +WHERE speed::INT = 30 +AND highway IN ('primary','primary_link','trunk','trunk_link') +AND cycleway = 'track' +AND seg_stress_ft IS NULL; +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 3, + seg_stress_tf = 3 +WHERE speed::INT = 30 +AND highway IN ('primary','primary_link','trunk','trunk_link') +AND (bicycle='lane' OR cycleway IN ('lane','buffered_lane')) +AND seg_stress_ft IS NULL; +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 2, + seg_stress_tf = 2 +WHERE speed::INT = 30 +AND highway IN ('tertiary','tertiary_link','secondary','secondary_link') +AND cycleway IN ('buffered_lane','track') +AND seg_stress_ft IS NULL; +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 3, + seg_stress_tf = 3 +WHERE speed::INT = 30 +AND highway IN ('tertiary','tertiary_link','secondary','secondary_link') +AND seg_stress_ft IS NULL; + +-- anything primary/trunk without bike facilities +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 4, + seg_stress_tf = 4 +WHERE speed IS NOT NULL +AND highway IN ('primary','primary_link','trunk','trunk_link') +AND seg_stress_ft IS NULL; + +-- anything with speed > 30 +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 4, + seg_stress_tf = 4 +WHERE speed::INT > 30 +AND seg_stress_ft IS NULL; + +------------------------------------------------------ +-- lane data but no speeds +------------------------------------------------------ +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 4, + seg_stress_tf = 4 +WHERE lanes::INT > 5 +AND seg_stress_ft IS NULL; + +-- 2-3 +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 1, + seg_stress_tf = 1 +WHERE lanes::INT IN (2,3) +AND highway IN ('tertiary','tertiary_link','secondary','secondary_link') +AND (bicycle='lane' OR cycleway IN ('lane','buffered_lane','track')) +AND seg_stress_ft IS NULL; +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 2, + seg_stress_tf = 2 +WHERE lanes::INT IN (2,3) +AND highway IN ('tertiary','tertiary_link') +AND seg_stress_ft IS NULL; +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 3, + seg_stress_tf = 3 +WHERE lanes::INT IN (2,3) +AND highway IN ('secondary','secondary_link') +AND seg_stress_ft IS NULL; +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 3, + seg_stress_tf = 3 +WHERE lanes::INT IN (2,3) +AND highway IN ('primary','primary_link','trunk','trunk_link') +AND seg_stress_ft IS NULL; + +-- 4-5 +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 2, + seg_stress_tf = 2 +WHERE lanes::INT IN (4,5) +AND highway IN ('tertiary','tertiary_link','secondary','secondary_link') +AND cycleway IN ('track') +AND seg_stress_ft IS NULL; +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 4, + seg_stress_tf = 4 +WHERE lanes::INT IN (4,5) +AND highway IN ('tertiary','tertiary_link','secondary','secondary_link') +AND seg_stress_ft IS NULL; + +-- anything primary/trunk without bike facilities +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 4, + seg_stress_tf = 4 +WHERE lanes IS NOT NULL +AND highway IN ('primary','primary_link','trunk','trunk_link') +AND seg_stress_ft IS NULL; + +--anything more than 5 lanes +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 4, + seg_stress_tf = 4 +WHERE lanes::INT > 5 +AND seg_stress_ft IS NULL; + + +------------------------------------------------------ +-- no lane or speed data +------------------------------------------------------ +-- bike lanes +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 2, + seg_stress_tf = 2 +WHERE highway IN ('tertiary','tertiary_link') +AND (bicycle='lane' OR cycleway = 'lane') +AND seg_stress_ft IS NULL; +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 3, + seg_stress_tf = 3 +WHERE (bicycle='lane' OR cycleway = 'lane') +AND seg_stress_ft IS NULL; + +-- buffered lanes +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 2, + seg_stress_tf = 2 +WHERE highway IN ('tertiary','tertiary_link') +AND cycleway = 'buffered_lane' +AND seg_stress_ft IS NULL; +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 2, + seg_stress_tf = 2 +WHERE highway IN ('secondary','secondary_link') +AND cycleway = 'buffered_lane' +AND seg_stress_ft IS NULL; + +-- tracks +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 1, + seg_stress_tf = 1 +WHERE highway IN ('tertiary','tertiary_link','secondary','secondary_link') +AND cycleway = 'track' +AND seg_stress_ft IS NULL; +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 2, + seg_stress_tf = 2 +WHERE cycleway = 'track' +AND seg_stress_ft IS NULL; + +-- shared +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 3, + seg_stress_tf = 3 +WHERE highway IN ('tertiary','tertiary_link') +AND seg_stress_ft IS NULL; +UPDATE boston_massachusetts_osm_line +SET seg_stress_ft = 4, + seg_stress_tf = 4 +WHERE highway IN ('secondary','secondary_link') +AND seg_stress_ft IS NULL; +-- UPDATE boston_massachusetts_osm_line +-- SET seg_stress_ft = 4, +-- seg_stress_tf = 4 +-- WHERE seg_stress_ft IS NULL; From 0915e503fd206cd375742fcd3093b5eb2e83d908 Mon Sep 17 00:00:00 2001 From: Spencer Date: Thu, 15 Sep 2016 17:19:37 -0500 Subject: [PATCH 05/94] sldfkjd --- functional_class.sql | 54 +++++ import osm.sh | 81 +++++++ mapconfig_cycleway.xml | 15 ++ mapconfig_pfb.xml => mapconfig_highway.xml | 1 - pfb.style | 243 +++++++++++++++++++++ prepare_tables.sql | 74 +++++++ process.txt | 4 + speed_limit.sql | 0 stress validation.sql | 32 +-- 9 files changed, 487 insertions(+), 17 deletions(-) create mode 100644 functional_class.sql create mode 100644 import osm.sh create mode 100644 mapconfig_cycleway.xml rename mapconfig_pfb.xml => mapconfig_highway.xml (99%) create mode 100644 pfb.style create mode 100644 prepare_tables.sql create mode 100644 process.txt create mode 100644 speed_limit.sql diff --git a/functional_class.sql b/functional_class.sql new file mode 100644 index 00000000..7a30c6b1 --- /dev/null +++ b/functional_class.sql @@ -0,0 +1,54 @@ +---------------------------------------- +-- INPUTS +-- location: cambridge +---------------------------------------- + +UPDATE cambridge_ways +SET functional_class = osm.highway +FROM cambridge_osm_full_line osm +WHERE cambridge_ways.osm_id = osm.osm_id +AND osm.highway IN ( + 'motorway', + 'tertiary', + 'trunk', + 'tertiary_link', + 'motorway_link', + 'secondary_link', + 'primary_link', + 'trunk_link', + 'residential', + 'secondary', + 'primary', + 'living_street' +); -- note that we're leaving out "road" and "unclassified" + +UPDATE cambridge_ways +SET functional_class = 'track' +FROM cambridge_osm_full_line osm +WHERE cambridge_ways.osm_id = osm.osm_id +AND osm.highway = 'track' +AND osm.tracktype = 'grade1'; + +UPDATE cambridge_ways +SET functional_class = 'path' +FROM cambridge_osm_full_line osm +WHERE cambridge_ways.osm_id = osm.osm_id +AND osm.highway IN ('cycleway','path'); + +UPDATE cambridge_ways +SET functional_class = 'path' +FROM cambridge_osm_full_line osm +WHERE cambridge_ways.osm_id = osm.osm_id +AND osm.highway = 'footway' +AND osm.bicycle IN ('yes','permissive') +AND (osm.access IS NULL OR osm.access NOT IN ('no','private')); + +UPDATE cambridge_ways +SET functional_class = 'living_street' +FROM cambridge_osm_full_line osm +WHERE cambridge_ways.osm_id = osm.osm_id +AND osm.highway = 'pedestrian' +AND osm.bicycle IN ('yes','permissive') +AND (osm.access IS NULL OR osm.access NOT IN ('no','private')); + +--elevators? diff --git a/import osm.sh b/import osm.sh new file mode 100644 index 00000000..47e4000d --- /dev/null +++ b/import osm.sh @@ -0,0 +1,81 @@ +# vars +OSMPREFIX='cambridge' +OSMFILE='/home/spencer/gis/boston_massachusetts.osm' + +# drop old tables +psql -h 192.168.40.225 -U gis -d people_for_bikes \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_ways;" +psql -h 192.168.40.225 -U gis -d people_for_bikes \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_ways_intersections;" +psql -h 192.168.40.225 -U gis -d people_for_bikes \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_relations_ways;" +psql -h 192.168.40.225 -U gis -d people_for_bikes \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_nodes;" +psql -h 192.168.40.225 -U gis -d people_for_bikes \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_relations;" +psql -h 192.168.40.225 -U gis -d people_for_bikes \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_way_classes;" +psql -h 192.168.40.225 -U gis -d people_for_bikes \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_way_tags;" +psql -h 192.168.40.225 -U gis -d people_for_bikes \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_way_types;" + +# import the osm optimized for routing +osm2pgrouting \ + -f $OSMFILE \ + -h 192.168.40.225 \ + --dbname people_for_bikes \ + --username gis \ + --schema received \ + --prefix ${OSMPREFIX}_ \ + --clean + +# rename a few tables +psql -h 192.168.40.225 -U gis -d people_for_bikes \ + -c "ALTER TABLE received.${OSMPREFIX}_ways_vertices_pgr RENAME TO ${OSMPREFIX}_ways_intersections;" +psql -h 192.168.40.225 -U gis -d people_for_bikes \ + -c "ALTER TABLE received.osm_nodes RENAME TO ${OSMPREFIX}_osm_nodes;" +psql -h 192.168.40.225 -U gis -d people_for_bikes \ + -c "ALTER TABLE received.osm_relations RENAME TO ${OSMPREFIX}_osm_relations;" +psql -h 192.168.40.225 -U gis -d people_for_bikes \ + -c "ALTER TABLE received.osm_way_classes RENAME TO ${OSMPREFIX}_osm_way_classes;" +psql -h 192.168.40.225 -U gis -d people_for_bikes \ + -c "ALTER TABLE received.osm_way_tags RENAME TO ${OSMPREFIX}_osm_way_tags;" +psql -h 192.168.40.225 -U gis -d people_for_bikes \ + -c "ALTER TABLE received.osm_way_types RENAME TO ${OSMPREFIX}_osm_way_types;" + + +# import full osm to fill out additional data needs +# not met by osm2pgrouting + +# drop old tables +psql -h 192.168.40.225 -U gis -d people_for_bikes \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_full_line;" +psql -h 192.168.40.225 -U gis -d people_for_bikes \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_full_point;" +psql -h 192.168.40.225 -U gis -d people_for_bikes \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_full_polygon;" +psql -h 192.168.40.225 -U gis -d people_for_bikes \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_full_roads;" + +# import +osm2pgsql \ + --host 192.168.40.225 \ + --username gis \ + --port 5432 \ + --create \ + --database people_for_bikes \ + --prefix ${OSMPREFIX}_osm_full \ + --proj 2249 \ + --style /home/spencer/dev/pfb/pfb.style \ + /home/spencer/gis/boston_massachusetts.osm + +# move the full osm tables to the received schema +psql -h 192.168.40.225 -U gis -d people_for_bikes \ + -c "ALTER TABLE generated.${OSMPREFIX}_osm_full_line SET SCHEMA received;" +psql -h 192.168.40.225 -U gis -d people_for_bikes \ + -c "ALTER TABLE generated.${OSMPREFIX}_osm_full_point SET SCHEMA received;" +psql -h 192.168.40.225 -U gis -d people_for_bikes \ + -c "ALTER TABLE generated.${OSMPREFIX}_osm_full_polygon SET SCHEMA received;" +psql -h 192.168.40.225 -U gis -d people_for_bikes \ + -c "ALTER TABLE generated.${OSMPREFIX}_osm_full_roads SET SCHEMA received;" diff --git a/mapconfig_cycleway.xml b/mapconfig_cycleway.xml new file mode 100644 index 00000000..6745678f --- /dev/null +++ b/mapconfig_cycleway.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + +import all and then import only highways and copy in anything that doesn't already +exist diff --git a/mapconfig_pfb.xml b/mapconfig_highway.xml similarity index 99% rename from mapconfig_pfb.xml rename to mapconfig_highway.xml index 8a78ca13..9a7bb8e2 100644 --- a/mapconfig_pfb.xml +++ b/mapconfig_highway.xml @@ -25,7 +25,6 @@ - diff --git a/pfb.style b/pfb.style new file mode 100644 index 00000000..12ff9f5c --- /dev/null +++ b/pfb.style @@ -0,0 +1,243 @@ +# This is the default osm2pgsql .style file that comes with osm2pgsql. +# +# A .style file has 4 columns that define how OSM objects end up in tables in +# the database and what columns are created. It interacts with the command-line +# hstore options. +# +# Columns +# ======= +# +# OsmType: This is either "node", "way" or "node,way" and indicates if this tag +# applies to nodes, ways, or both. +# +# Tag: The tag +# +# DataType: The type of the column to be created. Normally "text" +# +# Flags: Flags that indicate what table the OSM object is moved into. +# +# There are 6 possible flags. These flags are used both to indicate if a column +# should be created, and if ways with the tag are assumed to be areas. The area +# assumptions can be overridden with an area=yes/no tag +# +# polygon - Create a column for this tag, and objects with the tag are areas +# +# linear - Create a column for this tag +# +# nocolumn - Override the above and don't create a column for the tag, but do +# include objects with this tag +# +# phstore - Same as polygon,nocolumn for backward compatibility +# +# delete - Drop this tag completely and don't create a column for it. This also +# prevents the tag from being added to hstore columns +# +# nocache - Deprecated and does nothing +# +# If an object has a tag that indicates it is an area or has area=yes/1, +# osm2pgsql will try to turn it into an area. If it succeeds, it places it in +# the polygon table. If it fails (e.g. not a closed way) it places it in the +# line table. +# +# Nodes are never placed into the polygon or line table and are always placed in +# the point table. +# +# Hstore +# ====== +# +# The options --hstore, --hstore-match-only, and --hstore-all interact with +# the .style file. +# +# With --hstore any tags without a column will be added to the hstore column. +# This will also cause all objects to be kept. +# +# With --hstore-match-only the behavior for tags is the same, but objects are +# only kept if they have a non-NULL value in one of the columns. +# +# With --hstore-all all tags are added to the hstore column unless they appear +# in the style file with a delete flag, causing duplication between the normal +# columns and the hstore column. +# +# Special database columns +# ======================== +# +# There are some special database columns that if present in the .style file +# will be populated by osm2pgsql. +# +# These are +# +# z_order - datatype int4 +# +# way_area - datatype real. The area of the way, in the units of the projection +# (e.g. square mercator meters). Only applies to areas +# +# osm_user - datatype text +# osm_uid - datatype integer +# osm_version - datatype integer +# osm_changeset - datatype integer +# osm_timestamp - datatype timestamptz(0). +# Used with the --extra-attributes option to include metadata in the database. +# If importing with both --hstore and --extra-attributes the meta-data will +# end up in the tags hstore column regardless of the style file. + +# OsmType Tag DataType Flags +node,way access text linear +node,way bicycle text linear +node,way bridge text linear +node,way crossing text linear +way cycleway text linear +node,way foot text linear +node,way highway text linear +node,way junction text linear +way lanes text linear +way maxspeed text linear +node,way motorcar text linear +node,way name text linear +node,way oneway text linear +way parking TEXT linear +node,way segregated text linear +node,way stop TEXT linear +node,way surface text linear +way tracktype text linear +node,way traffic_sign text linear +node,way traffic_signals text linear +node,way tunnel text linear +node,way width text linear + + +# node,way addr:housename text linear +# node,way addr:housenumber text linear +# node,way addr:interpolation text linear +# node,way admin_level text linear +# node,way aerialway text linear +# node,way aeroway text polygon +# node,way amenity text polygon +# node,way area text polygon # hard coded support for area=1/yes => polygon is in osm2pgsql +# node,way barrier text linear +# node,way brand text linear +# node,way boundary text linear +# node,way building text polygon +# node capital text linear +# node,way construction text linear +# node,way covered text linear +# node,way culvert text linear +# node,way cutting text linear +# node,way denomination text linear +# node,way disused text linear +# node ele text linear +# node,way embankment text linear +# node,way generator:source text linear +# node,way harbour text polygon +# node,way historic text polygon +# node,way horse text linear +# node,way intermittent text linear +# node,way landuse text polygon +# node,way layer text linear +# node,way leisure text polygon +# node,way lock text linear +# node,way man_made text polygon +# node,way military text polygon +# node,way natural text polygon # natural=coastline tags are discarded by a hard coded rule in osm2pgsql +# node,way office text polygon +# node,way operator text linear +# node,way place text polygon +# node,way population text linear +# node,way power text polygon +# node,way power_source text linear +# node,way public_transport text polygon +# node,way railway text linear +# node,way ref text linear +# node,way religion text linear +# node,way route text linear +# node,way service text linear +# node,way shop text polygon +# node,way sport text polygon +# node,way toll text linear +# node,way tourism text polygon +# node,way tower:type text linear +# node,way water text polygon +# node,way waterway text polygon +# node,way wetland text polygon +# node,way wood text linear +# node,way z_order int4 linear # This is calculated during import +# way way_area real linear # This is calculated during import + +# Area tags +# We don't make columns for these tags, but objects with them are areas. +# Mainly for use with hstore +# way abandoned:aeroway text polygon,nocolumn +# way abandoned:amenity text polygon,nocolumn +# way abandoned:building text polygon,nocolumn +# way abandoned:landuse text polygon,nocolumn +# way abandoned:power text polygon,nocolumn +# way area:highway text polygon,nocolumn + +# Deleted tags +# These are tags that are generally regarded as useless for most rendering. +# Most of them are from imports or intended as internal information for mappers +# Some of them are automatically deleted by editors. +# If you want some of them, perhaps for a debugging layer, just delete the lines. + +# These tags are used by mappers to keep track of data. +# They aren't very useful for rendering. +# node,way note text delete +# node,way note:* text delete +# node,way source text delete +# node,way source_ref text delete +# node,way source:* text delete +# node,way attribution text delete +# node,way comment text delete +# node,way fixme text delete + +# Tags generally dropped by editors, not otherwise covered +# node,way created_by text delete +# node,way odbl text delete +# node,way odbl:note text delete +# node,way SK53_bulk:load text delete + +# Lots of import tags +# TIGER (US) +# node,way tiger:* text delete + +# NHD (US) +# NHD has been converted every way imaginable +# node,way NHD:* text delete +# node,way nhd:* text delete + +# GNIS (US) +# node,way gnis:* text delete + +# Geobase (CA) +# node,way geobase:* text delete +# NHN (CA) +# node,way accuracy:meters text delete +# node,way sub_sea:type text delete +# node,way waterway:type text delete + +# KSJ2 (JA) +# See also note:ja and source_ref above +# node,way KSJ2:* text delete +# Yahoo/ALPS (JA) +# node,way yh:* text delete + +# osak (DK) +# node,way osak:* text delete + +# kms (DK) +# node,way kms:* text delete + +# ngbe (ES) +# See also note:es and source:file above +# node,way ngbe:* text delete + +# naptan (UK) +# node,way naptan:* text delete + +# Corine (CLC) (Europe) +# node,way CLC:* text delete + +# misc +# node,way 3dshapes:ggmodelk text delete +# node,way AND_nosr_r text delete +# node,way import text delete +# node,way it:fvg:* text delete diff --git a/prepare_tables.sql b/prepare_tables.sql new file mode 100644 index 00000000..0e045af0 --- /dev/null +++ b/prepare_tables.sql @@ -0,0 +1,74 @@ +---------------------------------------- +-- INPUTS +-- location: cambridge +-- proj: 2249 +---------------------------------------- + +-- add tdg_id field to roads +ALTER TABLE cambridge_ways ADD COLUMN tdg_id TEXT DEFAULT uuid_generate_v4(); + +-- drop unnecessary columns +ALTER TABLE cambridge_ways DROP COLUMN class_id; +ALTER TABLE cambridge_ways DROP COLUMN length; +ALTER TABLE cambridge_ways DROP COLUMN length_m; +ALTER TABLE cambridge_ways DROP COLUMN x1; +ALTER TABLE cambridge_ways DROP COLUMN y1; +ALTER TABLE cambridge_ways DROP COLUMN x2; +ALTER TABLE cambridge_ways DROP COLUMN y2; +ALTER TABLE cambridge_ways DROP COLUMN cost; +ALTER TABLE cambridge_ways DROP COLUMN reverse_cost; +ALTER TABLE cambridge_ways DROP COLUMN cost_s; +ALTER TABLE cambridge_ways DROP COLUMN reverse_cost_s; +ALTER TABLE cambridge_ways DROP COLUMN rule; +ALTER TABLE cambridge_ways DROP COLUMN maxspeed_forward; +ALTER TABLE cambridge_ways DROP COLUMN maxspeed_backward; +ALTER TABLE cambridge_ways DROP COLUMN source_osm; +ALTER TABLE cambridge_ways DROP COLUMN target_osm; +ALTER TABLE cambridge_ways DROP COLUMN priority; + +ALTER TABLE cambridge_ways_intersections DROP COLUMN cnt; +ALTER TABLE cambridge_ways_intersections DROP COLUMN chk; +ALTER TABLE cambridge_ways_intersections DROP COLUMN ein; +ALTER TABLE cambridge_ways_intersections DROP COLUMN eout; +ALTER TABLE cambridge_ways_intersections DROP COLUMN lon; +ALTER TABLE cambridge_ways_intersections DROP COLUMN lat; + +-- change column names +ALTER TABLE cambridge_ways RENAME COLUMN gid TO road_id; +ALTER TABLE cambridge_ways RENAME COLUMN the_geom TO geom; +ALTER TABLE cambridge_ways RENAME COLUMN source TO intersection_from; +ALTER TABLE cambridge_ways RENAME COLUMN target TO intersection_to; + +ALTER TABLE cambridge_ways_intersections RENAME COLUMN id TO int_id; +ALTER TABLE cambridge_ways_intersections RENAME COLUMN the_geom TO geom; + +-- reproject +ALTER TABLE cambridge_ways ALTER COLUMN geom TYPE geometry(linestring,2249) +USING ST_Transform(geom,2249); +ALTER TABLE cambridge_ways_intersections ALTER COLUMN geom TYPE geometry(point,2249) +USING ST_Transform(geom,2249); + +-- add columns +ALTER TABLE cambridge_ways ADD COLUMN functional_class TEXT; +ALTER TABLE cambridge_ways ADD COLUMN speed_limit INT; +ALTER TABLE cambridge_ways ADD COLUMN width_ft INT; +ALTER TABLE cambridge_ways ADD COLUMN ft_bike_infra TEXT; +ALTER TABLE cambridge_ways ADD COLUMN tf_bike_infra TEXT; +ALTER TABLE cambridge_ways ADD COLUMN ft_lanes INT; +ALTER TABLE cambridge_ways ADD COLUMN tf_lanes INT; +ALTER TABLE cambridge_ways ADD COLUMN ft_park INT; +ALTER TABLE cambridge_ways ADD COLUMN tf_park INT; +ALTER TABLE cambridge_ways ADD COLUMN ft_seg_stress INT; +ALTER TABLE cambridge_ways ADD COLUMN ft_int_stress INT; +ALTER TABLE cambridge_ways ADD COLUMN tf_seg_stress INT; +ALTER TABLE cambridge_ways ADD COLUMN tf_int_stress INT; + +-- indexes +CREATE INDEX idx_cambridge_ways_osm ON cambridge_ways (osm_id); +CREATE INDEX idx_cambridge_ways_ints_osm ON cambridge_ways_intersections (osm_id); +CREATE INDEX idx_cambridge_fullways ON cambridge_osm_full_line (osm_id); +CREATE INDEX idx_cambrdige_fullpoints ON cambridge_osm_full_point (osm_id); +ANALYZE cambridge_ways (osm_id); +ANALYZE cambridge_ways_intersections (osm_id); +ANALYZE cambridge_osm_full_line (osm_id); +ANALYZE cambridge_osm_full_point (osm_id); diff --git a/process.txt b/process.txt new file mode 100644 index 00000000..7b60d4f1 --- /dev/null +++ b/process.txt @@ -0,0 +1,4 @@ +1: Run "import osm.sh" +2: Run prepare_tables.sql +3: Run functional_class.sql +4: Run speed_limit.sql diff --git a/speed_limit.sql b/speed_limit.sql new file mode 100644 index 00000000..e69de29b diff --git a/stress validation.sql b/stress validation.sql index b34d156f..f392e843 100644 --- a/stress validation.sql +++ b/stress validation.sql @@ -36,7 +36,7 @@ WHERE highway = 'residential'; UPDATE boston_massachusetts_osm_line SET seg_stress_ft = 1, seg_stress_tf = 1 -WHERE lanes::INT IN (2,3) +WHERE lanes::INT IN (1,2,3) AND speed::INT = 25 AND (bicycle='lane' OR cycleway='lane') AND seg_stress_ft IS NULL; @@ -50,7 +50,7 @@ AND seg_stress_ft IS NULL; UPDATE boston_massachusetts_osm_line SET seg_stress_ft = 2, seg_stress_tf = 2 -WHERE lanes::INT IN (2,3) +WHERE lanes::INT IN (1,2,3) AND speed::INT = 30 AND (bicycle='lane' OR cycleway='lane') AND seg_stress_ft IS NULL; @@ -78,7 +78,7 @@ AND seg_stress_ft IS NULL; UPDATE boston_massachusetts_osm_line SET seg_stress_ft = 3, seg_stress_tf = 3 -WHERE lanes::INT IN (2,3) +WHERE lanes::INT IN (1,2,3) AND speed::INT >= 35 AND (bicycle='lane' OR cycleway='lane') AND seg_stress_ft IS NULL; @@ -101,7 +101,7 @@ AND seg_stress_ft IS NULL; UPDATE boston_massachusetts_osm_line SET seg_stress_ft = 1, seg_stress_tf = 1 -WHERE lanes::INT IN (2,3) +WHERE lanes::INT IN (1,2,3) AND speed::INT = 25 AND cycleway='buffered_lane' AND seg_stress_ft IS NULL; @@ -115,7 +115,7 @@ AND seg_stress_ft IS NULL; UPDATE boston_massachusetts_osm_line SET seg_stress_ft = 2, seg_stress_tf = 2 -WHERE lanes::INT IN (2,3) +WHERE lanes::INT IN (1,2,3) AND speed::INT = 30 AND cycleway='buffered_lane' AND seg_stress_ft IS NULL; @@ -143,7 +143,7 @@ AND seg_stress_ft IS NULL; UPDATE boston_massachusetts_osm_line SET seg_stress_ft = 3, seg_stress_tf = 3 -WHERE lanes::INT IN (2,3) +WHERE lanes::INT IN (1,2,3) AND speed::INT >= 35 AND cycleway='buffered_lane' AND seg_stress_ft IS NULL; @@ -166,7 +166,7 @@ AND seg_stress_ft IS NULL; UPDATE boston_massachusetts_osm_line SET seg_stress_ft = 1, seg_stress_tf = 1 -WHERE lanes::INT IN (2,3) +WHERE lanes::INT IN (1,2,3) AND speed::INT = 25 AND cycleway='track' AND seg_stress_ft IS NULL; @@ -180,7 +180,7 @@ AND seg_stress_ft IS NULL; UPDATE boston_massachusetts_osm_line SET seg_stress_ft = 1, seg_stress_tf = 1 -WHERE lanes::INT IN (2,3) +WHERE lanes::INT IN (1,2,3) AND speed::INT = 30 AND cycleway='track' AND seg_stress_ft IS NULL; @@ -208,7 +208,7 @@ AND seg_stress_ft IS NULL; UPDATE boston_massachusetts_osm_line SET seg_stress_ft = 2, seg_stress_tf = 2 -WHERE lanes::INT IN (2,3) +WHERE lanes::INT IN (1,2,3) AND speed::INT >= 35 AND cycleway='track' AND seg_stress_ft IS NULL; @@ -231,7 +231,7 @@ AND seg_stress_ft IS NULL; UPDATE boston_massachusetts_osm_line SET seg_stress_ft = 2, seg_stress_tf = 2 -WHERE lanes::INT IN (2,3) +WHERE lanes::INT IN (1,2,3) AND speed::INT = 25 AND seg_stress_ft IS NULL; UPDATE boston_massachusetts_osm_line @@ -243,7 +243,7 @@ AND seg_stress_ft IS NULL; UPDATE boston_massachusetts_osm_line SET seg_stress_ft = 3, seg_stress_tf = 3 -WHERE lanes::INT IN (2,3) +WHERE lanes::INT IN (1,2,3) AND speed::INT = 30 AND seg_stress_ft IS NULL; UPDATE boston_massachusetts_osm_line @@ -267,7 +267,7 @@ AND seg_stress_ft IS NULL; UPDATE boston_massachusetts_osm_line SET seg_stress_ft = 4, seg_stress_tf = 4 -WHERE lanes::INT IN (2,3) +WHERE lanes::INT IN (1,2,3) AND speed::INT >= 35 AND seg_stress_ft IS NULL; UPDATE boston_massachusetts_osm_line @@ -380,26 +380,26 @@ AND seg_stress_ft IS NULL; UPDATE boston_massachusetts_osm_line SET seg_stress_ft = 1, seg_stress_tf = 1 -WHERE lanes::INT IN (2,3) +WHERE lanes::INT IN (1,2,3) AND highway IN ('tertiary','tertiary_link','secondary','secondary_link') AND (bicycle='lane' OR cycleway IN ('lane','buffered_lane','track')) AND seg_stress_ft IS NULL; UPDATE boston_massachusetts_osm_line SET seg_stress_ft = 2, seg_stress_tf = 2 -WHERE lanes::INT IN (2,3) +WHERE lanes::INT IN (1,2,3) AND highway IN ('tertiary','tertiary_link') AND seg_stress_ft IS NULL; UPDATE boston_massachusetts_osm_line SET seg_stress_ft = 3, seg_stress_tf = 3 -WHERE lanes::INT IN (2,3) +WHERE lanes::INT IN (1,2,3) AND highway IN ('secondary','secondary_link') AND seg_stress_ft IS NULL; UPDATE boston_massachusetts_osm_line SET seg_stress_ft = 3, seg_stress_tf = 3 -WHERE lanes::INT IN (2,3) +WHERE lanes::INT IN (1,2,3) AND highway IN ('primary','primary_link','trunk','trunk_link') AND seg_stress_ft IS NULL; From 61940cd0f364582e121b6be8ee140b2b1ba0255e Mon Sep 17 00:00:00 2001 From: Spencer Gardner Date: Fri, 16 Sep 2016 00:34:39 -0500 Subject: [PATCH 06/94] sdflkjsdf --- functional_class.sql | 8 +++ import osm.sh | 81 ---------------------------- import_osm.sh | 120 +++++++++++++++++++++++++++++++++++++++++ lanes.sql | 52 ++++++++++++++++++ mapconfig_all.xml | 37 +++++++++++++ mapconfig_cycleway.xml | 15 ------ mapconfig_highway.xml | 16 ------ one_way.sql | 19 +++++++ prepare_tables.sql | 31 ++++++++++- process.txt | 9 ++-- speed_limit.sql | 11 ++++ width_ft.sql | 87 ++++++++++++++++++++++++++++++ 12 files changed, 370 insertions(+), 116 deletions(-) delete mode 100644 import osm.sh create mode 100644 import_osm.sh create mode 100644 lanes.sql create mode 100644 mapconfig_all.xml delete mode 100644 mapconfig_cycleway.xml create mode 100644 one_way.sql create mode 100644 width_ft.sql diff --git a/functional_class.sql b/functional_class.sql index 7a30c6b1..db3ca730 100644 --- a/functional_class.sql +++ b/functional_class.sql @@ -2,6 +2,7 @@ -- INPUTS -- location: cambridge ---------------------------------------- +UPDATE cambridge_ways SET functional_class = NULL; UPDATE cambridge_ways SET functional_class = osm.highway @@ -51,4 +52,11 @@ AND osm.highway = 'pedestrian' AND osm.bicycle IN ('yes','permissive') AND (osm.access IS NULL OR osm.access NOT IN ('no','private')); +DELETE FROM cambridge_ways WHERE functional_class IS NULL; +DELETE FROM cambridge_ways_intersections +WHERE NOT EXISTS ( + SELECT 1 + FROM cambridge_ways + WHERE cambridge_ways_intersections.int_id IN (intersection_from,intersection_to) +); --elevators? diff --git a/import osm.sh b/import osm.sh deleted file mode 100644 index 47e4000d..00000000 --- a/import osm.sh +++ /dev/null @@ -1,81 +0,0 @@ -# vars -OSMPREFIX='cambridge' -OSMFILE='/home/spencer/gis/boston_massachusetts.osm' - -# drop old tables -psql -h 192.168.40.225 -U gis -d people_for_bikes \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_ways;" -psql -h 192.168.40.225 -U gis -d people_for_bikes \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_ways_intersections;" -psql -h 192.168.40.225 -U gis -d people_for_bikes \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_relations_ways;" -psql -h 192.168.40.225 -U gis -d people_for_bikes \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_nodes;" -psql -h 192.168.40.225 -U gis -d people_for_bikes \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_relations;" -psql -h 192.168.40.225 -U gis -d people_for_bikes \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_way_classes;" -psql -h 192.168.40.225 -U gis -d people_for_bikes \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_way_tags;" -psql -h 192.168.40.225 -U gis -d people_for_bikes \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_way_types;" - -# import the osm optimized for routing -osm2pgrouting \ - -f $OSMFILE \ - -h 192.168.40.225 \ - --dbname people_for_bikes \ - --username gis \ - --schema received \ - --prefix ${OSMPREFIX}_ \ - --clean - -# rename a few tables -psql -h 192.168.40.225 -U gis -d people_for_bikes \ - -c "ALTER TABLE received.${OSMPREFIX}_ways_vertices_pgr RENAME TO ${OSMPREFIX}_ways_intersections;" -psql -h 192.168.40.225 -U gis -d people_for_bikes \ - -c "ALTER TABLE received.osm_nodes RENAME TO ${OSMPREFIX}_osm_nodes;" -psql -h 192.168.40.225 -U gis -d people_for_bikes \ - -c "ALTER TABLE received.osm_relations RENAME TO ${OSMPREFIX}_osm_relations;" -psql -h 192.168.40.225 -U gis -d people_for_bikes \ - -c "ALTER TABLE received.osm_way_classes RENAME TO ${OSMPREFIX}_osm_way_classes;" -psql -h 192.168.40.225 -U gis -d people_for_bikes \ - -c "ALTER TABLE received.osm_way_tags RENAME TO ${OSMPREFIX}_osm_way_tags;" -psql -h 192.168.40.225 -U gis -d people_for_bikes \ - -c "ALTER TABLE received.osm_way_types RENAME TO ${OSMPREFIX}_osm_way_types;" - - -# import full osm to fill out additional data needs -# not met by osm2pgrouting - -# drop old tables -psql -h 192.168.40.225 -U gis -d people_for_bikes \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_full_line;" -psql -h 192.168.40.225 -U gis -d people_for_bikes \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_full_point;" -psql -h 192.168.40.225 -U gis -d people_for_bikes \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_full_polygon;" -psql -h 192.168.40.225 -U gis -d people_for_bikes \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_full_roads;" - -# import -osm2pgsql \ - --host 192.168.40.225 \ - --username gis \ - --port 5432 \ - --create \ - --database people_for_bikes \ - --prefix ${OSMPREFIX}_osm_full \ - --proj 2249 \ - --style /home/spencer/dev/pfb/pfb.style \ - /home/spencer/gis/boston_massachusetts.osm - -# move the full osm tables to the received schema -psql -h 192.168.40.225 -U gis -d people_for_bikes \ - -c "ALTER TABLE generated.${OSMPREFIX}_osm_full_line SET SCHEMA received;" -psql -h 192.168.40.225 -U gis -d people_for_bikes \ - -c "ALTER TABLE generated.${OSMPREFIX}_osm_full_point SET SCHEMA received;" -psql -h 192.168.40.225 -U gis -d people_for_bikes \ - -c "ALTER TABLE generated.${OSMPREFIX}_osm_full_polygon SET SCHEMA received;" -psql -h 192.168.40.225 -U gis -d people_for_bikes \ - -c "ALTER TABLE generated.${OSMPREFIX}_osm_full_roads SET SCHEMA received;" diff --git a/import_osm.sh b/import_osm.sh new file mode 100644 index 00000000..f28ed003 --- /dev/null +++ b/import_osm.sh @@ -0,0 +1,120 @@ +# vars +DBHOST='192.168.1.144' +DBNAME='people_for_bikes' +OSMPREFIX='cambridge' +OSMFILE='/home/spencer/Downloads/boston_massachusetts.osm' + +# drop old tables +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_ways;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_ways_intersections;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_relations_ways;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_nodes;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_relations;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_way_classes;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_way_tags;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_way_types;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_hwys_ways;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_hwys_ways_vertices_pgr;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_hwys_relations_ways;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_hwys_osm_nodes;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_hwys_osm_relations;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_hwys_osm_way_classes;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_hwys_osm_way_tags;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_hwys_osm_way_types;" + +# import the osm optimized for routing +osm2pgrouting \ + -f $OSMFILE \ + -h $DBHOST \ + --dbname ${DBNAME} \ + --username gis \ + --schema received \ + --prefix ${OSMPREFIX}_ \ + --conf ./mapconfig_all.xml + --clean + +# import the osm with highways that the above misses (bug in osm2pgrouting) +osm2pgrouting \ + -f $OSMFILE \ + -h $DBHOST \ + --dbname ${DBNAME} \ + --username gis \ + --schema scratch \ + --prefix ${OSMPREFIX}_hwys_ \ + --conf ./mapconfig_highway.xml + --clean + +# rename a few tables +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE received.${OSMPREFIX}_ways_vertices_pgr RENAME TO ${OSMPREFIX}_ways_intersections;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE received.osm_nodes RENAME TO ${OSMPREFIX}_osm_nodes;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE received.osm_relations RENAME TO ${OSMPREFIX}_osm_relations;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE received.osm_way_classes RENAME TO ${OSMPREFIX}_osm_way_classes;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE received.osm_way_tags RENAME TO ${OSMPREFIX}_osm_way_tags;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE received.osm_way_types RENAME TO ${OSMPREFIX}_osm_way_types;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE scratch.osm_nodes RENAME TO ${OSMPREFIX}_hwys_osm_nodes;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE scratch.osm_relations RENAME TO ${OSMPREFIX}_hwys_osm_relations;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE scratch.osm_way_classes RENAME TO ${OSMPREFIX}_hwys_osm_way_classes;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE scratch.osm_way_tags RENAME TO ${OSMPREFIX}_hwys_osm_way_tags;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE scratch.osm_way_types RENAME TO ${OSMPREFIX}_hwys_osm_way_types;" + +# import full osm to fill out additional data needs +# not met by osm2pgrouting + +# drop old tables +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_full_line;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_full_point;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_full_polygon;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_full_roads;" + +# import +osm2pgsql \ + --host $DBHOST \ + --username gis \ + --port 5432 \ + --create \ + --database ${DBNAME} \ + --prefix ${OSMPREFIX}_osm_full \ + --proj 2249 \ + --style /home/spencer/dev/pfb/pfb.style \ + $OSMFILE + +# move the full osm tables to the received schema +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE generated.${OSMPREFIX}_osm_full_line SET SCHEMA received;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE generated.${OSMPREFIX}_osm_full_point SET SCHEMA received;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE generated.${OSMPREFIX}_osm_full_polygon SET SCHEMA received;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE generated.${OSMPREFIX}_osm_full_roads SET SCHEMA received;" diff --git a/lanes.sql b/lanes.sql new file mode 100644 index 00000000..ab873ad7 --- /dev/null +++ b/lanes.sql @@ -0,0 +1,52 @@ +---------------------------------------- +-- INPUTS +-- location: cambridge +---------------------------------------- +UPDATE cambridge_ways SET ft_lanes = NULL, tf_lanes = NULL; + +-- forward +UPDATE cambridge_ways +SET ft_lanes = substring(osm.lanes FROM '\d+')::INT +FROM cambridge_osm_full_line osm +WHERE cambridge_ways.osm_id = osm.osm_id +AND ft_lanes IS NULL +AND osm.lanes IS NOT NULL +AND osm.lanes LIKE '%forward%'; + +-- backward +UPDATE cambridge_ways +SET tf_lanes = substring(osm.lanes FROM '\d+')::INT +FROM cambridge_osm_full_line osm +WHERE cambridge_ways.osm_id = osm.osm_id +AND tf_lanes IS NULL +AND osm.lanes IS NOT NULL +AND osm.lanes LIKE '%backward%'; + +-- all lanes (no direction given) +-- two way +UPDATE cambridge_ways +SET ft_lanes = floor(substring(osm.lanes FROM '\d+')::FLOAT / 2), + tf_lanes = floor(substring(osm.lanes FROM '\d+')::FLOAT / 2) +FROM cambridge_osm_full_line osm +WHERE cambridge_ways.osm_id = osm.osm_id +AND tf_lanes IS NULL +AND ft_lanes IS NULL +AND one_way NOT IN ('ft','tf') +AND osm.lanes IS NOT NULL; + +-- all lanes (no direction given) +-- one way +UPDATE cambridge_ways +SET ft_lanes = substring(osm.lanes FROM '\d+')::INT +FROM cambridge_osm_full_line osm +WHERE cambridge_ways.osm_id = osm.osm_id +AND one_way = 'ft' +AND ft_lanes IS NULL +AND osm.lanes IS NOT NULL; +UPDATE cambridge_ways +SET tf_lanes = substring(osm.lanes FROM '\d+')::INT +FROM cambridge_osm_full_line osm +WHERE cambridge_ways.osm_id = osm.osm_id +AND one_way = 'tf' +AND ft_lanes IS NULL +AND osm.lanes IS NOT NULL; diff --git a/mapconfig_all.xml b/mapconfig_all.xml new file mode 100644 index 00000000..6679e393 --- /dev/null +++ b/mapconfig_all.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/mapconfig_cycleway.xml b/mapconfig_cycleway.xml deleted file mode 100644 index 6745678f..00000000 --- a/mapconfig_cycleway.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - -import all and then import only highways and copy in anything that doesn't already -exist diff --git a/mapconfig_highway.xml b/mapconfig_highway.xml index 9a7bb8e2..549e1e14 100644 --- a/mapconfig_highway.xml +++ b/mapconfig_highway.xml @@ -28,20 +28,4 @@ - - - - - - - - - - - - - - - - diff --git a/one_way.sql b/one_way.sql new file mode 100644 index 00000000..c661500c --- /dev/null +++ b/one_way.sql @@ -0,0 +1,19 @@ +---------------------------------------- +-- INPUTS +-- location: cambridge +---------------------------------------- +UPDATE cambridge_ways SET one_way = NULL; + +-- ft direction +UPDATE cambridge_ways +SET one_way = 'ft' +FROM cambridge_osm_full_line osm +WHERE cambridge_ways.osm_id = osm.osm_id +AND trim(osm.oneway) IN ('1','yes'); + +-- tf direction +UPDATE cambridge_ways +SET one_way = 'tf' +FROM cambridge_osm_full_line osm +WHERE cambridge_ways.osm_id = osm.osm_id +AND trim(osm.oneway) = '-1'; diff --git a/prepare_tables.sql b/prepare_tables.sql index 0e045af0..75871fea 100644 --- a/prepare_tables.sql +++ b/prepare_tables.sql @@ -25,6 +25,7 @@ ALTER TABLE cambridge_ways DROP COLUMN maxspeed_backward; ALTER TABLE cambridge_ways DROP COLUMN source_osm; ALTER TABLE cambridge_ways DROP COLUMN target_osm; ALTER TABLE cambridge_ways DROP COLUMN priority; +ALTER TABLE cambridge_ways DROP COLUMN one_way; ALTER TABLE cambridge_ways_intersections DROP COLUMN cnt; ALTER TABLE cambridge_ways_intersections DROP COLUMN chk; @@ -45,12 +46,15 @@ ALTER TABLE cambridge_ways_intersections RENAME COLUMN the_geom TO geom; -- reproject ALTER TABLE cambridge_ways ALTER COLUMN geom TYPE geometry(linestring,2249) USING ST_Transform(geom,2249); +ALTER TABLE cambridge_hwys_ways ALTER COLUMN the_geom TYPE geometry(linestring,2249) +USING ST_Transform(the_geom,2249); ALTER TABLE cambridge_ways_intersections ALTER COLUMN geom TYPE geometry(point,2249) USING ST_Transform(geom,2249); -- add columns ALTER TABLE cambridge_ways ADD COLUMN functional_class TEXT; ALTER TABLE cambridge_ways ADD COLUMN speed_limit INT; +ALTER TABLE cambridge_ways ADD COLUMN one_way VARCHAR(2); ALTER TABLE cambridge_ways ADD COLUMN width_ft INT; ALTER TABLE cambridge_ways ADD COLUMN ft_bike_infra TEXT; ALTER TABLE cambridge_ways ADD COLUMN tf_bike_infra TEXT; @@ -68,7 +72,32 @@ CREATE INDEX idx_cambridge_ways_osm ON cambridge_ways (osm_id); CREATE INDEX idx_cambridge_ways_ints_osm ON cambridge_ways_intersections (osm_id); CREATE INDEX idx_cambridge_fullways ON cambridge_osm_full_line (osm_id); CREATE INDEX idx_cambrdige_fullpoints ON cambridge_osm_full_point (osm_id); -ANALYZE cambridge_ways (osm_id); +ANALYZE cambridge_ways (osm_id,geom); +ANALYZE cambridge_hwys_ways (the_geom); ANALYZE cambridge_ways_intersections (osm_id); ANALYZE cambridge_osm_full_line (osm_id); ANALYZE cambridge_osm_full_point (osm_id); + +-- add in highway data that is missing from first osm2pgrouting call +INSERT INTO cambridge_ways ( + name, intersection_from, intersection_to, osm_id, geom +) +SELECT name, + (SELECT i.int_id + FROM cambridge_ways_intersections i + WHERE i.geom <#> cambridge_hwys_ways.the_geom < 20 + ORDER BY ST_Distance(ST_StartPoint(cambridge_hwys_ways.the_geom),i.geom) ASC + LIMIT 1), + (SELECT i.int_id + FROM cambridge_ways_intersections i + WHERE i.geom <#> cambridge_hwys_ways.the_geom < 20 + ORDER BY ST_Distance(ST_EndPoint(cambridge_hwys_ways.the_geom),i.geom) ASC + LIMIT 1), + osm_id, + the_geom +FROM cambridge_hwys_ways +WHERE NOT EXISTS ( + SELECT 1 + FROM cambridge_ways w2 + WHERE w2.osm_id = cambridge_hwys_ways.osm_id +); diff --git a/process.txt b/process.txt index 7b60d4f1..cd828c50 100644 --- a/process.txt +++ b/process.txt @@ -1,4 +1,7 @@ -1: Run "import osm.sh" +1: Run import_osm.sh 2: Run prepare_tables.sql -3: Run functional_class.sql -4: Run speed_limit.sql +3: Run one_way.sql +4: Run functional_class.sql +5: Run speed_limit.sql +6: Run width_ft.sql +7: Run lanes.sql diff --git a/speed_limit.sql b/speed_limit.sql index e69de29b..35e1803b 100644 --- a/speed_limit.sql +++ b/speed_limit.sql @@ -0,0 +1,11 @@ +---------------------------------------- +-- INPUTS +-- location: cambridge +---------------------------------------- +UPDATE cambridge_ways SET speed_limit = NULL; + +UPDATE cambridge_ways +SET speed_limit = substring(osm.maxspeed from '\d+')::INT +FROM cambridge_osm_full_line osm +WHERE cambridge_ways.osm_id = osm.osm_id +AND osm.maxspeed LIKE '% mph'; diff --git a/width_ft.sql b/width_ft.sql new file mode 100644 index 00000000..1564d571 --- /dev/null +++ b/width_ft.sql @@ -0,0 +1,87 @@ +---------------------------------------- +-- INPUTS +-- location: cambridge +---------------------------------------- +UPDATE cambridge_ways SET width_ft = NULL; + +-- first forward/backward (if given) +-- feet +UPDATE cambridge_ways +SET width_ft = substring(osm.width FROM '\d+\.?\d?\d?')::FLOAT +FROM cambridge_osm_full_line osm +WHERE cambridge_ways.osm_id = osm.osm_id +AND osm.width LIKE '% ft' +AND osm.width LIKE '%forward%'; +UPDATE cambridge_ways +SET width_ft = COALESCE(width_ft,0) + substring(osm.width FROM '\d+\.?\d?\d?')::FLOAT +FROM cambridge_osm_full_line osm +WHERE cambridge_ways.osm_id = osm.osm_id +AND osm.width LIKE '% ft' +AND osm.width LIKE '%backward%'; + +-- meters +UPDATE cambridge_ways +SET width_ft = 3.28084 * substring(osm.width FROM '\d+\.?\d?\d?')::FLOAT +FROM cambridge_osm_full_line osm +WHERE cambridge_ways.osm_id = osm.osm_id +AND osm.width LIKE '% m' +AND osm.width LIKE '%forward%'; +UPDATE cambridge_ways +SET width_ft = COALESCE(width_ft,0) + + (3.28084 * substring(osm.width FROM '\d+\.?\d?\d?')::FLOAT) +FROM cambridge_osm_full_line osm +WHERE cambridge_ways.osm_id = osm.osm_id +AND osm.width LIKE '% m' +AND osm.width LIKE '%backward%'; + +-- no units (default=meters) +-- N.B. we weed out anything more than 20, since that's likely either bogus +-- or not in meters +UPDATE cambridge_ways +SET width_ft = 3.28084 * substring(osm.width FROM '\d+\.?\d?\d?')::FLOAT +FROM cambridge_osm_full_line osm +WHERE cambridge_ways.osm_id = osm.osm_id +AND osm.width NOT LIKE '% m' +AND osm.width NOT LIKE '% ft' +AND osm.width LIKE '%forward%'; +UPDATE cambridge_ways +SET width_ft = COALESCE(width_ft,0) + + (3.28084 * substring(osm.width FROM '\d+\.?\d?\d?')::FLOAT) +FROM cambridge_osm_full_line osm +WHERE cambridge_ways.osm_id = osm.osm_id +AND NOT osm.width LIKE '% m' +AND NOT osm.width LIKE '% ft' +AND osm.width LIKE '%backward%'; + +-- then singles +-- feet +UPDATE cambridge_ways +SET width_ft = substring(osm.width from '\d+\.?\d?\d?')::FLOAT +FROM cambridge_osm_full_line osm +WHERE cambridge_ways.osm_id = osm.osm_id +AND osm.width IS NOT NULL +AND NOT osm.width LIKE '%forward%' +AND NOT osm.width LIKE '%backward%' +AND osm.width LIKE '% ft'; + +-- meters +UPDATE cambridge_ways +SET width_ft = 3.28084 * substring(osm.width from '\d+\.?\d?\d?')::FLOAT +FROM cambridge_osm_full_line osm +WHERE cambridge_ways.osm_id = osm.osm_id +AND osm.width IS NOT NULL +AND NOT osm.width LIKE '%forward%' +AND NOT osm.width LIKE '%backward%' +AND osm.width LIKE '% m'; + +-- no units (default=meters) +-- N.B. we weed out anything more than 20, since that's likely either bogus +-- or not in meters +UPDATE cambridge_ways +SET width_ft = 3.28084 * substring(osm.width from '\d+\.?\d?\d?')::FLOAT +FROM cambridge_osm_full_line osm +WHERE cambridge_ways.osm_id = osm.osm_id +AND osm.width IS NOT NULL +AND NOT osm.width LIKE '%forward%' +AND NOT osm.width LIKE '%backward%' +AND substring(osm.width from '\d+\.?\d?\d?')::FLOAT < 20; From 062d4de10f41eca719405040e2e38d3b683de403 Mon Sep 17 00:00:00 2001 From: Spencer Gardner Date: Sat, 17 Sep 2016 16:10:54 -0500 Subject: [PATCH 07/94] slkjsdfjls --- bike_infra.sql | 140 +++++++++++++++++++++++++++++++++++++++++++++ import_osm.sh | 16 ++++++ lanes.sql | 18 +++--- one_way.sql | 6 +- park.sql | 48 ++++++++++++++++ pfb.style | 16 +++++- prepare_tables.sql | 1 + process.txt | 16 +++--- width_ft.sql | 56 ------------------ 9 files changed, 240 insertions(+), 77 deletions(-) create mode 100644 bike_infra.sql create mode 100644 park.sql diff --git a/bike_infra.sql b/bike_infra.sql new file mode 100644 index 00000000..ec1797ae --- /dev/null +++ b/bike_infra.sql @@ -0,0 +1,140 @@ +---------------------------------------- +-- INPUTS +-- location: cambridge +---------------------------------------- +UPDATE cambridge_ways SET ft_bike_infra = NULL, tf_bike_infra = NULL; + +---------------------- +-- ft direction +---------------------- +-- sharrow +UPDATE cambridge_ways +SET ft_bike_infra = 'sharrow' +FROM cambridge_osm_full_line osm +WHERE cambridge_ways.osm_id = osm.osm_id +AND ( + osm."cycleway:both" = 'shared_lane' + OR (COALESCE(one_way_car,'ft') = 'ft' AND osm.cycleway = 'shared_lane') + OR (COALESCE(one_way_car,'ft') = 'ft' AND osm."cycleway:right" = 'shared_lane') + OR (one_way_car = 'ft' AND osm."cycleway:left" = 'shared_lane') +); + +-- lane +UPDATE cambridge_ways +SET ft_bike_infra = 'lane' +FROM cambridge_osm_full_line osm +WHERE cambridge_ways.osm_id = osm.osm_id +AND ( + osm."cycleway:both" = 'lane' + OR (COALESCE(one_way_car,'ft') = 'ft' AND osm.cycleway = 'lane') + OR (COALESCE(one_way_car,'ft') = 'ft' AND osm."cycleway:right" = 'lane') + OR (one_way_car = 'ft' AND osm."cycleway:left" = 'lane') + OR (one_way_car = 'tf' AND osm.cycleway = 'opposite_lane') + OR (one_way_car = 'tf' AND osm."cycleway:left" = 'opposite_lane') +); + +-- buffered lane +UPDATE cambridge_ways +SET ft_bike_infra = 'buffered_lane' +FROM cambridge_osm_full_line osm +WHERE cambridge_ways.osm_id = osm.osm_id +AND ( + osm."cycleway:both" = 'buffered_lane' + OR (COALESCE(one_way_car,'ft') = 'ft' AND osm.cycleway = 'buffered_lane') + OR (COALESCE(one_way_car,'ft') = 'ft' AND osm."cycleway:right" = 'buffered_lane') + OR (COALESCE(one_way_car,'ft') = 'ft' AND osm.cycleway = 'lane' AND osm."cycleway:buffer" IN ('yes','both','right','left')) + OR (COALESCE(one_way_car,'ft') = 'ft' AND osm."cycleway:right" = 'lane' AND osm."cycleway:right:buffer" IN ('yes','both','right','left')) + OR (one_way_car = 'ft' AND osm."cycleway:left" = 'lane' AND osm."cycleway:left:buffer" IN ('yes','both','right','left')) + OR (one_way_car = 'tf' AND osm.cycleway = 'opposite_lane' AND osm."cycleway:buffer" IN ('yes','both','right','left')) + OR (one_way_car = 'tf' AND osm."cycleway:left" = 'opposite_lane' AND osm."cycleway:left:buffer" IN ('yes','both','right','left')) +); + +-- track +UPDATE cambridge_ways +SET ft_bike_infra = 'track' +FROM cambridge_osm_full_line osm +WHERE cambridge_ways.osm_id = osm.osm_id +AND ( + osm."cycleway:both" = 'track' + OR (osm."cycleway:right" = 'track' AND osm."oneway:bicycle" = 'no') + OR (osm."cycleway:left" = 'track' AND osm."oneway:bicycle" = 'no') + OR (osm.cycleway = 'track' AND osm."oneway:bicycle" = 'no') + OR (COALESCE(one_way_car,'ft') = 'ft' AND osm."cycleway" = 'track') + OR (COALESCE(one_way_car,'ft') = 'ft' AND osm."cycleway:right" = 'track') +); + + +---------------------- +-- tf direction +---------------------- +-- sharrow +UPDATE cambridge_ways +SET tf_bike_infra = 'sharrow' +FROM cambridge_osm_full_line osm +WHERE cambridge_ways.osm_id = osm.osm_id +AND ( + osm."cycleway:both" = 'shared_lane' + OR (COALESCE(one_way_car,'tf') = 'tf' AND osm.cycleway = 'shared_lane') + OR (COALESCE(one_way_car,'tf') = 'tf' AND osm."cycleway:left" = 'shared_lane') + OR (one_way_car = 'tf' AND osm."cycleway:right" = 'shared_lane') +); + +-- lane +UPDATE cambridge_ways +SET tf_bike_infra = 'lane' +FROM cambridge_osm_full_line osm +WHERE cambridge_ways.osm_id = osm.osm_id +AND ( + osm."cycleway:both" = 'lane' + OR (COALESCE(one_way_car,'tf') = 'tf' AND osm.cycleway = 'lane') + OR (COALESCE(one_way_car,'tf') = 'tf' AND osm."cycleway:left" = 'lane') + OR (one_way_car = 'tf' AND osm."cycleway:right" = 'lane') + OR (one_way_car = 'ft' AND osm.cycleway = 'opposite_lane') + OR (one_way_car = 'ft' AND osm."cycleway:right" = 'opposite_lane') +); + +-- buffered lane +UPDATE cambridge_ways +SET tf_bike_infra = 'buffered_lane' +FROM cambridge_osm_full_line osm +WHERE cambridge_ways.osm_id = osm.osm_id +AND ( + osm."cycleway:both" = 'buffered_lane' + OR (COALESCE(one_way_car,'tf') = 'tf' AND osm.cycleway = 'buffered_lane') + OR (COALESCE(one_way_car,'tf') = 'tf' AND osm."cycleway:left" = 'buffered_lane') + OR (COALESCE(one_way_car,'tf') = 'tf' AND osm.cycleway = 'lane' AND osm."cycleway:buffer" IN ('yes','both','right','left')) + OR (COALESCE(one_way_car,'tf') = 'tf' AND osm."cycleway:left" = 'lane' AND osm."cycleway:left:buffer" IN ('yes','both','right','left')) + OR (one_way_car = 'tf' AND osm."cycleway:right" = 'lane' AND osm."cycleway:right:buffer" IN ('yes','both','right','left')) + OR (one_way_car = 'ft' AND osm.cycleway = 'opposite_lane' AND osm."cycleway:buffer" IN ('yes','both','right','left')) + OR (one_way_car = 'ft' AND osm."cycleway:right" = 'opposite_lane' AND osm."cycleway:right:buffer" IN ('yes','both','right','left')) +); + +-- track +UPDATE cambridge_ways +SET tf_bike_infra = 'track' +FROM cambridge_osm_full_line osm +WHERE cambridge_ways.osm_id = osm.osm_id +AND ( + osm."cycleway:both" = 'track' + OR (osm."cycleway:left" = 'track' AND osm."oneway:bicycle" = 'no') + OR (osm."cycleway:right" = 'track' AND osm."oneway:bicycle" = 'no') + OR (osm.cycleway = 'track' AND osm."oneway:bicycle" = 'no') + OR (COALESCE(one_way_car,'tf') = 'tf' AND osm."cycleway" = 'track') + OR (COALESCE(one_way_car,'tf') = 'tf' AND osm."cycleway:left" = 'track') +); + +-- update one_way based on bike infra +UPDATE cambridge_ways +SET one_way = NULL; +UPDATE cambridge_ways +SET one_way = one_way_car +FROM cambridge_osm_full_line osm +WHERE cambridge_ways.osm_id = osm.osm_id +AND one_way_car = 'ft' +AND NOT (tf_bike_infra IS NOT NULL OR COALESCE(osm."oneway:bicycle",'yes') = 'no'); +UPDATE cambridge_ways +SET one_way = one_way_car +FROM cambridge_osm_full_line osm +WHERE cambridge_ways.osm_id = osm.osm_id +AND one_way_car = 'tf' +AND NOT (ft_bike_infra IS NOT NULL OR COALESCE(osm."oneway:bicycle",'yes') = 'no'); diff --git a/import_osm.sh b/import_osm.sh index f28ed003..9fe63e20 100644 --- a/import_osm.sh +++ b/import_osm.sh @@ -5,6 +5,7 @@ OSMPREFIX='cambridge' OSMFILE='/home/spencer/Downloads/boston_massachusetts.osm' # drop old tables +echo 'Dropping old tables' psql -h $DBHOST -U gis -d ${DBNAME} \ -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_ways;" psql -h $DBHOST -U gis -d ${DBNAME} \ @@ -61,6 +62,7 @@ osm2pgrouting \ --clean # rename a few tables +echo 'Renaming tables' psql -h $DBHOST -U gis -d ${DBNAME} \ -c "ALTER TABLE received.${OSMPREFIX}_ways_vertices_pgr RENAME TO ${OSMPREFIX}_ways_intersections;" psql -h $DBHOST -U gis -d ${DBNAME} \ @@ -88,6 +90,7 @@ psql -h $DBHOST -U gis -d ${DBNAME} \ # not met by osm2pgrouting # drop old tables +echo 'Dropping old tables' psql -h $DBHOST -U gis -d ${DBNAME} \ -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_full_line;" psql -h $DBHOST -U gis -d ${DBNAME} \ @@ -110,6 +113,7 @@ osm2pgsql \ $OSMFILE # move the full osm tables to the received schema +echo 'Moving tables to received schema' psql -h $DBHOST -U gis -d ${DBNAME} \ -c "ALTER TABLE generated.${OSMPREFIX}_osm_full_line SET SCHEMA received;" psql -h $DBHOST -U gis -d ${DBNAME} \ @@ -118,3 +122,15 @@ psql -h $DBHOST -U gis -d ${DBNAME} \ -c "ALTER TABLE generated.${OSMPREFIX}_osm_full_polygon SET SCHEMA received;" psql -h $DBHOST -U gis -d ${DBNAME} \ -c "ALTER TABLE generated.${OSMPREFIX}_osm_full_roads SET SCHEMA received;" + +# process tables +echo 'Updating field names' +psql -h $DBHOST -U gis -d ${DBNAME} -f ./prepare_tables.sql +echo 'Setting values' +psql -h $DBHOST -U gis -d ${DBNAME} -f ./one_way.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./functional_class.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./speed_limit.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./width_ft.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./lanes.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./park.sql +#psql -h $DBHOST -U gis -d ${DBNAME} -f ./bike_infra.sql diff --git a/lanes.sql b/lanes.sql index ab873ad7..4ef36e1c 100644 --- a/lanes.sql +++ b/lanes.sql @@ -6,21 +6,19 @@ UPDATE cambridge_ways SET ft_lanes = NULL, tf_lanes = NULL; -- forward UPDATE cambridge_ways -SET ft_lanes = substring(osm.lanes FROM '\d+')::INT +SET ft_lanes = substring(osm."lanes:forward" FROM '\d+')::INT FROM cambridge_osm_full_line osm WHERE cambridge_ways.osm_id = osm.osm_id AND ft_lanes IS NULL -AND osm.lanes IS NOT NULL -AND osm.lanes LIKE '%forward%'; +AND osm."lanes:forward" IS NOT NULL; -- backward UPDATE cambridge_ways -SET tf_lanes = substring(osm.lanes FROM '\d+')::INT +SET tf_lanes = substring(osm."lanes:backward" FROM '\d+')::INT FROM cambridge_osm_full_line osm WHERE cambridge_ways.osm_id = osm.osm_id AND tf_lanes IS NULL -AND osm.lanes IS NOT NULL -AND osm.lanes LIKE '%backward%'; +AND osm."lanes:backward" IS NOT NULL; -- all lanes (no direction given) -- two way @@ -31,7 +29,7 @@ FROM cambridge_osm_full_line osm WHERE cambridge_ways.osm_id = osm.osm_id AND tf_lanes IS NULL AND ft_lanes IS NULL -AND one_way NOT IN ('ft','tf') +AND one_way_car NOT IN ('ft','tf') AND osm.lanes IS NOT NULL; -- all lanes (no direction given) @@ -40,13 +38,13 @@ UPDATE cambridge_ways SET ft_lanes = substring(osm.lanes FROM '\d+')::INT FROM cambridge_osm_full_line osm WHERE cambridge_ways.osm_id = osm.osm_id -AND one_way = 'ft' +AND one_way_car = 'ft' AND ft_lanes IS NULL AND osm.lanes IS NOT NULL; UPDATE cambridge_ways SET tf_lanes = substring(osm.lanes FROM '\d+')::INT FROM cambridge_osm_full_line osm WHERE cambridge_ways.osm_id = osm.osm_id -AND one_way = 'tf' -AND ft_lanes IS NULL +AND one_way_car = 'tf' +AND tf_lanes IS NULL AND osm.lanes IS NOT NULL; diff --git a/one_way.sql b/one_way.sql index c661500c..c3269a50 100644 --- a/one_way.sql +++ b/one_way.sql @@ -2,18 +2,18 @@ -- INPUTS -- location: cambridge ---------------------------------------- -UPDATE cambridge_ways SET one_way = NULL; +UPDATE cambridge_ways SET one_way_car = NULL; -- ft direction UPDATE cambridge_ways -SET one_way = 'ft' +SET one_way_car = 'ft' FROM cambridge_osm_full_line osm WHERE cambridge_ways.osm_id = osm.osm_id AND trim(osm.oneway) IN ('1','yes'); -- tf direction UPDATE cambridge_ways -SET one_way = 'tf' +SET one_way_car = 'tf' FROM cambridge_osm_full_line osm WHERE cambridge_ways.osm_id = osm.osm_id AND trim(osm.oneway) = '-1'; diff --git a/park.sql b/park.sql new file mode 100644 index 00000000..e8dbf0d0 --- /dev/null +++ b/park.sql @@ -0,0 +1,48 @@ +---------------------------------------- +-- INPUTS +-- location: cambridge +---------------------------------------- +UPDATE cambridge_ways SET ft_park = NULL, tf_park = NULL; + +-- both +UPDATE cambridge_ways +SET ft_park = CASE WHEN osm."parking:lane:both" = 'parallel' THEN 1 + WHEN osm."parking:lane:both" = 'paralell' THEN 1 + WHEN osm."parking:lane:both" = 'diagonal' THEN 1 + WHEN osm."parking:lane:both" = 'perpendicular' THEN 1 + WHEN osm."parking:lane:both" = 'no_parking' THEN 0 + WHEN osm."parking:lane:both" = 'no_stopping' THEN 0 + END, + tf_park = CASE WHEN osm."parking:lane:both" = 'parallel' THEN 1 + WHEN osm."parking:lane:both" = 'paralell' THEN 1 + WHEN osm."parking:lane:both" = 'diagonal' THEN 1 + WHEN osm."parking:lane:both" = 'perpendicular' THEN 1 + WHEN osm."parking:lane:both" = 'no_parking' THEN 0 + WHEN osm."parking:lane:both" = 'no_stopping' THEN 0 + END +FROM cambridge_osm_full_line osm +WHERE cambridge_ways.osm_id = osm.osm_id; + +-- right +UPDATE cambridge_ways +SET ft_park = CASE WHEN osm."parking:lane:right" = 'parallel' THEN 1 + WHEN osm."parking:lane:right" = 'paralell' THEN 1 + WHEN osm."parking:lane:right" = 'diagonal' THEN 1 + WHEN osm."parking:lane:right" = 'perpendicular' THEN 1 + WHEN osm."parking:lane:right" = 'no_parking' THEN 0 + WHEN osm."parking:lane:right" = 'no_stopping' THEN 0 + END +FROM cambridge_osm_full_line osm +WHERE cambridge_ways.osm_id = osm.osm_id; + +-- left +UPDATE cambridge_ways +SET tf_park = CASE WHEN osm."parking:lane:left" = 'parallel' THEN 1 + WHEN osm."parking:lane:left" = 'paralell' THEN 1 + WHEN osm."parking:lane:left" = 'diagonal' THEN 1 + WHEN osm."parking:lane:left" = 'perpendicular' THEN 1 + WHEN osm."parking:lane:left" = 'no_parking' THEN 0 + WHEN osm."parking:lane:left" = 'no_stopping' THEN 0 + END +FROM cambridge_osm_full_line osm +WHERE cambridge_ways.osm_id = osm.osm_id; diff --git a/pfb.style b/pfb.style index 12ff9f5c..448ec1e4 100644 --- a/pfb.style +++ b/pfb.style @@ -86,15 +86,29 @@ node,way bicycle text linear node,way bridge text linear node,way crossing text linear way cycleway text linear +way cycleway:left text linear +way cycleway:right text linear +way cycleway:both text linear +way cycleway:buffer text linear +way cycleway:left:buffer text linear +way cycleway:right:buffer text linear +way cycleway:both:buffer text linear node,way foot text linear node,way highway text linear node,way junction text linear way lanes text linear +way lanes:forward text linear +way lanes:backward text linear way maxspeed text linear node,way motorcar text linear node,way name text linear node,way oneway text linear -way parking TEXT linear +node,way oneway:bicycle text linear +way parking text linear +way parking:lane text linear +way parking:lane:right text linear +way parking:lane:left text linear +way parking:lane:both text linear node,way segregated text linear node,way stop TEXT linear node,way surface text linear diff --git a/prepare_tables.sql b/prepare_tables.sql index 75871fea..6a9bdad4 100644 --- a/prepare_tables.sql +++ b/prepare_tables.sql @@ -54,6 +54,7 @@ USING ST_Transform(geom,2249); -- add columns ALTER TABLE cambridge_ways ADD COLUMN functional_class TEXT; ALTER TABLE cambridge_ways ADD COLUMN speed_limit INT; +ALTER TABLE cambridge_ways ADD COLUMN one_way_car VARCHAR(2); ALTER TABLE cambridge_ways ADD COLUMN one_way VARCHAR(2); ALTER TABLE cambridge_ways ADD COLUMN width_ft INT; ALTER TABLE cambridge_ways ADD COLUMN ft_bike_infra TEXT; diff --git a/process.txt b/process.txt index cd828c50..0131ef94 100644 --- a/process.txt +++ b/process.txt @@ -1,7 +1,9 @@ -1: Run import_osm.sh -2: Run prepare_tables.sql -3: Run one_way.sql -4: Run functional_class.sql -5: Run speed_limit.sql -6: Run width_ft.sql -7: Run lanes.sql +1: Run import_osm.sh +2: Run prepare_tables.sql +3: Run one_way.sql +4: Run functional_class.sql +5: Run speed_limit.sql +6: Run width_ft.sql +7: Run lanes.sql +8: Run park.sql +9: Run bike_infra.sql diff --git a/width_ft.sql b/width_ft.sql index 1564d571..69710209 100644 --- a/width_ft.sql +++ b/width_ft.sql @@ -4,64 +4,12 @@ ---------------------------------------- UPDATE cambridge_ways SET width_ft = NULL; --- first forward/backward (if given) --- feet -UPDATE cambridge_ways -SET width_ft = substring(osm.width FROM '\d+\.?\d?\d?')::FLOAT -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id -AND osm.width LIKE '% ft' -AND osm.width LIKE '%forward%'; -UPDATE cambridge_ways -SET width_ft = COALESCE(width_ft,0) + substring(osm.width FROM '\d+\.?\d?\d?')::FLOAT -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id -AND osm.width LIKE '% ft' -AND osm.width LIKE '%backward%'; - --- meters -UPDATE cambridge_ways -SET width_ft = 3.28084 * substring(osm.width FROM '\d+\.?\d?\d?')::FLOAT -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id -AND osm.width LIKE '% m' -AND osm.width LIKE '%forward%'; -UPDATE cambridge_ways -SET width_ft = COALESCE(width_ft,0) + - (3.28084 * substring(osm.width FROM '\d+\.?\d?\d?')::FLOAT) -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id -AND osm.width LIKE '% m' -AND osm.width LIKE '%backward%'; - --- no units (default=meters) --- N.B. we weed out anything more than 20, since that's likely either bogus --- or not in meters -UPDATE cambridge_ways -SET width_ft = 3.28084 * substring(osm.width FROM '\d+\.?\d?\d?')::FLOAT -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id -AND osm.width NOT LIKE '% m' -AND osm.width NOT LIKE '% ft' -AND osm.width LIKE '%forward%'; -UPDATE cambridge_ways -SET width_ft = COALESCE(width_ft,0) + - (3.28084 * substring(osm.width FROM '\d+\.?\d?\d?')::FLOAT) -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id -AND NOT osm.width LIKE '% m' -AND NOT osm.width LIKE '% ft' -AND osm.width LIKE '%backward%'; - --- then singles -- feet UPDATE cambridge_ways SET width_ft = substring(osm.width from '\d+\.?\d?\d?')::FLOAT FROM cambridge_osm_full_line osm WHERE cambridge_ways.osm_id = osm.osm_id AND osm.width IS NOT NULL -AND NOT osm.width LIKE '%forward%' -AND NOT osm.width LIKE '%backward%' AND osm.width LIKE '% ft'; -- meters @@ -70,8 +18,6 @@ SET width_ft = 3.28084 * substring(osm.width from '\d+\.?\d?\d?')::FLOAT FROM cambridge_osm_full_line osm WHERE cambridge_ways.osm_id = osm.osm_id AND osm.width IS NOT NULL -AND NOT osm.width LIKE '%forward%' -AND NOT osm.width LIKE '%backward%' AND osm.width LIKE '% m'; -- no units (default=meters) @@ -82,6 +28,4 @@ SET width_ft = 3.28084 * substring(osm.width from '\d+\.?\d?\d?')::FLOAT FROM cambridge_osm_full_line osm WHERE cambridge_ways.osm_id = osm.osm_id AND osm.width IS NOT NULL -AND NOT osm.width LIKE '%forward%' -AND NOT osm.width LIKE '%backward%' AND substring(osm.width from '\d+\.?\d?\d?')::FLOAT < 20; From b1bfdd428632ff7b5e62cbab198cecd5c199efd9 Mon Sep 17 00:00:00 2001 From: Spencer Gardner Date: Sat, 17 Sep 2016 23:48:09 -0500 Subject: [PATCH 08/94] flkjsdf --- import_osm.sh | 10 +++++++- process.txt | 8 ++++++ stress_living_street.sql | 11 +++++++++ stress_motorway-trunk.sql | 9 +++++++ stress_path.sql | 11 +++++++++ stress_primary.sql | 22 +++++++++++++++++ stress_residential.sql | 26 ++++++++++++++++++++ stress_secondary.sql | 52 +++++++++++++++++++++++++++++++++++++++ stress_tertiary.sql | 52 +++++++++++++++++++++++++++++++++++++++ stress_track.sql | 11 +++++++++ 10 files changed, 211 insertions(+), 1 deletion(-) create mode 100644 stress_living_street.sql create mode 100644 stress_motorway-trunk.sql create mode 100644 stress_path.sql create mode 100644 stress_primary.sql create mode 100644 stress_residential.sql create mode 100644 stress_secondary.sql create mode 100644 stress_tertiary.sql create mode 100644 stress_track.sql diff --git a/import_osm.sh b/import_osm.sh index 9fe63e20..1d145c5e 100644 --- a/import_osm.sh +++ b/import_osm.sh @@ -133,4 +133,12 @@ psql -h $DBHOST -U gis -d ${DBNAME} -f ./speed_limit.sql psql -h $DBHOST -U gis -d ${DBNAME} -f ./width_ft.sql psql -h $DBHOST -U gis -d ${DBNAME} -f ./lanes.sql psql -h $DBHOST -U gis -d ${DBNAME} -f ./park.sql -#psql -h $DBHOST -U gis -d ${DBNAME} -f ./bike_infra.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./bike_infra.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_motorway-trunk.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_primary.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_secondary.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_tertiary.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_residential.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_living_street.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_track.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_path.sql diff --git a/process.txt b/process.txt index 0131ef94..9e475316 100644 --- a/process.txt +++ b/process.txt @@ -7,3 +7,11 @@ 7: Run lanes.sql 8: Run park.sql 9: Run bike_infra.sql +10: Run stress_motorway-trunk.sql +11: Run stress_primary.sql +12: Run stress_secondary.sql +13: Run stress_tertiary.sql +14: Run stress_residential.sql +15: Run stress_living_street.sql +16: Run stress_track.sql +17: Run stress_path.sql diff --git a/stress_living_street.sql b/stress_living_street.sql new file mode 100644 index 00000000..7be738be --- /dev/null +++ b/stress_living_street.sql @@ -0,0 +1,11 @@ +---------------------------------------- +-- INPUTS +-- location: cambridge +---------------------------------------- +UPDATE cambridge_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL +WHERE functional_class = 'living_street'; + +UPDATE cambridge_ways +SET ft_seg_stress = 1, + tf_seg_stress = 1 +WHERE functional_class = 'living_street'; diff --git a/stress_motorway-trunk.sql b/stress_motorway-trunk.sql new file mode 100644 index 00000000..9b1c8962 --- /dev/null +++ b/stress_motorway-trunk.sql @@ -0,0 +1,9 @@ +---------------------------------------- +-- INPUTS +-- location: cambridge +---------------------------------------- +UPDATE cambridge_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL +WHERE functional_class IN ('motorway','motorway_link','trunk','trunk_link'); + +UPDATE cambridge_ways SET ft_seg_stress = 4, tf_seg_stress = 4 +WHERE functional_class IN ('motorway','motorway_link','trunk','trunk_link'); diff --git a/stress_path.sql b/stress_path.sql new file mode 100644 index 00000000..19057fdd --- /dev/null +++ b/stress_path.sql @@ -0,0 +1,11 @@ +---------------------------------------- +-- INPUTS +-- location: cambridge +---------------------------------------- +UPDATE cambridge_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL +WHERE functional_class = 'path'; + +UPDATE cambridge_ways +SET ft_seg_stress = 1, + tf_seg_stress = 1 +WHERE functional_class = 'path'; diff --git a/stress_primary.sql b/stress_primary.sql new file mode 100644 index 00000000..faa09cc8 --- /dev/null +++ b/stress_primary.sql @@ -0,0 +1,22 @@ +---------------------------------------- +-- INPUTS +-- location: cambridge +---------------------------------------- +UPDATE cambridge_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL +WHERE functional_class IN ('primary','primary_link'); + +-- no additional information +UPDATE cambridge_ways +SET ft_seg_stress = 4, + tf_seg_stress = 4 +WHERE functional_class IN ('primary','primary_link'); + +-- stress reduction for cycle track +UPDATE cambridge_ways +SET ft_seg_stress = 2 +WHERE functional_class IN ('primary','primary_link') +AND ft_bike_infra = 'track'; +UPDATE cambridge_ways +SET tf_seg_stress = 2 +WHERE functional_class IN ('primary','primary_link') +AND tf_bike_infra = 'track'; diff --git a/stress_residential.sql b/stress_residential.sql new file mode 100644 index 00000000..800ace95 --- /dev/null +++ b/stress_residential.sql @@ -0,0 +1,26 @@ +---------------------------------------- +-- INPUTS +-- location: cambridge +---------------------------------------- +UPDATE cambridge_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL +WHERE functional_class = 'residential'; + +-- no additional information +UPDATE cambridge_ways +SET ft_seg_stress = 1, + tf_seg_stress = 1 +WHERE functional_class = 'residential'; + +-- stress increase for multiple lanes or high speeds +UPDATE cambridge_ways +SET ft_seg_stress = 3 +WHERE functional_class = 'residential' +AND (ft_lanes > 1 OR speed_limit > 30); + +-- stress increase for narrow one way and parking on both sides +UPDATE cambridge_ways +SET ft_seg_stress = 3 +WHERE functional_class = 'residential' +AND width_ft <= 28 +AND ft_park = 1 +AND tf_park = 1; diff --git a/stress_secondary.sql b/stress_secondary.sql new file mode 100644 index 00000000..138c13be --- /dev/null +++ b/stress_secondary.sql @@ -0,0 +1,52 @@ +---------------------------------------- +-- INPUTS +-- location: cambridge +---------------------------------------- +UPDATE cambridge_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL +WHERE functional_class IN ('secondary','secondary_link'); + +-- no additional information +UPDATE cambridge_ways +SET ft_seg_stress = 4, + tf_seg_stress = 4 +WHERE functional_class IN ('secondary','secondary_link'); + +-- stress reduction for cycle track +UPDATE cambridge_ways +SET ft_seg_stress = 2 +WHERE functional_class IN ('secondary','secondary_link') +AND ft_bike_infra = 'track'; +UPDATE cambridge_ways +SET tf_seg_stress = 2 +WHERE functional_class IN ('secondary','secondary_link') +AND tf_bike_infra = 'track'; + +-- stress reduction for one vehicle lane and buffered lane +UPDATE cambridge_ways +SET ft_seg_stress = 2 +WHERE functional_class IN ('secondary','secondary_link') +AND ft_bike_infra = 'buffered_lane' +AND ft_lanes = 1 +AND speed_limit <= 30; +UPDATE cambridge_ways +SET tf_seg_stress = 2 +WHERE functional_class IN ('secondary','secondary_link') +AND tf_bike_infra = 'buffered_lane' +AND tf_lanes = 1 +AND speed_limit <= 30; + +-- stress reduction for one vehicle lane, no parking, and bike lane +UPDATE cambridge_ways +SET ft_seg_stress = 2 +WHERE functional_class IN ('secondary','secondary_link') +AND ft_bike_infra = 'lane' +AND ft_lanes = 1 +AND ft_park = 0 +AND speed_limit <= 30; +UPDATE cambridge_ways +SET tf_seg_stress = 2 +WHERE functional_class IN ('secondary','secondary_link') +AND tf_bike_infra = 'lane' +AND tf_lanes = 1 +AND ft_park = 0 +AND speed_limit <= 30; diff --git a/stress_tertiary.sql b/stress_tertiary.sql new file mode 100644 index 00000000..a7344e1b --- /dev/null +++ b/stress_tertiary.sql @@ -0,0 +1,52 @@ +---------------------------------------- +-- INPUTS +-- location: cambridge +---------------------------------------- +UPDATE cambridge_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL +WHERE functional_class IN ('tertiary','tertiary_link'); + +-- no additional information +UPDATE cambridge_ways +SET ft_seg_stress = 3, + tf_seg_stress = 3 +WHERE functional_class IN ('tertiary','tertiary_link'); + +-- stress reduction for cycle track +UPDATE cambridge_ways +SET ft_seg_stress = 2 +WHERE functional_class IN ('tertiary','tertiary_link') +AND ft_bike_infra = 'track'; +UPDATE cambridge_ways +SET tf_seg_stress = 2 +WHERE functional_class IN ('tertiary','tertiary_link') +AND tf_bike_infra = 'track'; + +-- stress reduction for buffered lane +UPDATE cambridge_ways +SET ft_seg_stress = 2 +WHERE functional_class IN ('tertiary','tertiary_link') +AND ft_bike_infra = 'buffered_lane' +AND COALESCE(speed_limit,35) <= 30 -- we don't want to penalize for speed but if it's there it should affect stress +AND COALESCE(ft_lanes,1) < 2; -- we don't want to penalize for lanes but if it's there it should affect stress +UPDATE cambridge_ways +SET tf_seg_stress = 2 +WHERE functional_class IN ('tertiary','tertiary_link') +AND tf_bike_infra = 'buffered_lane' +AND COALESCE(speed_limit,35) <= 30 -- we don't want to penalize for speed but if it's there it should affect stress +AND COALESCE(tf_lanes,1) < 2; -- we don't want to penalize for lanes but if it's there it should affect stress + +-- stress reduction for bike lane +UPDATE cambridge_ways +SET ft_seg_stress = 2 +WHERE functional_class IN ('tertiary','tertiary_link') +AND ft_bike_infra = 'lane' +AND COALESCE(ft_park,0) = 0 -- we don't want to penalize for parking but if it's there it should affect stress +AND COALESCE(speed_limit,35) <= 30 -- we don't want to penalize for speed but if it's there it should affect stress +AND COALESCE(ft_lanes,1) < 2; -- we don't want to penalize for lanes but if it's there it should affect stress +UPDATE cambridge_ways +SET tf_seg_stress = 2 +WHERE functional_class IN ('tertiary','tertiary_link') +AND tf_bike_infra = 'lane' +AND COALESCE(tf_park,0) = 0 -- we don't want to penalize for parking but if it's there it should affect stress +AND COALESCE(speed_limit,35) <= 30 -- we don't want to penalize for speed but if it's there it should affect stress +AND COALESCE(tf_lanes,1) < 2; -- we don't want to penalize for lanes but if it's there it should affect stress diff --git a/stress_track.sql b/stress_track.sql new file mode 100644 index 00000000..bdc75261 --- /dev/null +++ b/stress_track.sql @@ -0,0 +1,11 @@ +---------------------------------------- +-- INPUTS +-- location: cambridge +---------------------------------------- +UPDATE cambridge_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL +WHERE functional_class = 'track'; + +UPDATE cambridge_ways +SET ft_seg_stress = 1, + tf_seg_stress = 1 +WHERE functional_class = 'track'; From 592f5454144e41eb3a6b8f3466d714876e2eba58 Mon Sep 17 00:00:00 2001 From: Spencer Gardner Date: Mon, 19 Sep 2016 06:26:30 -0500 Subject: [PATCH 09/94] fhsklsd --- import_osm.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/import_osm.sh b/import_osm.sh index 1d145c5e..9a4a5bf1 100644 --- a/import_osm.sh +++ b/import_osm.sh @@ -65,26 +65,40 @@ osm2pgrouting \ echo 'Renaming tables' psql -h $DBHOST -U gis -d ${DBNAME} \ -c "ALTER TABLE received.${OSMPREFIX}_ways_vertices_pgr RENAME TO ${OSMPREFIX}_ways_intersections;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE received.${OSMPREFIX}_ways_intersections RENAME CONSTRAINT node_id TO ${OSMPREFIX}_node_id;" psql -h $DBHOST -U gis -d ${DBNAME} \ -c "ALTER TABLE received.osm_nodes RENAME TO ${OSMPREFIX}_osm_nodes;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE received.${OSMPREFIX}_osm_nodes RENAME CONSTRAINT node_id TO ${OSMPREFIX}_node_id;" psql -h $DBHOST -U gis -d ${DBNAME} \ -c "ALTER TABLE received.osm_relations RENAME TO ${OSMPREFIX}_osm_relations;" psql -h $DBHOST -U gis -d ${DBNAME} \ -c "ALTER TABLE received.osm_way_classes RENAME TO ${OSMPREFIX}_osm_way_classes;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE received.${OSMPREFIX}_osm_way_classes RENAME CONSTRAINT osm_way_classes_pkey TO ${OSMPREFIX}_osm_way_classes_pkey;" psql -h $DBHOST -U gis -d ${DBNAME} \ -c "ALTER TABLE received.osm_way_tags RENAME TO ${OSMPREFIX}_osm_way_tags;" psql -h $DBHOST -U gis -d ${DBNAME} \ -c "ALTER TABLE received.osm_way_types RENAME TO ${OSMPREFIX}_osm_way_types;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE received.${OSMPREFIX}_osm_way_types RENAME CONSTRAINT osm_way_types_pkey TO ${OSMPREFIX}_osm_way_types_pkey;" psql -h $DBHOST -U gis -d ${DBNAME} \ -c "ALTER TABLE scratch.osm_nodes RENAME TO ${OSMPREFIX}_hwys_osm_nodes;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE scratch.${OSMPREFIX}_hwys_osm_nodes RENAME CONSTRAINT node_id TO ${OSMPREFIX}_node_id;" psql -h $DBHOST -U gis -d ${DBNAME} \ -c "ALTER TABLE scratch.osm_relations RENAME TO ${OSMPREFIX}_hwys_osm_relations;" psql -h $DBHOST -U gis -d ${DBNAME} \ -c "ALTER TABLE scratch.osm_way_classes RENAME TO ${OSMPREFIX}_hwys_osm_way_classes;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE scratch.${OSMPREFIX}_hwys_osm_way_classes RENAME CONSTRAINT osm_way_classes_pkey TO ${OSMPREFIX}_osm_way_classes_pkey;" psql -h $DBHOST -U gis -d ${DBNAME} \ -c "ALTER TABLE scratch.osm_way_tags RENAME TO ${OSMPREFIX}_hwys_osm_way_tags;" psql -h $DBHOST -U gis -d ${DBNAME} \ -c "ALTER TABLE scratch.osm_way_types RENAME TO ${OSMPREFIX}_hwys_osm_way_types;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE scratch.${OSMPREFIX}_hwys_osm_way_types RENAME CONSTRAINT osm_way_types_pkey TO ${OSMPREFIX}_osm_way_types_pkey;" # import full osm to fill out additional data needs # not met by osm2pgrouting From 141a6ec175061a3aad163873fbfd6f166adbc0e8 Mon Sep 17 00:00:00 2001 From: Spencer Gardner Date: Mon, 19 Sep 2016 06:44:09 -0500 Subject: [PATCH 10/94] sd --- import_osm.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/import_osm.sh b/import_osm.sh index 9a4a5bf1..572d55eb 100644 --- a/import_osm.sh +++ b/import_osm.sh @@ -66,7 +66,7 @@ echo 'Renaming tables' psql -h $DBHOST -U gis -d ${DBNAME} \ -c "ALTER TABLE received.${OSMPREFIX}_ways_vertices_pgr RENAME TO ${OSMPREFIX}_ways_intersections;" psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE received.${OSMPREFIX}_ways_intersections RENAME CONSTRAINT node_id TO ${OSMPREFIX}_node_id;" + -c "ALTER TABLE received.${OSMPREFIX}_ways_intersections RENAME CONSTRAINT vertex_id TO ${OSMPREFIX}_vertex_id;" psql -h $DBHOST -U gis -d ${DBNAME} \ -c "ALTER TABLE received.osm_nodes RENAME TO ${OSMPREFIX}_osm_nodes;" psql -h $DBHOST -U gis -d ${DBNAME} \ @@ -83,6 +83,8 @@ psql -h $DBHOST -U gis -d ${DBNAME} \ -c "ALTER TABLE received.osm_way_types RENAME TO ${OSMPREFIX}_osm_way_types;" psql -h $DBHOST -U gis -d ${DBNAME} \ -c "ALTER TABLE received.${OSMPREFIX}_osm_way_types RENAME CONSTRAINT osm_way_types_pkey TO ${OSMPREFIX}_osm_way_types_pkey;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE scratch.${OSMPREFIX}_hwys_ways_vertices_pgr RENAME CONSTRAINT vertex_id TO ${OSMPREFIX}_vertex_id;" psql -h $DBHOST -U gis -d ${DBNAME} \ -c "ALTER TABLE scratch.osm_nodes RENAME TO ${OSMPREFIX}_hwys_osm_nodes;" psql -h $DBHOST -U gis -d ${DBNAME} \ From 8d5487bfdfbdde016eb48465c9abe6145c88e7de Mon Sep 17 00:00:00 2001 From: Spencer Gardner Date: Mon, 19 Sep 2016 06:54:09 -0500 Subject: [PATCH 11/94] j --- drop_tables.sh | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ import_osm.sh | 2 ++ 2 files changed, 51 insertions(+) create mode 100644 drop_tables.sh diff --git a/drop_tables.sh b/drop_tables.sh new file mode 100644 index 00000000..883e650f --- /dev/null +++ b/drop_tables.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash + +# vars +DBHOST='192.168.1.144' +DBNAME='people_for_bikes' +OSMPREFIX='cambridge' + +# drop old tables +echo 'Dropping old tables' +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_ways;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_ways_intersections;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_relations_ways;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_nodes;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_relations;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_way_classes;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_way_tags;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_way_types;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_hwys_ways;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_hwys_ways_vertices_pgr;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_hwys_relations_ways;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_hwys_osm_nodes;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_hwys_osm_relations;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_hwys_osm_way_classes;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_hwys_osm_way_tags;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_hwys_osm_way_types;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_full_line;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_full_point;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_full_polygon;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_full_roads;" diff --git a/import_osm.sh b/import_osm.sh index 572d55eb..21668bda 100644 --- a/import_osm.sh +++ b/import_osm.sh @@ -1,3 +1,5 @@ +#!/usr/bin/env bash + # vars DBHOST='192.168.1.144' DBNAME='people_for_bikes' From c5b3634c8fa9a4574b386e27305aefc8d30252d3 Mon Sep 17 00:00:00 2001 From: Spencer Gardner Date: Mon, 19 Sep 2016 06:57:22 -0500 Subject: [PATCH 12/94] j --- import_osm.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/import_osm.sh b/import_osm.sh index 21668bda..00565f79 100644 --- a/import_osm.sh +++ b/import_osm.sh @@ -152,6 +152,7 @@ psql -h $DBHOST -U gis -d ${DBNAME} -f ./width_ft.sql psql -h $DBHOST -U gis -d ${DBNAME} -f ./lanes.sql psql -h $DBHOST -U gis -d ${DBNAME} -f ./park.sql psql -h $DBHOST -U gis -d ${DBNAME} -f ./bike_infra.sql +echo 'Calculating stress' psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_motorway-trunk.sql psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_primary.sql psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_secondary.sql From a6e81267310bff2042f759660e03de3ccd4b5a21 Mon Sep 17 00:00:00 2001 From: Spencer Gardner Date: Mon, 19 Sep 2016 08:12:20 -0500 Subject: [PATCH 13/94] fj --- stress_residential.sql | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/stress_residential.sql b/stress_residential.sql index 800ace95..e529990f 100644 --- a/stress_residential.sql +++ b/stress_residential.sql @@ -16,10 +16,15 @@ UPDATE cambridge_ways SET ft_seg_stress = 3 WHERE functional_class = 'residential' AND (ft_lanes > 1 OR speed_limit > 30); +UPDATE cambridge_ways +SET tf_seg_stress = 3 +WHERE functional_class = 'residential' +AND (tf_lanes > 1 OR speed_limit > 30); -- stress increase for narrow one way and parking on both sides UPDATE cambridge_ways -SET ft_seg_stress = 3 +SET ft_seg_stress = 3, + tf_seg_stress = 3 WHERE functional_class = 'residential' AND width_ft <= 28 AND ft_park = 1 From 37aa146f0aded709ecf0529ddb4e38917f6ea048 Mon Sep 17 00:00:00 2001 From: Spencer Date: Mon, 19 Sep 2016 14:39:54 -0500 Subject: [PATCH 14/94] i --- drop_tables.sh | 2 +- import_osm.sh | 5 +++-- stress.sql | 2 -- stress_one_way_reset.sql | 7 +++++++ stress_tertiary.sql | 8 ++++---- 5 files changed, 15 insertions(+), 9 deletions(-) delete mode 100644 stress.sql create mode 100644 stress_one_way_reset.sql diff --git a/drop_tables.sh b/drop_tables.sh index 883e650f..1b079eb4 100644 --- a/drop_tables.sh +++ b/drop_tables.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # vars -DBHOST='192.168.1.144' +DBHOST='192.168.40.225' DBNAME='people_for_bikes' OSMPREFIX='cambridge' diff --git a/import_osm.sh b/import_osm.sh index 00565f79..e7872601 100644 --- a/import_osm.sh +++ b/import_osm.sh @@ -1,10 +1,10 @@ #!/usr/bin/env bash # vars -DBHOST='192.168.1.144' +DBHOST='192.168.40.225' DBNAME='people_for_bikes' OSMPREFIX='cambridge' -OSMFILE='/home/spencer/Downloads/boston_massachusetts.osm' +OSMFILE='/home/spencer/gis/cambridge.osm' # drop old tables echo 'Dropping old tables' @@ -161,3 +161,4 @@ psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_residential.sql psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_living_street.sql psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_track.sql psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_path.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_one_way_reset.sql diff --git a/stress.sql b/stress.sql deleted file mode 100644 index f1236958..00000000 --- a/stress.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE ways ADD COLUMN stress INT; -ALTER TABLE ways ADD COLUMN reverse_stress INT; diff --git a/stress_one_way_reset.sql b/stress_one_way_reset.sql new file mode 100644 index 00000000..a08a4498 --- /dev/null +++ b/stress_one_way_reset.sql @@ -0,0 +1,7 @@ +-- reset opposite stress for one-way +UPDATE cambridge_ways +SET ft_seg_stress = NULL +WHERE one_way = 'tf'; +UPDATE cambridge_ways +SET tf_seg_stress = NULL +WHERE one_way = 'ft'; diff --git a/stress_tertiary.sql b/stress_tertiary.sql index a7344e1b..abf3b050 100644 --- a/stress_tertiary.sql +++ b/stress_tertiary.sql @@ -26,13 +26,13 @@ UPDATE cambridge_ways SET ft_seg_stress = 2 WHERE functional_class IN ('tertiary','tertiary_link') AND ft_bike_infra = 'buffered_lane' -AND COALESCE(speed_limit,35) <= 30 -- we don't want to penalize for speed but if it's there it should affect stress +AND COALESCE(speed_limit,30) <= 30 -- we don't want to penalize for speed but if it's there it should affect stress AND COALESCE(ft_lanes,1) < 2; -- we don't want to penalize for lanes but if it's there it should affect stress UPDATE cambridge_ways SET tf_seg_stress = 2 WHERE functional_class IN ('tertiary','tertiary_link') AND tf_bike_infra = 'buffered_lane' -AND COALESCE(speed_limit,35) <= 30 -- we don't want to penalize for speed but if it's there it should affect stress +AND COALESCE(speed_limit,30) <= 30 -- we don't want to penalize for speed but if it's there it should affect stress AND COALESCE(tf_lanes,1) < 2; -- we don't want to penalize for lanes but if it's there it should affect stress -- stress reduction for bike lane @@ -41,12 +41,12 @@ SET ft_seg_stress = 2 WHERE functional_class IN ('tertiary','tertiary_link') AND ft_bike_infra = 'lane' AND COALESCE(ft_park,0) = 0 -- we don't want to penalize for parking but if it's there it should affect stress -AND COALESCE(speed_limit,35) <= 30 -- we don't want to penalize for speed but if it's there it should affect stress +AND COALESCE(speed_limit,30) <= 30 -- we don't want to penalize for speed but if it's there it should affect stress AND COALESCE(ft_lanes,1) < 2; -- we don't want to penalize for lanes but if it's there it should affect stress UPDATE cambridge_ways SET tf_seg_stress = 2 WHERE functional_class IN ('tertiary','tertiary_link') AND tf_bike_infra = 'lane' AND COALESCE(tf_park,0) = 0 -- we don't want to penalize for parking but if it's there it should affect stress -AND COALESCE(speed_limit,35) <= 30 -- we don't want to penalize for speed but if it's there it should affect stress +AND COALESCE(speed_limit,30) <= 30 -- we don't want to penalize for speed but if it's there it should affect stress AND COALESCE(tf_lanes,1) < 2; -- we don't want to penalize for lanes but if it's there it should affect stress From f8c7e92d22c0e4578278688b40c7cc74fad06f7c Mon Sep 17 00:00:00 2001 From: Spencer Date: Wed, 21 Sep 2016 17:09:22 -0500 Subject: [PATCH 15/94] gjsdlkf --- bike_infra.sql | 6 ++ prepare_tables.sql | 2 +- stress_tertiary.sql | 220 ++++++++++++++++++++++++++++++++++++-------- 3 files changed, 187 insertions(+), 41 deletions(-) diff --git a/bike_infra.sql b/bike_infra.sql index ec1797ae..36b4d15b 100644 --- a/bike_infra.sql +++ b/bike_infra.sql @@ -61,6 +61,9 @@ AND ( OR (osm.cycleway = 'track' AND osm."oneway:bicycle" = 'no') OR (COALESCE(one_way_car,'ft') = 'ft' AND osm."cycleway" = 'track') OR (COALESCE(one_way_car,'ft') = 'ft' AND osm."cycleway:right" = 'track') + OR (one_way_car = 'tf' AND osm."cycleway" = 'opposite_track') + OR (one_way_car = 'tf' AND osm."cycleway:left" = 'opposite_track') + OR (one_way_car = 'tf' AND osm."cycleway:right" = 'opposite_track') ); @@ -121,6 +124,9 @@ AND ( OR (osm.cycleway = 'track' AND osm."oneway:bicycle" = 'no') OR (COALESCE(one_way_car,'tf') = 'tf' AND osm."cycleway" = 'track') OR (COALESCE(one_way_car,'tf') = 'tf' AND osm."cycleway:left" = 'track') + OR (one_way_car = 'ft' AND osm."cycleway" = 'opposite_track') + OR (one_way_car = 'ft' AND osm."cycleway:left" = 'opposite_track') + OR (one_way_car = 'ft' AND osm."cycleway:right" = 'opposite_track') ); -- update one_way based on bike infra diff --git a/prepare_tables.sql b/prepare_tables.sql index 6a9bdad4..f58e09a6 100644 --- a/prepare_tables.sql +++ b/prepare_tables.sql @@ -72,7 +72,7 @@ ALTER TABLE cambridge_ways ADD COLUMN tf_int_stress INT; CREATE INDEX idx_cambridge_ways_osm ON cambridge_ways (osm_id); CREATE INDEX idx_cambridge_ways_ints_osm ON cambridge_ways_intersections (osm_id); CREATE INDEX idx_cambridge_fullways ON cambridge_osm_full_line (osm_id); -CREATE INDEX idx_cambrdige_fullpoints ON cambridge_osm_full_point (osm_id); +CREATE INDEX idx_cambridge_fullpoints ON cambridge_osm_full_point (osm_id); ANALYZE cambridge_ways (osm_id,geom); ANALYZE cambridge_hwys_ways (the_geom); ANALYZE cambridge_ways_intersections (osm_id); diff --git a/stress_tertiary.sql b/stress_tertiary.sql index abf3b050..d480b2b2 100644 --- a/stress_tertiary.sql +++ b/stress_tertiary.sql @@ -5,48 +5,188 @@ UPDATE cambridge_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL WHERE functional_class IN ('tertiary','tertiary_link'); --- no additional information +-- scoring with additional info UPDATE cambridge_ways -SET ft_seg_stress = 3, - tf_seg_stress = 3 +SET ft_seg_stress = + CASE + WHEN ft_bike_infra = 'track' THEN 1 + WHEN ft_bike_infra = 'buffered_lane' + THEN CASE + WHEN speed_limit > 30 THEN 3 + ELSE CASE + WHEN ft_lanes > 1 THEN 3 + ELSE 1 + END + END + WHEN ft_bike_infra = 'lane' + THEN CASE + WHEN speed_limit > 30 THEN 3 + WHEN speed_limit <= 25 + THEN CASE + WHEN ft_lanes > 2 THEN 3 + WHEN ft_lanes = 1 THEN CASE + WHEN ft_park = 1 THEN 3 + ELSE 2 + END + ELSE CASE + WHEN ft_park = 0 THEN 1 + ELSE 2 + END + END + ELSE CASE + WHEN ft_lanes > 1 THEN 3 + ELSE CASE + WHEN ft_park = 0 THEN 1 + ELSE 2 + END + END + END + ELSE CASE + WHEN speed_limit = 30 + THEN CASE + WHEN ft_lanes = 1 THEN 2 + ELSE 3 + END + WHEN speed_limit = 25 + THEN CASE + WHEN ft_lanes = 1 THEN 1 + ELSE 3 + END + ELSE 3 + END + END WHERE functional_class IN ('tertiary','tertiary_link'); - --- stress reduction for cycle track -UPDATE cambridge_ways -SET ft_seg_stress = 2 -WHERE functional_class IN ('tertiary','tertiary_link') -AND ft_bike_infra = 'track'; UPDATE cambridge_ways -SET tf_seg_stress = 2 -WHERE functional_class IN ('tertiary','tertiary_link') -AND tf_bike_infra = 'track'; +SET tf_seg_stress = + CASE + WHEN tf_bike_infra = 'track' THEN 1 + WHEN tf_bike_infra = 'buffered_lane' + THEN CASE + WHEN speed_limit > 30 THEN 3 + ELSE CASE + WHEN tf_lanes > 1 THEN 3 + ELSE 1 + END + END + WHEN tf_bike_infra = 'lane' + THEN CASE + WHEN speed_limit > 30 THEN 3 + WHEN speed_limit <= 25 + THEN CASE + WHEN tf_lanes > 2 THEN 3 + WHEN tf_lanes = 1 THEN CASE + WHEN tf_park = 1 THEN 3 + ELSE 2 + END + ELSE CASE + WHEN tf_park = 0 THEN 1 + ELSE 2 + END + END + ELSE CASE + WHEN tf_lanes > 1 THEN 3 + ELSE CASE + WHEN tf_park = 0 THEN 1 + ELSE 2 + END + END + END + ELSE CASE + WHEN speed_limit = 30 + THEN CASE + WHEN tf_lanes = 1 THEN 2 + ELSE 3 + END + WHEN speed_limit = 25 + THEN CASE + WHEN tf_lanes = 1 THEN 1 + ELSE 3 + END + ELSE 3 + END + END +WHERE functional_class IN ('tertiary','tertiary_link'); --- stress reduction for buffered lane -UPDATE cambridge_ways -SET ft_seg_stress = 2 -WHERE functional_class IN ('tertiary','tertiary_link') -AND ft_bike_infra = 'buffered_lane' -AND COALESCE(speed_limit,30) <= 30 -- we don't want to penalize for speed but if it's there it should affect stress -AND COALESCE(ft_lanes,1) < 2; -- we don't want to penalize for lanes but if it's there it should affect stress -UPDATE cambridge_ways -SET tf_seg_stress = 2 -WHERE functional_class IN ('tertiary','tertiary_link') -AND tf_bike_infra = 'buffered_lane' -AND COALESCE(speed_limit,30) <= 30 -- we don't want to penalize for speed but if it's there it should affect stress -AND COALESCE(tf_lanes,1) < 2; -- we don't want to penalize for lanes but if it's there it should affect stress --- stress reduction for bike lane -UPDATE cambridge_ways -SET ft_seg_stress = 2 -WHERE functional_class IN ('tertiary','tertiary_link') -AND ft_bike_infra = 'lane' -AND COALESCE(ft_park,0) = 0 -- we don't want to penalize for parking but if it's there it should affect stress -AND COALESCE(speed_limit,30) <= 30 -- we don't want to penalize for speed but if it's there it should affect stress -AND COALESCE(ft_lanes,1) < 2; -- we don't want to penalize for lanes but if it's there it should affect stress -UPDATE cambridge_ways -SET tf_seg_stress = 2 -WHERE functional_class IN ('tertiary','tertiary_link') -AND tf_bike_infra = 'lane' -AND COALESCE(tf_park,0) = 0 -- we don't want to penalize for parking but if it's there it should affect stress -AND COALESCE(speed_limit,30) <= 30 -- we don't want to penalize for speed but if it's there it should affect stress -AND COALESCE(tf_lanes,1) < 2; -- we don't want to penalize for lanes but if it's there it should affect stress +-- +-- +-- -- no additional information +-- UPDATE cambridge_ways +-- SET ft_seg_stress = 3, +-- tf_seg_stress = 3 +-- WHERE functional_class IN ('tertiary','tertiary_link'); +-- +-- -- stress reduction on shared lanes with additional information +-- UPDATE cambridge_ways +-- SET ft_seg_stress = 2 +-- WHERE functional_class IN ('tertiary','tertiary_link') +-- AND ft_bike_infra IS NULL +-- AND speed_limit <= 30 +-- AND ft_lanes < 2; +-- UPDATE cambridge_ways +-- SET ft_seg_stress = 1 +-- WHERE functional_class IN ('tertiary','tertiary_link') +-- AND ft_bike_infra IS NULL +-- AND speed_limit <= 25 +-- AND ft_lanes < 2; +-- +-- UPDATE cambridge_ways +-- SET tf_seg_stress = 2 +-- WHERE functional_class IN ('tertiary','tertiary_link') +-- AND tf_bike_infra IS NULL +-- AND speed_limit <= 30 +-- AND tf_lanes < 2; +-- UPDATE cambridge_ways +-- SET tf_seg_stress = 1 +-- WHERE functional_class IN ('tertiary','tertiary_link') +-- AND tf_bike_infra IS NULL +-- AND speed_limit <= 25 +-- AND tf_lanes < 2; +-- +-- -- stress reduction for cycle track +-- UPDATE cambridge_ways +-- SET ft_seg_stress = 1 +-- WHERE functional_class IN ('tertiary','tertiary_link') +-- AND ft_bike_infra = 'track'; +-- UPDATE cambridge_ways +-- SET tf_seg_stress = 1 +-- WHERE functional_class IN ('tertiary','tertiary_link') +-- AND tf_bike_infra = 'track'; +-- +-- -- stress reduction for buffered lane +-- UPDATE cambridge_ways +-- SET ft_seg_stress = 1 +-- WHERE functional_class IN ('tertiary','tertiary_link') +-- AND ft_bike_infra = 'buffered_lane' +-- AND COALESCE(speed_limit,30) <= 30 -- we don't want to penalize for speed but if it's there it should affect stress +-- AND COALESCE(ft_lanes,1) < 2; -- we don't want to penalize for lanes but if it's there it should affect stress +-- UPDATE cambridge_ways +-- SET tf_seg_stress = 1 +-- WHERE functional_class IN ('tertiary','tertiary_link') +-- AND tf_bike_infra = 'buffered_lane' +-- AND COALESCE(speed_limit,30) <= 30 -- we don't want to penalize for speed but if it's there it should affect stress +-- AND COALESCE(tf_lanes,1) < 2; -- we don't want to penalize for lanes but if it's there it should affect stress +-- +-- -- stress reduction for bike lane +-- UPDATE cambridge_ways +-- SET ft_seg_stress = 2 +-- WHERE functional_class IN ('tertiary','tertiary_link') +-- AND ft_bike_infra = 'lane' +-- AND COALESCE(speed_limit,30) <= 30 -- we don't want to penalize for speed but if it's there it should affect stress +-- AND COALESCE(ft_lanes,1) < 2 -- we don't want to penalize for lanes but if it's there it should affect stress +-- AND COALESCE(ft_park,0) = 0; -- we don't want to penalize for parking but if it's there it should affect stress +-- UPDATE cambridge_ways +-- SET ft_seg_stress = 2 +-- WHERE functional_class IN ('tertiary','tertiary_link') +-- AND ft_bike_infra = 'lane' +-- AND ft_park = 1 +-- AND COALESCE(speed_limit,30) <= 30 -- we don't want to penalize for speed but if it's there it should affect stress +-- AND COALESCE(ft_lanes,1) < 2; -- we don't want to penalize for lanes but if it's there it should affect stress +-- +-- UPDATE cambridge_ways +-- SET tf_seg_stress = 1 +-- WHERE functional_class IN ('tertiary','tertiary_link') +-- AND tf_bike_infra = 'lane' +-- AND COALESCE(tf_park,0) = 0 -- we don't want to penalize for parking but if it's there it should affect stress +-- AND COALESCE(speed_limit,30) <= 30 -- we don't want to penalize for speed but if it's there it should affect stress +-- AND COALESCE(tf_lanes,1) < 2; -- we don't want to penalize for lanes but if it's there it should affect stress From 1b8569ff01d8eedd81e41ec47e040f8bc800af5f Mon Sep 17 00:00:00 2001 From: Spencer Gardner Date: Wed, 21 Sep 2016 21:13:01 -0500 Subject: [PATCH 16/94] sdlkjf --- functional_class.sql | 8 +++++++- stress_residential.sql | 22 +++++++++++++++++----- stress_tertiary.sql | 15 ++++++++++++--- 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/functional_class.sql b/functional_class.sql index db3ca730..0c0eff22 100644 --- a/functional_class.sql +++ b/functional_class.sql @@ -21,7 +21,13 @@ AND osm.highway IN ( 'secondary', 'primary', 'living_street' -); -- note that we're leaving out "road" and "unclassified" +); -- note that we're leaving out "road" + +UPDATE cambridge_ways +SET functional_class = 'tertiary' +FROM cambridge_osm_full_line osm +WHERE cambridge_ways.osm_id = osm.osm_id +AND osm.highway = 'unclassified'; UPDATE cambridge_ways SET functional_class = 'track' diff --git a/stress_residential.sql b/stress_residential.sql index e529990f..be6af417 100644 --- a/stress_residential.sql +++ b/stress_residential.sql @@ -1,31 +1,43 @@ ---------------------------------------- -- INPUTS -- location: cambridge +-- notes: residential streets with bike lanes of any type +-- are scored as tertiary streets ---------------------------------------- UPDATE cambridge_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL -WHERE functional_class = 'residential'; +WHERE functional_class = 'residential' +AND (ft_bike_infra IS NULL OR ft_bike_infra NOT IN ('track','buffered_lane','lane')) +AND (tf_bike_infra IS NULL OR tf_bike_infra NOT IN ('track','buffered_lane','lane')); -- no additional information UPDATE cambridge_ways SET ft_seg_stress = 1, tf_seg_stress = 1 -WHERE functional_class = 'residential'; +WHERE functional_class = 'residential' +AND (ft_bike_infra IS NULL OR ft_bike_infra NOT IN ('track','buffered_lane','lane')) +AND (tf_bike_infra IS NULL OR tf_bike_infra NOT IN ('track','buffered_lane','lane')); -- stress increase for multiple lanes or high speeds UPDATE cambridge_ways SET ft_seg_stress = 3 WHERE functional_class = 'residential' +AND (ft_bike_infra IS NULL OR ft_bike_infra NOT IN ('track','buffered_lane','lane')) +AND (tf_bike_infra IS NULL OR tf_bike_infra NOT IN ('track','buffered_lane','lane')) AND (ft_lanes > 1 OR speed_limit > 30); UPDATE cambridge_ways SET tf_seg_stress = 3 WHERE functional_class = 'residential' +AND (ft_bike_infra IS NULL OR ft_bike_infra NOT IN ('track','buffered_lane','lane')) +AND (tf_bike_infra IS NULL OR tf_bike_infra NOT IN ('track','buffered_lane','lane')) AND (tf_lanes > 1 OR speed_limit > 30); -- stress increase for narrow one way and parking on both sides UPDATE cambridge_ways -SET ft_seg_stress = 3, - tf_seg_stress = 3 +SET ft_seg_stress = 2, + tf_seg_stress = 2 WHERE functional_class = 'residential' -AND width_ft <= 28 +AND (ft_bike_infra IS NULL OR ft_bike_infra NOT IN ('track','buffered_lane','lane')) +AND (tf_bike_infra IS NULL OR tf_bike_infra NOT IN ('track','buffered_lane','lane')) +AND width_ft <= 26 AND ft_park = 1 AND tf_park = 1; diff --git a/stress_tertiary.sql b/stress_tertiary.sql index d480b2b2..e7f9a76e 100644 --- a/stress_tertiary.sql +++ b/stress_tertiary.sql @@ -1,9 +1,13 @@ ---------------------------------------- -- INPUTS -- location: cambridge +-- notes: this includes residential streets that have bike lanes +-- of any type ---------------------------------------- UPDATE cambridge_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL -WHERE functional_class IN ('tertiary','tertiary_link'); +WHERE functional_class IN ('tertiary','tertiary_link') +OR (functional_class = 'residential' AND ft_bike_infra IN ('track','buffered_lane','lane')) +OR (functional_class = 'residential' AND tf_bike_infra IN ('track','buffered_lane','lane')); -- scoring with additional info UPDATE cambridge_ways @@ -55,7 +59,10 @@ SET ft_seg_stress = ELSE 3 END END -WHERE functional_class IN ('tertiary','tertiary_link'); +WHERE functional_class IN ('tertiary','tertiary_link') +OR (functional_class = 'residential' AND ft_bike_infra IN ('track','buffered_lane','lane')) +OR (functional_class = 'residential' AND tf_bike_infra IN ('track','buffered_lane','lane')); + UPDATE cambridge_ways SET tf_seg_stress = CASE @@ -105,7 +112,9 @@ SET tf_seg_stress = ELSE 3 END END -WHERE functional_class IN ('tertiary','tertiary_link'); +WHERE functional_class IN ('tertiary','tertiary_link') +OR (functional_class = 'residential' AND ft_bike_infra IN ('track','buffered_lane','lane')) +OR (functional_class = 'residential' AND tf_bike_infra IN ('track','buffered_lane','lane')); -- From 38efd9117833df10017eb88207620c25e9346b0a Mon Sep 17 00:00:00 2001 From: Spencer Date: Thu, 22 Sep 2016 12:52:06 -0500 Subject: [PATCH 17/94] sdlkj --- functional_class.sql | 136 ++++++++--------- stress_primary.sql | 96 ++++++++++-- stress_residential.sql | 86 +++++------ stress_secondary.sql | 126 ++++++++++------ stress_tertiary.sql | 323 ++++++++++++++++------------------------- 5 files changed, 403 insertions(+), 364 deletions(-) diff --git a/functional_class.sql b/functional_class.sql index 0c0eff22..4ea493c7 100644 --- a/functional_class.sql +++ b/functional_class.sql @@ -1,68 +1,68 @@ ----------------------------------------- --- INPUTS --- location: cambridge ----------------------------------------- -UPDATE cambridge_ways SET functional_class = NULL; - -UPDATE cambridge_ways -SET functional_class = osm.highway -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id -AND osm.highway IN ( - 'motorway', - 'tertiary', - 'trunk', - 'tertiary_link', - 'motorway_link', - 'secondary_link', - 'primary_link', - 'trunk_link', - 'residential', - 'secondary', - 'primary', - 'living_street' -); -- note that we're leaving out "road" - -UPDATE cambridge_ways -SET functional_class = 'tertiary' -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id -AND osm.highway = 'unclassified'; - -UPDATE cambridge_ways -SET functional_class = 'track' -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id -AND osm.highway = 'track' -AND osm.tracktype = 'grade1'; - -UPDATE cambridge_ways -SET functional_class = 'path' -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id -AND osm.highway IN ('cycleway','path'); - -UPDATE cambridge_ways -SET functional_class = 'path' -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id -AND osm.highway = 'footway' -AND osm.bicycle IN ('yes','permissive') -AND (osm.access IS NULL OR osm.access NOT IN ('no','private')); - -UPDATE cambridge_ways -SET functional_class = 'living_street' -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id -AND osm.highway = 'pedestrian' -AND osm.bicycle IN ('yes','permissive') -AND (osm.access IS NULL OR osm.access NOT IN ('no','private')); - -DELETE FROM cambridge_ways WHERE functional_class IS NULL; -DELETE FROM cambridge_ways_intersections -WHERE NOT EXISTS ( - SELECT 1 - FROM cambridge_ways - WHERE cambridge_ways_intersections.int_id IN (intersection_from,intersection_to) -); ---elevators? +---------------------------------------- +-- INPUTS +-- location: cambridge +---------------------------------------- +UPDATE cambridge_ways SET functional_class = NULL; + +UPDATE cambridge_ways +SET functional_class = osm.highway +FROM cambridge_osm_full_line osm +WHERE cambridge_ways.osm_id = osm.osm_id +AND osm.highway IN ( + 'motorway', + 'tertiary', + 'trunk', + 'tertiary_link', + 'motorway_link', + 'secondary_link', + 'primary_link', + 'trunk_link', + 'residential', + 'secondary', + 'primary', + 'living_street' +); -- note that we're leaving out "road" + +UPDATE cambridge_ways +SET functional_class = 'tertiary' +FROM cambridge_osm_full_line osm +WHERE cambridge_ways.osm_id = osm.osm_id +AND osm.highway = 'unclassified'; + +UPDATE cambridge_ways +SET functional_class = 'track' +FROM cambridge_osm_full_line osm +WHERE cambridge_ways.osm_id = osm.osm_id +AND osm.highway = 'track' +AND osm.tracktype = 'grade1'; + +UPDATE cambridge_ways +SET functional_class = 'path' +FROM cambridge_osm_full_line osm +WHERE cambridge_ways.osm_id = osm.osm_id +AND osm.highway IN ('cycleway','path'); + +UPDATE cambridge_ways +SET functional_class = 'path' +FROM cambridge_osm_full_line osm +WHERE cambridge_ways.osm_id = osm.osm_id +AND osm.highway = 'footway' +AND osm.bicycle IN ('yes','permissive') +AND (osm.access IS NULL OR osm.access NOT IN ('no','private')); + +UPDATE cambridge_ways +SET functional_class = 'living_street' +FROM cambridge_osm_full_line osm +WHERE cambridge_ways.osm_id = osm.osm_id +AND osm.highway = 'pedestrian' +AND osm.bicycle IN ('yes','permissive') +AND (osm.access IS NULL OR osm.access NOT IN ('no','private')); + +DELETE FROM cambridge_ways WHERE functional_class IS NULL; +DELETE FROM cambridge_ways_intersections +WHERE NOT EXISTS ( + SELECT 1 + FROM cambridge_ways + WHERE cambridge_ways_intersections.int_id IN (intersection_from,intersection_to) +); +--elevators? diff --git a/stress_primary.sql b/stress_primary.sql index faa09cc8..aa8f269e 100644 --- a/stress_primary.sql +++ b/stress_primary.sql @@ -5,18 +5,92 @@ UPDATE cambridge_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL WHERE functional_class IN ('primary','primary_link'); --- no additional information +-- ft direction UPDATE cambridge_ways -SET ft_seg_stress = 4, - tf_seg_stress = 4 +SET ft_seg_stress = + CASE + WHEN ft_bike_infra = 'track' THEN 1 + WHEN ft_bike_infra = 'buffered_lane' + THEN CASE + WHEN speed_limit = 35 THEN CASE + WHEN ft_lanes = 1 THEN 2 + ELSE 3 + END + WHEN speed_limit <= 30 THEN CASE + WHEN ft_lanes = 1 THEN 1 + ELSE 3 + END + ELSE 3 + END + WHEN ft_bike_infra = 'lane' + THEN CASE + WHEN speed_limit <= 25 + THEN CASE + WHEN ft_lanes = 1 THEN CASE + WHEN ft_park = 0 THEN 1 + ELSE 2 + END + WHEN ft_lanes > 2 THEN 3 + ELSE CASE + WHEN ft_park = 0 THEN 2 + ELSE 3 + END + END + WHEN speed_limit = 30 THEN CASE + WHEN ft_lanes = 1 THEN + CASE + WHEN ft_park = 0 THEN 1 + ELSE 2 + END + ELSE 3 + END + ELSE 3 + END + ELSE 3 + END WHERE functional_class IN ('primary','primary_link'); --- stress reduction for cycle track +-- tf direction UPDATE cambridge_ways -SET ft_seg_stress = 2 -WHERE functional_class IN ('primary','primary_link') -AND ft_bike_infra = 'track'; -UPDATE cambridge_ways -SET tf_seg_stress = 2 -WHERE functional_class IN ('primary','primary_link') -AND tf_bike_infra = 'track'; +SET tf_seg_stress = + CASE + WHEN tf_bike_infra = 'track' THEN 1 + WHEN tf_bike_infra = 'buffered_lane' + THEN CASE + WHEN speed_limit = 35 THEN CASE + WHEN tf_lanes = 1 THEN 2 + ELSE 3 + END + WHEN speed_limit <= 30 THEN CASE + WHEN tf_lanes = 1 THEN 1 + ELSE 3 + END + ELSE 3 + END + WHEN tf_bike_infra = 'lane' + THEN CASE + WHEN speed_limit <= 25 + THEN CASE + WHEN tf_lanes = 1 THEN CASE + WHEN tf_park = 0 THEN 1 + ELSE 2 + END + WHEN tf_lanes > 2 THEN 3 + ELSE CASE + WHEN tf_park = 0 THEN 2 + ELSE 3 + END + END + WHEN speed_limit = 30 THEN CASE + WHEN tf_lanes = 1 THEN + CASE + WHEN tf_park = 0 THEN 1 + ELSE 2 + END + ELSE 3 + END + ELSE 3 + END + ELSE 3 + END +WHERE functional_class IN ('primary','primary_link'); diff --git a/stress_residential.sql b/stress_residential.sql index be6af417..cdd51522 100644 --- a/stress_residential.sql +++ b/stress_residential.sql @@ -1,43 +1,43 @@ ----------------------------------------- --- INPUTS --- location: cambridge --- notes: residential streets with bike lanes of any type --- are scored as tertiary streets ----------------------------------------- -UPDATE cambridge_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL -WHERE functional_class = 'residential' -AND (ft_bike_infra IS NULL OR ft_bike_infra NOT IN ('track','buffered_lane','lane')) -AND (tf_bike_infra IS NULL OR tf_bike_infra NOT IN ('track','buffered_lane','lane')); - --- no additional information -UPDATE cambridge_ways -SET ft_seg_stress = 1, - tf_seg_stress = 1 -WHERE functional_class = 'residential' -AND (ft_bike_infra IS NULL OR ft_bike_infra NOT IN ('track','buffered_lane','lane')) -AND (tf_bike_infra IS NULL OR tf_bike_infra NOT IN ('track','buffered_lane','lane')); - --- stress increase for multiple lanes or high speeds -UPDATE cambridge_ways -SET ft_seg_stress = 3 -WHERE functional_class = 'residential' -AND (ft_bike_infra IS NULL OR ft_bike_infra NOT IN ('track','buffered_lane','lane')) -AND (tf_bike_infra IS NULL OR tf_bike_infra NOT IN ('track','buffered_lane','lane')) -AND (ft_lanes > 1 OR speed_limit > 30); -UPDATE cambridge_ways -SET tf_seg_stress = 3 -WHERE functional_class = 'residential' -AND (ft_bike_infra IS NULL OR ft_bike_infra NOT IN ('track','buffered_lane','lane')) -AND (tf_bike_infra IS NULL OR tf_bike_infra NOT IN ('track','buffered_lane','lane')) -AND (tf_lanes > 1 OR speed_limit > 30); - --- stress increase for narrow one way and parking on both sides -UPDATE cambridge_ways -SET ft_seg_stress = 2, - tf_seg_stress = 2 -WHERE functional_class = 'residential' -AND (ft_bike_infra IS NULL OR ft_bike_infra NOT IN ('track','buffered_lane','lane')) -AND (tf_bike_infra IS NULL OR tf_bike_infra NOT IN ('track','buffered_lane','lane')) -AND width_ft <= 26 -AND ft_park = 1 -AND tf_park = 1; +---------------------------------------- +-- INPUTS +-- location: cambridge +-- notes: residential streets with bike lanes of any type +-- are scored as tertiary streets +---------------------------------------- +UPDATE cambridge_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL +WHERE functional_class = 'residential' +AND (ft_bike_infra IS NULL OR ft_bike_infra NOT IN ('track','buffered_lane','lane')) +AND (tf_bike_infra IS NULL OR tf_bike_infra NOT IN ('track','buffered_lane','lane')); + +-- no additional information +UPDATE cambridge_ways +SET ft_seg_stress = 1, + tf_seg_stress = 1 +WHERE functional_class = 'residential' +AND (ft_bike_infra IS NULL OR ft_bike_infra NOT IN ('track','buffered_lane','lane')) +AND (tf_bike_infra IS NULL OR tf_bike_infra NOT IN ('track','buffered_lane','lane')); + +-- stress increase for multiple lanes or high speeds +UPDATE cambridge_ways +SET ft_seg_stress = 3 +WHERE functional_class = 'residential' +AND (ft_bike_infra IS NULL OR ft_bike_infra NOT IN ('track','buffered_lane','lane')) +AND (tf_bike_infra IS NULL OR tf_bike_infra NOT IN ('track','buffered_lane','lane')) +AND (ft_lanes > 1 OR speed_limit > 30); +UPDATE cambridge_ways +SET tf_seg_stress = 3 +WHERE functional_class = 'residential' +AND (ft_bike_infra IS NULL OR ft_bike_infra NOT IN ('track','buffered_lane','lane')) +AND (tf_bike_infra IS NULL OR tf_bike_infra NOT IN ('track','buffered_lane','lane')) +AND (tf_lanes > 1 OR speed_limit > 30); + +-- stress increase for narrow one way and parking on both sides +UPDATE cambridge_ways +SET ft_seg_stress = 2, + tf_seg_stress = 2 +WHERE functional_class = 'residential' +AND (ft_bike_infra IS NULL OR ft_bike_infra NOT IN ('track','buffered_lane','lane')) +AND (tf_bike_infra IS NULL OR tf_bike_infra NOT IN ('track','buffered_lane','lane')) +AND width_ft <= 26 +AND ft_park = 1 +AND tf_park = 1; diff --git a/stress_secondary.sql b/stress_secondary.sql index 138c13be..4975d28c 100644 --- a/stress_secondary.sql +++ b/stress_secondary.sql @@ -5,48 +5,92 @@ UPDATE cambridge_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL WHERE functional_class IN ('secondary','secondary_link'); --- no additional information +-- ft direction UPDATE cambridge_ways -SET ft_seg_stress = 4, - tf_seg_stress = 4 +SET ft_seg_stress = + CASE + WHEN ft_bike_infra = 'track' THEN 1 + WHEN ft_bike_infra = 'buffered_lane' + THEN CASE + WHEN speed_limit = 35 THEN CASE + WHEN ft_lanes = 1 THEN 2 + ELSE 3 + END + WHEN speed_limit <= 30 THEN CASE + WHEN ft_lanes = 1 THEN 1 + ELSE 3 + END + ELSE 3 + END + WHEN ft_bike_infra = 'lane' + THEN CASE + WHEN speed_limit <= 25 + THEN CASE + WHEN ft_lanes = 1 THEN CASE + WHEN ft_park = 0 THEN 1 + ELSE 2 + END + WHEN ft_lanes > 2 THEN 3 + ELSE CASE + WHEN ft_park = 0 THEN 2 + ELSE 3 + END + END + WHEN speed_limit = 30 THEN CASE + WHEN ft_lanes = 1 THEN + CASE + WHEN ft_park = 0 THEN 1 + ELSE 2 + END + ELSE 3 + END + ELSE 3 + END + ELSE 3 + END WHERE functional_class IN ('secondary','secondary_link'); --- stress reduction for cycle track +-- tf direction UPDATE cambridge_ways -SET ft_seg_stress = 2 -WHERE functional_class IN ('secondary','secondary_link') -AND ft_bike_infra = 'track'; -UPDATE cambridge_ways -SET tf_seg_stress = 2 -WHERE functional_class IN ('secondary','secondary_link') -AND tf_bike_infra = 'track'; - --- stress reduction for one vehicle lane and buffered lane -UPDATE cambridge_ways -SET ft_seg_stress = 2 -WHERE functional_class IN ('secondary','secondary_link') -AND ft_bike_infra = 'buffered_lane' -AND ft_lanes = 1 -AND speed_limit <= 30; -UPDATE cambridge_ways -SET tf_seg_stress = 2 -WHERE functional_class IN ('secondary','secondary_link') -AND tf_bike_infra = 'buffered_lane' -AND tf_lanes = 1 -AND speed_limit <= 30; - --- stress reduction for one vehicle lane, no parking, and bike lane -UPDATE cambridge_ways -SET ft_seg_stress = 2 -WHERE functional_class IN ('secondary','secondary_link') -AND ft_bike_infra = 'lane' -AND ft_lanes = 1 -AND ft_park = 0 -AND speed_limit <= 30; -UPDATE cambridge_ways -SET tf_seg_stress = 2 -WHERE functional_class IN ('secondary','secondary_link') -AND tf_bike_infra = 'lane' -AND tf_lanes = 1 -AND ft_park = 0 -AND speed_limit <= 30; +SET tf_seg_stress = + CASE + WHEN tf_bike_infra = 'track' THEN 1 + WHEN tf_bike_infra = 'buffered_lane' + THEN CASE + WHEN speed_limit = 35 THEN CASE + WHEN tf_lanes = 1 THEN 2 + ELSE 3 + END + WHEN speed_limit <= 30 THEN CASE + WHEN tf_lanes = 1 THEN 1 + ELSE 3 + END + ELSE 3 + END + WHEN tf_bike_infra = 'lane' + THEN CASE + WHEN speed_limit <= 25 + THEN CASE + WHEN tf_lanes = 1 THEN CASE + WHEN tf_park = 0 THEN 1 + ELSE 2 + END + WHEN tf_lanes > 2 THEN 3 + ELSE CASE + WHEN tf_park = 0 THEN 2 + ELSE 3 + END + END + WHEN speed_limit = 30 THEN CASE + WHEN tf_lanes = 1 THEN + CASE + WHEN tf_park = 0 THEN 1 + ELSE 2 + END + ELSE 3 + END + ELSE 3 + END + ELSE 3 + END +WHERE functional_class IN ('secondary','secondary_link'); diff --git a/stress_tertiary.sql b/stress_tertiary.sql index e7f9a76e..0855b7ce 100644 --- a/stress_tertiary.sql +++ b/stress_tertiary.sql @@ -1,201 +1,122 @@ ----------------------------------------- --- INPUTS --- location: cambridge --- notes: this includes residential streets that have bike lanes --- of any type ----------------------------------------- -UPDATE cambridge_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL -WHERE functional_class IN ('tertiary','tertiary_link') -OR (functional_class = 'residential' AND ft_bike_infra IN ('track','buffered_lane','lane')) -OR (functional_class = 'residential' AND tf_bike_infra IN ('track','buffered_lane','lane')); - --- scoring with additional info -UPDATE cambridge_ways -SET ft_seg_stress = - CASE - WHEN ft_bike_infra = 'track' THEN 1 - WHEN ft_bike_infra = 'buffered_lane' - THEN CASE - WHEN speed_limit > 30 THEN 3 - ELSE CASE - WHEN ft_lanes > 1 THEN 3 - ELSE 1 - END - END - WHEN ft_bike_infra = 'lane' - THEN CASE - WHEN speed_limit > 30 THEN 3 - WHEN speed_limit <= 25 - THEN CASE - WHEN ft_lanes > 2 THEN 3 - WHEN ft_lanes = 1 THEN CASE - WHEN ft_park = 1 THEN 3 - ELSE 2 - END - ELSE CASE - WHEN ft_park = 0 THEN 1 - ELSE 2 - END - END - ELSE CASE - WHEN ft_lanes > 1 THEN 3 - ELSE CASE - WHEN ft_park = 0 THEN 1 - ELSE 2 - END - END - END - ELSE CASE - WHEN speed_limit = 30 - THEN CASE - WHEN ft_lanes = 1 THEN 2 - ELSE 3 - END - WHEN speed_limit = 25 - THEN CASE - WHEN ft_lanes = 1 THEN 1 - ELSE 3 - END - ELSE 3 - END - END -WHERE functional_class IN ('tertiary','tertiary_link') -OR (functional_class = 'residential' AND ft_bike_infra IN ('track','buffered_lane','lane')) -OR (functional_class = 'residential' AND tf_bike_infra IN ('track','buffered_lane','lane')); - -UPDATE cambridge_ways -SET tf_seg_stress = - CASE - WHEN tf_bike_infra = 'track' THEN 1 - WHEN tf_bike_infra = 'buffered_lane' - THEN CASE - WHEN speed_limit > 30 THEN 3 - ELSE CASE - WHEN tf_lanes > 1 THEN 3 - ELSE 1 - END - END - WHEN tf_bike_infra = 'lane' - THEN CASE - WHEN speed_limit > 30 THEN 3 - WHEN speed_limit <= 25 - THEN CASE - WHEN tf_lanes > 2 THEN 3 - WHEN tf_lanes = 1 THEN CASE - WHEN tf_park = 1 THEN 3 - ELSE 2 - END - ELSE CASE - WHEN tf_park = 0 THEN 1 - ELSE 2 - END - END - ELSE CASE - WHEN tf_lanes > 1 THEN 3 - ELSE CASE - WHEN tf_park = 0 THEN 1 - ELSE 2 - END - END - END - ELSE CASE - WHEN speed_limit = 30 - THEN CASE - WHEN tf_lanes = 1 THEN 2 - ELSE 3 - END - WHEN speed_limit = 25 - THEN CASE - WHEN tf_lanes = 1 THEN 1 - ELSE 3 - END - ELSE 3 - END - END -WHERE functional_class IN ('tertiary','tertiary_link') -OR (functional_class = 'residential' AND ft_bike_infra IN ('track','buffered_lane','lane')) -OR (functional_class = 'residential' AND tf_bike_infra IN ('track','buffered_lane','lane')); - - --- --- --- -- no additional information --- UPDATE cambridge_ways --- SET ft_seg_stress = 3, --- tf_seg_stress = 3 --- WHERE functional_class IN ('tertiary','tertiary_link'); --- --- -- stress reduction on shared lanes with additional information --- UPDATE cambridge_ways --- SET ft_seg_stress = 2 --- WHERE functional_class IN ('tertiary','tertiary_link') --- AND ft_bike_infra IS NULL --- AND speed_limit <= 30 --- AND ft_lanes < 2; --- UPDATE cambridge_ways --- SET ft_seg_stress = 1 --- WHERE functional_class IN ('tertiary','tertiary_link') --- AND ft_bike_infra IS NULL --- AND speed_limit <= 25 --- AND ft_lanes < 2; --- --- UPDATE cambridge_ways --- SET tf_seg_stress = 2 --- WHERE functional_class IN ('tertiary','tertiary_link') --- AND tf_bike_infra IS NULL --- AND speed_limit <= 30 --- AND tf_lanes < 2; --- UPDATE cambridge_ways --- SET tf_seg_stress = 1 --- WHERE functional_class IN ('tertiary','tertiary_link') --- AND tf_bike_infra IS NULL --- AND speed_limit <= 25 --- AND tf_lanes < 2; --- --- -- stress reduction for cycle track --- UPDATE cambridge_ways --- SET ft_seg_stress = 1 --- WHERE functional_class IN ('tertiary','tertiary_link') --- AND ft_bike_infra = 'track'; --- UPDATE cambridge_ways --- SET tf_seg_stress = 1 --- WHERE functional_class IN ('tertiary','tertiary_link') --- AND tf_bike_infra = 'track'; --- --- -- stress reduction for buffered lane --- UPDATE cambridge_ways --- SET ft_seg_stress = 1 --- WHERE functional_class IN ('tertiary','tertiary_link') --- AND ft_bike_infra = 'buffered_lane' --- AND COALESCE(speed_limit,30) <= 30 -- we don't want to penalize for speed but if it's there it should affect stress --- AND COALESCE(ft_lanes,1) < 2; -- we don't want to penalize for lanes but if it's there it should affect stress --- UPDATE cambridge_ways --- SET tf_seg_stress = 1 --- WHERE functional_class IN ('tertiary','tertiary_link') --- AND tf_bike_infra = 'buffered_lane' --- AND COALESCE(speed_limit,30) <= 30 -- we don't want to penalize for speed but if it's there it should affect stress --- AND COALESCE(tf_lanes,1) < 2; -- we don't want to penalize for lanes but if it's there it should affect stress --- --- -- stress reduction for bike lane --- UPDATE cambridge_ways --- SET ft_seg_stress = 2 --- WHERE functional_class IN ('tertiary','tertiary_link') --- AND ft_bike_infra = 'lane' --- AND COALESCE(speed_limit,30) <= 30 -- we don't want to penalize for speed but if it's there it should affect stress --- AND COALESCE(ft_lanes,1) < 2 -- we don't want to penalize for lanes but if it's there it should affect stress --- AND COALESCE(ft_park,0) = 0; -- we don't want to penalize for parking but if it's there it should affect stress --- UPDATE cambridge_ways --- SET ft_seg_stress = 2 --- WHERE functional_class IN ('tertiary','tertiary_link') --- AND ft_bike_infra = 'lane' --- AND ft_park = 1 --- AND COALESCE(speed_limit,30) <= 30 -- we don't want to penalize for speed but if it's there it should affect stress --- AND COALESCE(ft_lanes,1) < 2; -- we don't want to penalize for lanes but if it's there it should affect stress --- --- UPDATE cambridge_ways --- SET tf_seg_stress = 1 --- WHERE functional_class IN ('tertiary','tertiary_link') --- AND tf_bike_infra = 'lane' --- AND COALESCE(tf_park,0) = 0 -- we don't want to penalize for parking but if it's there it should affect stress --- AND COALESCE(speed_limit,30) <= 30 -- we don't want to penalize for speed but if it's there it should affect stress --- AND COALESCE(tf_lanes,1) < 2; -- we don't want to penalize for lanes but if it's there it should affect stress +---------------------------------------- +-- INPUTS +-- location: cambridge +-- notes: this includes residential streets that have bike lanes +-- of any type +---------------------------------------- +UPDATE cambridge_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL +WHERE functional_class IN ('tertiary','tertiary_link') +OR (functional_class = 'residential' AND ft_bike_infra IN ('track','buffered_lane','lane')) +OR (functional_class = 'residential' AND tf_bike_infra IN ('track','buffered_lane','lane')); + +-- ft direction +UPDATE cambridge_ways +SET ft_seg_stress = + CASE + WHEN ft_bike_infra = 'track' THEN 1 + WHEN ft_bike_infra = 'buffered_lane' + THEN CASE + WHEN speed_limit > 35 THEN 3 + WHEN speed_limit = 35 THEN CASE + WHEN ft_lanes = 1 THEN 2 + ELSE 3 + END + ELSE CASE + WHEN ft_lanes > 1 THEN 3 + ELSE 1 + END + END + WHEN ft_bike_infra = 'lane' + THEN CASE + WHEN speed_limit > 30 THEN 3 + WHEN speed_limit <= 25 + THEN CASE + WHEN ft_lanes > 2 THEN 3 + WHEN ft_lanes = 1 THEN CASE + WHEN ft_park = 1 THEN 2 + ELSE 2 + END + ELSE CASE + WHEN ft_park = 0 THEN 1 + ELSE 2 + END + END + ELSE CASE + WHEN ft_lanes > 1 THEN 3 + ELSE CASE + WHEN ft_park = 0 THEN 1 + ELSE 2 + END + END + END + ELSE CASE + WHEN speed_limit = 30 + THEN CASE + WHEN ft_lanes = 1 THEN 2 + ELSE 3 + END + WHEN speed_limit = 25 + THEN CASE + WHEN ft_lanes = 1 THEN 1 + ELSE 3 + END + ELSE 3 + END + END +WHERE functional_class IN ('tertiary','tertiary_link') +OR (functional_class = 'residential' AND ft_bike_infra IN ('track','buffered_lane','lane')) +OR (functional_class = 'residential' AND tf_bike_infra IN ('track','buffered_lane','lane')); + +-- tf direction +UPDATE cambridge_ways +SET tf_seg_stress = + CASE + WHEN tf_bike_infra = 'track' THEN 1 + WHEN tf_bike_infra = 'buffered_lane' + THEN CASE + WHEN speed_limit > 30 THEN 3 + ELSE CASE + WHEN tf_lanes > 1 THEN 3 + ELSE 1 + END + END + WHEN tf_bike_infra = 'lane' + THEN CASE + WHEN speed_limit > 30 THEN 3 + WHEN speed_limit <= 25 + THEN CASE + WHEN tf_lanes > 2 THEN 3 + WHEN tf_lanes = 1 THEN CASE + WHEN tf_park = 1 THEN 2 + ELSE 2 + END + ELSE CASE + WHEN tf_park = 0 THEN 1 + ELSE 2 + END + END + ELSE CASE + WHEN tf_lanes > 1 THEN 3 + ELSE CASE + WHEN tf_park = 0 THEN 1 + ELSE 2 + END + END + END + ELSE CASE + WHEN speed_limit = 30 + THEN CASE + WHEN tf_lanes = 1 THEN 2 + ELSE 3 + END + WHEN speed_limit = 25 + THEN CASE + WHEN tf_lanes = 1 THEN 1 + ELSE 3 + END + ELSE 3 + END + END +WHERE functional_class IN ('tertiary','tertiary_link') +OR (functional_class = 'residential' AND ft_bike_infra IN ('track','buffered_lane','lane')) +OR (functional_class = 'residential' AND tf_bike_infra IN ('track','buffered_lane','lane')); From b0ab5b92f101dd334e5d7126e30bc87289decf93 Mon Sep 17 00:00:00 2001 From: Spencer Date: Thu, 22 Sep 2016 17:14:55 -0500 Subject: [PATCH 18/94] jjj --- import_osm.sh | 7 +- legs.sql | 10 +++ pfb.style | 5 +- prepare_tables.sql | 6 ++ process.txt | 20 +++-- signalized.sql | 27 +++++++ stops.sql | 12 +++ stress_intersections.sql | 154 +++++++++++++++++++++++++++++++++++++++ 8 files changed, 230 insertions(+), 11 deletions(-) create mode 100644 legs.sql create mode 100644 signalized.sql create mode 100644 stops.sql create mode 100644 stress_intersections.sql diff --git a/import_osm.sh b/import_osm.sh index e7872601..0785c925 100644 --- a/import_osm.sh +++ b/import_osm.sh @@ -144,7 +144,7 @@ psql -h $DBHOST -U gis -d ${DBNAME} \ # process tables echo 'Updating field names' psql -h $DBHOST -U gis -d ${DBNAME} -f ./prepare_tables.sql -echo 'Setting values' +echo 'Setting values on road segments' psql -h $DBHOST -U gis -d ${DBNAME} -f ./one_way.sql psql -h $DBHOST -U gis -d ${DBNAME} -f ./functional_class.sql psql -h $DBHOST -U gis -d ${DBNAME} -f ./speed_limit.sql @@ -152,6 +152,10 @@ psql -h $DBHOST -U gis -d ${DBNAME} -f ./width_ft.sql psql -h $DBHOST -U gis -d ${DBNAME} -f ./lanes.sql psql -h $DBHOST -U gis -d ${DBNAME} -f ./park.sql psql -h $DBHOST -U gis -d ${DBNAME} -f ./bike_infra.sql +echo 'Setting values on intersections' +psql -h $DBHOST -U gis -d ${DBNAME} -f ./legs.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./signalized.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./stops.sql echo 'Calculating stress' psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_motorway-trunk.sql psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_primary.sql @@ -162,3 +166,4 @@ psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_living_street.sql psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_track.sql psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_path.sql psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_one_way_reset.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_intersections.sql diff --git a/legs.sql b/legs.sql new file mode 100644 index 00000000..93255a62 --- /dev/null +++ b/legs.sql @@ -0,0 +1,10 @@ +---------------------------------------- +-- INPUTS +-- location: cambridge +---------------------------------------- +UPDATE received.cambridge_ways_intersections +SET legs = ( + SELECT COUNT(road_id) + FROM cambridge_ways + WHERE cambridge_ways_intersections.int_id IN (intersection_from,intersection_to) +); diff --git a/pfb.style b/pfb.style index 448ec1e4..a92152f0 100644 --- a/pfb.style +++ b/pfb.style @@ -110,11 +110,12 @@ way parking:lane:right text linear way parking:lane:left text linear way parking:lane:both text linear node,way segregated text linear -node,way stop TEXT linear +node,way stop text linear node,way surface text linear way tracktype text linear node,way traffic_sign text linear -node,way traffic_signals text linear +node traffic_signals text linear +way traffic_signals:direction text linear node,way tunnel text linear node,way width text linear diff --git a/prepare_tables.sql b/prepare_tables.sql index f58e09a6..8efc443b 100644 --- a/prepare_tables.sql +++ b/prepare_tables.sql @@ -102,3 +102,9 @@ WHERE NOT EXISTS ( FROM cambridge_ways w2 WHERE w2.osm_id = cambridge_hwys_ways.osm_id ); + +-- setup intersection table +ALTER TABLE cambridge_ways_intersections ADD COLUMN legs INT; +ALTER TABLE cambridge_ways_intersections ADD COLUMN signalized BOOLEAN; +ALTER TABLE cambridge_ways_intersections ADD COLUMN stops BOOLEAN; +CREATE INDEX idx_cambridge_ints_stop ON cambridge_ways_intersections (signalized,stops); diff --git a/process.txt b/process.txt index 9e475316..b8984a65 100644 --- a/process.txt +++ b/process.txt @@ -7,11 +7,15 @@ 7: Run lanes.sql 8: Run park.sql 9: Run bike_infra.sql -10: Run stress_motorway-trunk.sql -11: Run stress_primary.sql -12: Run stress_secondary.sql -13: Run stress_tertiary.sql -14: Run stress_residential.sql -15: Run stress_living_street.sql -16: Run stress_track.sql -17: Run stress_path.sql +10: Run legs.sql +11: Run signalized.sql +12: Run stops.sql +13: Run stress_motorway-trunk.sql +14: Run stress_primary.sql +15: Run stress_secondary.sql +16: Run stress_tertiary.sql +17: Run stress_residential.sql +18: Run stress_living_street.sql +19: Run stress_track.sql +20: Run stress_path.sql +21: Run stress_intersections.sql diff --git a/signalized.sql b/signalized.sql new file mode 100644 index 00000000..f0ebcd13 --- /dev/null +++ b/signalized.sql @@ -0,0 +1,27 @@ +---------------------------------------- +-- INPUTS +-- location: cambridge +---------------------------------------- +UPDATE cambridge_ways_intersections SET signalized = 'f'; + +UPDATE cambridge_ways_intersections +SET signalized = 't' +FROM cambridge_osm_full_point osm +WHERE cambridge_ways_intersections.osm_id = osm.osm_id +AND osm.highway = 'traffic_signals'; + +UPDATE cambridge_ways_intersections +SET signalized = 't' +FROM cambridge_ways, + cambridge_osm_full_line osm +WHERE cambridge_ways.osm_id = osm.osm_id +AND int_id = cambridge_ways.intersection_to +AND osm."traffic_signals:direction" = 'forward'; + +UPDATE cambridge_ways_intersections +SET signalized = 't' +FROM cambridge_ways, + cambridge_osm_full_line osm +WHERE cambridge_ways.osm_id = osm.osm_id +AND int_id = cambridge_ways.intersection_from +AND osm."traffic_signals:direction" = 'backward'; diff --git a/stops.sql b/stops.sql new file mode 100644 index 00000000..bdee62b7 --- /dev/null +++ b/stops.sql @@ -0,0 +1,12 @@ +---------------------------------------- +-- INPUTS +-- location: cambridge +---------------------------------------- +UPDATE cambridge_ways_intersections SET stops = 'f'; + +UPDATE cambridge_ways_intersections +SET stops = 't' +FROM cambridge_osm_full_point osm +WHERE cambridge_ways_intersections.osm_id = osm.osm_id +AND osm.highway = 'stop' +AND osm.stop = 'all'; diff --git a/stress_intersections.sql b/stress_intersections.sql new file mode 100644 index 00000000..ef6765c4 --- /dev/null +++ b/stress_intersections.sql @@ -0,0 +1,154 @@ +---------------------------------------- +-- INPUTS +-- location: cambridge +---------------------------------------- +-- start with assuming that every intersection is stressful +UPDATE cambridge_ways SET ft_int_stress = 3, tf_int_stress = 3; + +-- primary and higher +-- assume low stress, since these juncions would always be controlled +UPDATE cambridge_ways SET ft_int_stress = 1, tf_int_stress = 1 +WHERE functional_class IN ('motorway','motorway_link','trunk','trunk_link','primary','primary_link'); + + + + + + + + +-- secondary +-- assume low stress unless the junction is with primary or higher +UPDATE cambridge_ways SET ft_int_stress = 1 +WHERE functional_class IN ('secondary','secondary_link') +AND NOT EXISTS ( + SELECT 1 + FROM cambridge_ways w + WHERE intersection_to IN (w.intersection_to,w.intersection_from) + AND COALESCE(cambridge_ways.name,'a') != COALESCE(w.name,'b') + AND w.functional_class IN ( + 'motorway','motorway_link', + 'trunk','trunk_link', + 'primary','primary_link' + 'secondary','secondary_link' + ) +); +UPDATE cambridge_ways SET tf_int_stress = 1 +WHERE functional_class IN ('secondary','secondary_link') +AND NOT EXISTS ( + SELECT 1 + FROM cambridge_ways w + WHERE intersection_from IN (w.intersection_to,w.intersection_from) + AND COALESCE(cambridge_ways.name,'a') != COALESCE(w.name,'b') + AND w.functional_class IN ( + 'motorway','motorway_link', + 'trunk','trunk_link', + 'primary','primary_link' + 'secondary','secondary_link' + ) +); + +-- secondary +-- assume low stress unless the junction is with secondary or higher +UPDATE cambridge_ways SET ft_int_stress = 1 +WHERE functional_class IN ('secondary','secondary_link') +AND NOT EXISTS ( + SELECT 1 + FROM cambridge_ways w + WHERE intersection_to IN (w.intersection_to,w.intersection_from) + AND COALESCE(cambridge_ways.name,'a') != COALESCE(w.name,'b') + AND w.functional_class IN ( + 'motorway','motorway_link', + 'trunk','trunk_link', + 'primary','primary_link' + 'secondary','secondary_link' + ) +); +UPDATE cambridge_ways SET tf_int_stress = 1 +WHERE functional_class IN ('secondary','secondary_link') +AND NOT EXISTS ( + SELECT 1 + FROM cambridge_ways w + WHERE intersection_from IN (w.intersection_to,w.intersection_from) + AND COALESCE(cambridge_ways.name,'a') != COALESCE(w.name,'b') + AND w.functional_class IN ( + 'motorway','motorway_link', + 'trunk','trunk_link', + 'primary','primary_link' + 'secondary','secondary_link' + ) +); +-- assign low stress if lane and speed data are present and meet requirements +UPDATE cambridge_ways SET ft_int_stress = 1 +WHERE functional_class IN ('secondary','secondary_link') +AND EXISTS ( + SELECT 1 + FROM cambridge_ways w + WHERE intersection_to IN (w.intersection_to,w.intersection_from) + AND COALESCE(cambridge_ways.name,'a') != COALESCE(w.name,'b') + AND w.functional_class IN ( + 'motorway','motorway_link', + 'trunk','trunk_link', + 'primary','primary_link' + 'secondary','secondary_link' + ) +); + + + + +-- residential and lower +UPDATE cambridge_ways +SET ft_int_stress = CASE + WHEN + THEN +WHERE functional_class IN ('residential','living_street','track','path') + + + +-- UPDATE cambridge_ways +-- SET ft_int_stress = ( +-- SELECT MAX(GREATEST(r.ft_seg_stress,r.tf_seg_stress)) +-- FROM cambridge_ways r +-- WHERE NOT r.road_id = cambridge_ways.road_id +-- AND cambridge_ways.intersection_to IN (r.intersection_from,r.intersection_to) +-- ); +-- UPDATE generated.roads +-- SET tf_int_stress = ( +-- SELECT MAX(GREATEST(r.ft_seg_stress,r.tf_seg_stress)) +-- FROM cambridge_ways r +-- WHERE NOT r.road_id = cambridge_ways.road_id +-- AND cambridge_ways.intersection_from IN (r.intersection_from,r.intersection_to) +-- ); + + + +-- reduce stress for non-intersections +UPDATE cambridge_ways +SET ft_int_stress = 1 +FROM cambridge_ways_intersections i +WHERE cambridge_ways.intersection_to = i.int_id +AND i.legs < 3; +UPDATE cambridge_ways +SET tf_int_stress = 1 +FROM cambridge_ways_intersections i +WHERE cambridge_ways.intersection_from = i.int_id +AND i.legs < 3; + +-- reduce stress for stoplights or all-way stops +UPDATE cambridge_ways +SET ft_int_stress = 1 +WHERE EXISTS ( + SELECT 1 + FROM cambridge_ways_intersections i + WHERE i.int_id = cambridge_ways.intersection_to + AND (i.signalized OR i.stops) +); +UPDATE cambridge_ways +SET tf_int_stress = 1 +WHERE EXISTS ( + SELECT 1 + FROM cambridge_ways_intersections i + WHERE i.int_id = cambridge_ways.intersection_from + AND (i.signalized OR i.stops) +); From 526b49e2d0d271c3ec93902a247b25fb8bdfc7c1 Mon Sep 17 00:00:00 2001 From: Spencer Gardner Date: Thu, 22 Sep 2016 23:27:20 -0500 Subject: [PATCH 19/94] slkjdf --- import_osm.sh | 9 +- stress_intersections.sql | 154 --------------------------------- stress_lesser_ints.sql | 118 +++++++++++++++++++++++++ stress_link_ints.sql | 6 ++ stress_motorway-trunk.sql | 2 +- stress_motorway-trunk_ints.sql | 7 ++ stress_primary_ints.sql | 7 ++ stress_secondary_ints.sql | 90 +++++++++++++++++++ stress_tertiary_ints.sql | 118 +++++++++++++++++++++++++ 9 files changed, 354 insertions(+), 157 deletions(-) delete mode 100644 stress_intersections.sql create mode 100644 stress_lesser_ints.sql create mode 100644 stress_link_ints.sql create mode 100644 stress_motorway-trunk_ints.sql create mode 100644 stress_primary_ints.sql create mode 100644 stress_secondary_ints.sql create mode 100644 stress_tertiary_ints.sql diff --git a/import_osm.sh b/import_osm.sh index 0785c925..23a294d9 100644 --- a/import_osm.sh +++ b/import_osm.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # vars -DBHOST='192.168.40.225' +DBHOST='192.168.1.144' DBNAME='people_for_bikes' OSMPREFIX='cambridge' OSMFILE='/home/spencer/gis/cambridge.osm' @@ -166,4 +166,9 @@ psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_living_street.sql psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_track.sql psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_path.sql psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_one_way_reset.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_intersections.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_motorway-trunk_ints.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_primary_ints.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_secondary_ints.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_tertiary_ints.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_lesser_ints.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_link_ints.sql diff --git a/stress_intersections.sql b/stress_intersections.sql deleted file mode 100644 index ef6765c4..00000000 --- a/stress_intersections.sql +++ /dev/null @@ -1,154 +0,0 @@ ----------------------------------------- --- INPUTS --- location: cambridge ----------------------------------------- --- start with assuming that every intersection is stressful -UPDATE cambridge_ways SET ft_int_stress = 3, tf_int_stress = 3; - --- primary and higher --- assume low stress, since these juncions would always be controlled -UPDATE cambridge_ways SET ft_int_stress = 1, tf_int_stress = 1 -WHERE functional_class IN ('motorway','motorway_link','trunk','trunk_link','primary','primary_link'); - - - - - - - - --- secondary --- assume low stress unless the junction is with primary or higher -UPDATE cambridge_ways SET ft_int_stress = 1 -WHERE functional_class IN ('secondary','secondary_link') -AND NOT EXISTS ( - SELECT 1 - FROM cambridge_ways w - WHERE intersection_to IN (w.intersection_to,w.intersection_from) - AND COALESCE(cambridge_ways.name,'a') != COALESCE(w.name,'b') - AND w.functional_class IN ( - 'motorway','motorway_link', - 'trunk','trunk_link', - 'primary','primary_link' - 'secondary','secondary_link' - ) -); -UPDATE cambridge_ways SET tf_int_stress = 1 -WHERE functional_class IN ('secondary','secondary_link') -AND NOT EXISTS ( - SELECT 1 - FROM cambridge_ways w - WHERE intersection_from IN (w.intersection_to,w.intersection_from) - AND COALESCE(cambridge_ways.name,'a') != COALESCE(w.name,'b') - AND w.functional_class IN ( - 'motorway','motorway_link', - 'trunk','trunk_link', - 'primary','primary_link' - 'secondary','secondary_link' - ) -); - --- secondary --- assume low stress unless the junction is with secondary or higher -UPDATE cambridge_ways SET ft_int_stress = 1 -WHERE functional_class IN ('secondary','secondary_link') -AND NOT EXISTS ( - SELECT 1 - FROM cambridge_ways w - WHERE intersection_to IN (w.intersection_to,w.intersection_from) - AND COALESCE(cambridge_ways.name,'a') != COALESCE(w.name,'b') - AND w.functional_class IN ( - 'motorway','motorway_link', - 'trunk','trunk_link', - 'primary','primary_link' - 'secondary','secondary_link' - ) -); -UPDATE cambridge_ways SET tf_int_stress = 1 -WHERE functional_class IN ('secondary','secondary_link') -AND NOT EXISTS ( - SELECT 1 - FROM cambridge_ways w - WHERE intersection_from IN (w.intersection_to,w.intersection_from) - AND COALESCE(cambridge_ways.name,'a') != COALESCE(w.name,'b') - AND w.functional_class IN ( - 'motorway','motorway_link', - 'trunk','trunk_link', - 'primary','primary_link' - 'secondary','secondary_link' - ) -); --- assign low stress if lane and speed data are present and meet requirements -UPDATE cambridge_ways SET ft_int_stress = 1 -WHERE functional_class IN ('secondary','secondary_link') -AND EXISTS ( - SELECT 1 - FROM cambridge_ways w - WHERE intersection_to IN (w.intersection_to,w.intersection_from) - AND COALESCE(cambridge_ways.name,'a') != COALESCE(w.name,'b') - AND w.functional_class IN ( - 'motorway','motorway_link', - 'trunk','trunk_link', - 'primary','primary_link' - 'secondary','secondary_link' - ) -); - - - - --- residential and lower -UPDATE cambridge_ways -SET ft_int_stress = CASE - WHEN - THEN -WHERE functional_class IN ('residential','living_street','track','path') - - - --- UPDATE cambridge_ways --- SET ft_int_stress = ( --- SELECT MAX(GREATEST(r.ft_seg_stress,r.tf_seg_stress)) --- FROM cambridge_ways r --- WHERE NOT r.road_id = cambridge_ways.road_id --- AND cambridge_ways.intersection_to IN (r.intersection_from,r.intersection_to) --- ); --- UPDATE generated.roads --- SET tf_int_stress = ( --- SELECT MAX(GREATEST(r.ft_seg_stress,r.tf_seg_stress)) --- FROM cambridge_ways r --- WHERE NOT r.road_id = cambridge_ways.road_id --- AND cambridge_ways.intersection_from IN (r.intersection_from,r.intersection_to) --- ); - - - --- reduce stress for non-intersections -UPDATE cambridge_ways -SET ft_int_stress = 1 -FROM cambridge_ways_intersections i -WHERE cambridge_ways.intersection_to = i.int_id -AND i.legs < 3; -UPDATE cambridge_ways -SET tf_int_stress = 1 -FROM cambridge_ways_intersections i -WHERE cambridge_ways.intersection_from = i.int_id -AND i.legs < 3; - --- reduce stress for stoplights or all-way stops -UPDATE cambridge_ways -SET ft_int_stress = 1 -WHERE EXISTS ( - SELECT 1 - FROM cambridge_ways_intersections i - WHERE i.int_id = cambridge_ways.intersection_to - AND (i.signalized OR i.stops) -); -UPDATE cambridge_ways -SET tf_int_stress = 1 -WHERE EXISTS ( - SELECT 1 - FROM cambridge_ways_intersections i - WHERE i.int_id = cambridge_ways.intersection_from - AND (i.signalized OR i.stops) -); diff --git a/stress_lesser_ints.sql b/stress_lesser_ints.sql new file mode 100644 index 00000000..1fa83798 --- /dev/null +++ b/stress_lesser_ints.sql @@ -0,0 +1,118 @@ +---------------------------------------- +-- INPUTS +-- location: cambridge +---------------------------------------- +UPDATE cambridge_ways SET ft_int_stress = 1, tf_int_stress = 1 +WHERE functional_class IN ('residential','living_street','track','path'); + +-- ft +UPDATE cambridge_ways +SET ft_int_stress = 3 +WHERE functional_class IN ('residential','living_street','track','path') +AND EXISTS ( + SELECT 1 + FROM cambridge_ways w + WHERE cambridge_ways.intersection_to IN (w.intersection_to,w.intersection_from) + AND COALESCE(cambridge_ways.name,'a') != COALESCE(w.name,'b') + AND CASE + WHEN w.functional_class IN ('motorway','trunk','primary') + THEN CASE + WHEN w.ft_lanes + w.tf_lanes < 4 + THEN CASE + WHEN w.speed_limit <= 30 THEN 0::BOOLEAN + ELSE 1::BOOLEAN + END + WHEN w.ft_lanes + w.tf_lanes = 4 + THEN CASE + WHEN w.speed_limit <= 25 THEN 0::BOOLEAN + ELSE 1::BOOLEAN + END + ELSE 1::BOOLEAN + END + WHEN w.functional_class = 'secondary' + THEN CASE + WHEN w.ft_lanes + w.tf_lanes >= 5 + THEN 1::BOOLEAN + WHEN w.ft_lanes + w.tf_lanes < 4 + THEN CASE + WHEN w.speed_limit > 30 THEN 1::BOOLEAN + ELSE 0::BOOLEAN + END + ELSE CASE + WHEN w.speed_limit <= 25 THEN 0::BOOLEAN + ELSE 1::BOOLEAN + END + END + WHEN w.functional_class = 'tertiary' + THEN CASE + WHEN w.ft_lanes + w.tf_lanes >= 5 + THEN 1::BOOLEAN + WHEN w.ft_lanes + w.tf_lanes = 4 + THEN CASE + WHEN w.speed_limit > 25 THEN 1::BOOLEAN + ELSE 0::BOOLEAN + END + ELSE CASE + WHEN w.speed_limit > 30 THEN 1::BOOLEAN + ELSE 0::BOOLEAN + END + END + ELSE 0::BOOLEAN + END +); + +-- tf +UPDATE cambridge_ways +SET tf_int_stress = 3 +WHERE functional_class IN ('residential','living_street','track','path') +AND EXISTS ( + SELECT 1 + FROM cambridge_ways w + WHERE cambridge_ways.intersection_from IN (w.intersection_to,w.intersection_from) + AND COALESCE(cambridge_ways.name,'a') != COALESCE(w.name,'b') + AND CASE + WHEN w.functional_class IN ('motorway','trunk','primary') + THEN CASE + WHEN w.ft_lanes + w.tf_lanes < 4 + THEN CASE + WHEN w.speed_limit <= 30 THEN 0::BOOLEAN + ELSE 1::BOOLEAN + END + WHEN w.ft_lanes + w.tf_lanes = 4 + THEN CASE + WHEN w.speed_limit <= 25 THEN 0::BOOLEAN + ELSE 1::BOOLEAN + END + ELSE 1::BOOLEAN + END + WHEN w.functional_class = 'secondary' + THEN CASE + WHEN w.ft_lanes + w.tf_lanes >= 5 + THEN 1::BOOLEAN + WHEN w.ft_lanes + w.tf_lanes < 4 + THEN CASE + WHEN w.speed_limit > 30 THEN 1::BOOLEAN + ELSE 0::BOOLEAN + END + ELSE CASE + WHEN w.speed_limit <= 25 THEN 0::BOOLEAN + ELSE 1::BOOLEAN + END + END + WHEN w.functional_class = 'tertiary' + THEN CASE + WHEN w.ft_lanes + w.tf_lanes >= 5 + THEN 1::BOOLEAN + WHEN w.ft_lanes + w.tf_lanes = 4 + THEN CASE + WHEN w.speed_limit > 25 THEN 1::BOOLEAN + ELSE 0::BOOLEAN + END + ELSE CASE + WHEN w.speed_limit > 30 THEN 1::BOOLEAN + ELSE 0::BOOLEAN + END + END + ELSE 0::BOOLEAN + END +); diff --git a/stress_link_ints.sql b/stress_link_ints.sql new file mode 100644 index 00000000..16c1addb --- /dev/null +++ b/stress_link_ints.sql @@ -0,0 +1,6 @@ +---------------------------------------- +-- INPUTS +-- location: cambridge +---------------------------------------- +UPDATE cambridge_ways SET ft_int_stress = 1, tf_int_stress = 1 +WHERE functional_class LIKE '%_link'; diff --git a/stress_motorway-trunk.sql b/stress_motorway-trunk.sql index 9b1c8962..1da735a7 100644 --- a/stress_motorway-trunk.sql +++ b/stress_motorway-trunk.sql @@ -5,5 +5,5 @@ UPDATE cambridge_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL WHERE functional_class IN ('motorway','motorway_link','trunk','trunk_link'); -UPDATE cambridge_ways SET ft_seg_stress = 4, tf_seg_stress = 4 +UPDATE cambridge_ways SET ft_seg_stress = 3, tf_seg_stress = 3 WHERE functional_class IN ('motorway','motorway_link','trunk','trunk_link'); diff --git a/stress_motorway-trunk_ints.sql b/stress_motorway-trunk_ints.sql new file mode 100644 index 00000000..12fd8edb --- /dev/null +++ b/stress_motorway-trunk_ints.sql @@ -0,0 +1,7 @@ +---------------------------------------- +-- INPUTS +-- location: cambridge +---------------------------------------- +-- assume low stress, since these juncions would always be controlled or free flowing +UPDATE cambridge_ways SET ft_int_stress = 1, tf_int_stress = 1 +WHERE functional_class IN ('motorway','trunk'); diff --git a/stress_primary_ints.sql b/stress_primary_ints.sql new file mode 100644 index 00000000..38742401 --- /dev/null +++ b/stress_primary_ints.sql @@ -0,0 +1,7 @@ +---------------------------------------- +-- INPUTS +-- location: cambridge +---------------------------------------- +-- assume low stress, since these juncions would always be controlled or free flowing +UPDATE cambridge_ways SET ft_int_stress = 1, tf_int_stress = 1 +WHERE functional_class 'primary'; diff --git a/stress_secondary_ints.sql b/stress_secondary_ints.sql new file mode 100644 index 00000000..9e42a555 --- /dev/null +++ b/stress_secondary_ints.sql @@ -0,0 +1,90 @@ +---------------------------------------- +-- INPUTS +-- location: cambridge +---------------------------------------- +UPDATE cambridge_ways SET ft_int_stress = 1, tf_int_stress = 1 +WHERE functional_class = 'secondary'; + +-- ft +UPDATE cambridge_ways +SET ft_int_stress = 3 +WHERE functional_class = 'secondary' +AND EXISTS ( + SELECT 1 + FROM cambridge_ways w + WHERE cambridge_ways.intersection_to IN (w.intersection_to,w.intersection_from) + AND COALESCE(cambridge_ways.name,'a') != COALESCE(w.name,'b') + AND CASE + WHEN w.functional_class IN ('motorway','trunk','primary') + THEN CASE + WHEN w.ft_lanes + w.tf_lanes < 4 + THEN CASE + WHEN w.speed_limit <= 30 THEN 0::BOOLEAN + ELSE 1::BOOLEAN + END + WHEN w.ft_lanes + w.tf_lanes = 4 + THEN CASE + WHEN w.speed_limit <= 25 THEN 0::BOOLEAN + ELSE 1::BOOLEAN + END + ELSE 1::BOOLEAN + END + WHEN w.functional_class = 'secondary' + THEN CASE + WHEN w.ft_lanes + w.tf_lanes >= 5 + THEN 1::BOOLEAN + WHEN w.ft_lanes + w.tf_lanes < 4 + THEN CASE + WHEN w.speed_limit > 30 THEN 1::BOOLEAN + ELSE 0::BOOLEAN + END + ELSE CASE + WHEN w.speed_limit <= 25 THEN 0::BOOLEAN + ELSE 1::BOOLEAN + END + END + ELSE 0::BOOLEAN + END +); + +-- tf +UPDATE cambridge_ways +SET tf_int_stress = 3 +WHERE functional_class = 'secondary' +AND EXISTS ( + SELECT 1 + FROM cambridge_ways w + WHERE cambridge_ways.intersection_from IN (w.intersection_to,w.intersection_from) + AND COALESCE(cambridge_ways.name,'a') != COALESCE(w.name,'b') + AND CASE + WHEN w.functional_class IN ('motorway','trunk','primary') + THEN CASE + WHEN w.ft_lanes + w.tf_lanes < 4 + THEN CASE + WHEN w.speed_limit <= 30 THEN 0::BOOLEAN + ELSE 1::BOOLEAN + END + WHEN w.ft_lanes + w.tf_lanes = 4 + THEN CASE + WHEN w.speed_limit <= 25 THEN 0::BOOLEAN + ELSE 1::BOOLEAN + END + ELSE 1::BOOLEAN + END + WHEN w.functional_class = 'secondary' + THEN CASE + WHEN w.ft_lanes + w.tf_lanes >= 5 + THEN 1::BOOLEAN + WHEN w.ft_lanes + w.tf_lanes < 4 + THEN CASE + WHEN w.speed_limit > 30 THEN 1::BOOLEAN + ELSE 0::BOOLEAN + END + ELSE CASE + WHEN w.speed_limit <= 25 THEN 0::BOOLEAN + ELSE 1::BOOLEAN + END + END + ELSE 0::BOOLEAN + END +); diff --git a/stress_tertiary_ints.sql b/stress_tertiary_ints.sql new file mode 100644 index 00000000..feb754de --- /dev/null +++ b/stress_tertiary_ints.sql @@ -0,0 +1,118 @@ +---------------------------------------- +-- INPUTS +-- location: cambridge +---------------------------------------- +UPDATE cambridge_ways SET ft_int_stress = 1, tf_int_stress = 1 +WHERE functional_class = 'tertiary'; + +-- ft +UPDATE cambridge_ways +SET ft_int_stress = 3 +WHERE functional_class = 'tertiary' +AND EXISTS ( + SELECT 1 + FROM cambridge_ways w + WHERE cambridge_ways.intersection_to IN (w.intersection_to,w.intersection_from) + AND COALESCE(cambridge_ways.name,'a') != COALESCE(w.name,'b') + AND CASE + WHEN w.functional_class IN ('motorway','trunk','primary') + THEN CASE + WHEN w.ft_lanes + w.tf_lanes < 4 + THEN CASE + WHEN w.speed_limit <= 30 THEN 0::BOOLEAN + ELSE 1::BOOLEAN + END + WHEN w.ft_lanes + w.tf_lanes = 4 + THEN CASE + WHEN w.speed_limit <= 25 THEN 0::BOOLEAN + ELSE 1::BOOLEAN + END + ELSE 1::BOOLEAN + END + WHEN w.functional_class = 'secondary' + THEN CASE + WHEN w.ft_lanes + w.tf_lanes >= 5 + THEN 1::BOOLEAN + WHEN w.ft_lanes + w.tf_lanes < 4 + THEN CASE + WHEN w.speed_limit > 30 THEN 1::BOOLEAN + ELSE 0::BOOLEAN + END + ELSE CASE + WHEN w.speed_limit <= 25 THEN 0::BOOLEAN + ELSE 1::BOOLEAN + END + END + WHEN w.functional_class = 'tertiary' + THEN CASE + WHEN w.ft_lanes + w.tf_lanes >= 5 + THEN 1::BOOLEAN + WHEN w.ft_lanes + w.tf_lanes = 4 + THEN CASE + WHEN w.speed_limit > 25 THEN 1::BOOLEAN + ELSE 0::BOOLEAN + END + ELSE CASE + WHEN w.speed_limit > 30 THEN 1::BOOLEAN + ELSE 0::BOOLEAN + END + END + ELSE 0::BOOLEAN + END +); + +-- tf +UPDATE cambridge_ways +SET tf_int_stress = 3 +WHERE functional_class = 'tertiary' +AND EXISTS ( + SELECT 1 + FROM cambridge_ways w + WHERE cambridge_ways.intersection_from IN (w.intersection_to,w.intersection_from) + AND COALESCE(cambridge_ways.name,'a') != COALESCE(w.name,'b') + AND CASE + WHEN w.functional_class IN ('motorway','trunk','primary') + THEN CASE + WHEN w.ft_lanes + w.tf_lanes < 4 + THEN CASE + WHEN w.speed_limit <= 30 THEN 0::BOOLEAN + ELSE 1::BOOLEAN + END + WHEN w.ft_lanes + w.tf_lanes = 4 + THEN CASE + WHEN w.speed_limit <= 25 THEN 0::BOOLEAN + ELSE 1::BOOLEAN + END + ELSE 1::BOOLEAN + END + WHEN w.functional_class = 'secondary' + THEN CASE + WHEN w.ft_lanes + w.tf_lanes >= 5 + THEN 1::BOOLEAN + WHEN w.ft_lanes + w.tf_lanes < 4 + THEN CASE + WHEN w.speed_limit > 30 THEN 1::BOOLEAN + ELSE 0::BOOLEAN + END + ELSE CASE + WHEN w.speed_limit <= 25 THEN 0::BOOLEAN + ELSE 1::BOOLEAN + END + END + WHEN w.functional_class = 'tertiary' + THEN CASE + WHEN w.ft_lanes + w.tf_lanes >= 5 + THEN 1::BOOLEAN + WHEN w.ft_lanes + w.tf_lanes = 4 + THEN CASE + WHEN w.speed_limit > 25 THEN 1::BOOLEAN + ELSE 0::BOOLEAN + END + ELSE CASE + WHEN w.speed_limit > 30 THEN 1::BOOLEAN + ELSE 0::BOOLEAN + END + END + ELSE 0::BOOLEAN + END +); From 0cec2720037f9f9ecb991c05ad818a33fe364541 Mon Sep 17 00:00:00 2001 From: Spencer Gardner Date: Thu, 22 Sep 2016 23:55:26 -0500 Subject: [PATCH 20/94] lksjdf --- import_osm.sh | 2 +- stress_primary_ints.sql | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/import_osm.sh b/import_osm.sh index 23a294d9..891bc887 100644 --- a/import_osm.sh +++ b/import_osm.sh @@ -4,7 +4,7 @@ DBHOST='192.168.1.144' DBNAME='people_for_bikes' OSMPREFIX='cambridge' -OSMFILE='/home/spencer/gis/cambridge.osm' +OSMFILE='/home/spencer/Downloads/cambridge.osm' # drop old tables echo 'Dropping old tables' diff --git a/stress_primary_ints.sql b/stress_primary_ints.sql index 38742401..986db734 100644 --- a/stress_primary_ints.sql +++ b/stress_primary_ints.sql @@ -4,4 +4,4 @@ ---------------------------------------- -- assume low stress, since these juncions would always be controlled or free flowing UPDATE cambridge_ways SET ft_int_stress = 1, tf_int_stress = 1 -WHERE functional_class 'primary'; +WHERE functional_class = 'primary'; From a2320721e57de53fc5ebc60c58c95a1a6ecd0fde Mon Sep 17 00:00:00 2001 From: Spencer Gardner Date: Fri, 23 Sep 2016 00:16:29 -0500 Subject: [PATCH 21/94] lksdjf ; --- bike_infra.sql | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bike_infra.sql b/bike_infra.sql index 36b4d15b..e3b82947 100644 --- a/bike_infra.sql +++ b/bike_infra.sql @@ -43,9 +43,12 @@ AND ( OR (COALESCE(one_way_car,'ft') = 'ft' AND osm.cycleway = 'buffered_lane') OR (COALESCE(one_way_car,'ft') = 'ft' AND osm."cycleway:right" = 'buffered_lane') OR (COALESCE(one_way_car,'ft') = 'ft' AND osm.cycleway = 'lane' AND osm."cycleway:buffer" IN ('yes','both','right','left')) + OR (COALESCE(one_way_car,'ft') = 'ft' AND osm."cycleway:right" = 'lane' AND osm."cycleway:buffer" IN ('yes','both','right','left')) OR (COALESCE(one_way_car,'ft') = 'ft' AND osm."cycleway:right" = 'lane' AND osm."cycleway:right:buffer" IN ('yes','both','right','left')) + OR (one_way_car = 'ft' AND osm."cycleway:left" = 'lane' AND osm."cycleway:buffer" IN ('yes','both','right','left')) OR (one_way_car = 'ft' AND osm."cycleway:left" = 'lane' AND osm."cycleway:left:buffer" IN ('yes','both','right','left')) OR (one_way_car = 'tf' AND osm.cycleway = 'opposite_lane' AND osm."cycleway:buffer" IN ('yes','both','right','left')) + OR (one_way_car = 'tf' AND osm."cycleway:left" = 'opposite_lane' AND osm."cycleway:buffer" IN ('yes','both','right','left')) OR (one_way_car = 'tf' AND osm."cycleway:left" = 'opposite_lane' AND osm."cycleway:left:buffer" IN ('yes','both','right','left')) ); @@ -106,9 +109,12 @@ AND ( OR (COALESCE(one_way_car,'tf') = 'tf' AND osm.cycleway = 'buffered_lane') OR (COALESCE(one_way_car,'tf') = 'tf' AND osm."cycleway:left" = 'buffered_lane') OR (COALESCE(one_way_car,'tf') = 'tf' AND osm.cycleway = 'lane' AND osm."cycleway:buffer" IN ('yes','both','right','left')) + OR (COALESCE(one_way_car,'tf') = 'tf' AND osm."cycleway:left" = 'lane' AND osm."cycleway:buffer" IN ('yes','both','right','left')) OR (COALESCE(one_way_car,'tf') = 'tf' AND osm."cycleway:left" = 'lane' AND osm."cycleway:left:buffer" IN ('yes','both','right','left')) + OR (one_way_car = 'tf' AND osm."cycleway:right" = 'lane' AND osm."cycleway:buffer" IN ('yes','both','right','left')) OR (one_way_car = 'tf' AND osm."cycleway:right" = 'lane' AND osm."cycleway:right:buffer" IN ('yes','both','right','left')) OR (one_way_car = 'ft' AND osm.cycleway = 'opposite_lane' AND osm."cycleway:buffer" IN ('yes','both','right','left')) + OR (one_way_car = 'ft' AND osm."cycleway:right" = 'opposite_lane' AND osm."cycleway:buffer" IN ('yes','both','right','left')) OR (one_way_car = 'ft' AND osm."cycleway:right" = 'opposite_lane' AND osm."cycleway:right:buffer" IN ('yes','both','right','left')) ); From 63ed60211d06108b6be478c5de72a8d03e1b66ba Mon Sep 17 00:00:00 2001 From: Spencer Date: Fri, 23 Sep 2016 11:19:56 -0500 Subject: [PATCH 22/94] lksjdf --- import_osm.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/import_osm.sh b/import_osm.sh index 891bc887..4e811648 100644 --- a/import_osm.sh +++ b/import_osm.sh @@ -1,10 +1,10 @@ #!/usr/bin/env bash # vars -DBHOST='192.168.1.144' +DBHOST='192.168.40.225' DBNAME='people_for_bikes' OSMPREFIX='cambridge' -OSMFILE='/home/spencer/Downloads/cambridge.osm' +OSMFILE='/home/spencer/gis/cambridge.osm' # drop old tables echo 'Dropping old tables' From fb21b4fc66b80de7eca3e500384dff17026369b0 Mon Sep 17 00:00:00 2001 From: Spencer Date: Fri, 23 Sep 2016 15:35:18 -0500 Subject: [PATCH 23/94] lkjsdf --- connectivity/coverage.sql | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 connectivity/coverage.sql diff --git a/connectivity/coverage.sql b/connectivity/coverage.sql new file mode 100644 index 00000000..4d8fe048 --- /dev/null +++ b/connectivity/coverage.sql @@ -0,0 +1,22 @@ +SELECT r.road_id, + r.geom, + COUNT(sheds.node) AS ct +FROM cambridge_ways_net_vert v, + cambridge_ways r, + cambridge_boundary, + pgr_drivingDistance(' + SELECT link_id AS id, + source_vert AS source, + target_vert AS target, + link_cost AS cost + FROM cambridge_ways_net_link + WHERE link_stress = 1', + v.vert_id, + 10560, + directed := true + ) sheds +WHERE ST_Intersects(r.geom,cambridge_boundary.geom) +AND v.road_id = r.road_id +--and v.road_id = 1467 +GROUP BY r.road_id, + r.geom; From 199a977e830bfebc881446a88ea844c97123221a Mon Sep 17 00:00:00 2001 From: Spencer Gardner Date: Sat, 24 Sep 2016 13:27:30 -0500 Subject: [PATCH 24/94] lkjsdf --- .gitignore | 1 + connectivity/cycles.py | 19 +++++++++ connectivity/nxutils.py | 94 +++++++++++++++++++++++++++++++++++++++++ drop_tables.sh | 18 ++++---- functional_class.sql | 23 ++++++++-- import_osm.sh | 46 ++++++++++---------- mapconfig_all.xml | 37 ---------------- mapconfig_cycleway.xml | 9 ++++ mapconfig_highway.xml | 37 ++++++++-------- prepare_tables.sql | 18 ++++---- 10 files changed, 203 insertions(+), 99 deletions(-) create mode 100644 .gitignore create mode 100644 connectivity/cycles.py create mode 100644 connectivity/nxutils.py delete mode 100644 mapconfig_all.xml create mode 100644 mapconfig_cycleway.xml diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..0d20b648 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.pyc diff --git a/connectivity/cycles.py b/connectivity/cycles.py new file mode 100644 index 00000000..938c3e53 --- /dev/null +++ b/connectivity/cycles.py @@ -0,0 +1,19 @@ +import nxutils +import networkx as nx + +n = nxutils.NXUtils('cambridge') +n.buildNetwork() +DG = n.getNetwork() +fullCycles = len(list(nx.simple_cycles(DG))) +print('Number of cycles for all stress') +print(fullCycles) + +MG = n.getStressNetwork(2) +stressCycles = len(list(nx.simple_cycles(SG))) +print('Number of cycles for medium stress') +print(fullCycles) + +SG = n.getStressNetwork(1) +stressCycles = len(list(nx.simple_cycles(SG))) +print('Number of cycles for low stress') +print(fullCycles) diff --git a/connectivity/nxutils.py b/connectivity/nxutils.py new file mode 100644 index 00000000..946b11b8 --- /dev/null +++ b/connectivity/nxutils.py @@ -0,0 +1,94 @@ +# -*- coding: utf-8 -*- + +""" +*************************************************************************** + dbutils.py + --------------------- + Date : October 2015 + Copyright : (C) 2015 by Spencer Gardner + Email : spencergardner at gmail dot com +*************************************************************************** +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +*************************************************************************** +""" + +__author__ = 'Spencer Gardner' +__date__ = 'October 2015' +__copyright__ = '(C) 2015, Spencer Gardner' + +# This will get replaced with a git SHA1 when you do a git archive + +__revision__ = '$Format:%H$' + +import psycopg2 +import networkx as nx + +class NXUtils: + def __init__(self, prefix): + # set up connection + self.conn = psycopg2.connect("host=192.168.1.144 dbname=people_for_bikes user=gis password=gis") + + # layers + self.vertsTable = prefix + '_ways_net_vert' + self.linksTable = prefix + '_ways_net_link' + + # other vars + self.DG = nx.DiGraph() + + def buildNetwork(self): + # edges + edgeCur = self.conn.cursor() + edgeCur.execute('\ + SELECT source_vert, \ + target_vert, \ + COALESCE(link_cost,0), \ + link_id, \ + COALESCE(link_stress,99), \ + int_id \ + FROM ' + self.linksTable + ) + for record in edgeCur: + self.DG.add_edge( + int(record[0]), + int(record[1]), + weight=record[2], + link_id=record[3], + stress=record[4], + int_id=record[5] + ) + + # vertices + vertCur = self.conn.cursor() + vertCur.execute('\ + SELECT vert_id, \ + COALESCE(vert_cost,0), \ + road_id \ + FROM ' + self.vertsTable + ) + for record in vertCur: + vid = record[0] + self.DG.node[vid]['weight'] = record[1] + self.DG.node[vid]['road_id'] = record[2] + + def getNetwork(self): + return self.DG + + def getStressNetwork(self,stress): + '''SG = nx.DiGraph() + SG = nx.DiGraph( [ (u,v,d) for u,v,d in self.DG.edges(data=True) if d['stress'] <= stress ] ) + for v in SG.nodes(): + SG.node[v]['weight'] = self.DG.node[v].get('weight') + SG.node[v]['int_id'] = self.DG.node[v].get('int_id') + return SG''' + + nodeList = [] + for v in self.DG.nodes(): + if self.DG.node[v].get('stress') <= stress: + nodeList.append(v) + SG = self.DG.subgraph(nodeList) + return SG diff --git a/drop_tables.sh b/drop_tables.sh index 1b079eb4..60344d03 100644 --- a/drop_tables.sh +++ b/drop_tables.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # vars -DBHOST='192.168.40.225' +DBHOST='192.168.1.144' DBNAME='people_for_bikes' OSMPREFIX='cambridge' @@ -24,21 +24,21 @@ psql -h $DBHOST -U gis -d ${DBNAME} \ psql -h $DBHOST -U gis -d ${DBNAME} \ -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_way_types;" psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_hwys_ways;" + -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_ways;" psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_hwys_ways_vertices_pgr;" + -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_ways_vertices_pgr;" psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_hwys_relations_ways;" + -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_relations_ways;" psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_hwys_osm_nodes;" + -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_osm_nodes;" psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_hwys_osm_relations;" + -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_osm_relations;" psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_hwys_osm_way_classes;" + -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_osm_way_classes;" psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_hwys_osm_way_tags;" + -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_osm_way_tags;" psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_hwys_osm_way_types;" + -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_osm_way_types;" psql -h $DBHOST -U gis -d ${DBNAME} \ -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_full_line;" psql -h $DBHOST -U gis -d ${DBNAME} \ diff --git a/functional_class.sql b/functional_class.sql index 4ea493c7..b0d8fd53 100644 --- a/functional_class.sql +++ b/functional_class.sql @@ -58,11 +58,28 @@ AND osm.highway = 'pedestrian' AND osm.bicycle IN ('yes','permissive') AND (osm.access IS NULL OR osm.access NOT IN ('no','private')); +-- remove stuff that we don't want to route over DELETE FROM cambridge_ways WHERE functional_class IS NULL; + +-- remove orphans +DELETE FROM cambridge_ways +WHERE NOT EXISTS ( + SELECT 1 + FROM cambridge_ways w + WHERE cambridge_ways.intersection_to IN (w.intersection_to,w.intersection_from) + AND w.road_id != cambridge_ways.road_id +) +AND NOT EXISTS ( + SELECT 1 + FROM cambridge_ways w + WHERE cambridge_ways.intersection_from IN (w.intersection_to,w.intersection_from) + AND w.road_id != cambridge_ways.road_id +); + +-- remove obsolete intersections DELETE FROM cambridge_ways_intersections WHERE NOT EXISTS ( SELECT 1 - FROM cambridge_ways - WHERE cambridge_ways_intersections.int_id IN (intersection_from,intersection_to) + FROM cambridge_ways w + WHERE int_id IN (w.intersection_to,w.intersection_from) ); ---elevators? diff --git a/import_osm.sh b/import_osm.sh index 4e811648..e7f2d235 100644 --- a/import_osm.sh +++ b/import_osm.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # vars -DBHOST='192.168.40.225' +DBHOST='192.168.1.144' DBNAME='people_for_bikes' OSMPREFIX='cambridge' OSMFILE='/home/spencer/gis/cambridge.osm' @@ -25,23 +25,23 @@ psql -h $DBHOST -U gis -d ${DBNAME} \ psql -h $DBHOST -U gis -d ${DBNAME} \ -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_way_types;" psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_hwys_ways;" + -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_ways;" psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_hwys_ways_vertices_pgr;" + -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_ways_vertices_pgr;" psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_hwys_relations_ways;" + -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_relations_ways;" psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_hwys_osm_nodes;" + -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_osm_nodes;" psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_hwys_osm_relations;" + -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_osm_relations;" psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_hwys_osm_way_classes;" + -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_osm_way_classes;" psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_hwys_osm_way_tags;" + -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_osm_way_tags;" psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_hwys_osm_way_types;" + -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_osm_way_types;" -# import the osm optimized for routing +# import the osm with highways that the above misses (bug in osm2pgrouting) osm2pgrouting \ -f $OSMFILE \ -h $DBHOST \ @@ -49,18 +49,18 @@ osm2pgrouting \ --username gis \ --schema received \ --prefix ${OSMPREFIX}_ \ - --conf ./mapconfig_all.xml + --conf ./mapconfig_highway.xml \ --clean -# import the osm with highways that the above misses (bug in osm2pgrouting) +# import the osm optimized for routing osm2pgrouting \ -f $OSMFILE \ -h $DBHOST \ --dbname ${DBNAME} \ --username gis \ --schema scratch \ - --prefix ${OSMPREFIX}_hwys_ \ - --conf ./mapconfig_highway.xml + --prefix ${OSMPREFIX}_cycwys_ \ + --conf ./mapconfig_cycleway.xml \ --clean # rename a few tables @@ -86,23 +86,23 @@ psql -h $DBHOST -U gis -d ${DBNAME} \ psql -h $DBHOST -U gis -d ${DBNAME} \ -c "ALTER TABLE received.${OSMPREFIX}_osm_way_types RENAME CONSTRAINT osm_way_types_pkey TO ${OSMPREFIX}_osm_way_types_pkey;" psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE scratch.${OSMPREFIX}_hwys_ways_vertices_pgr RENAME CONSTRAINT vertex_id TO ${OSMPREFIX}_vertex_id;" + -c "ALTER TABLE scratch.${OSMPREFIX}_cycwys_ways_vertices_pgr RENAME CONSTRAINT vertex_id TO ${OSMPREFIX}_vertex_id;" psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE scratch.osm_nodes RENAME TO ${OSMPREFIX}_hwys_osm_nodes;" + -c "ALTER TABLE scratch.osm_nodes RENAME TO ${OSMPREFIX}_cycwys_osm_nodes;" psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE scratch.${OSMPREFIX}_hwys_osm_nodes RENAME CONSTRAINT node_id TO ${OSMPREFIX}_node_id;" + -c "ALTER TABLE scratch.${OSMPREFIX}_cycwys_osm_nodes RENAME CONSTRAINT node_id TO ${OSMPREFIX}_node_id;" psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE scratch.osm_relations RENAME TO ${OSMPREFIX}_hwys_osm_relations;" + -c "ALTER TABLE scratch.osm_relations RENAME TO ${OSMPREFIX}_cycwys_osm_relations;" psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE scratch.osm_way_classes RENAME TO ${OSMPREFIX}_hwys_osm_way_classes;" + -c "ALTER TABLE scratch.osm_way_classes RENAME TO ${OSMPREFIX}_cycwys_osm_way_classes;" psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE scratch.${OSMPREFIX}_hwys_osm_way_classes RENAME CONSTRAINT osm_way_classes_pkey TO ${OSMPREFIX}_osm_way_classes_pkey;" + -c "ALTER TABLE scratch.${OSMPREFIX}_cycwys_osm_way_classes RENAME CONSTRAINT osm_way_classes_pkey TO ${OSMPREFIX}_osm_way_classes_pkey;" psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE scratch.osm_way_tags RENAME TO ${OSMPREFIX}_hwys_osm_way_tags;" + -c "ALTER TABLE scratch.osm_way_tags RENAME TO ${OSMPREFIX}_cycwys_osm_way_tags;" psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE scratch.osm_way_types RENAME TO ${OSMPREFIX}_hwys_osm_way_types;" + -c "ALTER TABLE scratch.osm_way_types RENAME TO ${OSMPREFIX}_cycwys_osm_way_types;" psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE scratch.${OSMPREFIX}_hwys_osm_way_types RENAME CONSTRAINT osm_way_types_pkey TO ${OSMPREFIX}_osm_way_types_pkey;" + -c "ALTER TABLE scratch.${OSMPREFIX}_cycwys_osm_way_types RENAME CONSTRAINT osm_way_types_pkey TO ${OSMPREFIX}_osm_way_types_pkey;" # import full osm to fill out additional data needs # not met by osm2pgrouting diff --git a/mapconfig_all.xml b/mapconfig_all.xml deleted file mode 100644 index 6679e393..00000000 --- a/mapconfig_all.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/mapconfig_cycleway.xml b/mapconfig_cycleway.xml new file mode 100644 index 00000000..267b2207 --- /dev/null +++ b/mapconfig_cycleway.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/mapconfig_highway.xml b/mapconfig_highway.xml index 549e1e14..f1dc7fed 100644 --- a/mapconfig_highway.xml +++ b/mapconfig_highway.xml @@ -9,23 +9,24 @@ - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + diff --git a/prepare_tables.sql b/prepare_tables.sql index 8efc443b..5f13459f 100644 --- a/prepare_tables.sql +++ b/prepare_tables.sql @@ -46,7 +46,7 @@ ALTER TABLE cambridge_ways_intersections RENAME COLUMN the_geom TO geom; -- reproject ALTER TABLE cambridge_ways ALTER COLUMN geom TYPE geometry(linestring,2249) USING ST_Transform(geom,2249); -ALTER TABLE cambridge_hwys_ways ALTER COLUMN the_geom TYPE geometry(linestring,2249) +ALTER TABLE cambridge_cycwys_ways ALTER COLUMN the_geom TYPE geometry(linestring,2249) USING ST_Transform(the_geom,2249); ALTER TABLE cambridge_ways_intersections ALTER COLUMN geom TYPE geometry(point,2249) USING ST_Transform(geom,2249); @@ -74,33 +74,33 @@ CREATE INDEX idx_cambridge_ways_ints_osm ON cambridge_ways_intersections (osm_id CREATE INDEX idx_cambridge_fullways ON cambridge_osm_full_line (osm_id); CREATE INDEX idx_cambridge_fullpoints ON cambridge_osm_full_point (osm_id); ANALYZE cambridge_ways (osm_id,geom); -ANALYZE cambridge_hwys_ways (the_geom); +ANALYZE cambridge_cycwys_ways (the_geom); ANALYZE cambridge_ways_intersections (osm_id); ANALYZE cambridge_osm_full_line (osm_id); ANALYZE cambridge_osm_full_point (osm_id); --- add in highway data that is missing from first osm2pgrouting call +-- add in cycleway data that is missing from first osm2pgrouting call INSERT INTO cambridge_ways ( name, intersection_from, intersection_to, osm_id, geom ) SELECT name, (SELECT i.int_id FROM cambridge_ways_intersections i - WHERE i.geom <#> cambridge_hwys_ways.the_geom < 20 - ORDER BY ST_Distance(ST_StartPoint(cambridge_hwys_ways.the_geom),i.geom) ASC + WHERE i.geom <#> cambridge_cycwys_ways.the_geom < 20 + ORDER BY ST_Distance(ST_StartPoint(cambridge_cycwys_ways.the_geom),i.geom) ASC LIMIT 1), (SELECT i.int_id FROM cambridge_ways_intersections i - WHERE i.geom <#> cambridge_hwys_ways.the_geom < 20 - ORDER BY ST_Distance(ST_EndPoint(cambridge_hwys_ways.the_geom),i.geom) ASC + WHERE i.geom <#> cambridge_cycwys_ways.the_geom < 20 + ORDER BY ST_Distance(ST_EndPoint(cambridge_cycwys_ways.the_geom),i.geom) ASC LIMIT 1), osm_id, the_geom -FROM cambridge_hwys_ways +FROM cambridge_cycwys_ways WHERE NOT EXISTS ( SELECT 1 FROM cambridge_ways w2 - WHERE w2.osm_id = cambridge_hwys_ways.osm_id + WHERE w2.osm_id = cambridge_cycwys_ways.osm_id ); -- setup intersection table From ac387142b4e3465df34fd5da685e9bc75b33b34a Mon Sep 17 00:00:00 2001 From: Spencer Gardner Date: Mon, 26 Sep 2016 08:11:06 -0500 Subject: [PATCH 25/94] sldfkj --- connectivity/cycles.py | 9 ++++++--- connectivity/nxutils.py | 42 +++++++++++++++++++++++++++-------------- 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/connectivity/cycles.py b/connectivity/cycles.py index 938c3e53..96e484f6 100644 --- a/connectivity/cycles.py +++ b/connectivity/cycles.py @@ -1,12 +1,15 @@ import nxutils import networkx as nx -n = nxutils.NXUtils('cambridge') +zipCode = '02138' +prefix = 'cambridge' + +n = nxutils.NXUtils(prefix, zipCode) n.buildNetwork() DG = n.getNetwork() -fullCycles = len(list(nx.simple_cycles(DG))) +fullCycles = nx.simple_cycles(DG) print('Number of cycles for all stress') -print(fullCycles) +print(len(list(fullCycles))) MG = n.getStressNetwork(2) stressCycles = len(list(nx.simple_cycles(SG))) diff --git a/connectivity/nxutils.py b/connectivity/nxutils.py index 946b11b8..0bf737b3 100644 --- a/connectivity/nxutils.py +++ b/connectivity/nxutils.py @@ -29,29 +29,37 @@ import networkx as nx class NXUtils: - def __init__(self, prefix): + def __init__(self, prefix, zipCode): # set up connection self.conn = psycopg2.connect("host=192.168.1.144 dbname=people_for_bikes user=gis password=gis") # layers self.vertsTable = prefix + '_ways_net_vert' self.linksTable = prefix + '_ways_net_link' + self.zipsTable = prefix + '_zip_codes' # other vars + self.zipCode = zipCode self.DG = nx.DiGraph() def buildNetwork(self): # edges edgeCur = self.conn.cursor() edgeCur.execute('\ - SELECT source_vert, \ - target_vert, \ - COALESCE(link_cost,0), \ - link_id, \ - COALESCE(link_stress,99), \ - int_id \ - FROM ' + self.linksTable - ) + SELECT links.source_vert, \ + links.target_vert, \ + COALESCE(links.link_cost,0), \ + links.link_id, \ + COALESCE(links.link_stress,99), \ + links.int_id \ + FROM ' + self.linksTable + ' links \ + WHERE EXISTS ( \ + SELECT 1 \ + FROM ' + self.zipsTable + ' zips \ + WHERE zips.zip_code = \'' + self.zipCode + '\' \ + AND ST_Intersects(zips.geom,links.geom) \ + ) \ + ') for record in edgeCur: self.DG.add_edge( int(record[0]), @@ -65,11 +73,17 @@ def buildNetwork(self): # vertices vertCur = self.conn.cursor() vertCur.execute('\ - SELECT vert_id, \ - COALESCE(vert_cost,0), \ - road_id \ - FROM ' + self.vertsTable - ) + SELECT verts.vert_id, \ + COALESCE(verts.vert_cost,0), \ + verts.road_id \ + FROM ' + self.vertsTable + ' verts \ + WHERE EXISTS ( \ + SELECT 1 \ + FROM ' + self.zipsTable + ' zips \ + WHERE zips.zip_code = \'' + self.zipCode + '\' \ + AND ST_Intersects(zips.geom,verts.geom) \ + ) \ + ') for record in vertCur: vid = record[0] self.DG.node[vid]['weight'] = record[1] From 7bf1881deebc3d228a2b1eb374500b45ec9f10ef Mon Sep 17 00:00:00 2001 From: Spencer Date: Mon, 26 Sep 2016 14:15:01 -0500 Subject: [PATCH 26/94] lkjsdf --- .gitignore | 2 +- connectivity/census_block_roads.sql | 28 ++ connectivity/cycles.py | 44 +-- connectivity/nxutils.py | 216 ++++++------ connectivity/reachable_roads_high_stress.sql | 45 +++ connectivity/reachable_roads_low_stress.sql | 46 +++ drop_tables.sh | 98 +++--- import_osm.sh | 348 +++++++++---------- mapconfig_cycleway.xml | 18 +- mapconfig_highway.xml | 64 ++-- prepare_tables.sql | 220 ++++++------ 11 files changed, 624 insertions(+), 505 deletions(-) create mode 100644 connectivity/census_block_roads.sql create mode 100644 connectivity/reachable_roads_high_stress.sql create mode 100644 connectivity/reachable_roads_low_stress.sql diff --git a/.gitignore b/.gitignore index 0d20b648..94487b95 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -*.pyc +*.pyc diff --git a/connectivity/census_block_roads.sql b/connectivity/census_block_roads.sql new file mode 100644 index 00000000..4b6f0588 --- /dev/null +++ b/connectivity/census_block_roads.sql @@ -0,0 +1,28 @@ +---------------------------------------- +-- INPUTS +-- location: cambridge +---------------------------------------- + +CREATE TABLE generated.cambridge_census_block_roads ( + id SERIAL PRIMARY KEY, + blockid10 VARCHAR(15), + road_id INT +); + +INSERT INTO generated.cambridge_census_block_roads ( + blockid10, + road_id +) +SELECT blocks.blockid10, + ways.road_id +FROM cambridge_census_blocks blocks, + cambridge_zip_codes zips, + cambridge_ways ways +WHERE EXISTS ( + SELECT 1 + FROM cambridge_zip_codes zips + WHERE ST_Intersects(zips.geom,blocks.geom) + AND zips.zip_code = '02138' +) +AND blocks.geom <-> ways.geom < 50 + ST_Intersects(ST_Buffer(blocks.geom,50),ways.geom); diff --git a/connectivity/cycles.py b/connectivity/cycles.py index 96e484f6..515f8c97 100644 --- a/connectivity/cycles.py +++ b/connectivity/cycles.py @@ -1,22 +1,22 @@ -import nxutils -import networkx as nx - -zipCode = '02138' -prefix = 'cambridge' - -n = nxutils.NXUtils(prefix, zipCode) -n.buildNetwork() -DG = n.getNetwork() -fullCycles = nx.simple_cycles(DG) -print('Number of cycles for all stress') -print(len(list(fullCycles))) - -MG = n.getStressNetwork(2) -stressCycles = len(list(nx.simple_cycles(SG))) -print('Number of cycles for medium stress') -print(fullCycles) - -SG = n.getStressNetwork(1) -stressCycles = len(list(nx.simple_cycles(SG))) -print('Number of cycles for low stress') -print(fullCycles) +import nxutils +import networkx as nx + +zipCode = '02138' +prefix = 'cambridge' + +n = nxutils.NXUtils(prefix, zipCode) +n.buildNetwork() +DG = n.getNetwork() +fullCycles = nx.simple_cycles(DG) +print('Number of cycles for all stress') +print(len(list(fullCycles))) + +MG = n.getStressNetwork(2) +stressCycles = len(list(nx.simple_cycles(SG))) +print('Number of cycles for medium stress') +print(fullCycles) + +SG = n.getStressNetwork(1) +stressCycles = len(list(nx.simple_cycles(SG))) +print('Number of cycles for low stress') +print(fullCycles) diff --git a/connectivity/nxutils.py b/connectivity/nxutils.py index 0bf737b3..1e751d55 100644 --- a/connectivity/nxutils.py +++ b/connectivity/nxutils.py @@ -1,108 +1,108 @@ -# -*- coding: utf-8 -*- - -""" -*************************************************************************** - dbutils.py - --------------------- - Date : October 2015 - Copyright : (C) 2015 by Spencer Gardner - Email : spencergardner at gmail dot com -*************************************************************************** -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU General Public License as published by * -* the Free Software Foundation; either version 2 of the License, or * -* (at your option) any later version. * -* * -*************************************************************************** -""" - -__author__ = 'Spencer Gardner' -__date__ = 'October 2015' -__copyright__ = '(C) 2015, Spencer Gardner' - -# This will get replaced with a git SHA1 when you do a git archive - -__revision__ = '$Format:%H$' - -import psycopg2 -import networkx as nx - -class NXUtils: - def __init__(self, prefix, zipCode): - # set up connection - self.conn = psycopg2.connect("host=192.168.1.144 dbname=people_for_bikes user=gis password=gis") - - # layers - self.vertsTable = prefix + '_ways_net_vert' - self.linksTable = prefix + '_ways_net_link' - self.zipsTable = prefix + '_zip_codes' - - # other vars - self.zipCode = zipCode - self.DG = nx.DiGraph() - - def buildNetwork(self): - # edges - edgeCur = self.conn.cursor() - edgeCur.execute('\ - SELECT links.source_vert, \ - links.target_vert, \ - COALESCE(links.link_cost,0), \ - links.link_id, \ - COALESCE(links.link_stress,99), \ - links.int_id \ - FROM ' + self.linksTable + ' links \ - WHERE EXISTS ( \ - SELECT 1 \ - FROM ' + self.zipsTable + ' zips \ - WHERE zips.zip_code = \'' + self.zipCode + '\' \ - AND ST_Intersects(zips.geom,links.geom) \ - ) \ - ') - for record in edgeCur: - self.DG.add_edge( - int(record[0]), - int(record[1]), - weight=record[2], - link_id=record[3], - stress=record[4], - int_id=record[5] - ) - - # vertices - vertCur = self.conn.cursor() - vertCur.execute('\ - SELECT verts.vert_id, \ - COALESCE(verts.vert_cost,0), \ - verts.road_id \ - FROM ' + self.vertsTable + ' verts \ - WHERE EXISTS ( \ - SELECT 1 \ - FROM ' + self.zipsTable + ' zips \ - WHERE zips.zip_code = \'' + self.zipCode + '\' \ - AND ST_Intersects(zips.geom,verts.geom) \ - ) \ - ') - for record in vertCur: - vid = record[0] - self.DG.node[vid]['weight'] = record[1] - self.DG.node[vid]['road_id'] = record[2] - - def getNetwork(self): - return self.DG - - def getStressNetwork(self,stress): - '''SG = nx.DiGraph() - SG = nx.DiGraph( [ (u,v,d) for u,v,d in self.DG.edges(data=True) if d['stress'] <= stress ] ) - for v in SG.nodes(): - SG.node[v]['weight'] = self.DG.node[v].get('weight') - SG.node[v]['int_id'] = self.DG.node[v].get('int_id') - return SG''' - - nodeList = [] - for v in self.DG.nodes(): - if self.DG.node[v].get('stress') <= stress: - nodeList.append(v) - SG = self.DG.subgraph(nodeList) - return SG +# -*- coding: utf-8 -*- + +""" +*************************************************************************** + dbutils.py + --------------------- + Date : October 2015 + Copyright : (C) 2015 by Spencer Gardner + Email : spencergardner at gmail dot com +*************************************************************************** +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +*************************************************************************** +""" + +__author__ = 'Spencer Gardner' +__date__ = 'October 2015' +__copyright__ = '(C) 2015, Spencer Gardner' + +# This will get replaced with a git SHA1 when you do a git archive + +__revision__ = '$Format:%H$' + +import psycopg2 +import networkx as nx + +class NXUtils: + def __init__(self, prefix, zipCode): + # set up connection + self.conn = psycopg2.connect("host=192.168.1.144 dbname=people_for_bikes user=gis password=gis") + + # layers + self.vertsTable = prefix + '_ways_net_vert' + self.linksTable = prefix + '_ways_net_link' + self.zipsTable = prefix + '_zip_codes' + + # other vars + self.zipCode = zipCode + self.DG = nx.DiGraph() + + def buildNetwork(self): + # edges + edgeCur = self.conn.cursor() + edgeCur.execute('\ + SELECT links.source_vert, \ + links.target_vert, \ + COALESCE(links.link_cost,0), \ + links.link_id, \ + COALESCE(links.link_stress,99), \ + links.int_id \ + FROM ' + self.linksTable + ' links \ + WHERE EXISTS ( \ + SELECT 1 \ + FROM ' + self.zipsTable + ' zips \ + WHERE zips.zip_code = \'' + self.zipCode + '\' \ + AND ST_Intersects(zips.geom,links.geom) \ + ) \ + ') + for record in edgeCur: + self.DG.add_edge( + int(record[0]), + int(record[1]), + weight=record[2], + link_id=record[3], + stress=record[4], + int_id=record[5] + ) + + # vertices + vertCur = self.conn.cursor() + vertCur.execute('\ + SELECT verts.vert_id, \ + COALESCE(verts.vert_cost,0), \ + verts.road_id \ + FROM ' + self.vertsTable + ' verts \ + WHERE EXISTS ( \ + SELECT 1 \ + FROM ' + self.zipsTable + ' zips \ + WHERE zips.zip_code = \'' + self.zipCode + '\' \ + AND ST_Intersects(zips.geom,verts.geom) \ + ) \ + ') + for record in vertCur: + vid = record[0] + self.DG.node[vid]['weight'] = record[1] + self.DG.node[vid]['road_id'] = record[2] + + def getNetwork(self): + return self.DG + + def getStressNetwork(self,stress): + '''SG = nx.DiGraph() + SG = nx.DiGraph( [ (u,v,d) for u,v,d in self.DG.edges(data=True) if d['stress'] <= stress ] ) + for v in SG.nodes(): + SG.node[v]['weight'] = self.DG.node[v].get('weight') + SG.node[v]['int_id'] = self.DG.node[v].get('int_id') + return SG''' + + nodeList = [] + for v in self.DG.nodes(): + if self.DG.node[v].get('stress') <= stress: + nodeList.append(v) + SG = self.DG.subgraph(nodeList) + return SG diff --git a/connectivity/reachable_roads_high_stress.sql b/connectivity/reachable_roads_high_stress.sql new file mode 100644 index 00000000..6ac03826 --- /dev/null +++ b/connectivity/reachable_roads_high_stress.sql @@ -0,0 +1,45 @@ +---------------------------------------- +-- INPUTS +-- location: cambridge +---------------------------------------- + +CREATE TABLE generated.cambridge_reachable_roads_high_stress ( + id SERIAL PRIMARY KEY, + base_road INT, + target_road INT, + total_cost FLOAT +); + +INSERT INTO generated.cambridge_reachable_roads_high_stress ( + base_road, + target_road, + total_cost +) +SELECT r1.road_id, + v2.road_id, + sheds.agg_cost +FROM cambridge_ways r1, + cambridge_ways_net_vert v1, + cambridge_ways_net_vert v2, + pgr_drivingDistance(' + SELECT link_id AS id, + source_vert AS source, + target_vert AS target, + link_cost AS cost + FROM cambridge_ways_net_link', + v1.vert_id, + 10560, + directed := true + ) sheds +WHERE EXISTS ( + SELECT 1 + FROM cambridge_zip_codes zips + WHERE ST_Intersects(zips.geom,r1.geom) + AND zips.zip_code = '02138' +) +AND r1.road_id = v1.road_id +AND v2.vert_id = sheds.node; + +CREATE INDEX idx_cambridge_rchblrdshistrss +ON generated.cambridge_reachable_roads_high_stress (base_road,target_road); +ANALYZE generated.cambridge_reachable_roads_high_stress; diff --git a/connectivity/reachable_roads_low_stress.sql b/connectivity/reachable_roads_low_stress.sql new file mode 100644 index 00000000..2062d0c1 --- /dev/null +++ b/connectivity/reachable_roads_low_stress.sql @@ -0,0 +1,46 @@ +---------------------------------------- +-- INPUTS +-- location: cambridge +---------------------------------------- + +CREATE TABLE generated.cambridge_reachable_roads_low_stress ( + id SERIAL PRIMARY KEY, + base_road INT, + target_road INT, + total_cost FLOAT +); + +INSERT INTO generated.cambridge_reachable_roads_low_stress ( + base_road, + target_road, + total_cost +) +SELECT r1.road_id, + v2.road_id, + sheds.agg_cost +FROM cambridge_ways r1, + cambridge_ways_net_vert v1, + cambridge_ways_net_vert v2, + pgr_drivingDistance(' + SELECT link_id AS id, + source_vert AS source, + target_vert AS target, + link_cost AS cost + FROM cambridge_ways_net_link + WHERE link_stress = 1', + v1.vert_id, + 10560, + directed := true + ) sheds +WHERE EXISTS ( + SELECT 1 + FROM cambridge_zip_codes zips + WHERE ST_Intersects(zips.geom,r1.geom) + AND zips.zip_code = '02138' +) +AND r1.road_id = v1.road_id +AND v2.vert_id = sheds.node; + +CREATE INDEX idx_cambridge_rchblrdslowstrss +ON generated.cambridge_reachable_roads_low_stress (base_road,target_road); +ANALYZE generated.cambridge_reachable_roads_low_stress; diff --git a/drop_tables.sh b/drop_tables.sh index 60344d03..bdd7ffd3 100644 --- a/drop_tables.sh +++ b/drop_tables.sh @@ -1,49 +1,49 @@ -#!/usr/bin/env bash - -# vars -DBHOST='192.168.1.144' -DBNAME='people_for_bikes' -OSMPREFIX='cambridge' - -# drop old tables -echo 'Dropping old tables' -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_ways;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_ways_intersections;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_relations_ways;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_nodes;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_relations;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_way_classes;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_way_tags;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_way_types;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_ways;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_ways_vertices_pgr;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_relations_ways;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_osm_nodes;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_osm_relations;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_osm_way_classes;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_osm_way_tags;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_osm_way_types;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_full_line;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_full_point;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_full_polygon;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_full_roads;" +#!/usr/bin/env bash + +# vars +DBHOST='192.168.1.144' +DBNAME='people_for_bikes' +OSMPREFIX='cambridge' + +# drop old tables +echo 'Dropping old tables' +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_ways;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_ways_intersections;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_relations_ways;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_nodes;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_relations;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_way_classes;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_way_tags;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_way_types;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_ways;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_ways_vertices_pgr;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_relations_ways;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_osm_nodes;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_osm_relations;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_osm_way_classes;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_osm_way_tags;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_osm_way_types;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_full_line;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_full_point;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_full_polygon;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_full_roads;" diff --git a/import_osm.sh b/import_osm.sh index e7f2d235..80853db1 100644 --- a/import_osm.sh +++ b/import_osm.sh @@ -1,174 +1,174 @@ -#!/usr/bin/env bash - -# vars -DBHOST='192.168.1.144' -DBNAME='people_for_bikes' -OSMPREFIX='cambridge' -OSMFILE='/home/spencer/gis/cambridge.osm' - -# drop old tables -echo 'Dropping old tables' -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_ways;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_ways_intersections;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_relations_ways;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_nodes;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_relations;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_way_classes;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_way_tags;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_way_types;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_ways;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_ways_vertices_pgr;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_relations_ways;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_osm_nodes;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_osm_relations;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_osm_way_classes;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_osm_way_tags;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_osm_way_types;" - -# import the osm with highways that the above misses (bug in osm2pgrouting) -osm2pgrouting \ - -f $OSMFILE \ - -h $DBHOST \ - --dbname ${DBNAME} \ - --username gis \ - --schema received \ - --prefix ${OSMPREFIX}_ \ - --conf ./mapconfig_highway.xml \ - --clean - -# import the osm optimized for routing -osm2pgrouting \ - -f $OSMFILE \ - -h $DBHOST \ - --dbname ${DBNAME} \ - --username gis \ - --schema scratch \ - --prefix ${OSMPREFIX}_cycwys_ \ - --conf ./mapconfig_cycleway.xml \ - --clean - -# rename a few tables -echo 'Renaming tables' -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE received.${OSMPREFIX}_ways_vertices_pgr RENAME TO ${OSMPREFIX}_ways_intersections;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE received.${OSMPREFIX}_ways_intersections RENAME CONSTRAINT vertex_id TO ${OSMPREFIX}_vertex_id;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE received.osm_nodes RENAME TO ${OSMPREFIX}_osm_nodes;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE received.${OSMPREFIX}_osm_nodes RENAME CONSTRAINT node_id TO ${OSMPREFIX}_node_id;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE received.osm_relations RENAME TO ${OSMPREFIX}_osm_relations;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE received.osm_way_classes RENAME TO ${OSMPREFIX}_osm_way_classes;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE received.${OSMPREFIX}_osm_way_classes RENAME CONSTRAINT osm_way_classes_pkey TO ${OSMPREFIX}_osm_way_classes_pkey;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE received.osm_way_tags RENAME TO ${OSMPREFIX}_osm_way_tags;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE received.osm_way_types RENAME TO ${OSMPREFIX}_osm_way_types;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE received.${OSMPREFIX}_osm_way_types RENAME CONSTRAINT osm_way_types_pkey TO ${OSMPREFIX}_osm_way_types_pkey;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE scratch.${OSMPREFIX}_cycwys_ways_vertices_pgr RENAME CONSTRAINT vertex_id TO ${OSMPREFIX}_vertex_id;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE scratch.osm_nodes RENAME TO ${OSMPREFIX}_cycwys_osm_nodes;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE scratch.${OSMPREFIX}_cycwys_osm_nodes RENAME CONSTRAINT node_id TO ${OSMPREFIX}_node_id;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE scratch.osm_relations RENAME TO ${OSMPREFIX}_cycwys_osm_relations;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE scratch.osm_way_classes RENAME TO ${OSMPREFIX}_cycwys_osm_way_classes;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE scratch.${OSMPREFIX}_cycwys_osm_way_classes RENAME CONSTRAINT osm_way_classes_pkey TO ${OSMPREFIX}_osm_way_classes_pkey;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE scratch.osm_way_tags RENAME TO ${OSMPREFIX}_cycwys_osm_way_tags;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE scratch.osm_way_types RENAME TO ${OSMPREFIX}_cycwys_osm_way_types;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE scratch.${OSMPREFIX}_cycwys_osm_way_types RENAME CONSTRAINT osm_way_types_pkey TO ${OSMPREFIX}_osm_way_types_pkey;" - -# import full osm to fill out additional data needs -# not met by osm2pgrouting - -# drop old tables -echo 'Dropping old tables' -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_full_line;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_full_point;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_full_polygon;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_full_roads;" - -# import -osm2pgsql \ - --host $DBHOST \ - --username gis \ - --port 5432 \ - --create \ - --database ${DBNAME} \ - --prefix ${OSMPREFIX}_osm_full \ - --proj 2249 \ - --style /home/spencer/dev/pfb/pfb.style \ - $OSMFILE - -# move the full osm tables to the received schema -echo 'Moving tables to received schema' -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE generated.${OSMPREFIX}_osm_full_line SET SCHEMA received;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE generated.${OSMPREFIX}_osm_full_point SET SCHEMA received;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE generated.${OSMPREFIX}_osm_full_polygon SET SCHEMA received;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE generated.${OSMPREFIX}_osm_full_roads SET SCHEMA received;" - -# process tables -echo 'Updating field names' -psql -h $DBHOST -U gis -d ${DBNAME} -f ./prepare_tables.sql -echo 'Setting values on road segments' -psql -h $DBHOST -U gis -d ${DBNAME} -f ./one_way.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./functional_class.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./speed_limit.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./width_ft.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./lanes.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./park.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./bike_infra.sql -echo 'Setting values on intersections' -psql -h $DBHOST -U gis -d ${DBNAME} -f ./legs.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./signalized.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./stops.sql -echo 'Calculating stress' -psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_motorway-trunk.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_primary.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_secondary.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_tertiary.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_residential.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_living_street.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_track.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_path.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_one_way_reset.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_motorway-trunk_ints.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_primary_ints.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_secondary_ints.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_tertiary_ints.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_lesser_ints.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_link_ints.sql +#!/usr/bin/env bash + +# vars +DBHOST='192.168.1.144' +DBNAME='people_for_bikes' +OSMPREFIX='cambridge' +OSMFILE='/home/spencer/gis/cambridge.osm' + +# drop old tables +echo 'Dropping old tables' +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_ways;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_ways_intersections;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_relations_ways;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_nodes;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_relations;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_way_classes;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_way_tags;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_way_types;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_ways;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_ways_vertices_pgr;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_relations_ways;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_osm_nodes;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_osm_relations;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_osm_way_classes;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_osm_way_tags;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_osm_way_types;" + +# import the osm with highways that the above misses (bug in osm2pgrouting) +osm2pgrouting \ + -f $OSMFILE \ + -h $DBHOST \ + --dbname ${DBNAME} \ + --username gis \ + --schema received \ + --prefix ${OSMPREFIX}_ \ + --conf ./mapconfig_highway.xml \ + --clean + +# import the osm optimized for routing +osm2pgrouting \ + -f $OSMFILE \ + -h $DBHOST \ + --dbname ${DBNAME} \ + --username gis \ + --schema scratch \ + --prefix ${OSMPREFIX}_cycwys_ \ + --conf ./mapconfig_cycleway.xml \ + --clean + +# rename a few tables +echo 'Renaming tables' +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE received.${OSMPREFIX}_ways_vertices_pgr RENAME TO ${OSMPREFIX}_ways_intersections;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE received.${OSMPREFIX}_ways_intersections RENAME CONSTRAINT vertex_id TO ${OSMPREFIX}_vertex_id;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE received.osm_nodes RENAME TO ${OSMPREFIX}_osm_nodes;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE received.${OSMPREFIX}_osm_nodes RENAME CONSTRAINT node_id TO ${OSMPREFIX}_node_id;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE received.osm_relations RENAME TO ${OSMPREFIX}_osm_relations;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE received.osm_way_classes RENAME TO ${OSMPREFIX}_osm_way_classes;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE received.${OSMPREFIX}_osm_way_classes RENAME CONSTRAINT osm_way_classes_pkey TO ${OSMPREFIX}_osm_way_classes_pkey;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE received.osm_way_tags RENAME TO ${OSMPREFIX}_osm_way_tags;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE received.osm_way_types RENAME TO ${OSMPREFIX}_osm_way_types;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE received.${OSMPREFIX}_osm_way_types RENAME CONSTRAINT osm_way_types_pkey TO ${OSMPREFIX}_osm_way_types_pkey;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE scratch.${OSMPREFIX}_cycwys_ways_vertices_pgr RENAME CONSTRAINT vertex_id TO ${OSMPREFIX}_vertex_id;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE scratch.osm_nodes RENAME TO ${OSMPREFIX}_cycwys_osm_nodes;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE scratch.${OSMPREFIX}_cycwys_osm_nodes RENAME CONSTRAINT node_id TO ${OSMPREFIX}_node_id;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE scratch.osm_relations RENAME TO ${OSMPREFIX}_cycwys_osm_relations;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE scratch.osm_way_classes RENAME TO ${OSMPREFIX}_cycwys_osm_way_classes;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE scratch.${OSMPREFIX}_cycwys_osm_way_classes RENAME CONSTRAINT osm_way_classes_pkey TO ${OSMPREFIX}_osm_way_classes_pkey;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE scratch.osm_way_tags RENAME TO ${OSMPREFIX}_cycwys_osm_way_tags;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE scratch.osm_way_types RENAME TO ${OSMPREFIX}_cycwys_osm_way_types;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE scratch.${OSMPREFIX}_cycwys_osm_way_types RENAME CONSTRAINT osm_way_types_pkey TO ${OSMPREFIX}_osm_way_types_pkey;" + +# import full osm to fill out additional data needs +# not met by osm2pgrouting + +# drop old tables +echo 'Dropping old tables' +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_full_line;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_full_point;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_full_polygon;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_full_roads;" + +# import +osm2pgsql \ + --host $DBHOST \ + --username gis \ + --port 5432 \ + --create \ + --database ${DBNAME} \ + --prefix ${OSMPREFIX}_osm_full \ + --proj 2249 \ + --style /home/spencer/dev/pfb/pfb.style \ + $OSMFILE + +# move the full osm tables to the received schema +echo 'Moving tables to received schema' +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE generated.${OSMPREFIX}_osm_full_line SET SCHEMA received;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE generated.${OSMPREFIX}_osm_full_point SET SCHEMA received;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE generated.${OSMPREFIX}_osm_full_polygon SET SCHEMA received;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE generated.${OSMPREFIX}_osm_full_roads SET SCHEMA received;" + +# process tables +echo 'Updating field names' +psql -h $DBHOST -U gis -d ${DBNAME} -f ./prepare_tables.sql +echo 'Setting values on road segments' +psql -h $DBHOST -U gis -d ${DBNAME} -f ./one_way.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./functional_class.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./speed_limit.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./width_ft.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./lanes.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./park.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./bike_infra.sql +echo 'Setting values on intersections' +psql -h $DBHOST -U gis -d ${DBNAME} -f ./legs.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./signalized.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./stops.sql +echo 'Calculating stress' +psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_motorway-trunk.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_primary.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_secondary.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_tertiary.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_residential.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_living_street.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_track.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_path.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_one_way_reset.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_motorway-trunk_ints.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_primary_ints.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_secondary_ints.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_tertiary_ints.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_lesser_ints.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_link_ints.sql diff --git a/mapconfig_cycleway.xml b/mapconfig_cycleway.xml index 267b2207..f611cf7f 100644 --- a/mapconfig_cycleway.xml +++ b/mapconfig_cycleway.xml @@ -1,9 +1,9 @@ - - - - - - - - - + + + + + + + + + diff --git a/mapconfig_highway.xml b/mapconfig_highway.xml index f1dc7fed..848f5cc8 100644 --- a/mapconfig_highway.xml +++ b/mapconfig_highway.xml @@ -1,32 +1,32 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/prepare_tables.sql b/prepare_tables.sql index 5f13459f..4ffee231 100644 --- a/prepare_tables.sql +++ b/prepare_tables.sql @@ -1,110 +1,110 @@ ----------------------------------------- --- INPUTS --- location: cambridge --- proj: 2249 ----------------------------------------- - --- add tdg_id field to roads -ALTER TABLE cambridge_ways ADD COLUMN tdg_id TEXT DEFAULT uuid_generate_v4(); - --- drop unnecessary columns -ALTER TABLE cambridge_ways DROP COLUMN class_id; -ALTER TABLE cambridge_ways DROP COLUMN length; -ALTER TABLE cambridge_ways DROP COLUMN length_m; -ALTER TABLE cambridge_ways DROP COLUMN x1; -ALTER TABLE cambridge_ways DROP COLUMN y1; -ALTER TABLE cambridge_ways DROP COLUMN x2; -ALTER TABLE cambridge_ways DROP COLUMN y2; -ALTER TABLE cambridge_ways DROP COLUMN cost; -ALTER TABLE cambridge_ways DROP COLUMN reverse_cost; -ALTER TABLE cambridge_ways DROP COLUMN cost_s; -ALTER TABLE cambridge_ways DROP COLUMN reverse_cost_s; -ALTER TABLE cambridge_ways DROP COLUMN rule; -ALTER TABLE cambridge_ways DROP COLUMN maxspeed_forward; -ALTER TABLE cambridge_ways DROP COLUMN maxspeed_backward; -ALTER TABLE cambridge_ways DROP COLUMN source_osm; -ALTER TABLE cambridge_ways DROP COLUMN target_osm; -ALTER TABLE cambridge_ways DROP COLUMN priority; -ALTER TABLE cambridge_ways DROP COLUMN one_way; - -ALTER TABLE cambridge_ways_intersections DROP COLUMN cnt; -ALTER TABLE cambridge_ways_intersections DROP COLUMN chk; -ALTER TABLE cambridge_ways_intersections DROP COLUMN ein; -ALTER TABLE cambridge_ways_intersections DROP COLUMN eout; -ALTER TABLE cambridge_ways_intersections DROP COLUMN lon; -ALTER TABLE cambridge_ways_intersections DROP COLUMN lat; - --- change column names -ALTER TABLE cambridge_ways RENAME COLUMN gid TO road_id; -ALTER TABLE cambridge_ways RENAME COLUMN the_geom TO geom; -ALTER TABLE cambridge_ways RENAME COLUMN source TO intersection_from; -ALTER TABLE cambridge_ways RENAME COLUMN target TO intersection_to; - -ALTER TABLE cambridge_ways_intersections RENAME COLUMN id TO int_id; -ALTER TABLE cambridge_ways_intersections RENAME COLUMN the_geom TO geom; - --- reproject -ALTER TABLE cambridge_ways ALTER COLUMN geom TYPE geometry(linestring,2249) -USING ST_Transform(geom,2249); -ALTER TABLE cambridge_cycwys_ways ALTER COLUMN the_geom TYPE geometry(linestring,2249) -USING ST_Transform(the_geom,2249); -ALTER TABLE cambridge_ways_intersections ALTER COLUMN geom TYPE geometry(point,2249) -USING ST_Transform(geom,2249); - --- add columns -ALTER TABLE cambridge_ways ADD COLUMN functional_class TEXT; -ALTER TABLE cambridge_ways ADD COLUMN speed_limit INT; -ALTER TABLE cambridge_ways ADD COLUMN one_way_car VARCHAR(2); -ALTER TABLE cambridge_ways ADD COLUMN one_way VARCHAR(2); -ALTER TABLE cambridge_ways ADD COLUMN width_ft INT; -ALTER TABLE cambridge_ways ADD COLUMN ft_bike_infra TEXT; -ALTER TABLE cambridge_ways ADD COLUMN tf_bike_infra TEXT; -ALTER TABLE cambridge_ways ADD COLUMN ft_lanes INT; -ALTER TABLE cambridge_ways ADD COLUMN tf_lanes INT; -ALTER TABLE cambridge_ways ADD COLUMN ft_park INT; -ALTER TABLE cambridge_ways ADD COLUMN tf_park INT; -ALTER TABLE cambridge_ways ADD COLUMN ft_seg_stress INT; -ALTER TABLE cambridge_ways ADD COLUMN ft_int_stress INT; -ALTER TABLE cambridge_ways ADD COLUMN tf_seg_stress INT; -ALTER TABLE cambridge_ways ADD COLUMN tf_int_stress INT; - --- indexes -CREATE INDEX idx_cambridge_ways_osm ON cambridge_ways (osm_id); -CREATE INDEX idx_cambridge_ways_ints_osm ON cambridge_ways_intersections (osm_id); -CREATE INDEX idx_cambridge_fullways ON cambridge_osm_full_line (osm_id); -CREATE INDEX idx_cambridge_fullpoints ON cambridge_osm_full_point (osm_id); -ANALYZE cambridge_ways (osm_id,geom); -ANALYZE cambridge_cycwys_ways (the_geom); -ANALYZE cambridge_ways_intersections (osm_id); -ANALYZE cambridge_osm_full_line (osm_id); -ANALYZE cambridge_osm_full_point (osm_id); - --- add in cycleway data that is missing from first osm2pgrouting call -INSERT INTO cambridge_ways ( - name, intersection_from, intersection_to, osm_id, geom -) -SELECT name, - (SELECT i.int_id - FROM cambridge_ways_intersections i - WHERE i.geom <#> cambridge_cycwys_ways.the_geom < 20 - ORDER BY ST_Distance(ST_StartPoint(cambridge_cycwys_ways.the_geom),i.geom) ASC - LIMIT 1), - (SELECT i.int_id - FROM cambridge_ways_intersections i - WHERE i.geom <#> cambridge_cycwys_ways.the_geom < 20 - ORDER BY ST_Distance(ST_EndPoint(cambridge_cycwys_ways.the_geom),i.geom) ASC - LIMIT 1), - osm_id, - the_geom -FROM cambridge_cycwys_ways -WHERE NOT EXISTS ( - SELECT 1 - FROM cambridge_ways w2 - WHERE w2.osm_id = cambridge_cycwys_ways.osm_id -); - --- setup intersection table -ALTER TABLE cambridge_ways_intersections ADD COLUMN legs INT; -ALTER TABLE cambridge_ways_intersections ADD COLUMN signalized BOOLEAN; -ALTER TABLE cambridge_ways_intersections ADD COLUMN stops BOOLEAN; -CREATE INDEX idx_cambridge_ints_stop ON cambridge_ways_intersections (signalized,stops); +---------------------------------------- +-- INPUTS +-- location: cambridge +-- proj: 2249 +---------------------------------------- + +-- add tdg_id field to roads +ALTER TABLE cambridge_ways ADD COLUMN tdg_id TEXT DEFAULT uuid_generate_v4(); + +-- drop unnecessary columns +ALTER TABLE cambridge_ways DROP COLUMN class_id; +ALTER TABLE cambridge_ways DROP COLUMN length; +ALTER TABLE cambridge_ways DROP COLUMN length_m; +ALTER TABLE cambridge_ways DROP COLUMN x1; +ALTER TABLE cambridge_ways DROP COLUMN y1; +ALTER TABLE cambridge_ways DROP COLUMN x2; +ALTER TABLE cambridge_ways DROP COLUMN y2; +ALTER TABLE cambridge_ways DROP COLUMN cost; +ALTER TABLE cambridge_ways DROP COLUMN reverse_cost; +ALTER TABLE cambridge_ways DROP COLUMN cost_s; +ALTER TABLE cambridge_ways DROP COLUMN reverse_cost_s; +ALTER TABLE cambridge_ways DROP COLUMN rule; +ALTER TABLE cambridge_ways DROP COLUMN maxspeed_forward; +ALTER TABLE cambridge_ways DROP COLUMN maxspeed_backward; +ALTER TABLE cambridge_ways DROP COLUMN source_osm; +ALTER TABLE cambridge_ways DROP COLUMN target_osm; +ALTER TABLE cambridge_ways DROP COLUMN priority; +ALTER TABLE cambridge_ways DROP COLUMN one_way; + +ALTER TABLE cambridge_ways_intersections DROP COLUMN cnt; +ALTER TABLE cambridge_ways_intersections DROP COLUMN chk; +ALTER TABLE cambridge_ways_intersections DROP COLUMN ein; +ALTER TABLE cambridge_ways_intersections DROP COLUMN eout; +ALTER TABLE cambridge_ways_intersections DROP COLUMN lon; +ALTER TABLE cambridge_ways_intersections DROP COLUMN lat; + +-- change column names +ALTER TABLE cambridge_ways RENAME COLUMN gid TO road_id; +ALTER TABLE cambridge_ways RENAME COLUMN the_geom TO geom; +ALTER TABLE cambridge_ways RENAME COLUMN source TO intersection_from; +ALTER TABLE cambridge_ways RENAME COLUMN target TO intersection_to; + +ALTER TABLE cambridge_ways_intersections RENAME COLUMN id TO int_id; +ALTER TABLE cambridge_ways_intersections RENAME COLUMN the_geom TO geom; + +-- reproject +ALTER TABLE cambridge_ways ALTER COLUMN geom TYPE geometry(linestring,2249) +USING ST_Transform(geom,2249); +ALTER TABLE cambridge_cycwys_ways ALTER COLUMN the_geom TYPE geometry(linestring,2249) +USING ST_Transform(the_geom,2249); +ALTER TABLE cambridge_ways_intersections ALTER COLUMN geom TYPE geometry(point,2249) +USING ST_Transform(geom,2249); + +-- add columns +ALTER TABLE cambridge_ways ADD COLUMN functional_class TEXT; +ALTER TABLE cambridge_ways ADD COLUMN speed_limit INT; +ALTER TABLE cambridge_ways ADD COLUMN one_way_car VARCHAR(2); +ALTER TABLE cambridge_ways ADD COLUMN one_way VARCHAR(2); +ALTER TABLE cambridge_ways ADD COLUMN width_ft INT; +ALTER TABLE cambridge_ways ADD COLUMN ft_bike_infra TEXT; +ALTER TABLE cambridge_ways ADD COLUMN tf_bike_infra TEXT; +ALTER TABLE cambridge_ways ADD COLUMN ft_lanes INT; +ALTER TABLE cambridge_ways ADD COLUMN tf_lanes INT; +ALTER TABLE cambridge_ways ADD COLUMN ft_park INT; +ALTER TABLE cambridge_ways ADD COLUMN tf_park INT; +ALTER TABLE cambridge_ways ADD COLUMN ft_seg_stress INT; +ALTER TABLE cambridge_ways ADD COLUMN ft_int_stress INT; +ALTER TABLE cambridge_ways ADD COLUMN tf_seg_stress INT; +ALTER TABLE cambridge_ways ADD COLUMN tf_int_stress INT; + +-- indexes +CREATE INDEX idx_cambridge_ways_osm ON cambridge_ways (osm_id); +CREATE INDEX idx_cambridge_ways_ints_osm ON cambridge_ways_intersections (osm_id); +CREATE INDEX idx_cambridge_fullways ON cambridge_osm_full_line (osm_id); +CREATE INDEX idx_cambridge_fullpoints ON cambridge_osm_full_point (osm_id); +ANALYZE cambridge_ways (osm_id,geom); +ANALYZE cambridge_cycwys_ways (the_geom); +ANALYZE cambridge_ways_intersections (osm_id); +ANALYZE cambridge_osm_full_line (osm_id); +ANALYZE cambridge_osm_full_point (osm_id); + +-- add in cycleway data that is missing from first osm2pgrouting call +INSERT INTO cambridge_ways ( + name, intersection_from, intersection_to, osm_id, geom +) +SELECT name, + (SELECT i.int_id + FROM cambridge_ways_intersections i + WHERE i.geom <#> cambridge_cycwys_ways.the_geom < 20 + ORDER BY ST_Distance(ST_StartPoint(cambridge_cycwys_ways.the_geom),i.geom) ASC + LIMIT 1), + (SELECT i.int_id + FROM cambridge_ways_intersections i + WHERE i.geom <#> cambridge_cycwys_ways.the_geom < 20 + ORDER BY ST_Distance(ST_EndPoint(cambridge_cycwys_ways.the_geom),i.geom) ASC + LIMIT 1), + osm_id, + the_geom +FROM cambridge_cycwys_ways +WHERE NOT EXISTS ( + SELECT 1 + FROM cambridge_ways w2 + WHERE w2.osm_id = cambridge_cycwys_ways.osm_id +); + +-- setup intersection table +ALTER TABLE cambridge_ways_intersections ADD COLUMN legs INT; +ALTER TABLE cambridge_ways_intersections ADD COLUMN signalized BOOLEAN; +ALTER TABLE cambridge_ways_intersections ADD COLUMN stops BOOLEAN; +CREATE INDEX idx_cambridge_ints_stop ON cambridge_ways_intersections (signalized,stops); From fc2f499a49aef7e446a4f38764c28de3eff8cbab Mon Sep 17 00:00:00 2001 From: Spencer Date: Mon, 26 Sep 2016 16:42:19 -0500 Subject: [PATCH 27/94] slkjf --- connectivity/access_pop_to_pop.sql | 4 ++++ connectivity/census_block_roads.sql | 6 +++++- import_osm.sh | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 connectivity/access_pop_to_pop.sql diff --git a/connectivity/access_pop_to_pop.sql b/connectivity/access_pop_to_pop.sql new file mode 100644 index 00000000..12aad03f --- /dev/null +++ b/connectivity/access_pop_to_pop.sql @@ -0,0 +1,4 @@ +---------------------------------------- +-- INPUTS +-- location: cambridge +---------------------------------------- diff --git a/connectivity/census_block_roads.sql b/connectivity/census_block_roads.sql index 4b6f0588..bd0e1e90 100644 --- a/connectivity/census_block_roads.sql +++ b/connectivity/census_block_roads.sql @@ -25,4 +25,8 @@ WHERE EXISTS ( AND zips.zip_code = '02138' ) AND blocks.geom <-> ways.geom < 50 - ST_Intersects(ST_Buffer(blocks.geom,50),ways.geom); +AND ST_Intersects(ST_Buffer(blocks.geom,50),ways.geom); + +CREATE INDEX idx_cambridge_censblkrds +ON generated.cambridge_census_block_roads (blockid10,road_id); +ANALYZE generated.cambridge_census_block_roads; diff --git a/import_osm.sh b/import_osm.sh index 80853db1..e2bb79fc 100644 --- a/import_osm.sh +++ b/import_osm.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # vars -DBHOST='192.168.1.144' +DBHOST='192.168.40.225' DBNAME='people_for_bikes' OSMPREFIX='cambridge' OSMFILE='/home/spencer/gis/cambridge.osm' From 7e4bf4f5559d637bfaf4a048269b999b84b13f91 Mon Sep 17 00:00:00 2001 From: Spencer Date: Wed, 28 Sep 2016 17:37:16 -0500 Subject: [PATCH 28/94] lksjdf ; --- connectivity/access_pop_to_pop.sql | 35 ++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/connectivity/access_pop_to_pop.sql b/connectivity/access_pop_to_pop.sql index 12aad03f..abedebaf 100644 --- a/connectivity/access_pop_to_pop.sql +++ b/connectivity/access_pop_to_pop.sql @@ -2,3 +2,38 @@ -- INPUTS -- location: cambridge ---------------------------------------- + +SELECT blocks.id, + blocks.blockid10, + ( + SELECT SUM(b.pop10) + FROM cambridge_reachable_roads_low_stress ls, + cambridge_census_block_roads br, + cambridge_census_blocks b, + WHERE blocks.blockid10 = + ) AS low_stress_pop, + +FROM cambridge_census_blocks blocks + + + + +SELECT DISTINCT + source_block.id, + source_block.blockid10, + target_block.id, + target_block.blockid10, + target_block.pop10 +FROM cambridge_census_blocks source_block, + cambridge_census_block_roads source_br, + cambridge_census_blocks target_block, + cambridge_census_block_roads target_br +WHERE source_block.blockid10 = source_br.blockid10 +AND target_block.blockid10 = target_br.blockid10 +AND EXISTS ( + SELECT 1 + FROM cambridge_reachable_roads_low_stress ls + WHERE ls.base_road = source_br.road_id + AND ls.target_road = target_br.road_id +) +-- and source_block.id = 88206 From 35fb01310ce38fb5467ee2b1fe8167c310af0e2a Mon Sep 17 00:00:00 2001 From: Spencer Gardner Date: Thu, 29 Sep 2016 07:24:08 -0500 Subject: [PATCH 29/94] lkjsdf --- connectivity/access_pop_to_pop.sql | 66 +++++++++++++++-------------- connectivity/census_block_roads.sql | 3 +- 2 files changed, 37 insertions(+), 32 deletions(-) diff --git a/connectivity/access_pop_to_pop.sql b/connectivity/access_pop_to_pop.sql index abedebaf..312e5739 100644 --- a/connectivity/access_pop_to_pop.sql +++ b/connectivity/access_pop_to_pop.sql @@ -3,37 +3,41 @@ -- location: cambridge ---------------------------------------- -SELECT blocks.id, - blocks.blockid10, - ( - SELECT SUM(b.pop10) - FROM cambridge_reachable_roads_low_stress ls, - cambridge_census_block_roads br, - cambridge_census_blocks b, - WHERE blocks.blockid10 = - ) AS low_stress_pop, - -FROM cambridge_census_blocks blocks - - - - -SELECT DISTINCT - source_block.id, - source_block.blockid10, - target_block.id, - target_block.blockid10, - target_block.pop10 +SELECT source_block.id AS source_id, + source_block.blockid10 AS source_blockid10, + target_block.id AS target_id, + target_block.blockid10 AS target_blockid10, + target_block.pop10 AS target_pop FROM cambridge_census_blocks source_block, - cambridge_census_block_roads source_br, - cambridge_census_blocks target_block, - cambridge_census_block_roads target_br -WHERE source_block.blockid10 = source_br.blockid10 -AND target_block.blockid10 = target_br.blockid10 -AND EXISTS ( + cambridge_census_blocks target_block +WHERE EXISTS ( SELECT 1 - FROM cambridge_reachable_roads_low_stress ls - WHERE ls.base_road = source_br.road_id + FROM cambridge_census_block_roads source_br, + cambridge_census_block_roads target_br, + cambridge_reachable_roads_low_stress ls + WHERE source_block.blockid10 = source_br.blockid10 + AND target_block.blockid10 = target_br.blockid10 + AND ls.base_road = source_br.road_id AND ls.target_road = target_br.road_id -) --- and source_block.id = 88206 + ) +AND ( + SELECT MIN(total_cost) + FROM cambridge_census_block_roads source_br, + cambridge_census_block_roads target_br, + cambridge_reachable_roads_low_stress ls + WHERE source_block.blockid10 = source_br.blockid10 + AND target_block.blockid10 = target_br.blockid10 + AND ls.base_road = source_br.road_id + AND ls.target_road = target_br.road_id + ) / + ( + SELECT MIN(total_cost) + 1 + FROM cambridge_census_block_roads source_br, + cambridge_census_block_roads target_br, + cambridge_reachable_roads_high_stress hs + WHERE source_block.blockid10 = source_br.blockid10 + AND target_block.blockid10 = target_br.blockid10 + AND hs.base_road = source_br.road_id + AND hs.target_road = target_br.road_id + ) <= 1.3 --30% max deviation +-- and source_block.blockid10 = '250173540002000' diff --git a/connectivity/census_block_roads.sql b/connectivity/census_block_roads.sql index bd0e1e90..674da3a5 100644 --- a/connectivity/census_block_roads.sql +++ b/connectivity/census_block_roads.sql @@ -2,6 +2,7 @@ -- INPUTS -- location: cambridge ---------------------------------------- +DROP TABLE IF EXISTS generated.cambridge_census_block_roads; CREATE TABLE generated.cambridge_census_block_roads ( id SERIAL PRIMARY KEY, @@ -21,7 +22,7 @@ FROM cambridge_census_blocks blocks, WHERE EXISTS ( SELECT 1 FROM cambridge_zip_codes zips - WHERE ST_Intersects(zips.geom,blocks.geom) + WHERE zips.geom <-> blocks.geom < 11000 AND zips.zip_code = '02138' ) AND blocks.geom <-> ways.geom < 50 From f31e368386d77725fed56738a4ffb63e7fbe580b Mon Sep 17 00:00:00 2001 From: Spencer Date: Thu, 29 Sep 2016 16:59:15 -0500 Subject: [PATCH 30/94] lkjsdf --- ...s_pop_to_pop.sql => access_population.sql} | 19 ++- connectivity/census_block_jobs.sql | 61 ++++++++++ connectivity/census_block_roads.sql | 66 +++++------ connectivity/census_blocks.sql | 15 +++ connectivity/connected_census_blocks.sql | 109 ++++++++++++++++++ connectivity/reachable_roads_high_stress.sql | 92 +++++++-------- connectivity/reachable_roads_low_stress.sql | 94 +++++++-------- process.txt | 67 +++++++---- 8 files changed, 377 insertions(+), 146 deletions(-) rename connectivity/{access_pop_to_pop.sql => access_population.sql} (85%) create mode 100644 connectivity/census_block_jobs.sql create mode 100644 connectivity/census_blocks.sql create mode 100644 connectivity/connected_census_blocks.sql diff --git a/connectivity/access_pop_to_pop.sql b/connectivity/access_population.sql similarity index 85% rename from connectivity/access_pop_to_pop.sql rename to connectivity/access_population.sql index 312e5739..d4a704a9 100644 --- a/connectivity/access_pop_to_pop.sql +++ b/connectivity/access_population.sql @@ -2,8 +2,25 @@ -- INPUTS -- location: cambridge ---------------------------------------- + AND zips.zip_code = '02138' + +-- low stress access + + + + + +UPDATE cambridge_census_blocks +SET pop_low_stress = ( + SELECT SUM(pop10) + FROM + ) + + + blocks.source_blockid10, + blocks.target_blockid10, + -SELECT source_block.id AS source_id, source_block.blockid10 AS source_blockid10, target_block.id AS target_id, target_block.blockid10 AS target_blockid10, diff --git a/connectivity/census_block_jobs.sql b/connectivity/census_block_jobs.sql new file mode 100644 index 00000000..2f9bca79 --- /dev/null +++ b/connectivity/census_block_jobs.sql @@ -0,0 +1,61 @@ +---------------------------------------- +-- INPUTS +-- location: cambridge +-- data downloaded from http://lehd.ces.census.gov/data/ +-- or http://lehd.ces.census.gov/data/lodes/LODES7/ +-- "ma_od_main_JT00_2014".csv +-- ma_od_aux_JT00_2014.csv +-- import to DB and check the block id to have 15 characters +-- also aggregate so 1 block has 1 number of total jobs +-- (total jobs comes from S000 field +-- as per http://lehd.ces.census.gov/data/lodes/LODES7/LODESTechDoc7.2.pdf +---------------------------------------- + +-- process imported tables +ALTER TABLE "ma_od_aux_JT00_2014" ALTER COLUMN w_geocode TYPE VARCHAR(15); +UPDATE "ma_od_aux_JT00_2014" SET w_geocode = rpad(w_geocode,15,'0'); --just in case we lost any trailing zeros +ALTER TABLE "ma_od_main_JT00_2014" ALTER COLUMN w_geocode TYPE VARCHAR(15); +UPDATE "ma_od_main_JT00_2014" SET w_geocode = rpad(w_geocode,15,'0'); --just in case we lost any trailing zeros + +-- indexes +CREATE INDEX tidx_auxjtw ON "ma_od_aux_JT00_2014" (w_geocode); +CREATE INDEX tidx_mainjtw ON "ma_od_main_JT00_2014" (w_geocode); +ANALYZE "ma_od_aux_JT00_2014" (w_geocode); +ANALYZE "ma_od_main_JT00_2014" (w_geocode); + +-- create combined table +CREATE TABLE scratch.cambridge_census_block_jobs ( + id SERIAL PRIMARY KEY, + blockid10 VARCHAR(15), + jobs INT +); + +-- add blocks of interest +INSERT INTO scratch.cambridge_census_block_jobs (blockid10) +SELECT blocks.blockid10 +FROM cambridge_census_blocks blocks; + +-- add main data +UPDATE scratch.cambridge_census_block_jobs +SET jobs = COALESCE(( + SELECT SUM(j."S000") + FROM "ma_od_main_JT00_2014" j + WHERE j.w_geocode = cambridge_census_block_jobs.blockid10 + ),0); + +-- add aux data +UPDATE scratch.cambridge_census_block_jobs +SET jobs = jobs + + COALESCE(( + SELECT SUM(j."S000") + FROM "ma_od_aux_JT00_2014" j + WHERE j.w_geocode = cambridge_census_block_jobs.blockid10 + ),0); + +-- indexes +CREATE INDEX idx_cambridge_blkjobs ON cambridge_census_block_jobs (blockid10); +ANALYZE cambridge_census_block_jobs (blockid10); + +-- drop import tables +DROP TABLE IF EXISTS "ma_od_aux_JT00_2014"; +DROP TABLE IF EXISTS "ma_od_main_JT00_2014"; diff --git a/connectivity/census_block_roads.sql b/connectivity/census_block_roads.sql index 674da3a5..75bbf33a 100644 --- a/connectivity/census_block_roads.sql +++ b/connectivity/census_block_roads.sql @@ -1,33 +1,33 @@ ----------------------------------------- --- INPUTS --- location: cambridge ----------------------------------------- -DROP TABLE IF EXISTS generated.cambridge_census_block_roads; - -CREATE TABLE generated.cambridge_census_block_roads ( - id SERIAL PRIMARY KEY, - blockid10 VARCHAR(15), - road_id INT -); - -INSERT INTO generated.cambridge_census_block_roads ( - blockid10, - road_id -) -SELECT blocks.blockid10, - ways.road_id -FROM cambridge_census_blocks blocks, - cambridge_zip_codes zips, - cambridge_ways ways -WHERE EXISTS ( - SELECT 1 - FROM cambridge_zip_codes zips - WHERE zips.geom <-> blocks.geom < 11000 - AND zips.zip_code = '02138' -) -AND blocks.geom <-> ways.geom < 50 -AND ST_Intersects(ST_Buffer(blocks.geom,50),ways.geom); - -CREATE INDEX idx_cambridge_censblkrds -ON generated.cambridge_census_block_roads (blockid10,road_id); -ANALYZE generated.cambridge_census_block_roads; +---------------------------------------- +-- INPUTS +-- location: cambridge +---------------------------------------- +DROP TABLE IF EXISTS generated.cambridge_census_block_roads; + +CREATE TABLE generated.cambridge_census_block_roads ( + id SERIAL PRIMARY KEY, + blockid10 VARCHAR(15), + road_id INT +); + +INSERT INTO generated.cambridge_census_block_roads ( + blockid10, + road_id +) +SELECT blocks.blockid10, + ways.road_id +FROM cambridge_census_blocks blocks, + cambridge_zip_codes zips, + cambridge_ways ways +WHERE EXISTS ( + SELECT 1 + FROM cambridge_zip_codes zips + WHERE zips.geom <-> blocks.geom < 11000 + AND zips.zip_code = '02138' +) +AND blocks.geom <-> ways.geom < 50 +AND ST_Intersects(ST_Buffer(blocks.geom,50),ways.geom); + +CREATE INDEX idx_cambridge_censblkrds +ON generated.cambridge_census_block_roads (blockid10,road_id); +ANALYZE generated.cambridge_census_block_roads; diff --git a/connectivity/census_blocks.sql b/connectivity/census_blocks.sql new file mode 100644 index 00000000..9ce6ec1b --- /dev/null +++ b/connectivity/census_blocks.sql @@ -0,0 +1,15 @@ +---------------------------------------- +-- INPUTS +-- location: cambridge +-- code to be run on table that has +-- been imported directly from US Census +-- blkpophu file +---------------------------------------- + +ALTER TABLE cambridge_census_blocks ADD COLUMN pop_low_stress INT; +ALTER TABLE cambridge_census_blocks ADD COLUMN pop_high_stress INT; +ALTER TABLE cambridge_census_blocks ADD COLUMN emp_low_stress INT; +ALTER TABLE cambridge_census_blocks ADD COLUMN emp_high_stress INT; + +CREATE INDEX idx_cambridge_blocks10 ON cambridge_census_blocks (blockid10); +ANALYZE cambridge_census_blocks (blockid10); diff --git a/connectivity/connected_census_blocks.sql b/connectivity/connected_census_blocks.sql new file mode 100644 index 00000000..6d85edf4 --- /dev/null +++ b/connectivity/connected_census_blocks.sql @@ -0,0 +1,109 @@ +---------------------------------------- +-- INPUTS +-- location: cambridge +---------------------------------------- +DROP TABLE IF EXISTS generated.cambridge_connected_census_blocks; + +CREATE TABLE generated.cambridge_connected_census_blocks ( + id SERIAL PRIMARY KEY, + source_block VARCHAR(15), + target_block VARCHAR(15), + low_stress BOOLEAN, + high_stress BOOLEAN +); + +INSERT INTO generated.cambridge_connected_census_blocks ( + source_block, target_block, low_stress, high_stress +) +SELECT source_block.blockid10 AS source_blockid10, + target_block.blockid10 AS target_blockid10, + 'f'::BOOLEAN, + 'f'::BOOLEAN +FROM cambridge_census_blocks source_block, + cambridge_census_blocks target_block +WHERE EXISTS ( + SELECT 1 + FROM cambridge_zip_codes zips + WHERE ST_Intersects(source_block.geom,zips.geom) + ) +AND source_block.geom <#> target_block.geom < 11000 +AND ( + EXISTS ( + SELECT 1 + FROM cambridge_census_block_roads source_br, + cambridge_census_block_roads target_br, + cambridge_reachable_roads_high_stress hs + WHERE source_block.blockid10 = source_br.blockid10 + AND target_block.blockid10 = target_br.blockid10 + AND hs.base_road = source_br.road_id + AND hs.target_road = target_br.road_id + ) + OR EXISTS ( + SELECT 1 + FROM cambridge_census_block_roads source_br, + cambridge_census_block_roads target_br, + cambridge_reachable_roads_low_stress ls + WHERE source_block.blockid10 = source_br.blockid10 + AND target_block.blockid10 = target_br.blockid10 + AND ls.base_road = source_br.road_id + AND ls.target_road = target_br.road_id + ) + ); + +-- block pair index +CREATE INDEX idx_cambridge_blockpairs +ON cambridge_connected_census_blocks (source_blockid10,target_blockid10); +ANALYZE cambridge_connected_census_blocks (source_blockid10,target_blockid10); + +-- high stress +UPDATE cambridge_connected_census_blocks +SET high_stress = 't'::BOOLEAN +WHERE EXISTS ( + SELECT 1 + FROM cambridge_census_block_roads source_br, + cambridge_census_block_roads target_br, + cambridge_reachable_roads_high_stress hs + WHERE source_block.blockid10 = source_br.blockid10 + AND target_block.blockid10 = target_br.blockid10 + AND hs.base_road = source_br.road_id + AND hs.target_road = target_br.road_id + ); + +-- low stress +UPDATE cambridge_connected_census_blocks +SET low_stress = 't'::BOOLEAN +WHERE EXISTS ( + SELECT 1 + FROM cambridge_census_block_roads source_br, + cambridge_census_block_roads target_br, + cambridge_reachable_roads_low_stress ls + WHERE source_block.blockid10 = source_br.blockid10 + AND target_block.blockid10 = target_br.blockid10 + AND ls.base_road = source_br.road_id + AND ls.target_road = target_br.road_id + ) +AND ( + SELECT MIN(total_cost) + FROM cambridge_census_block_roads source_br, + cambridge_census_block_roads target_br, + cambridge_reachable_roads_low_stress ls + WHERE source_block.blockid10 = source_br.blockid10 + AND target_block.blockid10 = target_br.blockid10 + AND ls.base_road = source_br.road_id + AND ls.target_road = target_br.road_id + )::FLOAT / + COALESCE(( + SELECT MIN(total_cost) + 1 + FROM cambridge_census_block_roads source_br, + cambridge_census_block_roads target_br, + cambridge_reachable_roads_high_stress hs + WHERE source_block.blockid10 = source_br.blockid10 + AND target_block.blockid10 = target_br.blockid10 + AND hs.base_road = source_br.road_id + AND hs.target_road = target_br.road_id + ),11000) <= 1.3; + +-- stress index +CREATE INDEX idx_cambridge_blockpairs_lstress ON cambridge_connected_census_blocks (low_stress); +CREATE INDEX idx_cambridge_blockpairs_hstress ON cambridge_connected_census_blocks (high_stress); +ANALYZE cambridge_connected_census_blocks (low_stress,high_stress); diff --git a/connectivity/reachable_roads_high_stress.sql b/connectivity/reachable_roads_high_stress.sql index 6ac03826..fee9236c 100644 --- a/connectivity/reachable_roads_high_stress.sql +++ b/connectivity/reachable_roads_high_stress.sql @@ -1,45 +1,47 @@ ----------------------------------------- --- INPUTS --- location: cambridge ----------------------------------------- - -CREATE TABLE generated.cambridge_reachable_roads_high_stress ( - id SERIAL PRIMARY KEY, - base_road INT, - target_road INT, - total_cost FLOAT -); - -INSERT INTO generated.cambridge_reachable_roads_high_stress ( - base_road, - target_road, - total_cost -) -SELECT r1.road_id, - v2.road_id, - sheds.agg_cost -FROM cambridge_ways r1, - cambridge_ways_net_vert v1, - cambridge_ways_net_vert v2, - pgr_drivingDistance(' - SELECT link_id AS id, - source_vert AS source, - target_vert AS target, - link_cost AS cost - FROM cambridge_ways_net_link', - v1.vert_id, - 10560, - directed := true - ) sheds -WHERE EXISTS ( - SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_Intersects(zips.geom,r1.geom) - AND zips.zip_code = '02138' -) -AND r1.road_id = v1.road_id -AND v2.vert_id = sheds.node; - -CREATE INDEX idx_cambridge_rchblrdshistrss -ON generated.cambridge_reachable_roads_high_stress (base_road,target_road); -ANALYZE generated.cambridge_reachable_roads_high_stress; +---------------------------------------- +-- INPUTS +-- location: cambridge +-- maximum network distsance: 10560 ft +---------------------------------------- +DROP TABLE IF EXISTS generated.cambridge_reachable_roads_high_stress; + +CREATE TABLE generated.cambridge_reachable_roads_high_stress ( + id SERIAL PRIMARY KEY, + base_road INT, + target_road INT, + total_cost FLOAT +); + +INSERT INTO generated.cambridge_reachable_roads_high_stress ( + base_road, + target_road, + total_cost +) +SELECT r1.road_id, + v2.road_id, + sheds.agg_cost +FROM cambridge_ways r1, + cambridge_ways_net_vert v1, + cambridge_ways_net_vert v2, + pgr_drivingDistance(' + SELECT link_id AS id, + source_vert AS source, + target_vert AS target, + link_cost AS cost + FROM cambridge_ways_net_link', + v1.vert_id, + 10560, + directed := true + ) sheds +WHERE EXISTS ( + SELECT 1 + FROM cambridge_zip_codes zips + WHERE ST_Intersects(zips.geom,r1.geom) + AND zips.zip_code = '02138' +) +AND r1.road_id = v1.road_id +AND v2.vert_id = sheds.node; + +CREATE INDEX idx_cambridge_rchblrdshistrss +ON generated.cambridge_reachable_roads_high_stress (base_road,target_road); +ANALYZE generated.cambridge_reachable_roads_high_stress; diff --git a/connectivity/reachable_roads_low_stress.sql b/connectivity/reachable_roads_low_stress.sql index 2062d0c1..90c666b4 100644 --- a/connectivity/reachable_roads_low_stress.sql +++ b/connectivity/reachable_roads_low_stress.sql @@ -1,46 +1,48 @@ ----------------------------------------- --- INPUTS --- location: cambridge ----------------------------------------- - -CREATE TABLE generated.cambridge_reachable_roads_low_stress ( - id SERIAL PRIMARY KEY, - base_road INT, - target_road INT, - total_cost FLOAT -); - -INSERT INTO generated.cambridge_reachable_roads_low_stress ( - base_road, - target_road, - total_cost -) -SELECT r1.road_id, - v2.road_id, - sheds.agg_cost -FROM cambridge_ways r1, - cambridge_ways_net_vert v1, - cambridge_ways_net_vert v2, - pgr_drivingDistance(' - SELECT link_id AS id, - source_vert AS source, - target_vert AS target, - link_cost AS cost - FROM cambridge_ways_net_link - WHERE link_stress = 1', - v1.vert_id, - 10560, - directed := true - ) sheds -WHERE EXISTS ( - SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_Intersects(zips.geom,r1.geom) - AND zips.zip_code = '02138' -) -AND r1.road_id = v1.road_id -AND v2.vert_id = sheds.node; - -CREATE INDEX idx_cambridge_rchblrdslowstrss -ON generated.cambridge_reachable_roads_low_stress (base_road,target_road); -ANALYZE generated.cambridge_reachable_roads_low_stress; +---------------------------------------- +-- INPUTS +-- location: cambridge +-- maximum network distsance: 10560 ft +---------------------------------------- +DROP TABLE IF EXISTS generated.cambridge_reachable_roads_low_stress; + +CREATE TABLE generated.cambridge_reachable_roads_low_stress ( + id SERIAL PRIMARY KEY, + base_road INT, + target_road INT, + total_cost FLOAT +); + +INSERT INTO generated.cambridge_reachable_roads_low_stress ( + base_road, + target_road, + total_cost +) +SELECT r1.road_id, + v2.road_id, + sheds.agg_cost +FROM cambridge_ways r1, + cambridge_ways_net_vert v1, + cambridge_ways_net_vert v2, + pgr_drivingDistance(' + SELECT link_id AS id, + source_vert AS source, + target_vert AS target, + link_cost AS cost + FROM cambridge_ways_net_link + WHERE link_stress = 1', + v1.vert_id, + 10560, + directed := true + ) sheds +WHERE EXISTS ( + SELECT 1 + FROM cambridge_zip_codes zips + WHERE ST_Intersects(zips.geom,r1.geom) + AND zips.zip_code = '02138' +) +AND r1.road_id = v1.road_id +AND v2.vert_id = sheds.node; + +CREATE INDEX idx_cambridge_rchblrdslowstrss +ON generated.cambridge_reachable_roads_low_stress (base_road,target_road); +ANALYZE generated.cambridge_reachable_roads_low_stress; diff --git a/process.txt b/process.txt index b8984a65..e9c1fc57 100644 --- a/process.txt +++ b/process.txt @@ -1,21 +1,46 @@ -1: Run import_osm.sh -2: Run prepare_tables.sql -3: Run one_way.sql -4: Run functional_class.sql -5: Run speed_limit.sql -6: Run width_ft.sql -7: Run lanes.sql -8: Run park.sql -9: Run bike_infra.sql -10: Run legs.sql -11: Run signalized.sql -12: Run stops.sql -13: Run stress_motorway-trunk.sql -14: Run stress_primary.sql -15: Run stress_secondary.sql -16: Run stress_tertiary.sql -17: Run stress_residential.sql -18: Run stress_living_street.sql -19: Run stress_track.sql -20: Run stress_path.sql -21: Run stress_intersections.sql +------------------------------------------- +-scripts given in order they should be run- +------------------------------------------- + +import_osm.sh (runs the following automatically) + - prepare_tables.sql + - one_way.sql + - functional_class.sql + - speed_limit.sql + - width_ft.sql + - lanes.sql + - park.sql + - bike_infra.sql + - legs.sql + - signalized.sql + - stops.sql + - stress_motorway-trunk.sql + - stress_primary.sql + - stress_secondary.sql + - stress_tertiary.sql + - stress_residential.sql + - stress_living_street.sql + - stress_track.sql + - stress_path.sql + - stress_one_way_reset.sql + - stress_motorway-trunk_ints.sql + - stress_primary_ints.sql + - stress_secondary_ints.sql + - stress_tertiary_ints.sql + - stress_lesser_ints.sql + - stress_link_ints.sql + +SELECT tdgBuildNetwork('cambridge_ways') + +(import census blocks with pop from census blkpophu dataset) +census_blocks.sql + +census_block_roads.sql +reachable_roads_high_stress.sql +reachable_roads_low_stress.sql +connected_census_blocks.sql +access_population.sql + +(import census blocks job data) +census_block_jobs.sql +access_jobs.sql From bda6ca2b4a53e89cf0264202cf48a978cb16cd93 Mon Sep 17 00:00:00 2001 From: Spencer Date: Fri, 30 Sep 2016 16:25:50 -0500 Subject: [PATCH 31/94] lkjsdf --- connectivity/census_block_jobs.sql | 8 +- connectivity/connected_census_blocks.sql | 134 ++++++++++++------- connectivity/reachable_roads_high_stress.sql | 6 +- connectivity/reachable_roads_low_stress.sql | 6 +- process.txt | 3 +- 5 files changed, 100 insertions(+), 57 deletions(-) diff --git a/connectivity/census_block_jobs.sql b/connectivity/census_block_jobs.sql index 2f9bca79..e7148585 100644 --- a/connectivity/census_block_jobs.sql +++ b/connectivity/census_block_jobs.sql @@ -24,19 +24,19 @@ ANALYZE "ma_od_aux_JT00_2014" (w_geocode); ANALYZE "ma_od_main_JT00_2014" (w_geocode); -- create combined table -CREATE TABLE scratch.cambridge_census_block_jobs ( +CREATE TABLE generated.cambridge_census_block_jobs ( id SERIAL PRIMARY KEY, blockid10 VARCHAR(15), jobs INT ); -- add blocks of interest -INSERT INTO scratch.cambridge_census_block_jobs (blockid10) +INSERT INTO generated.cambridge_census_block_jobs (blockid10) SELECT blocks.blockid10 FROM cambridge_census_blocks blocks; -- add main data -UPDATE scratch.cambridge_census_block_jobs +UPDATE generated.cambridge_census_block_jobs SET jobs = COALESCE(( SELECT SUM(j."S000") FROM "ma_od_main_JT00_2014" j @@ -44,7 +44,7 @@ SET jobs = COALESCE(( ),0); -- add aux data -UPDATE scratch.cambridge_census_block_jobs +UPDATE generated.cambridge_census_block_jobs SET jobs = jobs + COALESCE(( SELECT SUM(j."S000") diff --git a/connectivity/connected_census_blocks.sql b/connectivity/connected_census_blocks.sql index 6d85edf4..a73a0fe4 100644 --- a/connectivity/connected_census_blocks.sql +++ b/connectivity/connected_census_blocks.sql @@ -6,59 +6,31 @@ DROP TABLE IF EXISTS generated.cambridge_connected_census_blocks; CREATE TABLE generated.cambridge_connected_census_blocks ( id SERIAL PRIMARY KEY, - source_block VARCHAR(15), - target_block VARCHAR(15), + source_blockid10 VARCHAR(15), + target_blockid10 VARCHAR(15), low_stress BOOLEAN, - high_stress BOOLEAN + low_stress_cost INT, + high_stress BOOLEAN, + high_stress_cost INT ); -INSERT INTO generated.cambridge_connected_census_blocks ( - source_block, target_block, low_stress, high_stress +INSERT INTO generated.cambridge_connected_census_blocks ( -- took 2 hrs on the server + source_blockid10, target_blockid10, low_stress, high_stress ) -SELECT source_block.blockid10 AS source_blockid10, - target_block.blockid10 AS target_blockid10, +SELECT source_block.blockid10, + target_block.blockid10, 'f'::BOOLEAN, - 'f'::BOOLEAN + 't'::BOOLEAN FROM cambridge_census_blocks source_block, cambridge_census_blocks target_block WHERE EXISTS ( SELECT 1 FROM cambridge_zip_codes zips WHERE ST_Intersects(source_block.geom,zips.geom) + AND zips.zip_code = '02138' ) AND source_block.geom <#> target_block.geom < 11000 -AND ( - EXISTS ( - SELECT 1 - FROM cambridge_census_block_roads source_br, - cambridge_census_block_roads target_br, - cambridge_reachable_roads_high_stress hs - WHERE source_block.blockid10 = source_br.blockid10 - AND target_block.blockid10 = target_br.blockid10 - AND hs.base_road = source_br.road_id - AND hs.target_road = target_br.road_id - ) - OR EXISTS ( - SELECT 1 - FROM cambridge_census_block_roads source_br, - cambridge_census_block_roads target_br, - cambridge_reachable_roads_low_stress ls - WHERE source_block.blockid10 = source_br.blockid10 - AND target_block.blockid10 = target_br.blockid10 - AND ls.base_road = source_br.road_id - AND ls.target_road = target_br.road_id - ) - ); - --- block pair index -CREATE INDEX idx_cambridge_blockpairs -ON cambridge_connected_census_blocks (source_blockid10,target_blockid10); -ANALYZE cambridge_connected_census_blocks (source_blockid10,target_blockid10); - --- high stress -UPDATE cambridge_connected_census_blocks -SET high_stress = 't'::BOOLEAN -WHERE EXISTS ( +AND EXISTS ( SELECT 1 FROM cambridge_census_block_roads source_br, cambridge_census_block_roads target_br, @@ -69,6 +41,25 @@ WHERE EXISTS ( AND hs.target_road = target_br.road_id ); +-- block pair index +CREATE INDEX idx_cambridge_blockpairs +ON cambridge_connected_census_blocks (source_blockid10,target_blockid10); +ANALYZE cambridge_connected_census_blocks (source_blockid10,target_blockid10); + +-- -- high stress +-- UPDATE cambridge_connected_census_blocks +-- SET high_stress = 't'::BOOLEAN +-- WHERE EXISTS ( +-- SELECT 1 +-- FROM cambridge_census_block_roads source_br, +-- cambridge_census_block_roads target_br, +-- cambridge_reachable_roads_high_stress hs +-- WHERE source_block.blockid10 = source_br.blockid10 +-- AND target_block.blockid10 = target_br.blockid10 +-- AND hs.base_road = source_br.road_id +-- AND hs.target_road = target_br.road_id +-- ); + -- low stress UPDATE cambridge_connected_census_blocks SET low_stress = 't'::BOOLEAN @@ -77,8 +68,8 @@ WHERE EXISTS ( FROM cambridge_census_block_roads source_br, cambridge_census_block_roads target_br, cambridge_reachable_roads_low_stress ls - WHERE source_block.blockid10 = source_br.blockid10 - AND target_block.blockid10 = target_br.blockid10 + WHERE source_blockid10 = source_br.blockid10 + AND target_blockid10 = target_br.blockid10 AND ls.base_road = source_br.road_id AND ls.target_road = target_br.road_id ) @@ -87,8 +78,8 @@ AND ( FROM cambridge_census_block_roads source_br, cambridge_census_block_roads target_br, cambridge_reachable_roads_low_stress ls - WHERE source_block.blockid10 = source_br.blockid10 - AND target_block.blockid10 = target_br.blockid10 + WHERE source_blockid10 = source_br.blockid10 + AND target_blockid10 = target_br.blockid10 AND ls.base_road = source_br.road_id AND ls.target_road = target_br.road_id )::FLOAT / @@ -97,8 +88,8 @@ AND ( FROM cambridge_census_block_roads source_br, cambridge_census_block_roads target_br, cambridge_reachable_roads_high_stress hs - WHERE source_block.blockid10 = source_br.blockid10 - AND target_block.blockid10 = target_br.blockid10 + WHERE source_blockid10 = source_br.blockid10 + AND target_blockid10 = target_br.blockid10 AND hs.base_road = source_br.road_id AND hs.target_road = target_br.road_id ),11000) <= 1.3; @@ -107,3 +98,54 @@ AND ( CREATE INDEX idx_cambridge_blockpairs_lstress ON cambridge_connected_census_blocks (low_stress); CREATE INDEX idx_cambridge_blockpairs_hstress ON cambridge_connected_census_blocks (high_stress); ANALYZE cambridge_connected_census_blocks (low_stress,high_stress); + + + + + + + + + + + + + + + + + + +-- junk + + +SELECT source_block.blockid10 AS source_blockid10, + target_block.blockid10 AS target_blockid10, + 'f'::BOOLEAN, + 't'::BOOLEAN +FROM cambridge_census_blocks source_block, + cambridge_census_block_roads source_br, + cambridge_census_blocks target_block, + cambridge_census_block_roads target_br, + cambridge_reachable_roads_high_stress hs +WHERE EXISTS ( + SELECT 1 + FROM cambridge_zip_codes zips + WHERE ST_Intersects(source_block.geom,zips.geom) + AND zips.zip_code = '02138' + ) +AND source_block.geom <#> target_block.geom < 11000 + + + + +AND EXISTS ( + SELECT 1 + FROM cambridge_census_block_roads source_br, + cambridge_census_block_roads target_br, + cambridge_reachable_roads_high_stress hs + WHERE source_block.blockid10 = source_br.blockid10 + AND target_block.blockid10 = target_br.blockid10 + AND hs.base_road = source_br.road_id + AND hs.target_road = target_br.road_id + ); diff --git a/connectivity/reachable_roads_high_stress.sql b/connectivity/reachable_roads_high_stress.sql index fee9236c..9ecb37b3 100644 --- a/connectivity/reachable_roads_high_stress.sql +++ b/connectivity/reachable_roads_high_stress.sql @@ -42,6 +42,6 @@ WHERE EXISTS ( AND r1.road_id = v1.road_id AND v2.vert_id = sheds.node; -CREATE INDEX idx_cambridge_rchblrdshistrss -ON generated.cambridge_reachable_roads_high_stress (base_road,target_road); -ANALYZE generated.cambridge_reachable_roads_high_stress; +CREATE INDEX idx_cambridge_rchblrdshistrss_b ON generated.cambridge_reachable_roads_high_stress (base_road); +CREATE INDEX idx_cambridge_rchblrdshistrss_t ON generated.cambridge_reachable_roads_high_stress (target_road); +ANALYZE generated.cambridge_reachable_roads_high_stress (base_road,target_road); diff --git a/connectivity/reachable_roads_low_stress.sql b/connectivity/reachable_roads_low_stress.sql index 90c666b4..2c3510d6 100644 --- a/connectivity/reachable_roads_low_stress.sql +++ b/connectivity/reachable_roads_low_stress.sql @@ -43,6 +43,6 @@ WHERE EXISTS ( AND r1.road_id = v1.road_id AND v2.vert_id = sheds.node; -CREATE INDEX idx_cambridge_rchblrdslowstrss -ON generated.cambridge_reachable_roads_low_stress (base_road,target_road); -ANALYZE generated.cambridge_reachable_roads_low_stress; +CREATE INDEX idx_cambridge_rchblrdslowstrss_b ON generated.cambridge_reachable_roads_low_stress (base_road); +CREATE INDEX idx_cambridge_rchblrdslowstrss_t ON generated.cambridge_reachable_roads_low_stress (target_road); +ANALYZE generated.cambridge_reachable_roads_low_stress (base_road,target_road); diff --git a/process.txt b/process.txt index e9c1fc57..fa6775c4 100644 --- a/process.txt +++ b/process.txt @@ -30,7 +30,8 @@ import_osm.sh (runs the following automatically) - stress_lesser_ints.sql - stress_link_ints.sql -SELECT tdgBuildNetwork('cambridge_ways') +SELECT tdgBuildNetwork('cambridge_ways'); +SELECT tdgNetworkCostFromDistance('cambridge_ways'); (import census blocks with pop from census blkpophu dataset) census_blocks.sql From ae1b8f93a661096df443fb3def0b2de95ca2d2e9 Mon Sep 17 00:00:00 2001 From: Spencer Date: Mon, 3 Oct 2016 16:56:37 -0500 Subject: [PATCH 32/94] gjsoijsdfl --- connectivity/access_jobs.sql | 42 ++++++++ connectivity/access_population.sql | 102 ++++++++----------- connectivity/connected_census_blocks.sql | 65 ------------ connectivity/overall_scores.sql | 120 +++++++++++++++++++++++ 4 files changed, 204 insertions(+), 125 deletions(-) create mode 100644 connectivity/access_jobs.sql create mode 100644 connectivity/overall_scores.sql diff --git a/connectivity/access_jobs.sql b/connectivity/access_jobs.sql new file mode 100644 index 00000000..b30bebf2 --- /dev/null +++ b/connectivity/access_jobs.sql @@ -0,0 +1,42 @@ +---------------------------------------- +-- INPUTS +-- location: cambridge +---------------------------------------- +-- low stress access +UPDATE cambridge_census_blocks +SET emp_low_stress = ( + SELECT SUM(blocks2.jobs) + FROM cambridge_census_block_jobs blocks2 + WHERE EXISTS ( + SELECT 1 + FROM cambridge_connected_census_blocks cb + WHERE cb.source_blockid10 = cambridge_census_blocks.blockid10 + AND cb.target_blockid10 = blocks2.blockid10 + AND cb.low_stress + ) + ) +WHERE EXISTS ( + SELECT 1 + FROM cambridge_zip_codes zips + WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) + AND zips.zip_code = '02138' + ); + +-- high stress access +UPDATE cambridge_census_blocks +SET emp_high_stress = ( + SELECT SUM(blocks2.jobs) + FROM cambridge_census_block_jobs blocks2 + WHERE EXISTS ( + SELECT 1 + FROM cambridge_connected_census_blocks cb + WHERE cb.source_blockid10 = cambridge_census_blocks.blockid10 + AND cb.target_blockid10 = blocks2.blockid10 + ) + ) +WHERE EXISTS ( + SELECT 1 + FROM cambridge_zip_codes zips + WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) + AND zips.zip_code = '02138' + ); diff --git a/connectivity/access_population.sql b/connectivity/access_population.sql index d4a704a9..1163c6e2 100644 --- a/connectivity/access_population.sql +++ b/connectivity/access_population.sql @@ -1,60 +1,42 @@ ----------------------------------------- --- INPUTS --- location: cambridge ----------------------------------------- - AND zips.zip_code = '02138' - --- low stress access - - - - - -UPDATE cambridge_census_blocks -SET pop_low_stress = ( - SELECT SUM(pop10) - FROM - ) - - - blocks.source_blockid10, - blocks.target_blockid10, - - - source_block.blockid10 AS source_blockid10, - target_block.id AS target_id, - target_block.blockid10 AS target_blockid10, - target_block.pop10 AS target_pop -FROM cambridge_census_blocks source_block, - cambridge_census_blocks target_block -WHERE EXISTS ( - SELECT 1 - FROM cambridge_census_block_roads source_br, - cambridge_census_block_roads target_br, - cambridge_reachable_roads_low_stress ls - WHERE source_block.blockid10 = source_br.blockid10 - AND target_block.blockid10 = target_br.blockid10 - AND ls.base_road = source_br.road_id - AND ls.target_road = target_br.road_id - ) -AND ( - SELECT MIN(total_cost) - FROM cambridge_census_block_roads source_br, - cambridge_census_block_roads target_br, - cambridge_reachable_roads_low_stress ls - WHERE source_block.blockid10 = source_br.blockid10 - AND target_block.blockid10 = target_br.blockid10 - AND ls.base_road = source_br.road_id - AND ls.target_road = target_br.road_id - ) / - ( - SELECT MIN(total_cost) + 1 - FROM cambridge_census_block_roads source_br, - cambridge_census_block_roads target_br, - cambridge_reachable_roads_high_stress hs - WHERE source_block.blockid10 = source_br.blockid10 - AND target_block.blockid10 = target_br.blockid10 - AND hs.base_road = source_br.road_id - AND hs.target_road = target_br.road_id - ) <= 1.3 --30% max deviation --- and source_block.blockid10 = '250173540002000' +---------------------------------------- +-- INPUTS +-- location: cambridge +---------------------------------------- +-- low stress access +UPDATE cambridge_census_blocks +SET pop_low_stress = ( + SELECT SUM(blocks2.pop10) + FROM cambridge_census_blocks blocks2 + WHERE EXISTS ( + SELECT 1 + FROM cambridge_connected_census_blocks cb + WHERE cb.source_blockid10 = cambridge_census_blocks.blockid10 + AND cb.target_blockid10 = blocks2.blockid10 + AND cb.low_stress + ) + ) +WHERE EXISTS ( + SELECT 1 + FROM cambridge_zip_codes zips + WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) + AND zips.zip_code = '02138' + ); + +-- high stress access +UPDATE cambridge_census_blocks +SET pop_high_stress = ( + SELECT SUM(blocks2.pop10) + FROM cambridge_census_blocks blocks2 + WHERE EXISTS ( + SELECT 1 + FROM cambridge_connected_census_blocks cb + WHERE cb.source_blockid10 = cambridge_census_blocks.blockid10 + AND cb.target_blockid10 = blocks2.blockid10 + ) + ) +WHERE EXISTS ( + SELECT 1 + FROM cambridge_zip_codes zips + WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) + AND zips.zip_code = '02138' + ); diff --git a/connectivity/connected_census_blocks.sql b/connectivity/connected_census_blocks.sql index a73a0fe4..c7ff6119 100644 --- a/connectivity/connected_census_blocks.sql +++ b/connectivity/connected_census_blocks.sql @@ -46,20 +46,6 @@ CREATE INDEX idx_cambridge_blockpairs ON cambridge_connected_census_blocks (source_blockid10,target_blockid10); ANALYZE cambridge_connected_census_blocks (source_blockid10,target_blockid10); --- -- high stress --- UPDATE cambridge_connected_census_blocks --- SET high_stress = 't'::BOOLEAN --- WHERE EXISTS ( --- SELECT 1 --- FROM cambridge_census_block_roads source_br, --- cambridge_census_block_roads target_br, --- cambridge_reachable_roads_high_stress hs --- WHERE source_block.blockid10 = source_br.blockid10 --- AND target_block.blockid10 = target_br.blockid10 --- AND hs.base_road = source_br.road_id --- AND hs.target_road = target_br.road_id --- ); - -- low stress UPDATE cambridge_connected_census_blocks SET low_stress = 't'::BOOLEAN @@ -98,54 +84,3 @@ AND ( CREATE INDEX idx_cambridge_blockpairs_lstress ON cambridge_connected_census_blocks (low_stress); CREATE INDEX idx_cambridge_blockpairs_hstress ON cambridge_connected_census_blocks (high_stress); ANALYZE cambridge_connected_census_blocks (low_stress,high_stress); - - - - - - - - - - - - - - - - - - --- junk - - -SELECT source_block.blockid10 AS source_blockid10, - target_block.blockid10 AS target_blockid10, - 'f'::BOOLEAN, - 't'::BOOLEAN -FROM cambridge_census_blocks source_block, - cambridge_census_block_roads source_br, - cambridge_census_blocks target_block, - cambridge_census_block_roads target_br, - cambridge_reachable_roads_high_stress hs -WHERE EXISTS ( - SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_Intersects(source_block.geom,zips.geom) - AND zips.zip_code = '02138' - ) -AND source_block.geom <#> target_block.geom < 11000 - - - - -AND EXISTS ( - SELECT 1 - FROM cambridge_census_block_roads source_br, - cambridge_census_block_roads target_br, - cambridge_reachable_roads_high_stress hs - WHERE source_block.blockid10 = source_br.blockid10 - AND target_block.blockid10 = target_br.blockid10 - AND hs.base_road = source_br.road_id - AND hs.target_road = target_br.road_id - ); diff --git a/connectivity/overall_scores.sql b/connectivity/overall_scores.sql new file mode 100644 index 00000000..009698d5 --- /dev/null +++ b/connectivity/overall_scores.sql @@ -0,0 +1,120 @@ +---------------------------------------- +-- INPUTS +-- location: cambridge +---------------------------------------- +DROP TABLE IF EXISTS generated.cambridge_overall_scores; + +CREATE TABLE generated.cambridge_overall_scores ( + id SERIAL PRIMARY KEY, + score_name TEXT, + score NUMERIC(16,4), + notes TEXT +); + +-- median pop access ratio +INSERT INTO generated.cambridge_overall_scores ( + score_name, score, notes +) +SELECT 'Median ratio of access to population', + quantile(pop_low_stress::FLOAT/pop_high_stress,0.5), + 'Ratio of population accessible by low stress + to population accessible overall, expressed as + the median of all census blocks in the + neighborhood' +FROM cambridge_census_blocks +WHERE EXISTS ( + SELECT 1 + FROM cambridge_zip_codes zips + WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) + AND zips.zip_code = '02138' + ); + +-- 70th percentile pop access ratio +INSERT INTO generated.cambridge_overall_scores ( + score_name, score, notes +) +SELECT '70th percentile ratio of access to population', + quantile(pop_low_stress::FLOAT/pop_high_stress,0.7), + 'Ratio of population accessible by low stress + to population accessible overall, expressed as + the 70th percentile of all census blocks in the + neighborhood' +FROM cambridge_census_blocks +WHERE EXISTS ( + SELECT 1 + FROM cambridge_zip_codes zips + WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) + AND zips.zip_code = '02138' + ); + +-- avg pop access ratio +INSERT INTO generated.cambridge_overall_scores ( + score_name, score, notes +) +SELECT 'Average ratio of access to population', + AVG(pop_low_stress::FLOAT/pop_high_stress), + 'Ratio of population accessible by low stress + to population accessible overall, expressed as + the average of all census blocks in the + neighborhood' +FROM cambridge_census_blocks +WHERE EXISTS ( + SELECT 1 + FROM cambridge_zip_codes zips + WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) + AND zips.zip_code = '02138' + ); + +-- median jobs access ratio +INSERT INTO generated.cambridge_overall_scores ( + score_name, score, notes +) +SELECT 'Median ratio of access to employment', + quantile(emp_low_stress::FLOAT/emp_high_stress,0.5), + 'Ratio of employment accessible by low stress + to employment accessible overall, expressed as + the median of all census blocks in the + neighborhood' +FROM cambridge_census_blocks +WHERE EXISTS ( + SELECT 1 + FROM cambridge_zip_codes zips + WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) + AND zips.zip_code = '02138' + ); + +-- 70th percentile jobs access ratio +INSERT INTO generated.cambridge_overall_scores ( + score_name, score, notes +) +SELECT '70th percentile ratio of access to employment', + quantile(emp_low_stress::FLOAT/emp_high_stress,0.7), + 'Ratio of employment accessible by low stress + to employment accessible overall, expressed as + the 70th percentile of all census blocks in the + neighborhood' +FROM cambridge_census_blocks +WHERE EXISTS ( + SELECT 1 + FROM cambridge_zip_codes zips + WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) + AND zips.zip_code = '02138' + ); + +-- avg jobs access ratio +INSERT INTO generated.cambridge_overall_scores ( + score_name, score, notes +) +SELECT 'Average ratio of access to employment', + AVG(emp_low_stress::FLOAT/emp_high_stress), + 'Ratio of employment accessible by low stress + to employment accessible overall, expressed as + the average of all census blocks in the + neighborhood' +FROM cambridge_census_blocks +WHERE EXISTS ( + SELECT 1 + FROM cambridge_zip_codes zips + WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) + AND zips.zip_code = '02138' + ); From 9cced01963106d447dda0252c2e2a84feca2fe60 Mon Sep 17 00:00:00 2001 From: Spencer Date: Tue, 4 Oct 2016 16:24:12 -0500 Subject: [PATCH 33/94] lksdjf --- connectivity/access_schools.sql | 12 + connectivity/census_block_roads.sql | 6 +- .../connected_census_blocks_schools.sql | 86 +++++ connectivity/school_roads.sql | 58 +++ connectivity/schools.sql | 50 +++ import_osm.sh | 348 +++++++++--------- pfb.style | 3 + 7 files changed, 385 insertions(+), 178 deletions(-) create mode 100644 connectivity/access_schools.sql create mode 100644 connectivity/connected_census_blocks_schools.sql create mode 100644 connectivity/school_roads.sql create mode 100644 connectivity/schools.sql diff --git a/connectivity/access_schools.sql b/connectivity/access_schools.sql new file mode 100644 index 00000000..6d3636b7 --- /dev/null +++ b/connectivity/access_schools.sql @@ -0,0 +1,12 @@ +---------------------------------------- +-- INPUTS +-- location: cambridge +---------------------------------------- +-- low stress access + + +-- high stress access + + +-- should also set up a measure for pop reachable by all schools in the neighborhood +-- and report metrics diff --git a/connectivity/census_block_roads.sql b/connectivity/census_block_roads.sql index 75bbf33a..b69a6cf7 100644 --- a/connectivity/census_block_roads.sql +++ b/connectivity/census_block_roads.sql @@ -17,16 +17,14 @@ INSERT INTO generated.cambridge_census_block_roads ( SELECT blocks.blockid10, ways.road_id FROM cambridge_census_blocks blocks, - cambridge_zip_codes zips, cambridge_ways ways WHERE EXISTS ( SELECT 1 FROM cambridge_zip_codes zips - WHERE zips.geom <-> blocks.geom < 11000 + WHERE ST_DWithin(zips.geom, blocks.geom, 11000) AND zips.zip_code = '02138' ) -AND blocks.geom <-> ways.geom < 50 -AND ST_Intersects(ST_Buffer(blocks.geom,50),ways.geom); +AND ST_DWithin(blocks.geom,ways.geom,50); CREATE INDEX idx_cambridge_censblkrds ON generated.cambridge_census_block_roads (blockid10,road_id); diff --git a/connectivity/connected_census_blocks_schools.sql b/connectivity/connected_census_blocks_schools.sql new file mode 100644 index 00000000..07913754 --- /dev/null +++ b/connectivity/connected_census_blocks_schools.sql @@ -0,0 +1,86 @@ +---------------------------------------- +-- INPUTS +-- location: cambridge +---------------------------------------- +DROP TABLE IF EXISTS generated.cambridge_connected_census_blocks_schools; + +CREATE TABLE generated.cambridge_connected_census_blocks_schools ( + id SERIAL PRIMARY KEY, + source_blockid10 VARCHAR(15), + target_school_id INT, + low_stress BOOLEAN, + low_stress_cost INT, + high_stress BOOLEAN, + high_stress_cost INT +); + +INSERT INTO generated.cambridge_connected_census_blocks_schools ( + source_blockid10, target_school_id, low_stress, high_stress +) +SELECT blocks.blockid10, + schools.id, + 'f'::BOOLEAN, + 't'::BOOLEAN +FROM cambridge_census_blocks blocks, + cambridge_schools schools +WHERE EXISTS ( + SELECT 1 + FROM cambridge_zip_codes zips + WHERE ST_Intersects(blocks.geom,zips.geom) + AND zips.zip_code = '02138' + ) +AND blocks.geom <#> schools.geom_pt < 11000 +AND EXISTS ( + SELECT 1 + FROM cambridge_census_block_roads source_br, + cambridge_school_roads target_sr, + cambridge_reachable_roads_high_stress hs + WHERE blocks.blockid10 = source_br.blockid10 + AND schools.id = target_sr.school_id + AND hs.base_road = source_br.road_id + AND hs.target_road = target_sr.road_id + ); + +-- block pair index +CREATE INDEX idx_cambridge_blockschoolpairs +ON cambridge_connected_census_blocks_schools (source_blockid10,target_school_id); +ANALYZE cambridge_connected_census_blocks_schools (source_blockid10,target_school_id); + +-- low stress +UPDATE cambridge_connected_census_blocks_schools +SET low_stress = 't'::BOOLEAN +WHERE EXISTS ( + SELECT 1 + FROM cambridge_census_block_roads source_br, + cambridge_school_roads target_sr, + cambridge_reachable_roads_low_stress ls + WHERE source_blockid10 = source_br.blockid10 + AND target_school_id = target_sr.school_id + AND ls.base_road = source_br.road_id + AND ls.target_road = target_sr.road_id + ) +AND ( + SELECT MIN(total_cost) + FROM cambridge_census_block_roads source_br, + cambridge_school_roads target_sr, + cambridge_reachable_roads_low_stress ls + WHERE source_blockid10 = source_br.blockid10 + AND target_school_id = target_sr.school_id + AND ls.base_road = source_br.road_id + AND ls.target_road = target_sr.road_id + )::FLOAT / + COALESCE(( + SELECT MIN(total_cost) + 1 + FROM cambridge_census_block_roads source_br, + cambridge_school_roads target_sr, + cambridge_reachable_roads_high_stress hs + WHERE source_blockid10 = source_br.blockid10 + AND target_school_id = target_sr.school_id + AND hs.base_road = source_br.road_id + AND hs.target_road = target_sr.road_id + ),11000) <= 1.3; + +-- stress index +CREATE INDEX idx_cambridge_blockschl_lstress ON cambridge_connected_census_blocks_schools (low_stress); +CREATE INDEX idx_cambridge_blockschl_hstress ON cambridge_connected_census_blocks_schools (high_stress); +ANALYZE cambridge_connected_census_blocks_schools (low_stress,high_stress); diff --git a/connectivity/school_roads.sql b/connectivity/school_roads.sql new file mode 100644 index 00000000..fe65173d --- /dev/null +++ b/connectivity/school_roads.sql @@ -0,0 +1,58 @@ +---------------------------------------- +-- INPUTS +-- location: cambridge +---------------------------------------- +DROP TABLE IF EXISTS generated.cambridge_school_roads; + +CREATE TABLE generated.cambridge_school_roads ( + id SERIAL PRIMARY KEY, + school_id INT, + road_id INT +); + +-- polygons take any road within 50 feet +INSERT INTO generated.cambridge_school_roads ( + school_id, + road_id +) +SELECT schools.id, + ways.road_id +FROM cambridge_schools schools, + cambridge_ways ways +WHERE EXISTS ( + SELECT 1 + FROM cambridge_zip_codes zips + WHERE ST_DWithin(zips.geom, schools.geom_pt, 11000) + AND zips.zip_code = '02138' + ) +AND schools.geom_poly IS NOT NULL +AND ST_DWithin(schools.geom_poly,ways.geom,50); + +-- points take the nearest road +INSERT INTO generated.cambridge_school_roads ( + school_id, + road_id +) +SELECT schools.id, + ( + SELECT ways.road_id + FROM cambridge_ways ways + ORDER BY ST_Distance(ways.geom,schools.geom_pt) ASC + LIMIT 1 + ) +FROM cambridge_schools schools +WHERE EXISTS ( + SELECT 1 + FROM cambridge_zip_codes zips + WHERE ST_DWithin(zips.geom, schools.geom_pt, 11000) + AND zips.zip_code = '02138' + ) +AND NOT EXISTS ( + SELECT 1 + FROM cambridge_school_roads r + WHERE schools.id = r.school_id + ); + +CREATE INDEX idx_cambridge_schlrds_schlid ON generated.cambridge_school_roads (school_id); +CREATE INDEX idx_cambridge_schlrds_rdid ON generated.cambridge_school_roads (road_id); +ANALYZE generated.cambridge_school_roads (school_id, road_id); diff --git a/connectivity/schools.sql b/connectivity/schools.sql new file mode 100644 index 00000000..be10ef1b --- /dev/null +++ b/connectivity/schools.sql @@ -0,0 +1,50 @@ +---------------------------------------- +-- INPUTS +-- location: cambridge +---------------------------------------- +DROP TABLE IF EXISTS generated.cambridge_schools; + +CREATE TABLE generated.cambridge_schools ( + id SERIAL PRIMARY KEY, + osm_id BIGINT, + school_name TEXT, + geom_pt geometry(point,2249), + geom_poly geometry(polygon,2249) +); +CREATE INDEX sidx_cambridge_schools_geompt ON cambridge_schools USING GIST (geom_pt); +CREATE INDEX sidx_cambridge_schools_geomply ON cambridge_schools USING GIST (geom_poly); + +-- insert points from polygons +INSERT INTO generated.cambridge_schools ( + osm_id, school_name, geom_pt, geom_poly +) +SELECT osm_id, + name, + ST_Centroid(way), + way +FROM cambridge_osm_full_polygon +WHERE amenity = 'school'; + +-- remove subareas that are mistakenly designated as amenity=school +DELETE FROM generated.cambridge_schools +WHERE EXISTS ( + SELECT 1 + FROM generated.cambridge_schools s + WHERE ST_Contains(s.geom_poly,cambridge_schools.geom_poly) + AND s.id != generated.cambridge_schools.id +); + +-- insert points +INSERT INTO generated.cambridge_schools ( + osm_id, school_name, geom_pt +) +SELECT osm_id, + name, + way +FROM cambridge_osm_full_point +WHERE amenity = 'school' +AND NOT EXISTS ( + SELECT 1 + FROM cambridge_schools s + WHERE ST_Intersects(s.geom_poly,cambridge_osm_full_point.way) + ); diff --git a/import_osm.sh b/import_osm.sh index e2bb79fc..16a5f3c9 100644 --- a/import_osm.sh +++ b/import_osm.sh @@ -1,174 +1,174 @@ -#!/usr/bin/env bash - -# vars -DBHOST='192.168.40.225' -DBNAME='people_for_bikes' -OSMPREFIX='cambridge' -OSMFILE='/home/spencer/gis/cambridge.osm' - -# drop old tables -echo 'Dropping old tables' -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_ways;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_ways_intersections;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_relations_ways;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_nodes;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_relations;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_way_classes;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_way_tags;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_way_types;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_ways;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_ways_vertices_pgr;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_relations_ways;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_osm_nodes;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_osm_relations;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_osm_way_classes;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_osm_way_tags;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_osm_way_types;" - -# import the osm with highways that the above misses (bug in osm2pgrouting) -osm2pgrouting \ - -f $OSMFILE \ - -h $DBHOST \ - --dbname ${DBNAME} \ - --username gis \ - --schema received \ - --prefix ${OSMPREFIX}_ \ - --conf ./mapconfig_highway.xml \ - --clean - -# import the osm optimized for routing -osm2pgrouting \ - -f $OSMFILE \ - -h $DBHOST \ - --dbname ${DBNAME} \ - --username gis \ - --schema scratch \ - --prefix ${OSMPREFIX}_cycwys_ \ - --conf ./mapconfig_cycleway.xml \ - --clean - -# rename a few tables -echo 'Renaming tables' -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE received.${OSMPREFIX}_ways_vertices_pgr RENAME TO ${OSMPREFIX}_ways_intersections;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE received.${OSMPREFIX}_ways_intersections RENAME CONSTRAINT vertex_id TO ${OSMPREFIX}_vertex_id;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE received.osm_nodes RENAME TO ${OSMPREFIX}_osm_nodes;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE received.${OSMPREFIX}_osm_nodes RENAME CONSTRAINT node_id TO ${OSMPREFIX}_node_id;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE received.osm_relations RENAME TO ${OSMPREFIX}_osm_relations;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE received.osm_way_classes RENAME TO ${OSMPREFIX}_osm_way_classes;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE received.${OSMPREFIX}_osm_way_classes RENAME CONSTRAINT osm_way_classes_pkey TO ${OSMPREFIX}_osm_way_classes_pkey;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE received.osm_way_tags RENAME TO ${OSMPREFIX}_osm_way_tags;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE received.osm_way_types RENAME TO ${OSMPREFIX}_osm_way_types;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE received.${OSMPREFIX}_osm_way_types RENAME CONSTRAINT osm_way_types_pkey TO ${OSMPREFIX}_osm_way_types_pkey;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE scratch.${OSMPREFIX}_cycwys_ways_vertices_pgr RENAME CONSTRAINT vertex_id TO ${OSMPREFIX}_vertex_id;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE scratch.osm_nodes RENAME TO ${OSMPREFIX}_cycwys_osm_nodes;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE scratch.${OSMPREFIX}_cycwys_osm_nodes RENAME CONSTRAINT node_id TO ${OSMPREFIX}_node_id;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE scratch.osm_relations RENAME TO ${OSMPREFIX}_cycwys_osm_relations;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE scratch.osm_way_classes RENAME TO ${OSMPREFIX}_cycwys_osm_way_classes;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE scratch.${OSMPREFIX}_cycwys_osm_way_classes RENAME CONSTRAINT osm_way_classes_pkey TO ${OSMPREFIX}_osm_way_classes_pkey;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE scratch.osm_way_tags RENAME TO ${OSMPREFIX}_cycwys_osm_way_tags;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE scratch.osm_way_types RENAME TO ${OSMPREFIX}_cycwys_osm_way_types;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE scratch.${OSMPREFIX}_cycwys_osm_way_types RENAME CONSTRAINT osm_way_types_pkey TO ${OSMPREFIX}_osm_way_types_pkey;" - -# import full osm to fill out additional data needs -# not met by osm2pgrouting - -# drop old tables -echo 'Dropping old tables' -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_full_line;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_full_point;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_full_polygon;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_full_roads;" - -# import -osm2pgsql \ - --host $DBHOST \ - --username gis \ - --port 5432 \ - --create \ - --database ${DBNAME} \ - --prefix ${OSMPREFIX}_osm_full \ - --proj 2249 \ - --style /home/spencer/dev/pfb/pfb.style \ - $OSMFILE - -# move the full osm tables to the received schema -echo 'Moving tables to received schema' -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE generated.${OSMPREFIX}_osm_full_line SET SCHEMA received;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE generated.${OSMPREFIX}_osm_full_point SET SCHEMA received;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE generated.${OSMPREFIX}_osm_full_polygon SET SCHEMA received;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE generated.${OSMPREFIX}_osm_full_roads SET SCHEMA received;" - -# process tables -echo 'Updating field names' -psql -h $DBHOST -U gis -d ${DBNAME} -f ./prepare_tables.sql -echo 'Setting values on road segments' -psql -h $DBHOST -U gis -d ${DBNAME} -f ./one_way.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./functional_class.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./speed_limit.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./width_ft.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./lanes.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./park.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./bike_infra.sql -echo 'Setting values on intersections' -psql -h $DBHOST -U gis -d ${DBNAME} -f ./legs.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./signalized.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./stops.sql -echo 'Calculating stress' -psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_motorway-trunk.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_primary.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_secondary.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_tertiary.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_residential.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_living_street.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_track.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_path.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_one_way_reset.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_motorway-trunk_ints.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_primary_ints.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_secondary_ints.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_tertiary_ints.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_lesser_ints.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_link_ints.sql +#!/usr/bin/env bash + +# vars +DBHOST='192.168.40.225' +DBNAME='people_for_bikes' +OSMPREFIX='cambridge' +OSMFILE='/home/spencer/gis/cambridge.osm' + +# drop old tables +echo 'Dropping old tables' +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_ways;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_ways_intersections;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_relations_ways;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_nodes;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_relations;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_way_classes;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_way_tags;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_way_types;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_ways;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_ways_vertices_pgr;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_relations_ways;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_osm_nodes;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_osm_relations;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_osm_way_classes;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_osm_way_tags;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_osm_way_types;" + +# import the osm with highways that the above misses (bug in osm2pgrouting) +osm2pgrouting \ + -f $OSMFILE \ + -h $DBHOST \ + --dbname ${DBNAME} \ + --username gis \ + --schema received \ + --prefix ${OSMPREFIX}_ \ + --conf ./mapconfig_highway.xml \ + --clean + +# import the osm optimized for routing +osm2pgrouting \ + -f $OSMFILE \ + -h $DBHOST \ + --dbname ${DBNAME} \ + --username gis \ + --schema scratch \ + --prefix ${OSMPREFIX}_cycwys_ \ + --conf ./mapconfig_cycleway.xml \ + --clean + +# rename a few tables +echo 'Renaming tables' +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE received.${OSMPREFIX}_ways_vertices_pgr RENAME TO ${OSMPREFIX}_ways_intersections;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE received.${OSMPREFIX}_ways_intersections RENAME CONSTRAINT vertex_id TO ${OSMPREFIX}_vertex_id;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE received.osm_nodes RENAME TO ${OSMPREFIX}_osm_nodes;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE received.${OSMPREFIX}_osm_nodes RENAME CONSTRAINT node_id TO ${OSMPREFIX}_node_id;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE received.osm_relations RENAME TO ${OSMPREFIX}_osm_relations;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE received.osm_way_classes RENAME TO ${OSMPREFIX}_osm_way_classes;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE received.${OSMPREFIX}_osm_way_classes RENAME CONSTRAINT osm_way_classes_pkey TO ${OSMPREFIX}_osm_way_classes_pkey;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE received.osm_way_tags RENAME TO ${OSMPREFIX}_osm_way_tags;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE received.osm_way_types RENAME TO ${OSMPREFIX}_osm_way_types;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE received.${OSMPREFIX}_osm_way_types RENAME CONSTRAINT osm_way_types_pkey TO ${OSMPREFIX}_osm_way_types_pkey;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE scratch.${OSMPREFIX}_cycwys_ways_vertices_pgr RENAME CONSTRAINT vertex_id TO ${OSMPREFIX}_vertex_id;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE scratch.osm_nodes RENAME TO ${OSMPREFIX}_cycwys_osm_nodes;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE scratch.${OSMPREFIX}_cycwys_osm_nodes RENAME CONSTRAINT node_id TO ${OSMPREFIX}_node_id;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE scratch.osm_relations RENAME TO ${OSMPREFIX}_cycwys_osm_relations;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE scratch.osm_way_classes RENAME TO ${OSMPREFIX}_cycwys_osm_way_classes;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE scratch.${OSMPREFIX}_cycwys_osm_way_classes RENAME CONSTRAINT osm_way_classes_pkey TO ${OSMPREFIX}_osm_way_classes_pkey;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE scratch.osm_way_tags RENAME TO ${OSMPREFIX}_cycwys_osm_way_tags;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE scratch.osm_way_types RENAME TO ${OSMPREFIX}_cycwys_osm_way_types;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE scratch.${OSMPREFIX}_cycwys_osm_way_types RENAME CONSTRAINT osm_way_types_pkey TO ${OSMPREFIX}_osm_way_types_pkey;" + +# import full osm to fill out additional data needs +# not met by osm2pgrouting + +# drop old tables +echo 'Dropping old tables' +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_full_line;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_full_point;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_full_polygon;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_full_roads;" + +# import +osm2pgsql \ + --host $DBHOST \ + --username gis \ + --port 5432 \ + --create \ + --database ${DBNAME} \ + --prefix ${OSMPREFIX}_osm_full \ + --proj 2249 \ + --style /home/spencer/dev/pfb/pfb.style \ + $OSMFILE + +# move the full osm tables to the received schema +echo 'Moving tables to received schema' +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE generated.${OSMPREFIX}_osm_full_line SET SCHEMA received;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE generated.${OSMPREFIX}_osm_full_point SET SCHEMA received;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE generated.${OSMPREFIX}_osm_full_polygon SET SCHEMA received;" +psql -h $DBHOST -U gis -d ${DBNAME} \ + -c "ALTER TABLE generated.${OSMPREFIX}_osm_full_roads SET SCHEMA received;" + +# process tables +echo 'Updating field names' +psql -h $DBHOST -U gis -d ${DBNAME} -f ./prepare_tables.sql +echo 'Setting values on road segments' +psql -h $DBHOST -U gis -d ${DBNAME} -f ./one_way.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./functional_class.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./speed_limit.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./width_ft.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./lanes.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./park.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./bike_infra.sql +echo 'Setting values on intersections' +psql -h $DBHOST -U gis -d ${DBNAME} -f ./legs.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./signalized.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./stops.sql +echo 'Calculating stress' +psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_motorway-trunk.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_primary.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_secondary.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_tertiary.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_residential.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_living_street.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_track.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_path.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_one_way_reset.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_motorway-trunk_ints.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_primary_ints.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_secondary_ints.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_tertiary_ints.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_lesser_ints.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_link_ints.sql diff --git a/pfb.style b/pfb.style index a92152f0..f76c13fe 100644 --- a/pfb.style +++ b/pfb.style @@ -82,6 +82,8 @@ # OsmType Tag DataType Flags node,way access text linear +node amenity text linear +way amenity text polygon node,way bicycle text linear node,way bridge text linear node,way crossing text linear @@ -104,6 +106,7 @@ node,way motorcar text linear node,way name text linear node,way oneway text linear node,way oneway:bicycle text linear +node,way operator text linear,polygon way parking text linear way parking:lane text linear way parking:lane:right text linear From 230501cd5f87631a69ca31b4b0d7d2a6e1e26a0b Mon Sep 17 00:00:00 2001 From: Spencer Gardner Date: Tue, 4 Oct 2016 21:18:20 -0500 Subject: [PATCH 34/94] lksjdfkj --- connectivity/access_schools.sql | 59 +++++++- connectivity/census_blocks.sql | 2 + connectivity/overall_scores.sql | 242 +++++++++++++++++++++++++++----- connectivity/schools.sql | 2 + import_osm.sh | 2 +- process.txt | 7 + 6 files changed, 274 insertions(+), 40 deletions(-) diff --git a/connectivity/access_schools.sql b/connectivity/access_schools.sql index 6d3636b7..f521d283 100644 --- a/connectivity/access_schools.sql +++ b/connectivity/access_schools.sql @@ -3,10 +3,63 @@ -- location: cambridge ---------------------------------------- -- low stress access - +UPDATE cambridge_census_blocks +SET schools_low_stress = ( + SELECT COUNT(cbs.id) + FROM cambridge_connected_census_blocks_schools cbs + WHERE cbs.source_blockid10 = cambridge_census_blocks.blockid10 + AND cbs.low_stress + ) +WHERE EXISTS ( + SELECT 1 + FROM cambridge_zip_codes zips + WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) + AND zips.zip_code = '02138' + ); -- high stress access +UPDATE cambridge_census_blocks +SET schools_high_stress = ( + SELECT COUNT(cbs.id) + FROM cambridge_connected_census_blocks_schools cbs + WHERE cbs.source_blockid10 = cambridge_census_blocks.blockid10 + ) +WHERE EXISTS ( + SELECT 1 + FROM cambridge_zip_codes zips + WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) + AND zips.zip_code = '02138' + ); +-- low stress population shed for schools in neighborhood +UPDATE cambridge_schools +SET pop_low_stress = ( + SELECT SUM(cb.pop10) + FROM cambridge_census_blocks cb, + cambridge_connected_census_blocks_schools cbs + WHERE cb.blockid10 = cbs.source_blockid10 + AND cambridge_schools.id = cbs.target_school_id + AND cbs.low_stress + ) +WHERE EXISTS ( + SELECT 1 + FROM cambridge_zip_codes zips + WHERE ST_Intersects(cambridge_schools.geom_pt,zips.geom) + AND zips.zip_code = '02138' + ); --- should also set up a measure for pop reachable by all schools in the neighborhood --- and report metrics +-- low stress population shed for schools in neighborhood +UPDATE cambridge_schools +SET pop_high_stress = ( + SELECT SUM(cb.pop10) + FROM cambridge_census_blocks cb, + cambridge_connected_census_blocks_schools cbs + WHERE cb.blockid10 = cbs.source_blockid10 + AND cambridge_schools.id = cbs.target_school_id + ) +WHERE EXISTS ( + SELECT 1 + FROM cambridge_zip_codes zips + WHERE ST_Intersects(cambridge_schools.geom_pt,zips.geom) + AND zips.zip_code = '02138' + ); diff --git a/connectivity/census_blocks.sql b/connectivity/census_blocks.sql index 9ce6ec1b..03e84b41 100644 --- a/connectivity/census_blocks.sql +++ b/connectivity/census_blocks.sql @@ -10,6 +10,8 @@ ALTER TABLE cambridge_census_blocks ADD COLUMN pop_low_stress INT; ALTER TABLE cambridge_census_blocks ADD COLUMN pop_high_stress INT; ALTER TABLE cambridge_census_blocks ADD COLUMN emp_low_stress INT; ALTER TABLE cambridge_census_blocks ADD COLUMN emp_high_stress INT; +ALTER TABLE cambridge_census_blocks ADD COLUMN schools_low_stress INT; +ALTER TABLE cambridge_census_blocks ADD COLUMN schools_high_stress INT; CREATE INDEX idx_cambridge_blocks10 ON cambridge_census_blocks (blockid10); ANALYZE cambridge_census_blocks (blockid10); diff --git a/connectivity/overall_scores.sql b/connectivity/overall_scores.sql index 009698d5..7527b288 100644 --- a/connectivity/overall_scores.sql +++ b/connectivity/overall_scores.sql @@ -6,21 +6,59 @@ DROP TABLE IF EXISTS generated.cambridge_overall_scores; CREATE TABLE generated.cambridge_overall_scores ( id SERIAL PRIMARY KEY, + category TEXT, score_name TEXT, score NUMERIC(16,4), notes TEXT ); +-- median pop access low stress +INSERT INTO generated.cambridge_overall_scores ( + category, score_name, score, notes +) +SELECT 'Population', + 'Median population accessible by low stress', + quantile(pop_low_stress,0.5), + regexp_replace('Total population accessible by low stress + expressed as the median of all census blocks in the + neighborhood','\n\s+',' ') +FROM cambridge_census_blocks +WHERE EXISTS ( + SELECT 1 + FROM cambridge_zip_codes zips + WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) + AND zips.zip_code = '02138' + ); + +-- median pop access high stress +INSERT INTO generated.cambridge_overall_scores ( + category, score_name, score, notes +) +SELECT 'Population', + 'Median population accessible by high stress', + quantile(pop_high_stress,0.5), + regexp_replace('Total population accessible by high stress + expressed as the median of all census blocks in the + neighborhood','\n\s+',' ') +FROM cambridge_census_blocks +WHERE EXISTS ( + SELECT 1 + FROM cambridge_zip_codes zips + WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) + AND zips.zip_code = '02138' + ); + -- median pop access ratio INSERT INTO generated.cambridge_overall_scores ( - score_name, score, notes + category, score_name, score, notes ) -SELECT 'Median ratio of access to population', +SELECT 'Population', + 'Median ratio of access to population', quantile(pop_low_stress::FLOAT/pop_high_stress,0.5), - 'Ratio of population accessible by low stress - to population accessible overall, expressed as - the median of all census blocks in the - neighborhood' + regexp_replace('Ratio of population accessible by low stress + to population accessible overall, expressed as + the median of all census blocks in the + neighborhood','\n\s+',' ') FROM cambridge_census_blocks WHERE EXISTS ( SELECT 1 @@ -31,14 +69,15 @@ WHERE EXISTS ( -- 70th percentile pop access ratio INSERT INTO generated.cambridge_overall_scores ( - score_name, score, notes + category, score_name, score, notes ) -SELECT '70th percentile ratio of access to population', +SELECT 'Population', + '70th percentile ratio of access to population', quantile(pop_low_stress::FLOAT/pop_high_stress,0.7), - 'Ratio of population accessible by low stress - to population accessible overall, expressed as - the 70th percentile of all census blocks in the - neighborhood' + regexp_replace('Ratio of population accessible by low stress + to population accessible overall, expressed as + the 70th percentile of all census blocks in the + neighborhood','\n\s+',' ') FROM cambridge_census_blocks WHERE EXISTS ( SELECT 1 @@ -49,14 +88,51 @@ WHERE EXISTS ( -- avg pop access ratio INSERT INTO generated.cambridge_overall_scores ( - score_name, score, notes + category, score_name, score, notes ) -SELECT 'Average ratio of access to population', +SELECT 'Population', + 'Average ratio of access to population', AVG(pop_low_stress::FLOAT/pop_high_stress), - 'Ratio of population accessible by low stress - to population accessible overall, expressed as - the average of all census blocks in the - neighborhood' + regexp_replace('Ratio of population accessible by low stress + to population accessible overall, expressed as + the average of all census blocks in the + neighborhood','\n\s+',' ') +FROM cambridge_census_blocks +WHERE EXISTS ( + SELECT 1 + FROM cambridge_zip_codes zips + WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) + AND zips.zip_code = '02138' + ); + +-- median jobs access low stress +INSERT INTO generated.cambridge_overall_scores ( + category, score_name, score, notes +) +SELECT 'Employment', + 'Median employment accessible by low stress', + quantile(emp_low_stress,0.5), + regexp_replace('Total jobs accessible by low stress + expressed as the median of all census blocks in the + neighborhood','\n\s+',' ') +FROM cambridge_census_blocks +WHERE EXISTS ( + SELECT 1 + FROM cambridge_zip_codes zips + WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) + AND zips.zip_code = '02138' + ); + +-- median jobs access high stress +INSERT INTO generated.cambridge_overall_scores ( + category, score_name, score, notes +) +SELECT 'Employment', + 'Median employment accessible by high stress', + quantile(emp_high_stress,0.5), + regexp_replace('Total jobs accessible by high stress + expressed as the median of all census blocks in the + neighborhood','\n\s+',' ') FROM cambridge_census_blocks WHERE EXISTS ( SELECT 1 @@ -67,14 +143,15 @@ WHERE EXISTS ( -- median jobs access ratio INSERT INTO generated.cambridge_overall_scores ( - score_name, score, notes + category, score_name, score, notes ) -SELECT 'Median ratio of access to employment', +SELECT 'Employment', + 'Median ratio of access to employment', quantile(emp_low_stress::FLOAT/emp_high_stress,0.5), - 'Ratio of employment accessible by low stress - to employment accessible overall, expressed as - the median of all census blocks in the - neighborhood' + regexp_replace('Ratio of employment accessible by low stress + to employment accessible overall, expressed as + the median of all census blocks in the + neighborhood','\n\s+',' ') FROM cambridge_census_blocks WHERE EXISTS ( SELECT 1 @@ -85,14 +162,15 @@ WHERE EXISTS ( -- 70th percentile jobs access ratio INSERT INTO generated.cambridge_overall_scores ( - score_name, score, notes + category, score_name, score, notes ) -SELECT '70th percentile ratio of access to employment', +SELECT 'Employment', + '70th percentile ratio of access to employment', quantile(emp_low_stress::FLOAT/emp_high_stress,0.7), - 'Ratio of employment accessible by low stress - to employment accessible overall, expressed as - the 70th percentile of all census blocks in the - neighborhood' + regexp_replace('Ratio of employment accessible by low stress + to employment accessible overall, expressed as + the 70th percentile of all census blocks in the + neighborhood','\n\s+',' ') FROM cambridge_census_blocks WHERE EXISTS ( SELECT 1 @@ -103,14 +181,15 @@ WHERE EXISTS ( -- avg jobs access ratio INSERT INTO generated.cambridge_overall_scores ( - score_name, score, notes + category, score_name, score, notes ) -SELECT 'Average ratio of access to employment', +SELECT 'Employment', + 'Average ratio of access to employment', AVG(emp_low_stress::FLOAT/emp_high_stress), - 'Ratio of employment accessible by low stress - to employment accessible overall, expressed as - the average of all census blocks in the - neighborhood' + regexp_replace('Ratio of employment accessible by low stress + to employment accessible overall, expressed as + the average of all census blocks in the + neighborhood','\n\s+',' ') FROM cambridge_census_blocks WHERE EXISTS ( SELECT 1 @@ -118,3 +197,94 @@ WHERE EXISTS ( WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) AND zips.zip_code = '02138' ); + +-- median schools access low stress +INSERT INTO generated.cambridge_overall_scores ( + category, score_name, score, notes +) +SELECT 'Schools', + 'Average low stress school access', + AVG(schools_low_stress), + regexp_replace('Number of schools accessible by low stress + expressed as an average of all census blocks in the + neighborhood','\n\s+',' ') +FROM cambridge_census_blocks +WHERE EXISTS ( + SELECT 1 + FROM cambridge_zip_codes zips + WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) + AND zips.zip_code = '02138' + ); + +-- median schools access high stress +INSERT INTO generated.cambridge_overall_scores ( + category, score_name, score, notes +) +SELECT 'Schools', + 'Average high stress school access', + AVG(schools_high_stress), + regexp_replace('Number of schools accessible by high stress + expressed as an average of all census blocks in the + neighborhood','\n\s+',' ') +FROM cambridge_census_blocks +WHERE EXISTS ( + SELECT 1 + FROM cambridge_zip_codes zips + WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) + AND zips.zip_code = '02138' + ); + +-- school low stress pop shed access +INSERT INTO generated.cambridge_overall_scores ( + category, score_name, score, notes +) +SELECT 'Schools', + 'Average school low stress population shed', + AVG(pop_low_stress), + regexp_replace('Population with low stress access to schools + in the neighborhood expressed as an average of all + schools in the neighborhood','\n\s+',' ') +FROM cambridge_schools +WHERE EXISTS ( + SELECT 1 + FROM cambridge_zip_codes zips + WHERE ST_Intersects(cambridge_schools.geom_pt,zips.geom) + AND zips.zip_code = '02138' + ); + +-- school high stress pop shed access +INSERT INTO generated.cambridge_overall_scores ( + category, score_name, score, notes +) +SELECT 'Schools', + 'Average school high stress population shed', + AVG(pop_high_stress), + regexp_replace('Population with high stress access to schools + in the neighborhood expressed as an average of all + schools in the neighborhood','\n\s+',' ') +FROM cambridge_schools +WHERE EXISTS ( + SELECT 1 + FROM cambridge_zip_codes zips + WHERE ST_Intersects(cambridge_schools.geom_pt,zips.geom) + AND zips.zip_code = '02138' + ); + +-- school pop shed access ratio +INSERT INTO generated.cambridge_overall_scores ( + category, score_name, score, notes +) +SELECT 'Schools', + 'Average school population shed ratio', + AVG(pop_low_stress::FLOAT/pop_high_stress), + regexp_replace('Ratio of population with low stress + access to schools to population with high stress access + in the neighborhood expressed as an average of all + schools in the neighborhood','\n\s+',' ') +FROM cambridge_schools +WHERE EXISTS ( + SELECT 1 + FROM cambridge_zip_codes zips + WHERE ST_Intersects(cambridge_schools.geom_pt,zips.geom) + AND zips.zip_code = '02138' + ); diff --git a/connectivity/schools.sql b/connectivity/schools.sql index be10ef1b..da1648e6 100644 --- a/connectivity/schools.sql +++ b/connectivity/schools.sql @@ -8,6 +8,8 @@ CREATE TABLE generated.cambridge_schools ( id SERIAL PRIMARY KEY, osm_id BIGINT, school_name TEXT, + pop_low_stress INT, + pop_high_stress INT, geom_pt geometry(point,2249), geom_poly geometry(polygon,2249) ); diff --git a/import_osm.sh b/import_osm.sh index 16a5f3c9..e7f2d235 100644 --- a/import_osm.sh +++ b/import_osm.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # vars -DBHOST='192.168.40.225' +DBHOST='192.168.1.144' DBNAME='people_for_bikes' OSMPREFIX='cambridge' OSMFILE='/home/spencer/gis/cambridge.osm' diff --git a/process.txt b/process.txt index fa6775c4..e72d9a1e 100644 --- a/process.txt +++ b/process.txt @@ -45,3 +45,10 @@ access_population.sql (import census blocks job data) census_block_jobs.sql access_jobs.sql + +schools.sql +school_roads.sql +connected_census_blocks_schools.sql +access_schools.sql + +overall_scores.sql From 535e84d1118b4dc4fd6b6a361721dbdf92715d7d Mon Sep 17 00:00:00 2001 From: Spencer Date: Mon, 10 Oct 2016 17:12:58 -0500 Subject: [PATCH 35/94] lkjsdfl --- connectivity/access_parks.sql | 0 connectivity/access_recreation.sql | 26 ++++++ connectivity/access_schools.sql | 2 +- connectivity/census_blocks.sql | 2 + .../connected_census_blocks_recreation.sql | 86 +++++++++++++++++++ import_osm.sh | 7 +- paths.sql | 65 ++++++++++++++ prepare_tables.sql | 1 + process.txt | 1 + 9 files changed, 186 insertions(+), 4 deletions(-) create mode 100644 connectivity/access_parks.sql create mode 100644 connectivity/access_recreation.sql create mode 100644 connectivity/connected_census_blocks_recreation.sql create mode 100644 paths.sql diff --git a/connectivity/access_parks.sql b/connectivity/access_parks.sql new file mode 100644 index 00000000..e69de29b diff --git a/connectivity/access_recreation.sql b/connectivity/access_recreation.sql new file mode 100644 index 00000000..8129e5b7 --- /dev/null +++ b/connectivity/access_recreation.sql @@ -0,0 +1,26 @@ +---------------------------------------- +-- INPUTS +-- location: cambridge +---------------------------------------- +-- low stress access +UPDATE cambridge_census_blocks +SET rec_low_stress = ( + SELECT COUNT(path_id) + FROM cambridge_paths + WHERE EXISTS ( + SELECT 1 + FROM cambridge_census_block_roads cbr, + cambridge_reachable_roads_low_stress ls, + cambridge_ways, + cambridge_paths + WHERE cb.source_blockid10 = cambridge_census_blocks.blockid10 + AND cb.target_blockid10 = blocks2.blockid10 + AND cb.low_stress + ) + ) +WHERE EXISTS ( + SELECT 1 + FROM cambridge_zip_codes zips + WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) + AND zips.zip_code = '02138' + ); diff --git a/connectivity/access_schools.sql b/connectivity/access_schools.sql index f521d283..58cf950f 100644 --- a/connectivity/access_schools.sql +++ b/connectivity/access_schools.sql @@ -48,7 +48,7 @@ WHERE EXISTS ( AND zips.zip_code = '02138' ); --- low stress population shed for schools in neighborhood +-- high stress population shed for schools in neighborhood UPDATE cambridge_schools SET pop_high_stress = ( SELECT SUM(cb.pop10) diff --git a/connectivity/census_blocks.sql b/connectivity/census_blocks.sql index 03e84b41..66041044 100644 --- a/connectivity/census_blocks.sql +++ b/connectivity/census_blocks.sql @@ -12,6 +12,8 @@ ALTER TABLE cambridge_census_blocks ADD COLUMN emp_low_stress INT; ALTER TABLE cambridge_census_blocks ADD COLUMN emp_high_stress INT; ALTER TABLE cambridge_census_blocks ADD COLUMN schools_low_stress INT; ALTER TABLE cambridge_census_blocks ADD COLUMN schools_high_stress INT; +ALTER TABLE cambridge_census_blocks ADD COLUMN rec_low_stress INT; +ALTER TABLE cambridge_census_blocks ADD COLUMN rec_high_stress INT; CREATE INDEX idx_cambridge_blocks10 ON cambridge_census_blocks (blockid10); ANALYZE cambridge_census_blocks (blockid10); diff --git a/connectivity/connected_census_blocks_recreation.sql b/connectivity/connected_census_blocks_recreation.sql new file mode 100644 index 00000000..188a4246 --- /dev/null +++ b/connectivity/connected_census_blocks_recreation.sql @@ -0,0 +1,86 @@ +---------------------------------------- +-- INPUTS +-- location: cambridge +---------------------------------------- +DROP TABLE IF EXISTS generated.cambridge_connected_census_blocks_recreation; + +CREATE TABLE generated.cambridge_connected_census_blocks_recreation ( + id SERIAL PRIMARY KEY, + source_blockid10 VARCHAR(15), + target_path_id INT, + low_stress BOOLEAN, + low_stress_cost INT, + high_stress BOOLEAN, + high_stress_cost INT +); + +INSERT INTO generated.cambridge_connected_census_blocks_recreation ( + source_blockid10, target_school_id, low_stress, high_stress +) +SELECT blocks.blockid10, + schools.id, + 'f'::BOOLEAN, + 't'::BOOLEAN +FROM cambridge_census_blocks blocks, + cambridge_paths paths +WHERE EXISTS ( + SELECT 1 + FROM cambridge_zip_codes zips + WHERE ST_Intersects(blocks.geom,zips.geom) + AND zips.zip_code = '02138' + ) +AND blocks.geom <#> paths.geom < 11000 +AND EXISTS ( + SELECT 1 + FROM cambridge_census_block_roads source_br, + cambridge_ways target_r, + cambridge_reachable_roads_high_stress hs + WHERE blocks.blockid10 = source_br.blockid10 + AND paths.path_id = target_r.path_id + AND hs.base_road = source_br.road_id + AND hs.target_road = target_sr.road_id + ); + +-- block pair index +CREATE INDEX idx_cambridge_blockschoolpairs +ON cambridge_connected_census_blocks_recreation (source_blockid10,target_school_id); +ANALYZE cambridge_connected_census_blocks_recreation (source_blockid10,target_school_id); + +-- low stress +UPDATE cambridge_connected_census_blocks_recreation +SET low_stress = 't'::BOOLEAN +WHERE EXISTS ( + SELECT 1 + FROM cambridge_census_block_roads source_br, + cambridge_school_roads target_sr, + cambridge_reachable_roads_low_stress ls + WHERE source_blockid10 = source_br.blockid10 + AND target_school_id = target_sr.school_id + AND ls.base_road = source_br.road_id + AND ls.target_road = target_sr.road_id + ) +AND ( + SELECT MIN(total_cost) + FROM cambridge_census_block_roads source_br, + cambridge_school_roads target_sr, + cambridge_reachable_roads_low_stress ls + WHERE source_blockid10 = source_br.blockid10 + AND target_school_id = target_sr.school_id + AND ls.base_road = source_br.road_id + AND ls.target_road = target_sr.road_id + )::FLOAT / + COALESCE(( + SELECT MIN(total_cost) + 1 + FROM cambridge_census_block_roads source_br, + cambridge_school_roads target_sr, + cambridge_reachable_roads_high_stress hs + WHERE source_blockid10 = source_br.blockid10 + AND target_school_id = target_sr.school_id + AND hs.base_road = source_br.road_id + AND hs.target_road = target_sr.road_id + ),11000) <= 1.3; + +-- stress index +CREATE INDEX idx_cambridge_blockschl_lstress ON cambridge_connected_census_blocks_recreation (low_stress); +CREATE INDEX idx_cambridge_blockschl_hstress ON cambridge_connected_census_blocks_recreation (high_stress); +ANALYZE cambridge_connected_census_blocks_recreation (low_stress,high_stress); diff --git a/import_osm.sh b/import_osm.sh index e7f2d235..837ac6d1 100644 --- a/import_osm.sh +++ b/import_osm.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # vars -DBHOST='192.168.1.144' +DBHOST='192.168.40.225' DBNAME='people_for_bikes' OSMPREFIX='cambridge' OSMFILE='/home/spencer/gis/cambridge.osm' @@ -41,7 +41,7 @@ psql -h $DBHOST -U gis -d ${DBNAME} \ psql -h $DBHOST -U gis -d ${DBNAME} \ -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_osm_way_types;" -# import the osm with highways that the above misses (bug in osm2pgrouting) +# import the osm with highways osm2pgrouting \ -f $OSMFILE \ -h $DBHOST \ @@ -52,7 +52,7 @@ osm2pgrouting \ --conf ./mapconfig_highway.xml \ --clean -# import the osm optimized for routing +# import the osm with cycleways that the above misses (bug in osm2pgrouting) osm2pgrouting \ -f $OSMFILE \ -h $DBHOST \ @@ -147,6 +147,7 @@ psql -h $DBHOST -U gis -d ${DBNAME} -f ./prepare_tables.sql echo 'Setting values on road segments' psql -h $DBHOST -U gis -d ${DBNAME} -f ./one_way.sql psql -h $DBHOST -U gis -d ${DBNAME} -f ./functional_class.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./paths.sql psql -h $DBHOST -U gis -d ${DBNAME} -f ./speed_limit.sql psql -h $DBHOST -U gis -d ${DBNAME} -f ./width_ft.sql psql -h $DBHOST -U gis -d ${DBNAME} -f ./lanes.sql diff --git a/paths.sql b/paths.sql new file mode 100644 index 00000000..70bb0646 --- /dev/null +++ b/paths.sql @@ -0,0 +1,65 @@ +---------------------------------------- +-- INPUTS +-- location: cambridge +---------------------------------------- +DROP TABLE IF EXISTS generated.cambridge_paths; +DROP INDEX IF EXISTS idx_cambridge_ways_path_id; + +CREATE TABLE generated.cambridge_paths ( + path_id SERIAL PRIMARY KEY, + geom geometry(multilinestring,2249), + path_length INTEGER, + bbox_length INTEGER +); + +-- combine contiguous paths +INSERT INTO cambridge_paths (geom) +SELECT ST_CollectionExtract( + ST_SetSRID( + unnest(ST_ClusterIntersecting(geom)), + 2249 + ), + 2 --linestrings + ) +FROM cambridge_ways +WHERE functional_class = 'path'; + +-- get raw lengths +UPDATE cambridge_paths +SET path_length = ST_Length(geom); + +-- get bounding box lengths +UPDATE cambridge_paths +SET bbox_length = ST_Length( + ST_SetSRID( + ST_MakeLine( + ST_MakePoint(ST_XMin(geom), ST_YMin(geom)), + ST_MakePoint(ST_XMax(geom), ST_YMax(geom)) + ), + 2249 + ) + ); + +-- set path_id on each road segment (if path) +UPDATE cambridge_ways +SET path_id = ( + SELECT paths.path_id + FROM cambridge_paths paths + WHERE ST_Intersects(cambridge_ways.geom,paths.geom) + AND ST_CoveredBy(cambridge_ways.geom,paths.geom) + LIMIT 1 + ) +WHERE functional_class = 'path'; + +-- get stragglers +UPDATE cambridge_ways +SET path_id = paths.path_id +FROM cambridge_paths paths +WHERE cambridge_ways.functional_class = 'path' +AND cambridge_ways.path_id IS NULL +AND ST_Intersects(cambridge_ways.geom,paths.geom) +AND ST_CoveredBy(cambridge_ways.geom,ST_Buffer(paths.geom,1)); + +-- set index +CREATE INDEX idx_cambridge_ways_path_id ON cambridge_ways (path_id); +ANALYZE cambridge_ways (path_id); diff --git a/prepare_tables.sql b/prepare_tables.sql index 4ffee231..de8b87a8 100644 --- a/prepare_tables.sql +++ b/prepare_tables.sql @@ -53,6 +53,7 @@ USING ST_Transform(geom,2249); -- add columns ALTER TABLE cambridge_ways ADD COLUMN functional_class TEXT; +ALTER TABLE cambridge_ways ADD COLUMN path_id INTEGER; ALTER TABLE cambridge_ways ADD COLUMN speed_limit INT; ALTER TABLE cambridge_ways ADD COLUMN one_way_car VARCHAR(2); ALTER TABLE cambridge_ways ADD COLUMN one_way VARCHAR(2); diff --git a/process.txt b/process.txt index e72d9a1e..5290e699 100644 --- a/process.txt +++ b/process.txt @@ -6,6 +6,7 @@ import_osm.sh (runs the following automatically) - prepare_tables.sql - one_way.sql - functional_class.sql + - paths.sql - speed_limit.sql - width_ft.sql - lanes.sql From 6a18382f58efe44922a4a25522a9a99dba513a36 Mon Sep 17 00:00:00 2001 From: Spencer Gardner Date: Tue, 11 Oct 2016 07:22:38 -0500 Subject: [PATCH 36/94] sdlfkjdf --- connectivity/connected_census_blocks_recreation.sql | 10 ++++++++-- import_osm.sh | 2 +- process.txt | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/connectivity/connected_census_blocks_recreation.sql b/connectivity/connected_census_blocks_recreation.sql index 188a4246..eba9c7ab 100644 --- a/connectivity/connected_census_blocks_recreation.sql +++ b/connectivity/connected_census_blocks_recreation.sql @@ -18,7 +18,7 @@ INSERT INTO generated.cambridge_connected_census_blocks_recreation ( source_blockid10, target_school_id, low_stress, high_stress ) SELECT blocks.blockid10, - schools.id, + paths.path_id, 'f'::BOOLEAN, 't'::BOOLEAN FROM cambridge_census_blocks blocks, @@ -38,9 +38,15 @@ AND EXISTS ( WHERE blocks.blockid10 = source_br.blockid10 AND paths.path_id = target_r.path_id AND hs.base_road = source_br.road_id - AND hs.target_road = target_sr.road_id + AND hs.target_road = target_r.road_id + AND paths.path_length > 15840 --path at least 3 mi long + AND paths.bbox_length > 10560 --extent of path at least 2 mi long ); + + + + -- block pair index CREATE INDEX idx_cambridge_blockschoolpairs ON cambridge_connected_census_blocks_recreation (source_blockid10,target_school_id); diff --git a/import_osm.sh b/import_osm.sh index 837ac6d1..c6a9c49e 100644 --- a/import_osm.sh +++ b/import_osm.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # vars -DBHOST='192.168.40.225' +DBHOST='192.168.1.144' DBNAME='people_for_bikes' OSMPREFIX='cambridge' OSMFILE='/home/spencer/gis/cambridge.osm' diff --git a/process.txt b/process.txt index 5290e699..9d08fbb8 100644 --- a/process.txt +++ b/process.txt @@ -31,7 +31,7 @@ import_osm.sh (runs the following automatically) - stress_lesser_ints.sql - stress_link_ints.sql -SELECT tdgBuildNetwork('cambridge_ways'); +SELECT tdgMakeNetwork('cambridge_ways'); SELECT tdgNetworkCostFromDistance('cambridge_ways'); (import census blocks with pop from census blkpophu dataset) From 29a6033b884a948189d4b95eb425330bc5db6128 Mon Sep 17 00:00:00 2001 From: CloudNiner Date: Thu, 13 Oct 2016 21:51:35 -0400 Subject: [PATCH 37/94] Tweak db settings and properly quote osm2pgsql call --- .gitignore | 1 + import_osm.sh | 16 ++++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) mode change 100644 => 100755 import_osm.sh diff --git a/.gitignore b/.gitignore index 94487b95..d5293f43 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ *.pyc +*.log diff --git a/import_osm.sh b/import_osm.sh old mode 100644 new mode 100755 index c6a9c49e..c3adcc01 --- a/import_osm.sh +++ b/import_osm.sh @@ -1,10 +1,10 @@ #!/usr/bin/env bash # vars -DBHOST='192.168.1.144' -DBNAME='people_for_bikes' +DBHOST='127.0.0.1' +DBNAME='pfb' OSMPREFIX='cambridge' -OSMFILE='/home/spencer/gis/cambridge.osm' +OSMFILE='/vagrant/data/cambridge.osm' # drop old tables echo 'Dropping old tables' @@ -120,15 +120,15 @@ psql -h $DBHOST -U gis -d ${DBNAME} \ # import osm2pgsql \ - --host $DBHOST \ + --host "${DBHOST}" \ --username gis \ --port 5432 \ --create \ - --database ${DBNAME} \ - --prefix ${OSMPREFIX}_osm_full \ + --database "${DBNAME}" \ + --prefix "${OSMPREFIX}_osm_full" \ --proj 2249 \ - --style /home/spencer/dev/pfb/pfb.style \ - $OSMFILE +# --style /home/spencer/dev/pfb/pfb.style \ + "${OSMFILE}" # move the full osm tables to the received schema echo 'Moving tables to received schema' From 86ccf38c8376a56a79c03613979097375acc700c Mon Sep 17 00:00:00 2001 From: CloudNiner Date: Fri, 14 Oct 2016 08:34:36 -0400 Subject: [PATCH 38/94] Use relative path to pfb.style since it exists in repo cd to script dir for consistent relative path base --- import_osm.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/import_osm.sh b/import_osm.sh index c3adcc01..e3b8fafd 100755 --- a/import_osm.sh +++ b/import_osm.sh @@ -1,5 +1,7 @@ #!/usr/bin/env bash +cd `dirname $0` + # vars DBHOST='127.0.0.1' DBNAME='pfb' @@ -127,7 +129,7 @@ osm2pgsql \ --database "${DBNAME}" \ --prefix "${OSMPREFIX}_osm_full" \ --proj 2249 \ -# --style /home/spencer/dev/pfb/pfb.style \ + --style ./pfb.style \ "${OSMFILE}" # move the full osm tables to the received schema From 1c41ec5925fbe9fbe5e937cdf1578cb86ca26ed9 Mon Sep 17 00:00:00 2001 From: CloudNiner Date: Mon, 17 Oct 2016 09:15:59 -0400 Subject: [PATCH 39/94] Add script to run everything in process.txt --- run_connectivity.sh | 55 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100755 run_connectivity.sh diff --git a/run_connectivity.sh b/run_connectivity.sh new file mode 100755 index 00000000..5883ad11 --- /dev/null +++ b/run_connectivity.sh @@ -0,0 +1,55 @@ +#!/usr/bin/env bash + +cd `dirname $0` + +DBHOST='127.0.0.1' +DBNAME='pfb' +OSMPREFIX='cambridge' + +# psql -h "${DBHOST}" -U gis -d "${DBNAME}" \ +# -c "SELECT tdgMakeNetwork('${OSMPREFIX}_ways');" + +# psql -h "${DBHOST}" -U gis -d "${DBNAME}" \ +# -c "SELECT tdgNetworkCostFromDistance('${OSMPREFIX}_ways');" + +/usr/bin/time -v psql -h "${DBHOST}" -U gis -d "${DBNAME}" \ + -f connectivity/census_blocks.sql + +/usr/bin/time -v psql -h "${DBHOST}" -U gis -d "${DBNAME}" \ + -f connectivity/census_block_roads.sql + +/usr/bin/time -v psql -h "${DBHOST}" -U gis -d "${DBNAME}" \ + -f connectivity/reachable_roads_high_stress.sql + +/usr/bin/time -v psql -h "${DBHOST}" -U gis -d "${DBNAME}" \ + -f connectivity/reachable_roads_low_stress.sql + +/usr/bin/time -v psql -h "${DBHOST}" -U gis -d "${DBNAME}" \ + -f connectivity/connected_census_blocks.sql + +/usr/bin/time -v psql -h "${DBHOST}" -U gis -d "${DBNAME}" \ + -f connectivity/access_population.sql + +/usr/bin/time -v psql -h "${DBHOST}" -U gis -d "${DBNAME}" \ + -f connectivity/census_block_jobs.sql + +/usr/bin/time -v psql -h "${DBHOST}" -U gis -d "${DBNAME}" \ + -f connectivity/access_jobs.sql + +/usr/bin/time -v psql -h "${DBHOST}" -U gis -d "${DBNAME}" \ + -f connectivity/schools.sql + +/usr/bin/time -v psql -h "${DBHOST}" -U gis -d "${DBNAME}" \ + -f connectivity/school_roads.sql + +/usr/bin/time -v psql -h "${DBHOST}" -U gis -d "${DBNAME}" \ + -f connectivity/school_roads.sql + +/usr/bin/time -v psql -h "${DBHOST}" -U gis -d "${DBNAME}" \ + -f connectivity/connected_census_blocks_schools.sql + +/usr/bin/time -v psql -h "${DBHOST}" -U gis -d "${DBNAME}" \ + -f connectivity/access_schools.sql + +/usr/bin/time -v psql -h "${DBHOST}" -U gis -d "${DBNAME}" \ + -f connectivity/overall_scores.sql From c75a3e0e99f03f68d2f165226b3b42d16a91374f Mon Sep 17 00:00:00 2001 From: CloudNiner Date: Mon, 17 Oct 2016 11:04:00 -0400 Subject: [PATCH 40/94] Don't delete jobs data after running task --- connectivity/census_block_jobs.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/connectivity/census_block_jobs.sql b/connectivity/census_block_jobs.sql index e7148585..42a181d5 100644 --- a/connectivity/census_block_jobs.sql +++ b/connectivity/census_block_jobs.sql @@ -57,5 +57,5 @@ CREATE INDEX idx_cambridge_blkjobs ON cambridge_census_block_jobs (blockid10); ANALYZE cambridge_census_block_jobs (blockid10); -- drop import tables -DROP TABLE IF EXISTS "ma_od_aux_JT00_2014"; -DROP TABLE IF EXISTS "ma_od_main_JT00_2014"; +# DROP TABLE IF EXISTS "ma_od_aux_JT00_2014"; +# DROP TABLE IF EXISTS "ma_od_main_JT00_2014"; From f1941fe89a8784fa6b9ed229197b61eaa124fac5 Mon Sep 17 00:00:00 2001 From: CloudNiner Date: Tue, 18 Oct 2016 09:20:07 -0400 Subject: [PATCH 41/94] Fix bad comment in census_block_jobs --- connectivity/census_block_jobs.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/connectivity/census_block_jobs.sql b/connectivity/census_block_jobs.sql index 42a181d5..0550e73a 100644 --- a/connectivity/census_block_jobs.sql +++ b/connectivity/census_block_jobs.sql @@ -57,5 +57,5 @@ CREATE INDEX idx_cambridge_blkjobs ON cambridge_census_block_jobs (blockid10); ANALYZE cambridge_census_block_jobs (blockid10); -- drop import tables -# DROP TABLE IF EXISTS "ma_od_aux_JT00_2014"; -# DROP TABLE IF EXISTS "ma_od_main_JT00_2014"; +-- DROP TABLE IF EXISTS "ma_od_aux_JT00_2014"; +-- DROP TABLE IF EXISTS "ma_od_main_JT00_2014"; From eb4b01e1d06babea4d6703965ff73e0bab15ca4c Mon Sep 17 00:00:00 2001 From: Spencer Date: Thu, 20 Oct 2016 16:02:00 -0500 Subject: [PATCH 42/94] create gates to grab streetlight data --- streetlight/streetlight_gates.sql | 56 +++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 streetlight/streetlight_gates.sql diff --git a/streetlight/streetlight_gates.sql b/streetlight/streetlight_gates.sql new file mode 100644 index 00000000..0a1468be --- /dev/null +++ b/streetlight/streetlight_gates.sql @@ -0,0 +1,56 @@ +---------------------------------------- +-- INPUTS +-- location: cambridge +-- proj: 2249 +---------------------------------------- +DROP TABLE IF EXISTS cambridge_streetlight_gates; +CREATE TABLE generated.cambridge_streetlight_gates ( + id SERIAL PRIMARY KEY, + geom geometry(polygon,2249), + road_id BIGINT, + functional_class TEXT, + direction INT, + is_pass INT +); + +INSERT INTO cambridge_streetlight_gates ( + road_id, + functional_class, + geom, + direction, + is_pass +) +SELECT road_id, + functional_class, + ST_Buffer( + ST_SetSRID( + ST_MakeLine( + ST_LineInterpolatePoint(geom,0.5), + ST_LineInterpolatePoint(geom,0.55) + ), + 2249 + ), + 100, + 'endcap=flat' + ) AS geom, + degrees(ST_Azimuth( + ST_LineInterpolatePoint(geom,0.5), + ST_LineInterpolatePoint(geom,0.55) + )), + 1 +FROM cambridge_ways +WHERE functional_class IN ('primary','secondary','tertiary','residential') +AND EXISTS ( + SELECT 1 + FROM cambridge_zip_codes zips + WHERE ST_DWithin(cambridge_ways.geom,zips.geom,11000) + AND zips.zip_code = '02138' + ); + +-- formatting for upload to SLD +SELECT road_id AS id, + road_id AS name, + is_pass, + direction, + geom +FROM cambridge_streetlight_gates; From 446c730742c84d18f4fb07bd1941add1d3df014f Mon Sep 17 00:00:00 2001 From: CloudNiner Date: Mon, 24 Oct 2016 14:09:55 -0400 Subject: [PATCH 43/94] Add script to load user-defined neighborhood to postgres db --- import_neighborhood.sh | 74 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100755 import_neighborhood.sh diff --git a/import_neighborhood.sh b/import_neighborhood.sh new file mode 100755 index 00000000..bd87b351 --- /dev/null +++ b/import_neighborhood.sh @@ -0,0 +1,74 @@ +#!/bin/bash + +NB_INPUT_SRID="${NB_INPUT_SRID:-4326}" +NB_OUTPUT_SRID="${NB_OUTPUT_SRID:-4326}" +NB_BOUNDARY_BUFFER="${NB_BOUNDARY_BUFFER:-0}" +NB_POSTGRESQL_HOST="${NB_POSTGRESQL_HOST:-127.0.0.1}" +NB_POSTGRESQL_DB="${NB_POSTGRESQL_DB:-pfb}" +NB_POSTGRESQL_USER="${NB_POSTGRESQL_USER:-gis}" +NB_POSTGRESQL_PASSWORD="${NB_POSTGRESQL_PASSWORD:-gis}" + +NB_TEMPDIR=`mktemp -d` + +set -e + +if [[ -n "${PFB_DEBUG}" ]]; then + set -x +fi + +function usage() { + echo -n \ +" +Usage: $(basename "$0") + +Import neighborhood boundary to postgres database, overwriting any existing boundary + +Requires passing path (relative or absolute) to the neighborhood boundary shapefile. +Requires passing the state FIPS ID that the neighborhood boundary is found in. e.g. MA is 25 + See: https://www.census.gov/geo/reference/ansi_statetables.html + +Optional ENV vars: + +NB_INPUT_SRID - Default: 4326 +NB_OUTPUT_SRID - Default: 4326 +NB_BOUNDARY_BUFFER - Default: 0 (Units is units of NB_OUTPUT_SRID) +NB_POSTGRESQL_HOST - Default: 127.0.0.1 +NB_POSTGRESQL_DB - Default: pfb +NB_POSTGRESQL_USER - Default: gis +NB_POSTGRESQL_PASSWORD - Default: gis + +" +} + +if [ "${BASH_SOURCE[0]}" = "${0}" ] +then + if [ "${1:-}" = "--help" ] || [ -z "${1:-}" ] + then + usage + else + NB_BOUNDARY_FILE="${1}" + NB_STATE_FIPS="${2}" + + # Import neighborhood boundary + shp2pgsql -d -s "${NB_INPUT_SRID}":"${NB_OUTPUT_SRID}" "${NB_BOUNDARY_FILE}" neighborhood_boundary \ + | psql -h "${NB_POSTGRESQL_HOST}" -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_DB}" + + # Get blocks for the state requested + NB_BLOCK_FILENAME="tabblock2010_${NB_STATE_FIPS}_pophu" + wget -P "${NB_TEMPDIR}" "http://www2.census.gov/geo/tiger/TIGER2010BLKPOPHU/${NB_BLOCK_FILENAME}.zip" + unzip "${NB_TEMPDIR}/${NB_BLOCK_FILENAME}.zip" -d "${NB_TEMPDIR}" + + # Import block shapefile + echo "START: Importing blocks" + shp2pgsql -d -s 4326:"${NB_OUTPUT_SRID}" "${NB_TEMPDIR}/${NB_BLOCK_FILENAME}.shp" neighborhood_census_blocks \ + | psql -h "${NB_POSTGRESQL_HOST}" -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_DB}" > /dev/null + echo "DONE: Importing blocks" + + # Only keep blocks in boundary+buffer + psql -h "${NB_POSTGRESQL_HOST}" -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_DB}" \ + -c "DELETE FROM neighborhood_census_blocks AS blocks USING neighborhood_boundary AS boundary WHERE NOT ST_DWithin(blocks.geom, boundary.geom, ${NB_BOUNDARY_BUFFER});" + + # Remove NB_TEMPDIR + rm -rf "${NB_TEMPDIR}" + fi +fi From cd099fcfd26973fa4dc4a2c7651e583c35a60de0 Mon Sep 17 00:00:00 2001 From: CloudNiner Date: Mon, 24 Oct 2016 15:21:46 -0400 Subject: [PATCH 44/94] Update boundary table names in connectivity sql scripts --- connectivity/access_jobs.sql | 18 ++-- connectivity/access_population.sql | 22 ++--- connectivity/access_schools.sql | 32 +++--- connectivity/census_block_jobs.sql | 26 ++--- connectivity/census_block_roads.sql | 10 +- connectivity/census_blocks.sql | 22 ++--- connectivity/connected_census_blocks.sql | 9 +- .../connected_census_blocks_schools.sql | 7 +- connectivity/overall_scores.sql | 99 ++++++++----------- connectivity/reachable_roads_high_stress.sql | 5 +- connectivity/reachable_roads_low_stress.sql | 5 +- connectivity/school_roads.sql | 10 +- 12 files changed, 115 insertions(+), 150 deletions(-) diff --git a/connectivity/access_jobs.sql b/connectivity/access_jobs.sql index b30bebf2..895c5c2d 100644 --- a/connectivity/access_jobs.sql +++ b/connectivity/access_jobs.sql @@ -3,40 +3,38 @@ -- location: cambridge ---------------------------------------- -- low stress access -UPDATE cambridge_census_blocks +UPDATE neighborhood_census_blocks SET emp_low_stress = ( SELECT SUM(blocks2.jobs) FROM cambridge_census_block_jobs blocks2 WHERE EXISTS ( SELECT 1 FROM cambridge_connected_census_blocks cb - WHERE cb.source_blockid10 = cambridge_census_blocks.blockid10 + WHERE cb.source_blockid10 = neighborhood_census_blocks.blockid10 AND cb.target_blockid10 = blocks2.blockid10 AND cb.low_stress ) ) WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) - AND zips.zip_code = '02138' + FROM neighborhood_boundary AS b + WHERE ST_Intersects(neighborhood_census_blocks.geom,b.geom) ); -- high stress access -UPDATE cambridge_census_blocks +UPDATE neighborhood_census_blocks SET emp_high_stress = ( SELECT SUM(blocks2.jobs) FROM cambridge_census_block_jobs blocks2 WHERE EXISTS ( SELECT 1 FROM cambridge_connected_census_blocks cb - WHERE cb.source_blockid10 = cambridge_census_blocks.blockid10 + WHERE cb.source_blockid10 = neighborhood_census_blocks.blockid10 AND cb.target_blockid10 = blocks2.blockid10 ) ) WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) - AND zips.zip_code = '02138' + FROM neighborhood_boundary AS b + WHERE ST_Intersects(neighborhood_census_blocks.geom,b.geom) ); diff --git a/connectivity/access_population.sql b/connectivity/access_population.sql index 1163c6e2..3374f3be 100644 --- a/connectivity/access_population.sql +++ b/connectivity/access_population.sql @@ -3,40 +3,38 @@ -- location: cambridge ---------------------------------------- -- low stress access -UPDATE cambridge_census_blocks +UPDATE neighborhood_census_blocks SET pop_low_stress = ( SELECT SUM(blocks2.pop10) - FROM cambridge_census_blocks blocks2 + FROM neighborhood_census_blocks blocks2 WHERE EXISTS ( SELECT 1 FROM cambridge_connected_census_blocks cb - WHERE cb.source_blockid10 = cambridge_census_blocks.blockid10 + WHERE cb.source_blockid10 = neighborhood_census_blocks.blockid10 AND cb.target_blockid10 = blocks2.blockid10 AND cb.low_stress ) ) WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) - AND zips.zip_code = '02138' + FROM neighborhood_boundary AS b + WHERE ST_Intersects(neighborhood_census_blocks.geom,b.geom) ); -- high stress access -UPDATE cambridge_census_blocks +UPDATE neighborhood_census_blocks SET pop_high_stress = ( SELECT SUM(blocks2.pop10) - FROM cambridge_census_blocks blocks2 + FROM neighborhood_census_blocks blocks2 WHERE EXISTS ( SELECT 1 FROM cambridge_connected_census_blocks cb - WHERE cb.source_blockid10 = cambridge_census_blocks.blockid10 + WHERE cb.source_blockid10 = neighborhood_census_blocks.blockid10 AND cb.target_blockid10 = blocks2.blockid10 ) ) WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) - AND zips.zip_code = '02138' + FROM neighborhood_boundary AS b + WHERE ST_Intersects(neighborhood_census_blocks.geom,b.geom) ); diff --git a/connectivity/access_schools.sql b/connectivity/access_schools.sql index 58cf950f..d63aa04d 100644 --- a/connectivity/access_schools.sql +++ b/connectivity/access_schools.sql @@ -3,39 +3,37 @@ -- location: cambridge ---------------------------------------- -- low stress access -UPDATE cambridge_census_blocks +UPDATE neighborhood_census_blocks SET schools_low_stress = ( SELECT COUNT(cbs.id) FROM cambridge_connected_census_blocks_schools cbs - WHERE cbs.source_blockid10 = cambridge_census_blocks.blockid10 + WHERE cbs.source_blockid10 = neighborhood_census_blocks.blockid10 AND cbs.low_stress ) WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) - AND zips.zip_code = '02138' + FROM neighborhood_boundary as b + WHERE ST_Intersects(neighborhood_census_blocks.geom,b.geom) ); -- high stress access -UPDATE cambridge_census_blocks +UPDATE neighborhood_census_blocks SET schools_high_stress = ( SELECT COUNT(cbs.id) FROM cambridge_connected_census_blocks_schools cbs - WHERE cbs.source_blockid10 = cambridge_census_blocks.blockid10 + WHERE cbs.source_blockid10 = neighborhood_census_blocks.blockid10 ) WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) - AND zips.zip_code = '02138' + FROM neighborhood_boundary as b + WHERE ST_Intersects(neighborhood_census_blocks.geom,b.geom) ); -- low stress population shed for schools in neighborhood UPDATE cambridge_schools SET pop_low_stress = ( SELECT SUM(cb.pop10) - FROM cambridge_census_blocks cb, + FROM neighborhood_census_blocks cb, cambridge_connected_census_blocks_schools cbs WHERE cb.blockid10 = cbs.source_blockid10 AND cambridge_schools.id = cbs.target_school_id @@ -43,23 +41,21 @@ SET pop_low_stress = ( ) WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_Intersects(cambridge_schools.geom_pt,zips.geom) - AND zips.zip_code = '02138' + FROM neighborhood_boundary as b + WHERE ST_Intersects(cambridge_schools.geom_pt,b.geom) ); -- high stress population shed for schools in neighborhood UPDATE cambridge_schools SET pop_high_stress = ( SELECT SUM(cb.pop10) - FROM cambridge_census_blocks cb, + FROM neighborhood_census_blocks cb, cambridge_connected_census_blocks_schools cbs WHERE cb.blockid10 = cbs.source_blockid10 AND cambridge_schools.id = cbs.target_school_id ) WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_Intersects(cambridge_schools.geom_pt,zips.geom) - AND zips.zip_code = '02138' + FROM neighborhood_boundary as b + WHERE ST_Intersects(cambridge_schools.geom_pt,b.geom) ); diff --git a/connectivity/census_block_jobs.sql b/connectivity/census_block_jobs.sql index 0550e73a..cda01ae4 100644 --- a/connectivity/census_block_jobs.sql +++ b/connectivity/census_block_jobs.sql @@ -12,16 +12,16 @@ ---------------------------------------- -- process imported tables -ALTER TABLE "ma_od_aux_JT00_2014" ALTER COLUMN w_geocode TYPE VARCHAR(15); -UPDATE "ma_od_aux_JT00_2014" SET w_geocode = rpad(w_geocode,15,'0'); --just in case we lost any trailing zeros -ALTER TABLE "ma_od_main_JT00_2014" ALTER COLUMN w_geocode TYPE VARCHAR(15); -UPDATE "ma_od_main_JT00_2014" SET w_geocode = rpad(w_geocode,15,'0'); --just in case we lost any trailing zeros +ALTER TABLE "state_od_aux_JT00_2014" ALTER COLUMN w_geocode TYPE VARCHAR(15); +UPDATE "state_od_aux_JT00_2014" SET w_geocode = rpad(w_geocode,15,'0'); --just in case we lost any trailing zeros +ALTER TABLE "state_od_main_JT00_2014" ALTER COLUMN w_geocode TYPE VARCHAR(15); +UPDATE "state_od_main_JT00_2014" SET w_geocode = rpad(w_geocode,15,'0'); --just in case we lost any trailing zeros -- indexes -CREATE INDEX tidx_auxjtw ON "ma_od_aux_JT00_2014" (w_geocode); -CREATE INDEX tidx_mainjtw ON "ma_od_main_JT00_2014" (w_geocode); -ANALYZE "ma_od_aux_JT00_2014" (w_geocode); -ANALYZE "ma_od_main_JT00_2014" (w_geocode); +CREATE INDEX tidx_auxjtw ON "state_od_aux_JT00_2014" (w_geocode); +CREATE INDEX tidx_mainjtw ON "state_od_main_JT00_2014" (w_geocode); +ANALYZE "state_od_aux_JT00_2014" (w_geocode); +ANALYZE "state_od_main_JT00_2014" (w_geocode); -- create combined table CREATE TABLE generated.cambridge_census_block_jobs ( @@ -33,13 +33,13 @@ CREATE TABLE generated.cambridge_census_block_jobs ( -- add blocks of interest INSERT INTO generated.cambridge_census_block_jobs (blockid10) SELECT blocks.blockid10 -FROM cambridge_census_blocks blocks; +FROM neighborhood_census_blocks blocks; -- add main data UPDATE generated.cambridge_census_block_jobs SET jobs = COALESCE(( SELECT SUM(j."S000") - FROM "ma_od_main_JT00_2014" j + FROM "state_od_main_JT00_2014" j WHERE j.w_geocode = cambridge_census_block_jobs.blockid10 ),0); @@ -48,7 +48,7 @@ UPDATE generated.cambridge_census_block_jobs SET jobs = jobs + COALESCE(( SELECT SUM(j."S000") - FROM "ma_od_aux_JT00_2014" j + FROM "state_od_aux_JT00_2014" j WHERE j.w_geocode = cambridge_census_block_jobs.blockid10 ),0); @@ -57,5 +57,5 @@ CREATE INDEX idx_cambridge_blkjobs ON cambridge_census_block_jobs (blockid10); ANALYZE cambridge_census_block_jobs (blockid10); -- drop import tables --- DROP TABLE IF EXISTS "ma_od_aux_JT00_2014"; --- DROP TABLE IF EXISTS "ma_od_main_JT00_2014"; +-- DROP TABLE IF EXISTS "state_od_aux_JT00_2014"; +-- DROP TABLE IF EXISTS "state_od_main_JT00_2014"; diff --git a/connectivity/census_block_roads.sql b/connectivity/census_block_roads.sql index b69a6cf7..d50964dc 100644 --- a/connectivity/census_block_roads.sql +++ b/connectivity/census_block_roads.sql @@ -16,15 +16,9 @@ INSERT INTO generated.cambridge_census_block_roads ( ) SELECT blocks.blockid10, ways.road_id -FROM cambridge_census_blocks blocks, +FROM neighborhood_census_blocks blocks, cambridge_ways ways -WHERE EXISTS ( - SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_DWithin(zips.geom, blocks.geom, 11000) - AND zips.zip_code = '02138' -) -AND ST_DWithin(blocks.geom,ways.geom,50); +WHERE ST_DWithin(blocks.geom,ways.geom,50); CREATE INDEX idx_cambridge_censblkrds ON generated.cambridge_census_block_roads (blockid10,road_id); diff --git a/connectivity/census_blocks.sql b/connectivity/census_blocks.sql index 66041044..3f2a1456 100644 --- a/connectivity/census_blocks.sql +++ b/connectivity/census_blocks.sql @@ -1,19 +1,19 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood -- code to be run on table that has -- been imported directly from US Census -- blkpophu file ---------------------------------------- -ALTER TABLE cambridge_census_blocks ADD COLUMN pop_low_stress INT; -ALTER TABLE cambridge_census_blocks ADD COLUMN pop_high_stress INT; -ALTER TABLE cambridge_census_blocks ADD COLUMN emp_low_stress INT; -ALTER TABLE cambridge_census_blocks ADD COLUMN emp_high_stress INT; -ALTER TABLE cambridge_census_blocks ADD COLUMN schools_low_stress INT; -ALTER TABLE cambridge_census_blocks ADD COLUMN schools_high_stress INT; -ALTER TABLE cambridge_census_blocks ADD COLUMN rec_low_stress INT; -ALTER TABLE cambridge_census_blocks ADD COLUMN rec_high_stress INT; +ALTER TABLE neighborhood_census_blocks ADD COLUMN pop_low_stress INT; +ALTER TABLE neighborhood_census_blocks ADD COLUMN pop_high_stress INT; +ALTER TABLE neighborhood_census_blocks ADD COLUMN emp_low_stress INT; +ALTER TABLE neighborhood_census_blocks ADD COLUMN emp_high_stress INT; +ALTER TABLE neighborhood_census_blocks ADD COLUMN schools_low_stress INT; +ALTER TABLE neighborhood_census_blocks ADD COLUMN schools_high_stress INT; +ALTER TABLE neighborhood_census_blocks ADD COLUMN rec_low_stress INT; +ALTER TABLE neighborhood_census_blocks ADD COLUMN rec_high_stress INT; -CREATE INDEX idx_cambridge_blocks10 ON cambridge_census_blocks (blockid10); -ANALYZE cambridge_census_blocks (blockid10); +CREATE INDEX idx_neighborhood_blocks10 ON neighborhood_census_blocks (blockid10); +ANALYZE neighborhood_census_blocks (blockid10); diff --git a/connectivity/connected_census_blocks.sql b/connectivity/connected_census_blocks.sql index c7ff6119..c93d2cc5 100644 --- a/connectivity/connected_census_blocks.sql +++ b/connectivity/connected_census_blocks.sql @@ -21,13 +21,12 @@ SELECT source_block.blockid10, target_block.blockid10, 'f'::BOOLEAN, 't'::BOOLEAN -FROM cambridge_census_blocks source_block, - cambridge_census_blocks target_block +FROM neighborhood_census_blocks source_block, + neighborhood_census_blocks target_block WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_Intersects(source_block.geom,zips.geom) - AND zips.zip_code = '02138' + FROM neighborhood_boundary AS b + WHERE ST_Intersects(source_block.geom,b.geom) ) AND source_block.geom <#> target_block.geom < 11000 AND EXISTS ( diff --git a/connectivity/connected_census_blocks_schools.sql b/connectivity/connected_census_blocks_schools.sql index 07913754..7b7ad4e9 100644 --- a/connectivity/connected_census_blocks_schools.sql +++ b/connectivity/connected_census_blocks_schools.sql @@ -21,13 +21,12 @@ SELECT blocks.blockid10, schools.id, 'f'::BOOLEAN, 't'::BOOLEAN -FROM cambridge_census_blocks blocks, +FROM neighborhood_census_blocks blocks, cambridge_schools schools WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_Intersects(blocks.geom,zips.geom) - AND zips.zip_code = '02138' + FROM neighborhood_boundary AS b + WHERE ST_Intersects(blocks.geom,b.geom) ) AND blocks.geom <#> schools.geom_pt < 11000 AND EXISTS ( diff --git a/connectivity/overall_scores.sql b/connectivity/overall_scores.sql index 7527b288..e779c77b 100644 --- a/connectivity/overall_scores.sql +++ b/connectivity/overall_scores.sql @@ -22,12 +22,11 @@ SELECT 'Population', regexp_replace('Total population accessible by low stress expressed as the median of all census blocks in the neighborhood','\n\s+',' ') -FROM cambridge_census_blocks +FROM neighborhood_census_blocks WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) - AND zips.zip_code = '02138' + FROM neighborhood_boundary AS b + WHERE ST_Intersects(neighborhood_census_blocks.geom,b.geom) ); -- median pop access high stress @@ -40,12 +39,11 @@ SELECT 'Population', regexp_replace('Total population accessible by high stress expressed as the median of all census blocks in the neighborhood','\n\s+',' ') -FROM cambridge_census_blocks +FROM neighborhood_census_blocks WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) - AND zips.zip_code = '02138' + FROM neighborhood_boundary AS b + WHERE ST_Intersects(neighborhood_census_blocks.geom,b.geom) ); -- median pop access ratio @@ -59,12 +57,11 @@ SELECT 'Population', to population accessible overall, expressed as the median of all census blocks in the neighborhood','\n\s+',' ') -FROM cambridge_census_blocks +FROM neighborhood_census_blocks WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) - AND zips.zip_code = '02138' + FROM neighborhood_boundary AS b + WHERE ST_Intersects(neighborhood_census_blocks.geom,b.geom) ); -- 70th percentile pop access ratio @@ -78,12 +75,11 @@ SELECT 'Population', to population accessible overall, expressed as the 70th percentile of all census blocks in the neighborhood','\n\s+',' ') -FROM cambridge_census_blocks +FROM neighborhood_census_blocks WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) - AND zips.zip_code = '02138' + FROM neighborhood_boundary AS b + WHERE ST_Intersects(neighborhood_census_blocks.geom,b.geom) ); -- avg pop access ratio @@ -97,12 +93,11 @@ SELECT 'Population', to population accessible overall, expressed as the average of all census blocks in the neighborhood','\n\s+',' ') -FROM cambridge_census_blocks +FROM neighborhood_census_blocks WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) - AND zips.zip_code = '02138' + FROM neighborhood_boundary AS b + WHERE ST_Intersects(neighborhood_census_blocks.geom,b.geom) ); -- median jobs access low stress @@ -115,12 +110,11 @@ SELECT 'Employment', regexp_replace('Total jobs accessible by low stress expressed as the median of all census blocks in the neighborhood','\n\s+',' ') -FROM cambridge_census_blocks +FROM neighborhood_census_blocks WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) - AND zips.zip_code = '02138' + FROM neighborhood_boundary AS b + WHERE ST_Intersects(neighborhood_census_blocks.geom,b.geom) ); -- median jobs access high stress @@ -133,12 +127,11 @@ SELECT 'Employment', regexp_replace('Total jobs accessible by high stress expressed as the median of all census blocks in the neighborhood','\n\s+',' ') -FROM cambridge_census_blocks +FROM neighborhood_census_blocks WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) - AND zips.zip_code = '02138' + FROM neighborhood_boundary AS b + WHERE ST_Intersects(neighborhood_census_blocks.geom,b.geom) ); -- median jobs access ratio @@ -152,12 +145,11 @@ SELECT 'Employment', to employment accessible overall, expressed as the median of all census blocks in the neighborhood','\n\s+',' ') -FROM cambridge_census_blocks +FROM neighborhood_census_blocks WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) - AND zips.zip_code = '02138' + FROM neighborhood_boundary AS b + WHERE ST_Intersects(neighborhood_census_blocks.geom,b.geom) ); -- 70th percentile jobs access ratio @@ -171,12 +163,11 @@ SELECT 'Employment', to employment accessible overall, expressed as the 70th percentile of all census blocks in the neighborhood','\n\s+',' ') -FROM cambridge_census_blocks +FROM neighborhood_census_blocks WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) - AND zips.zip_code = '02138' + FROM neighborhood_boundary AS b + WHERE ST_Intersects(neighborhood_census_blocks.geom,b.geom) ); -- avg jobs access ratio @@ -190,12 +181,11 @@ SELECT 'Employment', to employment accessible overall, expressed as the average of all census blocks in the neighborhood','\n\s+',' ') -FROM cambridge_census_blocks +FROM neighborhood_census_blocks WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) - AND zips.zip_code = '02138' + FROM neighborhood_boundary AS b + WHERE ST_Intersects(neighborhood_census_blocks.geom,b.geom) ); -- median schools access low stress @@ -208,12 +198,11 @@ SELECT 'Schools', regexp_replace('Number of schools accessible by low stress expressed as an average of all census blocks in the neighborhood','\n\s+',' ') -FROM cambridge_census_blocks +FROM neighborhood_census_blocks WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) - AND zips.zip_code = '02138' + FROM neighborhood_boundary AS b + WHERE ST_Intersects(neighborhood_census_blocks.geom,b.geom) ); -- median schools access high stress @@ -226,12 +215,11 @@ SELECT 'Schools', regexp_replace('Number of schools accessible by high stress expressed as an average of all census blocks in the neighborhood','\n\s+',' ') -FROM cambridge_census_blocks +FROM neighborhood_census_blocks WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) - AND zips.zip_code = '02138' + FROM neighborhood_boundary AS b + WHERE ST_Intersects(neighborhood_census_blocks.geom,b.geom) ); -- school low stress pop shed access @@ -247,9 +235,8 @@ SELECT 'Schools', FROM cambridge_schools WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_Intersects(cambridge_schools.geom_pt,zips.geom) - AND zips.zip_code = '02138' + FROM neighborhood_boundary AS b + WHERE ST_Intersects(cambridge_schools.geom_pt,b.geom) ); -- school high stress pop shed access @@ -265,9 +252,8 @@ SELECT 'Schools', FROM cambridge_schools WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_Intersects(cambridge_schools.geom_pt,zips.geom) - AND zips.zip_code = '02138' + FROM neighborhood_boundary AS b + WHERE ST_Intersects(cambridge_schools.geom_pt,b.geom) ); -- school pop shed access ratio @@ -284,7 +270,6 @@ SELECT 'Schools', FROM cambridge_schools WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_Intersects(cambridge_schools.geom_pt,zips.geom) - AND zips.zip_code = '02138' + FROM neighborhood_boundary AS b + WHERE ST_Intersects(cambridge_schools.geom_pt,b.geom) ); diff --git a/connectivity/reachable_roads_high_stress.sql b/connectivity/reachable_roads_high_stress.sql index 9ecb37b3..a2a16cc6 100644 --- a/connectivity/reachable_roads_high_stress.sql +++ b/connectivity/reachable_roads_high_stress.sql @@ -35,9 +35,8 @@ FROM cambridge_ways r1, ) sheds WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_Intersects(zips.geom,r1.geom) - AND zips.zip_code = '02138' + FROM neighborhood_boundary AS b + WHERE ST_Intersects(b.geom,r1.geom) ) AND r1.road_id = v1.road_id AND v2.vert_id = sheds.node; diff --git a/connectivity/reachable_roads_low_stress.sql b/connectivity/reachable_roads_low_stress.sql index 2c3510d6..afaaaec3 100644 --- a/connectivity/reachable_roads_low_stress.sql +++ b/connectivity/reachable_roads_low_stress.sql @@ -36,9 +36,8 @@ FROM cambridge_ways r1, ) sheds WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_Intersects(zips.geom,r1.geom) - AND zips.zip_code = '02138' + FROM neighborhood_boundary AS b + WHERE ST_Intersects(b.geom,r1.geom) ) AND r1.road_id = v1.road_id AND v2.vert_id = sheds.node; diff --git a/connectivity/school_roads.sql b/connectivity/school_roads.sql index fe65173d..394c637a 100644 --- a/connectivity/school_roads.sql +++ b/connectivity/school_roads.sql @@ -21,9 +21,8 @@ FROM cambridge_schools schools, cambridge_ways ways WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_DWithin(zips.geom, schools.geom_pt, 11000) - AND zips.zip_code = '02138' + FROM neighborhood_boundary AS b + WHERE ST_DWithin(b.geom, schools.geom_pt, 11000) ) AND schools.geom_poly IS NOT NULL AND ST_DWithin(schools.geom_poly,ways.geom,50); @@ -43,9 +42,8 @@ SELECT schools.id, FROM cambridge_schools schools WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_DWithin(zips.geom, schools.geom_pt, 11000) - AND zips.zip_code = '02138' + FROM neighborhood_boundary AS b + WHERE ST_DWithin(b.geom, schools.geom_pt, 11000) ) AND NOT EXISTS ( SELECT 1 From b33d2281340edad348f42001c8aea627d1c6cc9a Mon Sep 17 00:00:00 2001 From: CloudNiner Date: Mon, 24 Oct 2016 16:16:38 -0400 Subject: [PATCH 45/94] Closes #4: Add import_jobs.sh script to automate job data import --- import_jobs.sh | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100755 import_jobs.sh diff --git a/import_jobs.sh b/import_jobs.sh new file mode 100755 index 00000000..317f500d --- /dev/null +++ b/import_jobs.sh @@ -0,0 +1,87 @@ +#!/bin/bash + +NB_POSTGRESQL_HOST="${NB_POSTGRESQL_HOST:-127.0.0.1}" +NB_POSTGRESQL_DB="${NB_POSTGRESQL_DB:-pfb}" +NB_POSTGRESQL_USER="${NB_POSTGRESQL_USER:-gis}" +NB_POSTGRESQL_PASSWORD="${NB_POSTGRESQL_PASSWORD:-gis}" + + +set -e + +if [[ -n "${PFB_DEBUG}" ]]; then + set -x +fi + +function usage() { + echo -n \ +" +Usage: $(basename "$0") + +Import state jobs data into postgres database. + +Requires passing the state FIPS abbrev that the neighborhood boundary is found in. e.g. MA for Massachussetts + See: https://www.census.gov/geo/reference/ansi_statetables.html + +Optional ENV vars: + +NB_POSTGRESQL_HOST - Default: 127.0.0.1 +NB_POSTGRESQL_DB - Default: pfb +NB_POSTGRESQL_USER - Default: gis +NB_POSTGRESQL_PASSWORD - Default: gis + +" +} + +function import_job_data() { + NB_TEMPDIR=`mktemp -d` + NB_STATE_ABBREV="${1}" + NB_DATA_TYPE="${2-main}" # Either 'main' or 'aux' + NB_JOB_FILENAME="${NB_STATE_ABBREV}_od_${NB_DATA_TYPE}_JT00_2014.csv" + + wget -P "${NB_TEMPDIR}" "http://lehd.ces.census.gov/data/lodes/LODES7/${NB_STATE_ABBREV}/od/${NB_JOB_FILENAME}.gz" + gunzip -c "${NB_TEMPDIR}/${NB_JOB_FILENAME}.gz" > "${NB_TEMPDIR}/${NB_JOB_FILENAME}" + + # Import to postgresql + psql -h "${NB_POSTGRESQL_HOST}" -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_DB}" \ + -c " +CREATE TABLE IF NOT EXISTS \"state_od_${NB_DATA_TYPE}_JT00_2014\" ( + w_geocode varchar(15), + h_geocode varchar(15), + \"S000\" integer, + \"SA01\" integer, + \"SA02\" integer, + \"SA03\" integer, + \"SE01\" integer, + \"SE02\" integer, + \"SE03\" integer, + \"SI01\" integer, + \"SI02\" integer, + \"SI03\" integer, + createdate VARCHAR(32) +);" + psql -h "${NB_POSTGRESQL_HOST}" -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_DB}" \ + -c "TRUNCATE TABLE \"state_od_${NB_DATA_TYPE}_JT00_2014\";" + + # Load data + # Dir and files must be world readable/executable for postgres to use copy command + chmod -R 775 "${NB_TEMPDIR}" + psql -h "${NB_POSTGRESQL_HOST}" -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_DB}" \ + -c "COPY \"state_od_${NB_DATA_TYPE}_JT00_2014\"(w_geocode, h_geocode, \"S000\", \"SA01\", \"SA02\", \"SA03\", \"SE01\", \"SE02\", \"SE03\", \"SI01\", \"SI02\", \"SI03\", createdate) FROM '${NB_TEMPDIR}/${NB_JOB_FILENAME}' DELIMITER ',' CSV HEADER;" + + # Remove NB_TEMPDIR + rm -rf "${NB_TEMPDIR}" +} + +if [ "${BASH_SOURCE[0]}" = "${0}" ] +then + if [ "${1:-}" = "--help" ] || [ -z "${1:-}" ] + then + usage + else + NB_STATE_ABBREV="${1}" + + import_job_data "${NB_STATE_ABBREV}" "main" + import_job_data "${NB_STATE_ABBREV}" "aux" + + fi +fi From d168f8556bc5d86d0e453a66063b9c3509fefebf Mon Sep 17 00:00:00 2001 From: CloudNiner Date: Tue, 25 Oct 2016 08:37:14 -0400 Subject: [PATCH 46/94] Remove duplicate school_roads call --- run_connectivity.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/run_connectivity.sh b/run_connectivity.sh index 5883ad11..c38bc8e8 100755 --- a/run_connectivity.sh +++ b/run_connectivity.sh @@ -42,9 +42,6 @@ OSMPREFIX='cambridge' /usr/bin/time -v psql -h "${DBHOST}" -U gis -d "${DBNAME}" \ -f connectivity/school_roads.sql -/usr/bin/time -v psql -h "${DBHOST}" -U gis -d "${DBNAME}" \ - -f connectivity/school_roads.sql - /usr/bin/time -v psql -h "${DBHOST}" -U gis -d "${DBNAME}" \ -f connectivity/connected_census_blocks_schools.sql From 72136c32c8e4a6055aaeaa532ec6cce59e7740d8 Mon Sep 17 00:00:00 2001 From: CloudNiner Date: Tue, 25 Oct 2016 09:01:40 -0400 Subject: [PATCH 47/94] Update import_osm.sh to use same ENV as other scripts --- import_osm.sh | 267 +++++++++++++++++++++++++------------------------- 1 file changed, 134 insertions(+), 133 deletions(-) diff --git a/import_osm.sh b/import_osm.sh index e3b8fafd..ce2cd495 100755 --- a/import_osm.sh +++ b/import_osm.sh @@ -2,176 +2,177 @@ cd `dirname $0` -# vars -DBHOST='127.0.0.1' -DBNAME='pfb' -OSMPREFIX='cambridge' -OSMFILE='/vagrant/data/cambridge.osm' +NB_POSTGRESQL_HOST="${NB_POSTGRESQL_HOST:-127.0.0.1}" +NB_POSTGRESQL_DB="${NB_POSTGRESQL_DB:-pfb}" +NB_POSTGRESQL_USER="${NB_POSTGRESQL_USER:-gis}" +NB_POSTGRESQL_PASSWORD="${NB_POSTGRESQL_PASSWORD:-gis}" +NB_OSMPREFIX="${NB_OSMPREFIX:-cambridge}" +NB_OSMFILE="${NB_OSMFILE:-/vagrant/data/cambridge.osm}" # drop old tables echo 'Dropping old tables' -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_ways;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_ways_intersections;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_relations_ways;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_nodes;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_relations;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_way_classes;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_way_tags;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_way_types;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_ways;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_ways_vertices_pgr;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_relations_ways;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_osm_nodes;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_osm_relations;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_osm_way_classes;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_osm_way_tags;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_osm_way_types;" +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ + -c "DROP TABLE IF EXISTS received.${NB_OSMPREFIX}_ways;" +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ + -c "DROP TABLE IF EXISTS received.${NB_OSMPREFIX}_ways_intersections;" +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ + -c "DROP TABLE IF EXISTS received.${NB_OSMPREFIX}_relations_ways;" +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ + -c "DROP TABLE IF EXISTS received.${NB_OSMPREFIX}_osm_nodes;" +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ + -c "DROP TABLE IF EXISTS received.${NB_OSMPREFIX}_osm_relations;" +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ + -c "DROP TABLE IF EXISTS received.${NB_OSMPREFIX}_osm_way_classes;" +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ + -c "DROP TABLE IF EXISTS received.${NB_OSMPREFIX}_osm_way_tags;" +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ + -c "DROP TABLE IF EXISTS received.${NB_OSMPREFIX}_osm_way_types;" +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ + -c "DROP TABLE IF EXISTS scratch.${NB_OSMPREFIX}_cycwys_ways;" +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ + -c "DROP TABLE IF EXISTS scratch.${NB_OSMPREFIX}_cycwys_ways_vertices_pgr;" +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ + -c "DROP TABLE IF EXISTS scratch.${NB_OSMPREFIX}_cycwys_relations_ways;" +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ + -c "DROP TABLE IF EXISTS scratch.${NB_OSMPREFIX}_cycwys_osm_nodes;" +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ + -c "DROP TABLE IF EXISTS scratch.${NB_OSMPREFIX}_cycwys_osm_relations;" +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ + -c "DROP TABLE IF EXISTS scratch.${NB_OSMPREFIX}_cycwys_osm_way_classes;" +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ + -c "DROP TABLE IF EXISTS scratch.${NB_OSMPREFIX}_cycwys_osm_way_tags;" +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ + -c "DROP TABLE IF EXISTS scratch.${NB_OSMPREFIX}_cycwys_osm_way_types;" # import the osm with highways osm2pgrouting \ - -f $OSMFILE \ - -h $DBHOST \ - --dbname ${DBNAME} \ - --username gis \ + -f $NB_OSMFILE \ + -h $NB_POSTGRESQL_HOST \ + --dbname ${NB_POSTGRESQL_DB} \ + --username ${NB_POSTGRESQL_USER} \ --schema received \ - --prefix ${OSMPREFIX}_ \ + --prefix ${NB_OSMPREFIX}_ \ --conf ./mapconfig_highway.xml \ --clean # import the osm with cycleways that the above misses (bug in osm2pgrouting) osm2pgrouting \ - -f $OSMFILE \ - -h $DBHOST \ - --dbname ${DBNAME} \ - --username gis \ + -f $NB_OSMFILE \ + -h $NB_POSTGRESQL_HOST \ + --dbname ${NB_POSTGRESQL_DB} \ + --username ${NB_POSTGRESQL_USER} \ --schema scratch \ - --prefix ${OSMPREFIX}_cycwys_ \ + --prefix ${NB_OSMPREFIX}_cycwys_ \ --conf ./mapconfig_cycleway.xml \ --clean # rename a few tables echo 'Renaming tables' -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE received.${OSMPREFIX}_ways_vertices_pgr RENAME TO ${OSMPREFIX}_ways_intersections;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE received.${OSMPREFIX}_ways_intersections RENAME CONSTRAINT vertex_id TO ${OSMPREFIX}_vertex_id;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE received.osm_nodes RENAME TO ${OSMPREFIX}_osm_nodes;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE received.${OSMPREFIX}_osm_nodes RENAME CONSTRAINT node_id TO ${OSMPREFIX}_node_id;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE received.osm_relations RENAME TO ${OSMPREFIX}_osm_relations;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE received.osm_way_classes RENAME TO ${OSMPREFIX}_osm_way_classes;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE received.${OSMPREFIX}_osm_way_classes RENAME CONSTRAINT osm_way_classes_pkey TO ${OSMPREFIX}_osm_way_classes_pkey;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE received.osm_way_tags RENAME TO ${OSMPREFIX}_osm_way_tags;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE received.osm_way_types RENAME TO ${OSMPREFIX}_osm_way_types;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE received.${OSMPREFIX}_osm_way_types RENAME CONSTRAINT osm_way_types_pkey TO ${OSMPREFIX}_osm_way_types_pkey;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE scratch.${OSMPREFIX}_cycwys_ways_vertices_pgr RENAME CONSTRAINT vertex_id TO ${OSMPREFIX}_vertex_id;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE scratch.osm_nodes RENAME TO ${OSMPREFIX}_cycwys_osm_nodes;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE scratch.${OSMPREFIX}_cycwys_osm_nodes RENAME CONSTRAINT node_id TO ${OSMPREFIX}_node_id;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE scratch.osm_relations RENAME TO ${OSMPREFIX}_cycwys_osm_relations;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE scratch.osm_way_classes RENAME TO ${OSMPREFIX}_cycwys_osm_way_classes;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE scratch.${OSMPREFIX}_cycwys_osm_way_classes RENAME CONSTRAINT osm_way_classes_pkey TO ${OSMPREFIX}_osm_way_classes_pkey;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE scratch.osm_way_tags RENAME TO ${OSMPREFIX}_cycwys_osm_way_tags;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE scratch.osm_way_types RENAME TO ${OSMPREFIX}_cycwys_osm_way_types;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE scratch.${OSMPREFIX}_cycwys_osm_way_types RENAME CONSTRAINT osm_way_types_pkey TO ${OSMPREFIX}_osm_way_types_pkey;" +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ + -c "ALTER TABLE received.${NB_OSMPREFIX}_ways_vertices_pgr RENAME TO ${NB_OSMPREFIX}_ways_intersections;" +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ + -c "ALTER TABLE received.${NB_OSMPREFIX}_ways_intersections RENAME CONSTRAINT vertex_id TO ${NB_OSMPREFIX}_vertex_id;" +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ + -c "ALTER TABLE received.osm_nodes RENAME TO ${NB_OSMPREFIX}_osm_nodes;" +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ + -c "ALTER TABLE received.${NB_OSMPREFIX}_osm_nodes RENAME CONSTRAINT node_id TO ${NB_OSMPREFIX}_node_id;" +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ + -c "ALTER TABLE received.osm_relations RENAME TO ${NB_OSMPREFIX}_osm_relations;" +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ + -c "ALTER TABLE received.osm_way_classes RENAME TO ${NB_OSMPREFIX}_osm_way_classes;" +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ + -c "ALTER TABLE received.${NB_OSMPREFIX}_osm_way_classes RENAME CONSTRAINT osm_way_classes_pkey TO ${NB_OSMPREFIX}_osm_way_classes_pkey;" +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ + -c "ALTER TABLE received.osm_way_tags RENAME TO ${NB_OSMPREFIX}_osm_way_tags;" +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ + -c "ALTER TABLE received.osm_way_types RENAME TO ${NB_OSMPREFIX}_osm_way_types;" +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ + -c "ALTER TABLE received.${NB_OSMPREFIX}_osm_way_types RENAME CONSTRAINT osm_way_types_pkey TO ${NB_OSMPREFIX}_osm_way_types_pkey;" +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ + -c "ALTER TABLE scratch.${NB_OSMPREFIX}_cycwys_ways_vertices_pgr RENAME CONSTRAINT vertex_id TO ${NB_OSMPREFIX}_vertex_id;" +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ + -c "ALTER TABLE scratch.osm_nodes RENAME TO ${NB_OSMPREFIX}_cycwys_osm_nodes;" +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ + -c "ALTER TABLE scratch.${NB_OSMPREFIX}_cycwys_osm_nodes RENAME CONSTRAINT node_id TO ${NB_OSMPREFIX}_node_id;" +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ + -c "ALTER TABLE scratch.osm_relations RENAME TO ${NB_OSMPREFIX}_cycwys_osm_relations;" +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ + -c "ALTER TABLE scratch.osm_way_classes RENAME TO ${NB_OSMPREFIX}_cycwys_osm_way_classes;" +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ + -c "ALTER TABLE scratch.${NB_OSMPREFIX}_cycwys_osm_way_classes RENAME CONSTRAINT osm_way_classes_pkey TO ${NB_OSMPREFIX}_osm_way_classes_pkey;" +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ + -c "ALTER TABLE scratch.osm_way_tags RENAME TO ${NB_OSMPREFIX}_cycwys_osm_way_tags;" +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ + -c "ALTER TABLE scratch.osm_way_types RENAME TO ${NB_OSMPREFIX}_cycwys_osm_way_types;" +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ + -c "ALTER TABLE scratch.${NB_OSMPREFIX}_cycwys_osm_way_types RENAME CONSTRAINT osm_way_types_pkey TO ${NB_OSMPREFIX}_osm_way_types_pkey;" # import full osm to fill out additional data needs # not met by osm2pgrouting # drop old tables echo 'Dropping old tables' -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_full_line;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_full_point;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_full_polygon;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_full_roads;" +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ + -c "DROP TABLE IF EXISTS received.${NB_OSMPREFIX}_osm_full_line;" +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ + -c "DROP TABLE IF EXISTS received.${NB_OSMPREFIX}_osm_full_point;" +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ + -c "DROP TABLE IF EXISTS received.${NB_OSMPREFIX}_osm_full_polygon;" +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ + -c "DROP TABLE IF EXISTS received.${NB_OSMPREFIX}_osm_full_roads;" # import osm2pgsql \ - --host "${DBHOST}" \ - --username gis \ + --host "${NB_POSTGRESQL_HOST}" \ + --username ${NB_POSTGRESQL_USER} \ --port 5432 \ --create \ - --database "${DBNAME}" \ - --prefix "${OSMPREFIX}_osm_full" \ + --database "${NB_POSTGRESQL_DB}" \ + --prefix "${NB_OSMPREFIX}_osm_full" \ --proj 2249 \ --style ./pfb.style \ - "${OSMFILE}" + "${NB_OSMFILE}" # move the full osm tables to the received schema echo 'Moving tables to received schema' -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE generated.${OSMPREFIX}_osm_full_line SET SCHEMA received;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE generated.${OSMPREFIX}_osm_full_point SET SCHEMA received;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE generated.${OSMPREFIX}_osm_full_polygon SET SCHEMA received;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "ALTER TABLE generated.${OSMPREFIX}_osm_full_roads SET SCHEMA received;" +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ + -c "ALTER TABLE generated.${NB_OSMPREFIX}_osm_full_line SET SCHEMA received;" +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ + -c "ALTER TABLE generated.${NB_OSMPREFIX}_osm_full_point SET SCHEMA received;" +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ + -c "ALTER TABLE generated.${NB_OSMPREFIX}_osm_full_polygon SET SCHEMA received;" +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ + -c "ALTER TABLE generated.${NB_OSMPREFIX}_osm_full_roads SET SCHEMA received;" # process tables echo 'Updating field names' -psql -h $DBHOST -U gis -d ${DBNAME} -f ./prepare_tables.sql +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./prepare_tables.sql echo 'Setting values on road segments' -psql -h $DBHOST -U gis -d ${DBNAME} -f ./one_way.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./functional_class.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./paths.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./speed_limit.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./width_ft.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./lanes.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./park.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./bike_infra.sql +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./one_way.sql +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./functional_class.sql +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./paths.sql +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./speed_limit.sql +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./width_ft.sql +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./lanes.sql +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./park.sql +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./bike_infra.sql echo 'Setting values on intersections' -psql -h $DBHOST -U gis -d ${DBNAME} -f ./legs.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./signalized.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./stops.sql +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./legs.sql +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./signalized.sql +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./stops.sql echo 'Calculating stress' -psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_motorway-trunk.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_primary.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_secondary.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_tertiary.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_residential.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_living_street.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_track.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_path.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_one_way_reset.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_motorway-trunk_ints.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_primary_ints.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_secondary_ints.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_tertiary_ints.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_lesser_ints.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./stress_link_ints.sql +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./stress_motorway-trunk.sql +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./stress_primary.sql +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./stress_secondary.sql +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./stress_tertiary.sql +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./stress_residential.sql +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./stress_living_street.sql +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./stress_track.sql +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./stress_path.sql +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./stress_one_way_reset.sql +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./stress_motorway-trunk_ints.sql +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./stress_primary_ints.sql +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./stress_secondary_ints.sql +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./stress_tertiary_ints.sql +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./stress_lesser_ints.sql +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./stress_link_ints.sql From 3d774bcc04801d4d3e07a7d9f5ee562ffe95f8f1 Mon Sep 17 00:00:00 2001 From: Spencer Date: Wed, 26 Oct 2016 14:32:04 -0500 Subject: [PATCH 48/94] add leisure to osm import style so we can grab parks --- pfb.style | 1 + 1 file changed, 1 insertion(+) diff --git a/pfb.style b/pfb.style index f76c13fe..b91839e0 100644 --- a/pfb.style +++ b/pfb.style @@ -101,6 +101,7 @@ node,way junction text linear way lanes text linear way lanes:forward text linear way lanes:backward text linear +node,way leisure text linear,polygon way maxspeed text linear node,way motorcar text linear node,way name text linear From 15f852bcf494798bfe731e4aa25be14d18fa5fb2 Mon Sep 17 00:00:00 2001 From: CloudNiner Date: Thu, 27 Oct 2016 09:45:48 -0400 Subject: [PATCH 49/94] Rename 'cambridge' table prefix to 'neighborhood' Update reflects that this analysis will be run on more generic 'neighborhood' areas in the future, rather than specifically cambridge. Also cleans up postgresql ENV vars in import_osm.sh, run_connectivity.sh and drop_tables.sh to be consistent with other scripts. --- bike_infra.sql | 66 ++--- connectivity/access_jobs.sql | 10 +- connectivity/access_population.sql | 6 +- connectivity/access_recreation.sql | 20 +- connectivity/access_schools.sql | 22 +- connectivity/census_block_jobs.sql | 18 +- connectivity/census_block_roads.sql | 16 +- connectivity/connected_census_blocks.sql | 46 ++-- .../connected_census_blocks_recreation.sql | 54 ++-- .../connected_census_blocks_schools.sql | 48 ++-- connectivity/coverage.sql | 44 ++-- connectivity/overall_scores.sql | 48 ++-- connectivity/reachable_roads_high_stress.sql | 22 +- connectivity/reachable_roads_low_stress.sql | 22 +- connectivity/school_roads.sql | 26 +- connectivity/schools.sql | 30 +-- drop_tables.sh | 99 +++---- functional_class.sql | 170 ++++++------ import_osm.sh | 93 ++++--- lanes.sql | 34 +-- legs.sql | 20 +- one_way.sql | 16 +- park.sql | 22 +- paths.sql | 40 +-- prepare_tables.sql | 222 ++++++++-------- run_connectivity.sh | 41 +-- signalized.sql | 54 ++-- speed_limit.sql | 10 +- stops.sql | 24 +- stress_lesser_ints.sql | 20 +- stress_link_ints.sql | 4 +- stress_living_street.sql | 6 +- stress_motorway-trunk.sql | 6 +- stress_motorway-trunk_ints.sql | 4 +- stress_one_way_reset.sql | 4 +- stress_path.sql | 6 +- stress_primary.sql | 8 +- stress_primary_ints.sql | 4 +- stress_residential.sql | 86 +++--- stress_secondary.sql | 8 +- stress_secondary_ints.sql | 20 +- stress_tertiary.sql | 244 +++++++++--------- stress_tertiary_ints.sql | 20 +- stress_track.sql | 6 +- width_ft.sql | 22 +- 45 files changed, 906 insertions(+), 905 deletions(-) diff --git a/bike_infra.sql b/bike_infra.sql index e3b82947..dde91a1a 100644 --- a/bike_infra.sql +++ b/bike_infra.sql @@ -1,17 +1,17 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -UPDATE cambridge_ways SET ft_bike_infra = NULL, tf_bike_infra = NULL; +UPDATE neighborhood_ways SET ft_bike_infra = NULL, tf_bike_infra = NULL; ---------------------- -- ft direction ---------------------- -- sharrow -UPDATE cambridge_ways +UPDATE neighborhood_ways SET ft_bike_infra = 'sharrow' -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id AND ( osm."cycleway:both" = 'shared_lane' OR (COALESCE(one_way_car,'ft') = 'ft' AND osm.cycleway = 'shared_lane') @@ -20,10 +20,10 @@ AND ( ); -- lane -UPDATE cambridge_ways +UPDATE neighborhood_ways SET ft_bike_infra = 'lane' -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id AND ( osm."cycleway:both" = 'lane' OR (COALESCE(one_way_car,'ft') = 'ft' AND osm.cycleway = 'lane') @@ -34,10 +34,10 @@ AND ( ); -- buffered lane -UPDATE cambridge_ways +UPDATE neighborhood_ways SET ft_bike_infra = 'buffered_lane' -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id AND ( osm."cycleway:both" = 'buffered_lane' OR (COALESCE(one_way_car,'ft') = 'ft' AND osm.cycleway = 'buffered_lane') @@ -53,10 +53,10 @@ AND ( ); -- track -UPDATE cambridge_ways +UPDATE neighborhood_ways SET ft_bike_infra = 'track' -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id AND ( osm."cycleway:both" = 'track' OR (osm."cycleway:right" = 'track' AND osm."oneway:bicycle" = 'no') @@ -74,10 +74,10 @@ AND ( -- tf direction ---------------------- -- sharrow -UPDATE cambridge_ways +UPDATE neighborhood_ways SET tf_bike_infra = 'sharrow' -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id AND ( osm."cycleway:both" = 'shared_lane' OR (COALESCE(one_way_car,'tf') = 'tf' AND osm.cycleway = 'shared_lane') @@ -86,10 +86,10 @@ AND ( ); -- lane -UPDATE cambridge_ways +UPDATE neighborhood_ways SET tf_bike_infra = 'lane' -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id AND ( osm."cycleway:both" = 'lane' OR (COALESCE(one_way_car,'tf') = 'tf' AND osm.cycleway = 'lane') @@ -100,10 +100,10 @@ AND ( ); -- buffered lane -UPDATE cambridge_ways +UPDATE neighborhood_ways SET tf_bike_infra = 'buffered_lane' -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id AND ( osm."cycleway:both" = 'buffered_lane' OR (COALESCE(one_way_car,'tf') = 'tf' AND osm.cycleway = 'buffered_lane') @@ -119,10 +119,10 @@ AND ( ); -- track -UPDATE cambridge_ways +UPDATE neighborhood_ways SET tf_bike_infra = 'track' -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id AND ( osm."cycleway:both" = 'track' OR (osm."cycleway:left" = 'track' AND osm."oneway:bicycle" = 'no') @@ -136,17 +136,17 @@ AND ( ); -- update one_way based on bike infra -UPDATE cambridge_ways +UPDATE neighborhood_ways SET one_way = NULL; -UPDATE cambridge_ways +UPDATE neighborhood_ways SET one_way = one_way_car -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id AND one_way_car = 'ft' AND NOT (tf_bike_infra IS NOT NULL OR COALESCE(osm."oneway:bicycle",'yes') = 'no'); -UPDATE cambridge_ways +UPDATE neighborhood_ways SET one_way = one_way_car -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id AND one_way_car = 'tf' AND NOT (ft_bike_infra IS NOT NULL OR COALESCE(osm."oneway:bicycle",'yes') = 'no'); diff --git a/connectivity/access_jobs.sql b/connectivity/access_jobs.sql index 895c5c2d..8924744b 100644 --- a/connectivity/access_jobs.sql +++ b/connectivity/access_jobs.sql @@ -1,15 +1,15 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -- low stress access UPDATE neighborhood_census_blocks SET emp_low_stress = ( SELECT SUM(blocks2.jobs) - FROM cambridge_census_block_jobs blocks2 + FROM neighborhood_census_block_jobs blocks2 WHERE EXISTS ( SELECT 1 - FROM cambridge_connected_census_blocks cb + FROM neighborhood_connected_census_blocks cb WHERE cb.source_blockid10 = neighborhood_census_blocks.blockid10 AND cb.target_blockid10 = blocks2.blockid10 AND cb.low_stress @@ -25,10 +25,10 @@ WHERE EXISTS ( UPDATE neighborhood_census_blocks SET emp_high_stress = ( SELECT SUM(blocks2.jobs) - FROM cambridge_census_block_jobs blocks2 + FROM neighborhood_census_block_jobs blocks2 WHERE EXISTS ( SELECT 1 - FROM cambridge_connected_census_blocks cb + FROM neighborhood_connected_census_blocks cb WHERE cb.source_blockid10 = neighborhood_census_blocks.blockid10 AND cb.target_blockid10 = blocks2.blockid10 ) diff --git a/connectivity/access_population.sql b/connectivity/access_population.sql index 3374f3be..86f6e397 100644 --- a/connectivity/access_population.sql +++ b/connectivity/access_population.sql @@ -1,6 +1,6 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -- low stress access UPDATE neighborhood_census_blocks @@ -9,7 +9,7 @@ SET pop_low_stress = ( FROM neighborhood_census_blocks blocks2 WHERE EXISTS ( SELECT 1 - FROM cambridge_connected_census_blocks cb + FROM neighborhood_connected_census_blocks cb WHERE cb.source_blockid10 = neighborhood_census_blocks.blockid10 AND cb.target_blockid10 = blocks2.blockid10 AND cb.low_stress @@ -28,7 +28,7 @@ SET pop_high_stress = ( FROM neighborhood_census_blocks blocks2 WHERE EXISTS ( SELECT 1 - FROM cambridge_connected_census_blocks cb + FROM neighborhood_connected_census_blocks cb WHERE cb.source_blockid10 = neighborhood_census_blocks.blockid10 AND cb.target_blockid10 = blocks2.blockid10 ) diff --git a/connectivity/access_recreation.sql b/connectivity/access_recreation.sql index 8129e5b7..8846c648 100644 --- a/connectivity/access_recreation.sql +++ b/connectivity/access_recreation.sql @@ -1,26 +1,26 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -- low stress access -UPDATE cambridge_census_blocks +UPDATE neighborhood_census_blocks SET rec_low_stress = ( SELECT COUNT(path_id) - FROM cambridge_paths + FROM neighborhood_paths WHERE EXISTS ( SELECT 1 - FROM cambridge_census_block_roads cbr, - cambridge_reachable_roads_low_stress ls, - cambridge_ways, - cambridge_paths - WHERE cb.source_blockid10 = cambridge_census_blocks.blockid10 + FROM neighborhood_census_block_roads cbr, + neighborhood_reachable_roads_low_stress ls, + neighborhood_ways, + neighborhood_paths + WHERE cb.source_blockid10 = neighborhood_census_blocks.blockid10 AND cb.target_blockid10 = blocks2.blockid10 AND cb.low_stress ) ) WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) + FROM neighborhood_zip_codes zips + WHERE ST_Intersects(neighborhood_census_blocks.geom,zips.geom) AND zips.zip_code = '02138' ); diff --git a/connectivity/access_schools.sql b/connectivity/access_schools.sql index d63aa04d..d584ccd3 100644 --- a/connectivity/access_schools.sql +++ b/connectivity/access_schools.sql @@ -1,12 +1,12 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -- low stress access UPDATE neighborhood_census_blocks SET schools_low_stress = ( SELECT COUNT(cbs.id) - FROM cambridge_connected_census_blocks_schools cbs + FROM neighborhood_connected_census_blocks_schools cbs WHERE cbs.source_blockid10 = neighborhood_census_blocks.blockid10 AND cbs.low_stress ) @@ -20,7 +20,7 @@ WHERE EXISTS ( UPDATE neighborhood_census_blocks SET schools_high_stress = ( SELECT COUNT(cbs.id) - FROM cambridge_connected_census_blocks_schools cbs + FROM neighborhood_connected_census_blocks_schools cbs WHERE cbs.source_blockid10 = neighborhood_census_blocks.blockid10 ) WHERE EXISTS ( @@ -30,32 +30,32 @@ WHERE EXISTS ( ); -- low stress population shed for schools in neighborhood -UPDATE cambridge_schools +UPDATE neighborhood_schools SET pop_low_stress = ( SELECT SUM(cb.pop10) FROM neighborhood_census_blocks cb, - cambridge_connected_census_blocks_schools cbs + neighborhood_connected_census_blocks_schools cbs WHERE cb.blockid10 = cbs.source_blockid10 - AND cambridge_schools.id = cbs.target_school_id + AND neighborhood_schools.id = cbs.target_school_id AND cbs.low_stress ) WHERE EXISTS ( SELECT 1 FROM neighborhood_boundary as b - WHERE ST_Intersects(cambridge_schools.geom_pt,b.geom) + WHERE ST_Intersects(neighborhood_schools.geom_pt,b.geom) ); -- high stress population shed for schools in neighborhood -UPDATE cambridge_schools +UPDATE neighborhood_schools SET pop_high_stress = ( SELECT SUM(cb.pop10) FROM neighborhood_census_blocks cb, - cambridge_connected_census_blocks_schools cbs + neighborhood_connected_census_blocks_schools cbs WHERE cb.blockid10 = cbs.source_blockid10 - AND cambridge_schools.id = cbs.target_school_id + AND neighborhood_schools.id = cbs.target_school_id ) WHERE EXISTS ( SELECT 1 FROM neighborhood_boundary as b - WHERE ST_Intersects(cambridge_schools.geom_pt,b.geom) + WHERE ST_Intersects(neighborhood_schools.geom_pt,b.geom) ); diff --git a/connectivity/census_block_jobs.sql b/connectivity/census_block_jobs.sql index cda01ae4..bffd8994 100644 --- a/connectivity/census_block_jobs.sql +++ b/connectivity/census_block_jobs.sql @@ -1,6 +1,6 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood -- data downloaded from http://lehd.ces.census.gov/data/ -- or http://lehd.ces.census.gov/data/lodes/LODES7/ -- "ma_od_main_JT00_2014".csv @@ -24,37 +24,37 @@ ANALYZE "state_od_aux_JT00_2014" (w_geocode); ANALYZE "state_od_main_JT00_2014" (w_geocode); -- create combined table -CREATE TABLE generated.cambridge_census_block_jobs ( +CREATE TABLE generated.neighborhood_census_block_jobs ( id SERIAL PRIMARY KEY, blockid10 VARCHAR(15), jobs INT ); -- add blocks of interest -INSERT INTO generated.cambridge_census_block_jobs (blockid10) +INSERT INTO generated.neighborhood_census_block_jobs (blockid10) SELECT blocks.blockid10 FROM neighborhood_census_blocks blocks; -- add main data -UPDATE generated.cambridge_census_block_jobs +UPDATE generated.neighborhood_census_block_jobs SET jobs = COALESCE(( SELECT SUM(j."S000") FROM "state_od_main_JT00_2014" j - WHERE j.w_geocode = cambridge_census_block_jobs.blockid10 + WHERE j.w_geocode = neighborhood_census_block_jobs.blockid10 ),0); -- add aux data -UPDATE generated.cambridge_census_block_jobs +UPDATE generated.neighborhood_census_block_jobs SET jobs = jobs + COALESCE(( SELECT SUM(j."S000") FROM "state_od_aux_JT00_2014" j - WHERE j.w_geocode = cambridge_census_block_jobs.blockid10 + WHERE j.w_geocode = neighborhood_census_block_jobs.blockid10 ),0); -- indexes -CREATE INDEX idx_cambridge_blkjobs ON cambridge_census_block_jobs (blockid10); -ANALYZE cambridge_census_block_jobs (blockid10); +CREATE INDEX idx_neighborhood_blkjobs ON neighborhood_census_block_jobs (blockid10); +ANALYZE neighborhood_census_block_jobs (blockid10); -- drop import tables -- DROP TABLE IF EXISTS "state_od_aux_JT00_2014"; diff --git a/connectivity/census_block_roads.sql b/connectivity/census_block_roads.sql index d50964dc..f17cc004 100644 --- a/connectivity/census_block_roads.sql +++ b/connectivity/census_block_roads.sql @@ -1,25 +1,25 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -DROP TABLE IF EXISTS generated.cambridge_census_block_roads; +DROP TABLE IF EXISTS generated.neighborhood_census_block_roads; -CREATE TABLE generated.cambridge_census_block_roads ( +CREATE TABLE generated.neighborhood_census_block_roads ( id SERIAL PRIMARY KEY, blockid10 VARCHAR(15), road_id INT ); -INSERT INTO generated.cambridge_census_block_roads ( +INSERT INTO generated.neighborhood_census_block_roads ( blockid10, road_id ) SELECT blocks.blockid10, ways.road_id FROM neighborhood_census_blocks blocks, - cambridge_ways ways + neighborhood_ways ways WHERE ST_DWithin(blocks.geom,ways.geom,50); -CREATE INDEX idx_cambridge_censblkrds -ON generated.cambridge_census_block_roads (blockid10,road_id); -ANALYZE generated.cambridge_census_block_roads; +CREATE INDEX idx_neighborhood_censblkrds +ON generated.neighborhood_census_block_roads (blockid10,road_id); +ANALYZE generated.neighborhood_census_block_roads; diff --git a/connectivity/connected_census_blocks.sql b/connectivity/connected_census_blocks.sql index c93d2cc5..842d5601 100644 --- a/connectivity/connected_census_blocks.sql +++ b/connectivity/connected_census_blocks.sql @@ -1,10 +1,10 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -DROP TABLE IF EXISTS generated.cambridge_connected_census_blocks; +DROP TABLE IF EXISTS generated.neighborhood_connected_census_blocks; -CREATE TABLE generated.cambridge_connected_census_blocks ( +CREATE TABLE generated.neighborhood_connected_census_blocks ( id SERIAL PRIMARY KEY, source_blockid10 VARCHAR(15), target_blockid10 VARCHAR(15), @@ -14,7 +14,7 @@ CREATE TABLE generated.cambridge_connected_census_blocks ( high_stress_cost INT ); -INSERT INTO generated.cambridge_connected_census_blocks ( -- took 2 hrs on the server +INSERT INTO generated.neighborhood_connected_census_blocks ( -- took 2 hrs on the server source_blockid10, target_blockid10, low_stress, high_stress ) SELECT source_block.blockid10, @@ -31,9 +31,9 @@ WHERE EXISTS ( AND source_block.geom <#> target_block.geom < 11000 AND EXISTS ( SELECT 1 - FROM cambridge_census_block_roads source_br, - cambridge_census_block_roads target_br, - cambridge_reachable_roads_high_stress hs + FROM neighborhood_census_block_roads source_br, + neighborhood_census_block_roads target_br, + neighborhood_reachable_roads_high_stress hs WHERE source_block.blockid10 = source_br.blockid10 AND target_block.blockid10 = target_br.blockid10 AND hs.base_road = source_br.road_id @@ -41,18 +41,18 @@ AND EXISTS ( ); -- block pair index -CREATE INDEX idx_cambridge_blockpairs -ON cambridge_connected_census_blocks (source_blockid10,target_blockid10); -ANALYZE cambridge_connected_census_blocks (source_blockid10,target_blockid10); +CREATE INDEX idx_neighborhood_blockpairs +ON neighborhood_connected_census_blocks (source_blockid10,target_blockid10); +ANALYZE neighborhood_connected_census_blocks (source_blockid10,target_blockid10); -- low stress -UPDATE cambridge_connected_census_blocks +UPDATE neighborhood_connected_census_blocks SET low_stress = 't'::BOOLEAN WHERE EXISTS ( SELECT 1 - FROM cambridge_census_block_roads source_br, - cambridge_census_block_roads target_br, - cambridge_reachable_roads_low_stress ls + FROM neighborhood_census_block_roads source_br, + neighborhood_census_block_roads target_br, + neighborhood_reachable_roads_low_stress ls WHERE source_blockid10 = source_br.blockid10 AND target_blockid10 = target_br.blockid10 AND ls.base_road = source_br.road_id @@ -60,9 +60,9 @@ WHERE EXISTS ( ) AND ( SELECT MIN(total_cost) - FROM cambridge_census_block_roads source_br, - cambridge_census_block_roads target_br, - cambridge_reachable_roads_low_stress ls + FROM neighborhood_census_block_roads source_br, + neighborhood_census_block_roads target_br, + neighborhood_reachable_roads_low_stress ls WHERE source_blockid10 = source_br.blockid10 AND target_blockid10 = target_br.blockid10 AND ls.base_road = source_br.road_id @@ -70,9 +70,9 @@ AND ( )::FLOAT / COALESCE(( SELECT MIN(total_cost) + 1 - FROM cambridge_census_block_roads source_br, - cambridge_census_block_roads target_br, - cambridge_reachable_roads_high_stress hs + FROM neighborhood_census_block_roads source_br, + neighborhood_census_block_roads target_br, + neighborhood_reachable_roads_high_stress hs WHERE source_blockid10 = source_br.blockid10 AND target_blockid10 = target_br.blockid10 AND hs.base_road = source_br.road_id @@ -80,6 +80,6 @@ AND ( ),11000) <= 1.3; -- stress index -CREATE INDEX idx_cambridge_blockpairs_lstress ON cambridge_connected_census_blocks (low_stress); -CREATE INDEX idx_cambridge_blockpairs_hstress ON cambridge_connected_census_blocks (high_stress); -ANALYZE cambridge_connected_census_blocks (low_stress,high_stress); +CREATE INDEX idx_neighborhood_blockpairs_lstress ON neighborhood_connected_census_blocks (low_stress); +CREATE INDEX idx_neighborhood_blockpairs_hstress ON neighborhood_connected_census_blocks (high_stress); +ANALYZE neighborhood_connected_census_blocks (low_stress,high_stress); diff --git a/connectivity/connected_census_blocks_recreation.sql b/connectivity/connected_census_blocks_recreation.sql index eba9c7ab..cff8b0b1 100644 --- a/connectivity/connected_census_blocks_recreation.sql +++ b/connectivity/connected_census_blocks_recreation.sql @@ -1,10 +1,10 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -DROP TABLE IF EXISTS generated.cambridge_connected_census_blocks_recreation; +DROP TABLE IF EXISTS generated.neighborhood_connected_census_blocks_recreation; -CREATE TABLE generated.cambridge_connected_census_blocks_recreation ( +CREATE TABLE generated.neighborhood_connected_census_blocks_recreation ( id SERIAL PRIMARY KEY, source_blockid10 VARCHAR(15), target_path_id INT, @@ -14,27 +14,27 @@ CREATE TABLE generated.cambridge_connected_census_blocks_recreation ( high_stress_cost INT ); -INSERT INTO generated.cambridge_connected_census_blocks_recreation ( +INSERT INTO generated.neighborhood_connected_census_blocks_recreation ( source_blockid10, target_school_id, low_stress, high_stress ) SELECT blocks.blockid10, paths.path_id, 'f'::BOOLEAN, 't'::BOOLEAN -FROM cambridge_census_blocks blocks, - cambridge_paths paths +FROM neighborhood_census_blocks blocks, + neighborhood_paths paths WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips + FROM neighborhood_zip_codes zips WHERE ST_Intersects(blocks.geom,zips.geom) AND zips.zip_code = '02138' ) AND blocks.geom <#> paths.geom < 11000 AND EXISTS ( SELECT 1 - FROM cambridge_census_block_roads source_br, - cambridge_ways target_r, - cambridge_reachable_roads_high_stress hs + FROM neighborhood_census_block_roads source_br, + neighborhood_ways target_r, + neighborhood_reachable_roads_high_stress hs WHERE blocks.blockid10 = source_br.blockid10 AND paths.path_id = target_r.path_id AND hs.base_road = source_br.road_id @@ -45,21 +45,21 @@ AND EXISTS ( - + -- block pair index -CREATE INDEX idx_cambridge_blockschoolpairs -ON cambridge_connected_census_blocks_recreation (source_blockid10,target_school_id); -ANALYZE cambridge_connected_census_blocks_recreation (source_blockid10,target_school_id); +CREATE INDEX idx_neighborhood_blockschoolpairs +ON neighborhood_connected_census_blocks_recreation (source_blockid10,target_school_id); +ANALYZE neighborhood_connected_census_blocks_recreation (source_blockid10,target_school_id); -- low stress -UPDATE cambridge_connected_census_blocks_recreation +UPDATE neighborhood_connected_census_blocks_recreation SET low_stress = 't'::BOOLEAN WHERE EXISTS ( SELECT 1 - FROM cambridge_census_block_roads source_br, - cambridge_school_roads target_sr, - cambridge_reachable_roads_low_stress ls + FROM neighborhood_census_block_roads source_br, + neighborhood_school_roads target_sr, + neighborhood_reachable_roads_low_stress ls WHERE source_blockid10 = source_br.blockid10 AND target_school_id = target_sr.school_id AND ls.base_road = source_br.road_id @@ -67,9 +67,9 @@ WHERE EXISTS ( ) AND ( SELECT MIN(total_cost) - FROM cambridge_census_block_roads source_br, - cambridge_school_roads target_sr, - cambridge_reachable_roads_low_stress ls + FROM neighborhood_census_block_roads source_br, + neighborhood_school_roads target_sr, + neighborhood_reachable_roads_low_stress ls WHERE source_blockid10 = source_br.blockid10 AND target_school_id = target_sr.school_id AND ls.base_road = source_br.road_id @@ -77,9 +77,9 @@ AND ( )::FLOAT / COALESCE(( SELECT MIN(total_cost) + 1 - FROM cambridge_census_block_roads source_br, - cambridge_school_roads target_sr, - cambridge_reachable_roads_high_stress hs + FROM neighborhood_census_block_roads source_br, + neighborhood_school_roads target_sr, + neighborhood_reachable_roads_high_stress hs WHERE source_blockid10 = source_br.blockid10 AND target_school_id = target_sr.school_id AND hs.base_road = source_br.road_id @@ -87,6 +87,6 @@ AND ( ),11000) <= 1.3; -- stress index -CREATE INDEX idx_cambridge_blockschl_lstress ON cambridge_connected_census_blocks_recreation (low_stress); -CREATE INDEX idx_cambridge_blockschl_hstress ON cambridge_connected_census_blocks_recreation (high_stress); -ANALYZE cambridge_connected_census_blocks_recreation (low_stress,high_stress); +CREATE INDEX idx_neighborhood_blockschl_lstress ON neighborhood_connected_census_blocks_recreation (low_stress); +CREATE INDEX idx_neighborhood_blockschl_hstress ON neighborhood_connected_census_blocks_recreation (high_stress); +ANALYZE neighborhood_connected_census_blocks_recreation (low_stress,high_stress); diff --git a/connectivity/connected_census_blocks_schools.sql b/connectivity/connected_census_blocks_schools.sql index 7b7ad4e9..5f6fee53 100644 --- a/connectivity/connected_census_blocks_schools.sql +++ b/connectivity/connected_census_blocks_schools.sql @@ -1,10 +1,10 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -DROP TABLE IF EXISTS generated.cambridge_connected_census_blocks_schools; +DROP TABLE IF EXISTS generated.neighborhood_connected_census_blocks_schools; -CREATE TABLE generated.cambridge_connected_census_blocks_schools ( +CREATE TABLE generated.neighborhood_connected_census_blocks_schools ( id SERIAL PRIMARY KEY, source_blockid10 VARCHAR(15), target_school_id INT, @@ -14,7 +14,7 @@ CREATE TABLE generated.cambridge_connected_census_blocks_schools ( high_stress_cost INT ); -INSERT INTO generated.cambridge_connected_census_blocks_schools ( +INSERT INTO generated.neighborhood_connected_census_blocks_schools ( source_blockid10, target_school_id, low_stress, high_stress ) SELECT blocks.blockid10, @@ -22,7 +22,7 @@ SELECT blocks.blockid10, 'f'::BOOLEAN, 't'::BOOLEAN FROM neighborhood_census_blocks blocks, - cambridge_schools schools + neighborhood_schools schools WHERE EXISTS ( SELECT 1 FROM neighborhood_boundary AS b @@ -31,9 +31,9 @@ WHERE EXISTS ( AND blocks.geom <#> schools.geom_pt < 11000 AND EXISTS ( SELECT 1 - FROM cambridge_census_block_roads source_br, - cambridge_school_roads target_sr, - cambridge_reachable_roads_high_stress hs + FROM neighborhood_census_block_roads source_br, + neighborhood_school_roads target_sr, + neighborhood_reachable_roads_high_stress hs WHERE blocks.blockid10 = source_br.blockid10 AND schools.id = target_sr.school_id AND hs.base_road = source_br.road_id @@ -41,18 +41,18 @@ AND EXISTS ( ); -- block pair index -CREATE INDEX idx_cambridge_blockschoolpairs -ON cambridge_connected_census_blocks_schools (source_blockid10,target_school_id); -ANALYZE cambridge_connected_census_blocks_schools (source_blockid10,target_school_id); +CREATE INDEX idx_neighborhood_blockschoolpairs +ON neighborhood_connected_census_blocks_schools (source_blockid10,target_school_id); +ANALYZE neighborhood_connected_census_blocks_schools (source_blockid10,target_school_id); -- low stress -UPDATE cambridge_connected_census_blocks_schools +UPDATE neighborhood_connected_census_blocks_schools SET low_stress = 't'::BOOLEAN WHERE EXISTS ( SELECT 1 - FROM cambridge_census_block_roads source_br, - cambridge_school_roads target_sr, - cambridge_reachable_roads_low_stress ls + FROM neighborhood_census_block_roads source_br, + neighborhood_school_roads target_sr, + neighborhood_reachable_roads_low_stress ls WHERE source_blockid10 = source_br.blockid10 AND target_school_id = target_sr.school_id AND ls.base_road = source_br.road_id @@ -60,9 +60,9 @@ WHERE EXISTS ( ) AND ( SELECT MIN(total_cost) - FROM cambridge_census_block_roads source_br, - cambridge_school_roads target_sr, - cambridge_reachable_roads_low_stress ls + FROM neighborhood_census_block_roads source_br, + neighborhood_school_roads target_sr, + neighborhood_reachable_roads_low_stress ls WHERE source_blockid10 = source_br.blockid10 AND target_school_id = target_sr.school_id AND ls.base_road = source_br.road_id @@ -70,9 +70,9 @@ AND ( )::FLOAT / COALESCE(( SELECT MIN(total_cost) + 1 - FROM cambridge_census_block_roads source_br, - cambridge_school_roads target_sr, - cambridge_reachable_roads_high_stress hs + FROM neighborhood_census_block_roads source_br, + neighborhood_school_roads target_sr, + neighborhood_reachable_roads_high_stress hs WHERE source_blockid10 = source_br.blockid10 AND target_school_id = target_sr.school_id AND hs.base_road = source_br.road_id @@ -80,6 +80,6 @@ AND ( ),11000) <= 1.3; -- stress index -CREATE INDEX idx_cambridge_blockschl_lstress ON cambridge_connected_census_blocks_schools (low_stress); -CREATE INDEX idx_cambridge_blockschl_hstress ON cambridge_connected_census_blocks_schools (high_stress); -ANALYZE cambridge_connected_census_blocks_schools (low_stress,high_stress); +CREATE INDEX idx_neighborhood_blockschl_lstress ON neighborhood_connected_census_blocks_schools (low_stress); +CREATE INDEX idx_neighborhood_blockschl_hstress ON neighborhood_connected_census_blocks_schools (high_stress); +ANALYZE neighborhood_connected_census_blocks_schools (low_stress,high_stress); diff --git a/connectivity/coverage.sql b/connectivity/coverage.sql index 4d8fe048..c51388ac 100644 --- a/connectivity/coverage.sql +++ b/connectivity/coverage.sql @@ -1,22 +1,22 @@ -SELECT r.road_id, - r.geom, - COUNT(sheds.node) AS ct -FROM cambridge_ways_net_vert v, - cambridge_ways r, - cambridge_boundary, - pgr_drivingDistance(' - SELECT link_id AS id, - source_vert AS source, - target_vert AS target, - link_cost AS cost - FROM cambridge_ways_net_link - WHERE link_stress = 1', - v.vert_id, - 10560, - directed := true - ) sheds -WHERE ST_Intersects(r.geom,cambridge_boundary.geom) -AND v.road_id = r.road_id ---and v.road_id = 1467 -GROUP BY r.road_id, - r.geom; +SELECT r.road_id, + r.geom, + COUNT(sheds.node) AS ct +FROM neighborhood_ways_net_vert v, + neighborhood_ways r, + neighborhood_boundary, + pgr_drivingDistance(' + SELECT link_id AS id, + source_vert AS source, + target_vert AS target, + link_cost AS cost + FROM neighborhood_ways_net_link + WHERE link_stress = 1', + v.vert_id, + 10560, + directed := true + ) sheds +WHERE ST_Intersects(r.geom,neighborhood_boundary.geom) +AND v.road_id = r.road_id +--and v.road_id = 1467 +GROUP BY r.road_id, + r.geom; diff --git a/connectivity/overall_scores.sql b/connectivity/overall_scores.sql index e779c77b..1cab6b6c 100644 --- a/connectivity/overall_scores.sql +++ b/connectivity/overall_scores.sql @@ -1,10 +1,10 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -DROP TABLE IF EXISTS generated.cambridge_overall_scores; +DROP TABLE IF EXISTS generated.neighborhood_overall_scores; -CREATE TABLE generated.cambridge_overall_scores ( +CREATE TABLE generated.neighborhood_overall_scores ( id SERIAL PRIMARY KEY, category TEXT, score_name TEXT, @@ -13,7 +13,7 @@ CREATE TABLE generated.cambridge_overall_scores ( ); -- median pop access low stress -INSERT INTO generated.cambridge_overall_scores ( +INSERT INTO generated.neighborhood_overall_scores ( category, score_name, score, notes ) SELECT 'Population', @@ -30,7 +30,7 @@ WHERE EXISTS ( ); -- median pop access high stress -INSERT INTO generated.cambridge_overall_scores ( +INSERT INTO generated.neighborhood_overall_scores ( category, score_name, score, notes ) SELECT 'Population', @@ -47,7 +47,7 @@ WHERE EXISTS ( ); -- median pop access ratio -INSERT INTO generated.cambridge_overall_scores ( +INSERT INTO generated.neighborhood_overall_scores ( category, score_name, score, notes ) SELECT 'Population', @@ -65,7 +65,7 @@ WHERE EXISTS ( ); -- 70th percentile pop access ratio -INSERT INTO generated.cambridge_overall_scores ( +INSERT INTO generated.neighborhood_overall_scores ( category, score_name, score, notes ) SELECT 'Population', @@ -83,7 +83,7 @@ WHERE EXISTS ( ); -- avg pop access ratio -INSERT INTO generated.cambridge_overall_scores ( +INSERT INTO generated.neighborhood_overall_scores ( category, score_name, score, notes ) SELECT 'Population', @@ -101,7 +101,7 @@ WHERE EXISTS ( ); -- median jobs access low stress -INSERT INTO generated.cambridge_overall_scores ( +INSERT INTO generated.neighborhood_overall_scores ( category, score_name, score, notes ) SELECT 'Employment', @@ -118,7 +118,7 @@ WHERE EXISTS ( ); -- median jobs access high stress -INSERT INTO generated.cambridge_overall_scores ( +INSERT INTO generated.neighborhood_overall_scores ( category, score_name, score, notes ) SELECT 'Employment', @@ -135,7 +135,7 @@ WHERE EXISTS ( ); -- median jobs access ratio -INSERT INTO generated.cambridge_overall_scores ( +INSERT INTO generated.neighborhood_overall_scores ( category, score_name, score, notes ) SELECT 'Employment', @@ -153,7 +153,7 @@ WHERE EXISTS ( ); -- 70th percentile jobs access ratio -INSERT INTO generated.cambridge_overall_scores ( +INSERT INTO generated.neighborhood_overall_scores ( category, score_name, score, notes ) SELECT 'Employment', @@ -171,7 +171,7 @@ WHERE EXISTS ( ); -- avg jobs access ratio -INSERT INTO generated.cambridge_overall_scores ( +INSERT INTO generated.neighborhood_overall_scores ( category, score_name, score, notes ) SELECT 'Employment', @@ -189,7 +189,7 @@ WHERE EXISTS ( ); -- median schools access low stress -INSERT INTO generated.cambridge_overall_scores ( +INSERT INTO generated.neighborhood_overall_scores ( category, score_name, score, notes ) SELECT 'Schools', @@ -206,7 +206,7 @@ WHERE EXISTS ( ); -- median schools access high stress -INSERT INTO generated.cambridge_overall_scores ( +INSERT INTO generated.neighborhood_overall_scores ( category, score_name, score, notes ) SELECT 'Schools', @@ -223,7 +223,7 @@ WHERE EXISTS ( ); -- school low stress pop shed access -INSERT INTO generated.cambridge_overall_scores ( +INSERT INTO generated.neighborhood_overall_scores ( category, score_name, score, notes ) SELECT 'Schools', @@ -232,15 +232,15 @@ SELECT 'Schools', regexp_replace('Population with low stress access to schools in the neighborhood expressed as an average of all schools in the neighborhood','\n\s+',' ') -FROM cambridge_schools +FROM neighborhood_schools WHERE EXISTS ( SELECT 1 FROM neighborhood_boundary AS b - WHERE ST_Intersects(cambridge_schools.geom_pt,b.geom) + WHERE ST_Intersects(neighborhood_schools.geom_pt,b.geom) ); -- school high stress pop shed access -INSERT INTO generated.cambridge_overall_scores ( +INSERT INTO generated.neighborhood_overall_scores ( category, score_name, score, notes ) SELECT 'Schools', @@ -249,15 +249,15 @@ SELECT 'Schools', regexp_replace('Population with high stress access to schools in the neighborhood expressed as an average of all schools in the neighborhood','\n\s+',' ') -FROM cambridge_schools +FROM neighborhood_schools WHERE EXISTS ( SELECT 1 FROM neighborhood_boundary AS b - WHERE ST_Intersects(cambridge_schools.geom_pt,b.geom) + WHERE ST_Intersects(neighborhood_schools.geom_pt,b.geom) ); -- school pop shed access ratio -INSERT INTO generated.cambridge_overall_scores ( +INSERT INTO generated.neighborhood_overall_scores ( category, score_name, score, notes ) SELECT 'Schools', @@ -267,9 +267,9 @@ SELECT 'Schools', access to schools to population with high stress access in the neighborhood expressed as an average of all schools in the neighborhood','\n\s+',' ') -FROM cambridge_schools +FROM neighborhood_schools WHERE EXISTS ( SELECT 1 FROM neighborhood_boundary AS b - WHERE ST_Intersects(cambridge_schools.geom_pt,b.geom) + WHERE ST_Intersects(neighborhood_schools.geom_pt,b.geom) ); diff --git a/connectivity/reachable_roads_high_stress.sql b/connectivity/reachable_roads_high_stress.sql index a2a16cc6..14ef6849 100644 --- a/connectivity/reachable_roads_high_stress.sql +++ b/connectivity/reachable_roads_high_stress.sql @@ -1,18 +1,18 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood -- maximum network distsance: 10560 ft ---------------------------------------- -DROP TABLE IF EXISTS generated.cambridge_reachable_roads_high_stress; +DROP TABLE IF EXISTS generated.neighborhood_reachable_roads_high_stress; -CREATE TABLE generated.cambridge_reachable_roads_high_stress ( +CREATE TABLE generated.neighborhood_reachable_roads_high_stress ( id SERIAL PRIMARY KEY, base_road INT, target_road INT, total_cost FLOAT ); -INSERT INTO generated.cambridge_reachable_roads_high_stress ( +INSERT INTO generated.neighborhood_reachable_roads_high_stress ( base_road, target_road, total_cost @@ -20,15 +20,15 @@ INSERT INTO generated.cambridge_reachable_roads_high_stress ( SELECT r1.road_id, v2.road_id, sheds.agg_cost -FROM cambridge_ways r1, - cambridge_ways_net_vert v1, - cambridge_ways_net_vert v2, +FROM neighborhood_ways r1, + neighborhood_ways_net_vert v1, + neighborhood_ways_net_vert v2, pgr_drivingDistance(' SELECT link_id AS id, source_vert AS source, target_vert AS target, link_cost AS cost - FROM cambridge_ways_net_link', + FROM neighborhood_ways_net_link', v1.vert_id, 10560, directed := true @@ -41,6 +41,6 @@ WHERE EXISTS ( AND r1.road_id = v1.road_id AND v2.vert_id = sheds.node; -CREATE INDEX idx_cambridge_rchblrdshistrss_b ON generated.cambridge_reachable_roads_high_stress (base_road); -CREATE INDEX idx_cambridge_rchblrdshistrss_t ON generated.cambridge_reachable_roads_high_stress (target_road); -ANALYZE generated.cambridge_reachable_roads_high_stress (base_road,target_road); +CREATE INDEX idx_neighborhood_rchblrdshistrss_b ON generated.neighborhood_reachable_roads_high_stress (base_road); +CREATE INDEX idx_neighborhood_rchblrdshistrss_t ON generated.neighborhood_reachable_roads_high_stress (target_road); +ANALYZE generated.neighborhood_reachable_roads_high_stress (base_road,target_road); diff --git a/connectivity/reachable_roads_low_stress.sql b/connectivity/reachable_roads_low_stress.sql index afaaaec3..e134b1ae 100644 --- a/connectivity/reachable_roads_low_stress.sql +++ b/connectivity/reachable_roads_low_stress.sql @@ -1,18 +1,18 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood -- maximum network distsance: 10560 ft ---------------------------------------- -DROP TABLE IF EXISTS generated.cambridge_reachable_roads_low_stress; +DROP TABLE IF EXISTS generated.neighborhood_reachable_roads_low_stress; -CREATE TABLE generated.cambridge_reachable_roads_low_stress ( +CREATE TABLE generated.neighborhood_reachable_roads_low_stress ( id SERIAL PRIMARY KEY, base_road INT, target_road INT, total_cost FLOAT ); -INSERT INTO generated.cambridge_reachable_roads_low_stress ( +INSERT INTO generated.neighborhood_reachable_roads_low_stress ( base_road, target_road, total_cost @@ -20,15 +20,15 @@ INSERT INTO generated.cambridge_reachable_roads_low_stress ( SELECT r1.road_id, v2.road_id, sheds.agg_cost -FROM cambridge_ways r1, - cambridge_ways_net_vert v1, - cambridge_ways_net_vert v2, +FROM neighborhood_ways r1, + neighborhood_ways_net_vert v1, + neighborhood_ways_net_vert v2, pgr_drivingDistance(' SELECT link_id AS id, source_vert AS source, target_vert AS target, link_cost AS cost - FROM cambridge_ways_net_link + FROM neighborhood_ways_net_link WHERE link_stress = 1', v1.vert_id, 10560, @@ -42,6 +42,6 @@ WHERE EXISTS ( AND r1.road_id = v1.road_id AND v2.vert_id = sheds.node; -CREATE INDEX idx_cambridge_rchblrdslowstrss_b ON generated.cambridge_reachable_roads_low_stress (base_road); -CREATE INDEX idx_cambridge_rchblrdslowstrss_t ON generated.cambridge_reachable_roads_low_stress (target_road); -ANALYZE generated.cambridge_reachable_roads_low_stress (base_road,target_road); +CREATE INDEX idx_neighborhood_rchblrdslowstrss_b ON generated.neighborhood_reachable_roads_low_stress (base_road); +CREATE INDEX idx_neighborhood_rchblrdslowstrss_t ON generated.neighborhood_reachable_roads_low_stress (target_road); +ANALYZE generated.neighborhood_reachable_roads_low_stress (base_road,target_road); diff --git a/connectivity/school_roads.sql b/connectivity/school_roads.sql index 394c637a..8aac9875 100644 --- a/connectivity/school_roads.sql +++ b/connectivity/school_roads.sql @@ -1,24 +1,24 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -DROP TABLE IF EXISTS generated.cambridge_school_roads; +DROP TABLE IF EXISTS generated.neighborhood_school_roads; -CREATE TABLE generated.cambridge_school_roads ( +CREATE TABLE generated.neighborhood_school_roads ( id SERIAL PRIMARY KEY, school_id INT, road_id INT ); -- polygons take any road within 50 feet -INSERT INTO generated.cambridge_school_roads ( +INSERT INTO generated.neighborhood_school_roads ( school_id, road_id ) SELECT schools.id, ways.road_id -FROM cambridge_schools schools, - cambridge_ways ways +FROM neighborhood_schools schools, + neighborhood_ways ways WHERE EXISTS ( SELECT 1 FROM neighborhood_boundary AS b @@ -28,18 +28,18 @@ AND schools.geom_poly IS NOT NULL AND ST_DWithin(schools.geom_poly,ways.geom,50); -- points take the nearest road -INSERT INTO generated.cambridge_school_roads ( +INSERT INTO generated.neighborhood_school_roads ( school_id, road_id ) SELECT schools.id, ( SELECT ways.road_id - FROM cambridge_ways ways + FROM neighborhood_ways ways ORDER BY ST_Distance(ways.geom,schools.geom_pt) ASC LIMIT 1 ) -FROM cambridge_schools schools +FROM neighborhood_schools schools WHERE EXISTS ( SELECT 1 FROM neighborhood_boundary AS b @@ -47,10 +47,10 @@ WHERE EXISTS ( ) AND NOT EXISTS ( SELECT 1 - FROM cambridge_school_roads r + FROM neighborhood_school_roads r WHERE schools.id = r.school_id ); -CREATE INDEX idx_cambridge_schlrds_schlid ON generated.cambridge_school_roads (school_id); -CREATE INDEX idx_cambridge_schlrds_rdid ON generated.cambridge_school_roads (road_id); -ANALYZE generated.cambridge_school_roads (school_id, road_id); +CREATE INDEX idx_neighborhood_schlrds_schlid ON generated.neighborhood_school_roads (school_id); +CREATE INDEX idx_neighborhood_schlrds_rdid ON generated.neighborhood_school_roads (road_id); +ANALYZE generated.neighborhood_school_roads (school_id, road_id); diff --git a/connectivity/schools.sql b/connectivity/schools.sql index da1648e6..275bd4a4 100644 --- a/connectivity/schools.sql +++ b/connectivity/schools.sql @@ -1,10 +1,10 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -DROP TABLE IF EXISTS generated.cambridge_schools; +DROP TABLE IF EXISTS generated.neighborhood_schools; -CREATE TABLE generated.cambridge_schools ( +CREATE TABLE generated.neighborhood_schools ( id SERIAL PRIMARY KEY, osm_id BIGINT, school_name TEXT, @@ -13,40 +13,40 @@ CREATE TABLE generated.cambridge_schools ( geom_pt geometry(point,2249), geom_poly geometry(polygon,2249) ); -CREATE INDEX sidx_cambridge_schools_geompt ON cambridge_schools USING GIST (geom_pt); -CREATE INDEX sidx_cambridge_schools_geomply ON cambridge_schools USING GIST (geom_poly); +CREATE INDEX sidx_neighborhood_schools_geompt ON neighborhood_schools USING GIST (geom_pt); +CREATE INDEX sidx_neighborhood_schools_geomply ON neighborhood_schools USING GIST (geom_poly); -- insert points from polygons -INSERT INTO generated.cambridge_schools ( +INSERT INTO generated.neighborhood_schools ( osm_id, school_name, geom_pt, geom_poly ) SELECT osm_id, name, ST_Centroid(way), way -FROM cambridge_osm_full_polygon +FROM neighborhood_osm_full_polygon WHERE amenity = 'school'; -- remove subareas that are mistakenly designated as amenity=school -DELETE FROM generated.cambridge_schools +DELETE FROM generated.neighborhood_schools WHERE EXISTS ( SELECT 1 - FROM generated.cambridge_schools s - WHERE ST_Contains(s.geom_poly,cambridge_schools.geom_poly) - AND s.id != generated.cambridge_schools.id + FROM generated.neighborhood_schools s + WHERE ST_Contains(s.geom_poly,neighborhood_schools.geom_poly) + AND s.id != generated.neighborhood_schools.id ); -- insert points -INSERT INTO generated.cambridge_schools ( +INSERT INTO generated.neighborhood_schools ( osm_id, school_name, geom_pt ) SELECT osm_id, name, way -FROM cambridge_osm_full_point +FROM neighborhood_osm_full_point WHERE amenity = 'school' AND NOT EXISTS ( SELECT 1 - FROM cambridge_schools s - WHERE ST_Intersects(s.geom_poly,cambridge_osm_full_point.way) + FROM neighborhood_schools s + WHERE ST_Intersects(s.geom_poly,neighborhood_osm_full_point.way) ); diff --git a/drop_tables.sh b/drop_tables.sh index bdd7ffd3..a7b75eff 100644 --- a/drop_tables.sh +++ b/drop_tables.sh @@ -1,49 +1,50 @@ -#!/usr/bin/env bash - -# vars -DBHOST='192.168.1.144' -DBNAME='people_for_bikes' -OSMPREFIX='cambridge' - -# drop old tables -echo 'Dropping old tables' -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_ways;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_ways_intersections;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_relations_ways;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_nodes;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_relations;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_way_classes;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_way_tags;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_way_types;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_ways;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_ways_vertices_pgr;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_relations_ways;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_osm_nodes;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_osm_relations;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_osm_way_classes;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_osm_way_tags;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS scratch.${OSMPREFIX}_cycwys_osm_way_types;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_full_line;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_full_point;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_full_polygon;" -psql -h $DBHOST -U gis -d ${DBNAME} \ - -c "DROP TABLE IF EXISTS received.${OSMPREFIX}_osm_full_roads;" +#!/usr/bin/env bash + +# vars +NB_POSTGRESQL_HOST="${NB_POSTGRESQL_HOST:-127.0.0.1}" +NB_POSTGRESQL_DB="${NB_POSTGRESQL_DB:-pfb}" +NB_POSTGRESQL_USER="${NB_POSTGRESQL_USER:-gis}" +NB_POSTGRESQL_PASSWORD="${NB_POSTGRESQL_PASSWORD:-gis}" + +# drop old tables +echo 'Dropping old tables' +psql -h "${NB_POSTGRESQL_HOST}" -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_DB}" \ + -c "DROP TABLE IF EXISTS received.neighborhood_ways;" +psql -h "${NB_POSTGRESQL_HOST}" -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_DB}" \ + -c "DROP TABLE IF EXISTS received.neighborhood_ways_intersections;" +psql -h "${NB_POSTGRESQL_HOST}" -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_DB}" \ + -c "DROP TABLE IF EXISTS received.neighborhood_relations_ways;" +psql -h "${NB_POSTGRESQL_HOST}" -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_DB}" \ + -c "DROP TABLE IF EXISTS received.neighborhood_osm_nodes;" +psql -h "${NB_POSTGRESQL_HOST}" -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_DB}" \ + -c "DROP TABLE IF EXISTS received.neighborhood_osm_relations;" +psql -h "${NB_POSTGRESQL_HOST}" -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_DB}" \ + -c "DROP TABLE IF EXISTS received.neighborhood_osm_way_classes;" +psql -h "${NB_POSTGRESQL_HOST}" -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_DB}" \ + -c "DROP TABLE IF EXISTS received.neighborhood_osm_way_tags;" +psql -h "${NB_POSTGRESQL_HOST}" -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_DB}" \ + -c "DROP TABLE IF EXISTS received.neighborhood_osm_way_types;" +psql -h "${NB_POSTGRESQL_HOST}" -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_DB}" \ + -c "DROP TABLE IF EXISTS scratch.neighborhood_cycwys_ways;" +psql -h "${NB_POSTGRESQL_HOST}" -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_DB}" \ + -c "DROP TABLE IF EXISTS scratch.neighborhood_cycwys_ways_vertices_pgr;" +psql -h "${NB_POSTGRESQL_HOST}" -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_DB}" \ + -c "DROP TABLE IF EXISTS scratch.neighborhood_cycwys_relations_ways;" +psql -h "${NB_POSTGRESQL_HOST}" -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_DB}" \ + -c "DROP TABLE IF EXISTS scratch.neighborhood_cycwys_osm_nodes;" +psql -h "${NB_POSTGRESQL_HOST}" -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_DB}" \ + -c "DROP TABLE IF EXISTS scratch.neighborhood_cycwys_osm_relations;" +psql -h "${NB_POSTGRESQL_HOST}" -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_DB}" \ + -c "DROP TABLE IF EXISTS scratch.neighborhood_cycwys_osm_way_classes;" +psql -h "${NB_POSTGRESQL_HOST}" -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_DB}" \ + -c "DROP TABLE IF EXISTS scratch.neighborhood_cycwys_osm_way_tags;" +psql -h "${NB_POSTGRESQL_HOST}" -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_DB}" \ + -c "DROP TABLE IF EXISTS scratch.neighborhood_cycwys_osm_way_types;" +psql -h "${NB_POSTGRESQL_HOST}" -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_DB}" \ + -c "DROP TABLE IF EXISTS received.neighborhood_osm_full_line;" +psql -h "${NB_POSTGRESQL_HOST}" -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_DB}" \ + -c "DROP TABLE IF EXISTS received.neighborhood_osm_full_point;" +psql -h "${NB_POSTGRESQL_HOST}" -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_DB}" \ + -c "DROP TABLE IF EXISTS received.neighborhood_osm_full_polygon;" +psql -h "${NB_POSTGRESQL_HOST}" -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_DB}" \ + -c "DROP TABLE IF EXISTS received.neighborhood_osm_full_roads;" diff --git a/functional_class.sql b/functional_class.sql index b0d8fd53..4601a1a3 100644 --- a/functional_class.sql +++ b/functional_class.sql @@ -1,85 +1,85 @@ ----------------------------------------- --- INPUTS --- location: cambridge ----------------------------------------- -UPDATE cambridge_ways SET functional_class = NULL; - -UPDATE cambridge_ways -SET functional_class = osm.highway -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id -AND osm.highway IN ( - 'motorway', - 'tertiary', - 'trunk', - 'tertiary_link', - 'motorway_link', - 'secondary_link', - 'primary_link', - 'trunk_link', - 'residential', - 'secondary', - 'primary', - 'living_street' -); -- note that we're leaving out "road" - -UPDATE cambridge_ways -SET functional_class = 'tertiary' -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id -AND osm.highway = 'unclassified'; - -UPDATE cambridge_ways -SET functional_class = 'track' -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id -AND osm.highway = 'track' -AND osm.tracktype = 'grade1'; - -UPDATE cambridge_ways -SET functional_class = 'path' -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id -AND osm.highway IN ('cycleway','path'); - -UPDATE cambridge_ways -SET functional_class = 'path' -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id -AND osm.highway = 'footway' -AND osm.bicycle IN ('yes','permissive') -AND (osm.access IS NULL OR osm.access NOT IN ('no','private')); - -UPDATE cambridge_ways -SET functional_class = 'living_street' -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id -AND osm.highway = 'pedestrian' -AND osm.bicycle IN ('yes','permissive') -AND (osm.access IS NULL OR osm.access NOT IN ('no','private')); - --- remove stuff that we don't want to route over -DELETE FROM cambridge_ways WHERE functional_class IS NULL; - --- remove orphans -DELETE FROM cambridge_ways -WHERE NOT EXISTS ( - SELECT 1 - FROM cambridge_ways w - WHERE cambridge_ways.intersection_to IN (w.intersection_to,w.intersection_from) - AND w.road_id != cambridge_ways.road_id -) -AND NOT EXISTS ( - SELECT 1 - FROM cambridge_ways w - WHERE cambridge_ways.intersection_from IN (w.intersection_to,w.intersection_from) - AND w.road_id != cambridge_ways.road_id -); - --- remove obsolete intersections -DELETE FROM cambridge_ways_intersections -WHERE NOT EXISTS ( - SELECT 1 - FROM cambridge_ways w - WHERE int_id IN (w.intersection_to,w.intersection_from) -); +---------------------------------------- +-- INPUTS +-- location: neighborhood +---------------------------------------- +UPDATE neighborhood_ways SET functional_class = NULL; + +UPDATE neighborhood_ways +SET functional_class = osm.highway +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id +AND osm.highway IN ( + 'motorway', + 'tertiary', + 'trunk', + 'tertiary_link', + 'motorway_link', + 'secondary_link', + 'primary_link', + 'trunk_link', + 'residential', + 'secondary', + 'primary', + 'living_street' +); -- note that we're leaving out "road" + +UPDATE neighborhood_ways +SET functional_class = 'tertiary' +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id +AND osm.highway = 'unclassified'; + +UPDATE neighborhood_ways +SET functional_class = 'track' +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id +AND osm.highway = 'track' +AND osm.tracktype = 'grade1'; + +UPDATE neighborhood_ways +SET functional_class = 'path' +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id +AND osm.highway IN ('cycleway','path'); + +UPDATE neighborhood_ways +SET functional_class = 'path' +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id +AND osm.highway = 'footway' +AND osm.bicycle IN ('yes','permissive') +AND (osm.access IS NULL OR osm.access NOT IN ('no','private')); + +UPDATE neighborhood_ways +SET functional_class = 'living_street' +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id +AND osm.highway = 'pedestrian' +AND osm.bicycle IN ('yes','permissive') +AND (osm.access IS NULL OR osm.access NOT IN ('no','private')); + +-- remove stuff that we don't want to route over +DELETE FROM neighborhood_ways WHERE functional_class IS NULL; + +-- remove orphans +DELETE FROM neighborhood_ways +WHERE NOT EXISTS ( + SELECT 1 + FROM neighborhood_ways w + WHERE neighborhood_ways.intersection_to IN (w.intersection_to,w.intersection_from) + AND w.road_id != neighborhood_ways.road_id +) +AND NOT EXISTS ( + SELECT 1 + FROM neighborhood_ways w + WHERE neighborhood_ways.intersection_from IN (w.intersection_to,w.intersection_from) + AND w.road_id != neighborhood_ways.road_id +); + +-- remove obsolete intersections +DELETE FROM neighborhood_ways_intersections +WHERE NOT EXISTS ( + SELECT 1 + FROM neighborhood_ways w + WHERE int_id IN (w.intersection_to,w.intersection_from) +); diff --git a/import_osm.sh b/import_osm.sh index ce2cd495..13612694 100755 --- a/import_osm.sh +++ b/import_osm.sh @@ -6,43 +6,42 @@ NB_POSTGRESQL_HOST="${NB_POSTGRESQL_HOST:-127.0.0.1}" NB_POSTGRESQL_DB="${NB_POSTGRESQL_DB:-pfb}" NB_POSTGRESQL_USER="${NB_POSTGRESQL_USER:-gis}" NB_POSTGRESQL_PASSWORD="${NB_POSTGRESQL_PASSWORD:-gis}" -NB_OSMPREFIX="${NB_OSMPREFIX:-cambridge}" NB_OSMFILE="${NB_OSMFILE:-/vagrant/data/cambridge.osm}" # drop old tables echo 'Dropping old tables' psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ - -c "DROP TABLE IF EXISTS received.${NB_OSMPREFIX}_ways;" + -c "DROP TABLE IF EXISTS received.neighborhood_ways;" psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ - -c "DROP TABLE IF EXISTS received.${NB_OSMPREFIX}_ways_intersections;" + -c "DROP TABLE IF EXISTS received.neighborhood_ways_intersections;" psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ - -c "DROP TABLE IF EXISTS received.${NB_OSMPREFIX}_relations_ways;" + -c "DROP TABLE IF EXISTS received.neighborhood_relations_ways;" psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ - -c "DROP TABLE IF EXISTS received.${NB_OSMPREFIX}_osm_nodes;" + -c "DROP TABLE IF EXISTS received.neighborhood_osm_nodes;" psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ - -c "DROP TABLE IF EXISTS received.${NB_OSMPREFIX}_osm_relations;" + -c "DROP TABLE IF EXISTS received.neighborhood_osm_relations;" psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ - -c "DROP TABLE IF EXISTS received.${NB_OSMPREFIX}_osm_way_classes;" + -c "DROP TABLE IF EXISTS received.neighborhood_osm_way_classes;" psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ - -c "DROP TABLE IF EXISTS received.${NB_OSMPREFIX}_osm_way_tags;" + -c "DROP TABLE IF EXISTS received.neighborhood_osm_way_tags;" psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ - -c "DROP TABLE IF EXISTS received.${NB_OSMPREFIX}_osm_way_types;" + -c "DROP TABLE IF EXISTS received.neighborhood_osm_way_types;" psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ - -c "DROP TABLE IF EXISTS scratch.${NB_OSMPREFIX}_cycwys_ways;" + -c "DROP TABLE IF EXISTS scratch.neighborhood_cycwys_ways;" psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ - -c "DROP TABLE IF EXISTS scratch.${NB_OSMPREFIX}_cycwys_ways_vertices_pgr;" + -c "DROP TABLE IF EXISTS scratch.neighborhood_cycwys_ways_vertices_pgr;" psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ - -c "DROP TABLE IF EXISTS scratch.${NB_OSMPREFIX}_cycwys_relations_ways;" + -c "DROP TABLE IF EXISTS scratch.neighborhood_cycwys_relations_ways;" psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ - -c "DROP TABLE IF EXISTS scratch.${NB_OSMPREFIX}_cycwys_osm_nodes;" + -c "DROP TABLE IF EXISTS scratch.neighborhood_cycwys_osm_nodes;" psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ - -c "DROP TABLE IF EXISTS scratch.${NB_OSMPREFIX}_cycwys_osm_relations;" + -c "DROP TABLE IF EXISTS scratch.neighborhood_cycwys_osm_relations;" psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ - -c "DROP TABLE IF EXISTS scratch.${NB_OSMPREFIX}_cycwys_osm_way_classes;" + -c "DROP TABLE IF EXISTS scratch.neighborhood_cycwys_osm_way_classes;" psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ - -c "DROP TABLE IF EXISTS scratch.${NB_OSMPREFIX}_cycwys_osm_way_tags;" + -c "DROP TABLE IF EXISTS scratch.neighborhood_cycwys_osm_way_tags;" psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ - -c "DROP TABLE IF EXISTS scratch.${NB_OSMPREFIX}_cycwys_osm_way_types;" + -c "DROP TABLE IF EXISTS scratch.neighborhood_cycwys_osm_way_types;" # import the osm with highways osm2pgrouting \ @@ -51,7 +50,7 @@ osm2pgrouting \ --dbname ${NB_POSTGRESQL_DB} \ --username ${NB_POSTGRESQL_USER} \ --schema received \ - --prefix ${NB_OSMPREFIX}_ \ + --prefix neighborhood_ \ --conf ./mapconfig_highway.xml \ --clean @@ -62,50 +61,50 @@ osm2pgrouting \ --dbname ${NB_POSTGRESQL_DB} \ --username ${NB_POSTGRESQL_USER} \ --schema scratch \ - --prefix ${NB_OSMPREFIX}_cycwys_ \ + --prefix neighborhood_cycwys_ \ --conf ./mapconfig_cycleway.xml \ --clean # rename a few tables echo 'Renaming tables' psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ - -c "ALTER TABLE received.${NB_OSMPREFIX}_ways_vertices_pgr RENAME TO ${NB_OSMPREFIX}_ways_intersections;" + -c "ALTER TABLE received.neighborhood_ways_vertices_pgr RENAME TO neighborhood_ways_intersections;" psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ - -c "ALTER TABLE received.${NB_OSMPREFIX}_ways_intersections RENAME CONSTRAINT vertex_id TO ${NB_OSMPREFIX}_vertex_id;" + -c "ALTER TABLE received.neighborhood_ways_intersections RENAME CONSTRAINT vertex_id TO neighborhood_vertex_id;" psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ - -c "ALTER TABLE received.osm_nodes RENAME TO ${NB_OSMPREFIX}_osm_nodes;" + -c "ALTER TABLE received.osm_nodes RENAME TO neighborhood_osm_nodes;" psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ - -c "ALTER TABLE received.${NB_OSMPREFIX}_osm_nodes RENAME CONSTRAINT node_id TO ${NB_OSMPREFIX}_node_id;" + -c "ALTER TABLE received.neighborhood_osm_nodes RENAME CONSTRAINT node_id TO neighborhood_node_id;" psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ - -c "ALTER TABLE received.osm_relations RENAME TO ${NB_OSMPREFIX}_osm_relations;" + -c "ALTER TABLE received.osm_relations RENAME TO neighborhood_osm_relations;" psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ - -c "ALTER TABLE received.osm_way_classes RENAME TO ${NB_OSMPREFIX}_osm_way_classes;" + -c "ALTER TABLE received.osm_way_classes RENAME TO neighborhood_osm_way_classes;" psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ - -c "ALTER TABLE received.${NB_OSMPREFIX}_osm_way_classes RENAME CONSTRAINT osm_way_classes_pkey TO ${NB_OSMPREFIX}_osm_way_classes_pkey;" + -c "ALTER TABLE received.neighborhood_osm_way_classes RENAME CONSTRAINT osm_way_classes_pkey TO neighborhood_osm_way_classes_pkey;" psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ - -c "ALTER TABLE received.osm_way_tags RENAME TO ${NB_OSMPREFIX}_osm_way_tags;" + -c "ALTER TABLE received.osm_way_tags RENAME TO neighborhood_osm_way_tags;" psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ - -c "ALTER TABLE received.osm_way_types RENAME TO ${NB_OSMPREFIX}_osm_way_types;" + -c "ALTER TABLE received.osm_way_types RENAME TO neighborhood_osm_way_types;" psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ - -c "ALTER TABLE received.${NB_OSMPREFIX}_osm_way_types RENAME CONSTRAINT osm_way_types_pkey TO ${NB_OSMPREFIX}_osm_way_types_pkey;" + -c "ALTER TABLE received.neighborhood_osm_way_types RENAME CONSTRAINT osm_way_types_pkey TO neighborhood_osm_way_types_pkey;" psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ - -c "ALTER TABLE scratch.${NB_OSMPREFIX}_cycwys_ways_vertices_pgr RENAME CONSTRAINT vertex_id TO ${NB_OSMPREFIX}_vertex_id;" + -c "ALTER TABLE scratch.neighborhood_cycwys_ways_vertices_pgr RENAME CONSTRAINT vertex_id TO neighborhood_vertex_id;" psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ - -c "ALTER TABLE scratch.osm_nodes RENAME TO ${NB_OSMPREFIX}_cycwys_osm_nodes;" + -c "ALTER TABLE scratch.osm_nodes RENAME TO neighborhood_cycwys_osm_nodes;" psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ - -c "ALTER TABLE scratch.${NB_OSMPREFIX}_cycwys_osm_nodes RENAME CONSTRAINT node_id TO ${NB_OSMPREFIX}_node_id;" + -c "ALTER TABLE scratch.neighborhood_cycwys_osm_nodes RENAME CONSTRAINT node_id TO neighborhood_node_id;" psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ - -c "ALTER TABLE scratch.osm_relations RENAME TO ${NB_OSMPREFIX}_cycwys_osm_relations;" + -c "ALTER TABLE scratch.osm_relations RENAME TO neighborhood_cycwys_osm_relations;" psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ - -c "ALTER TABLE scratch.osm_way_classes RENAME TO ${NB_OSMPREFIX}_cycwys_osm_way_classes;" + -c "ALTER TABLE scratch.osm_way_classes RENAME TO neighborhood_cycwys_osm_way_classes;" psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ - -c "ALTER TABLE scratch.${NB_OSMPREFIX}_cycwys_osm_way_classes RENAME CONSTRAINT osm_way_classes_pkey TO ${NB_OSMPREFIX}_osm_way_classes_pkey;" + -c "ALTER TABLE scratch.neighborhood_cycwys_osm_way_classes RENAME CONSTRAINT osm_way_classes_pkey TO neighborhood_osm_way_classes_pkey;" psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ - -c "ALTER TABLE scratch.osm_way_tags RENAME TO ${NB_OSMPREFIX}_cycwys_osm_way_tags;" + -c "ALTER TABLE scratch.osm_way_tags RENAME TO neighborhood_cycwys_osm_way_tags;" psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ - -c "ALTER TABLE scratch.osm_way_types RENAME TO ${NB_OSMPREFIX}_cycwys_osm_way_types;" + -c "ALTER TABLE scratch.osm_way_types RENAME TO neighborhood_cycwys_osm_way_types;" psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ - -c "ALTER TABLE scratch.${NB_OSMPREFIX}_cycwys_osm_way_types RENAME CONSTRAINT osm_way_types_pkey TO ${NB_OSMPREFIX}_osm_way_types_pkey;" + -c "ALTER TABLE scratch.neighborhood_cycwys_osm_way_types RENAME CONSTRAINT osm_way_types_pkey TO neighborhood_osm_way_types_pkey;" # import full osm to fill out additional data needs # not met by osm2pgrouting @@ -113,13 +112,13 @@ psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ # drop old tables echo 'Dropping old tables' psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ - -c "DROP TABLE IF EXISTS received.${NB_OSMPREFIX}_osm_full_line;" + -c "DROP TABLE IF EXISTS received.neighborhood_osm_full_line;" psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ - -c "DROP TABLE IF EXISTS received.${NB_OSMPREFIX}_osm_full_point;" + -c "DROP TABLE IF EXISTS received.neighborhood_osm_full_point;" psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ - -c "DROP TABLE IF EXISTS received.${NB_OSMPREFIX}_osm_full_polygon;" + -c "DROP TABLE IF EXISTS received.neighborhood_osm_full_polygon;" psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ - -c "DROP TABLE IF EXISTS received.${NB_OSMPREFIX}_osm_full_roads;" + -c "DROP TABLE IF EXISTS received.neighborhood_osm_full_roads;" # import osm2pgsql \ @@ -128,7 +127,7 @@ osm2pgsql \ --port 5432 \ --create \ --database "${NB_POSTGRESQL_DB}" \ - --prefix "${NB_OSMPREFIX}_osm_full" \ + --prefix "neighborhood_osm_full" \ --proj 2249 \ --style ./pfb.style \ "${NB_OSMFILE}" @@ -136,13 +135,13 @@ osm2pgsql \ # move the full osm tables to the received schema echo 'Moving tables to received schema' psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ - -c "ALTER TABLE generated.${NB_OSMPREFIX}_osm_full_line SET SCHEMA received;" + -c "ALTER TABLE generated.neighborhood_osm_full_line SET SCHEMA received;" psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ - -c "ALTER TABLE generated.${NB_OSMPREFIX}_osm_full_point SET SCHEMA received;" + -c "ALTER TABLE generated.neighborhood_osm_full_point SET SCHEMA received;" psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ - -c "ALTER TABLE generated.${NB_OSMPREFIX}_osm_full_polygon SET SCHEMA received;" + -c "ALTER TABLE generated.neighborhood_osm_full_polygon SET SCHEMA received;" psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ - -c "ALTER TABLE generated.${NB_OSMPREFIX}_osm_full_roads SET SCHEMA received;" + -c "ALTER TABLE generated.neighborhood_osm_full_roads SET SCHEMA received;" # process tables echo 'Updating field names' diff --git a/lanes.sql b/lanes.sql index 4ef36e1c..0b50380c 100644 --- a/lanes.sql +++ b/lanes.sql @@ -1,32 +1,32 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -UPDATE cambridge_ways SET ft_lanes = NULL, tf_lanes = NULL; +UPDATE neighborhood_ways SET ft_lanes = NULL, tf_lanes = NULL; -- forward -UPDATE cambridge_ways +UPDATE neighborhood_ways SET ft_lanes = substring(osm."lanes:forward" FROM '\d+')::INT -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id AND ft_lanes IS NULL AND osm."lanes:forward" IS NOT NULL; -- backward -UPDATE cambridge_ways +UPDATE neighborhood_ways SET tf_lanes = substring(osm."lanes:backward" FROM '\d+')::INT -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id AND tf_lanes IS NULL AND osm."lanes:backward" IS NOT NULL; -- all lanes (no direction given) -- two way -UPDATE cambridge_ways +UPDATE neighborhood_ways SET ft_lanes = floor(substring(osm.lanes FROM '\d+')::FLOAT / 2), tf_lanes = floor(substring(osm.lanes FROM '\d+')::FLOAT / 2) -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id AND tf_lanes IS NULL AND ft_lanes IS NULL AND one_way_car NOT IN ('ft','tf') @@ -34,17 +34,17 @@ AND osm.lanes IS NOT NULL; -- all lanes (no direction given) -- one way -UPDATE cambridge_ways +UPDATE neighborhood_ways SET ft_lanes = substring(osm.lanes FROM '\d+')::INT -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id AND one_way_car = 'ft' AND ft_lanes IS NULL AND osm.lanes IS NOT NULL; -UPDATE cambridge_ways +UPDATE neighborhood_ways SET tf_lanes = substring(osm.lanes FROM '\d+')::INT -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id AND one_way_car = 'tf' AND tf_lanes IS NULL AND osm.lanes IS NOT NULL; diff --git a/legs.sql b/legs.sql index 93255a62..b96f25ba 100644 --- a/legs.sql +++ b/legs.sql @@ -1,10 +1,10 @@ ----------------------------------------- --- INPUTS --- location: cambridge ----------------------------------------- -UPDATE received.cambridge_ways_intersections -SET legs = ( - SELECT COUNT(road_id) - FROM cambridge_ways - WHERE cambridge_ways_intersections.int_id IN (intersection_from,intersection_to) -); +---------------------------------------- +-- INPUTS +-- location: neighborhood +---------------------------------------- +UPDATE received.neighborhood_ways_intersections +SET legs = ( + SELECT COUNT(road_id) + FROM neighborhood_ways + WHERE neighborhood_ways_intersections.int_id IN (intersection_from,intersection_to) +); diff --git a/one_way.sql b/one_way.sql index c3269a50..f2998258 100644 --- a/one_way.sql +++ b/one_way.sql @@ -1,19 +1,19 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -UPDATE cambridge_ways SET one_way_car = NULL; +UPDATE neighborhood_ways SET one_way_car = NULL; -- ft direction -UPDATE cambridge_ways +UPDATE neighborhood_ways SET one_way_car = 'ft' -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id AND trim(osm.oneway) IN ('1','yes'); -- tf direction -UPDATE cambridge_ways +UPDATE neighborhood_ways SET one_way_car = 'tf' -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id AND trim(osm.oneway) = '-1'; diff --git a/park.sql b/park.sql index e8dbf0d0..0f4b3063 100644 --- a/park.sql +++ b/park.sql @@ -1,11 +1,11 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -UPDATE cambridge_ways SET ft_park = NULL, tf_park = NULL; +UPDATE neighborhood_ways SET ft_park = NULL, tf_park = NULL; -- both -UPDATE cambridge_ways +UPDATE neighborhood_ways SET ft_park = CASE WHEN osm."parking:lane:both" = 'parallel' THEN 1 WHEN osm."parking:lane:both" = 'paralell' THEN 1 WHEN osm."parking:lane:both" = 'diagonal' THEN 1 @@ -20,11 +20,11 @@ SET ft_park = CASE WHEN osm."parking:lane:both" = 'parallel' THEN 1 WHEN osm."parking:lane:both" = 'no_parking' THEN 0 WHEN osm."parking:lane:both" = 'no_stopping' THEN 0 END -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id; +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id; -- right -UPDATE cambridge_ways +UPDATE neighborhood_ways SET ft_park = CASE WHEN osm."parking:lane:right" = 'parallel' THEN 1 WHEN osm."parking:lane:right" = 'paralell' THEN 1 WHEN osm."parking:lane:right" = 'diagonal' THEN 1 @@ -32,11 +32,11 @@ SET ft_park = CASE WHEN osm."parking:lane:right" = 'parallel' THEN 1 WHEN osm."parking:lane:right" = 'no_parking' THEN 0 WHEN osm."parking:lane:right" = 'no_stopping' THEN 0 END -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id; +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id; -- left -UPDATE cambridge_ways +UPDATE neighborhood_ways SET tf_park = CASE WHEN osm."parking:lane:left" = 'parallel' THEN 1 WHEN osm."parking:lane:left" = 'paralell' THEN 1 WHEN osm."parking:lane:left" = 'diagonal' THEN 1 @@ -44,5 +44,5 @@ SET tf_park = CASE WHEN osm."parking:lane:left" = 'parallel' THEN 1 WHEN osm."parking:lane:left" = 'no_parking' THEN 0 WHEN osm."parking:lane:left" = 'no_stopping' THEN 0 END -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id; +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id; diff --git a/paths.sql b/paths.sql index 70bb0646..b413d1f3 100644 --- a/paths.sql +++ b/paths.sql @@ -1,11 +1,11 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -DROP TABLE IF EXISTS generated.cambridge_paths; -DROP INDEX IF EXISTS idx_cambridge_ways_path_id; +DROP TABLE IF EXISTS generated.neighborhood_paths; +DROP INDEX IF EXISTS idx_neighborhood_ways_path_id; -CREATE TABLE generated.cambridge_paths ( +CREATE TABLE generated.neighborhood_paths ( path_id SERIAL PRIMARY KEY, geom geometry(multilinestring,2249), path_length INTEGER, @@ -13,7 +13,7 @@ CREATE TABLE generated.cambridge_paths ( ); -- combine contiguous paths -INSERT INTO cambridge_paths (geom) +INSERT INTO neighborhood_paths (geom) SELECT ST_CollectionExtract( ST_SetSRID( unnest(ST_ClusterIntersecting(geom)), @@ -21,15 +21,15 @@ SELECT ST_CollectionExtract( ), 2 --linestrings ) -FROM cambridge_ways +FROM neighborhood_ways WHERE functional_class = 'path'; -- get raw lengths -UPDATE cambridge_paths +UPDATE neighborhood_paths SET path_length = ST_Length(geom); -- get bounding box lengths -UPDATE cambridge_paths +UPDATE neighborhood_paths SET bbox_length = ST_Length( ST_SetSRID( ST_MakeLine( @@ -41,25 +41,25 @@ SET bbox_length = ST_Length( ); -- set path_id on each road segment (if path) -UPDATE cambridge_ways +UPDATE neighborhood_ways SET path_id = ( SELECT paths.path_id - FROM cambridge_paths paths - WHERE ST_Intersects(cambridge_ways.geom,paths.geom) - AND ST_CoveredBy(cambridge_ways.geom,paths.geom) + FROM neighborhood_paths paths + WHERE ST_Intersects(neighborhood_ways.geom,paths.geom) + AND ST_CoveredBy(neighborhood_ways.geom,paths.geom) LIMIT 1 ) WHERE functional_class = 'path'; -- get stragglers -UPDATE cambridge_ways +UPDATE neighborhood_ways SET path_id = paths.path_id -FROM cambridge_paths paths -WHERE cambridge_ways.functional_class = 'path' -AND cambridge_ways.path_id IS NULL -AND ST_Intersects(cambridge_ways.geom,paths.geom) -AND ST_CoveredBy(cambridge_ways.geom,ST_Buffer(paths.geom,1)); +FROM neighborhood_paths paths +WHERE neighborhood_ways.functional_class = 'path' +AND neighborhood_ways.path_id IS NULL +AND ST_Intersects(neighborhood_ways.geom,paths.geom) +AND ST_CoveredBy(neighborhood_ways.geom,ST_Buffer(paths.geom,1)); -- set index -CREATE INDEX idx_cambridge_ways_path_id ON cambridge_ways (path_id); -ANALYZE cambridge_ways (path_id); +CREATE INDEX idx_neighborhood_ways_path_id ON neighborhood_ways (path_id); +ANALYZE neighborhood_ways (path_id); diff --git a/prepare_tables.sql b/prepare_tables.sql index de8b87a8..335a7421 100644 --- a/prepare_tables.sql +++ b/prepare_tables.sql @@ -1,111 +1,111 @@ ----------------------------------------- --- INPUTS --- location: cambridge --- proj: 2249 ----------------------------------------- - --- add tdg_id field to roads -ALTER TABLE cambridge_ways ADD COLUMN tdg_id TEXT DEFAULT uuid_generate_v4(); - --- drop unnecessary columns -ALTER TABLE cambridge_ways DROP COLUMN class_id; -ALTER TABLE cambridge_ways DROP COLUMN length; -ALTER TABLE cambridge_ways DROP COLUMN length_m; -ALTER TABLE cambridge_ways DROP COLUMN x1; -ALTER TABLE cambridge_ways DROP COLUMN y1; -ALTER TABLE cambridge_ways DROP COLUMN x2; -ALTER TABLE cambridge_ways DROP COLUMN y2; -ALTER TABLE cambridge_ways DROP COLUMN cost; -ALTER TABLE cambridge_ways DROP COLUMN reverse_cost; -ALTER TABLE cambridge_ways DROP COLUMN cost_s; -ALTER TABLE cambridge_ways DROP COLUMN reverse_cost_s; -ALTER TABLE cambridge_ways DROP COLUMN rule; -ALTER TABLE cambridge_ways DROP COLUMN maxspeed_forward; -ALTER TABLE cambridge_ways DROP COLUMN maxspeed_backward; -ALTER TABLE cambridge_ways DROP COLUMN source_osm; -ALTER TABLE cambridge_ways DROP COLUMN target_osm; -ALTER TABLE cambridge_ways DROP COLUMN priority; -ALTER TABLE cambridge_ways DROP COLUMN one_way; - -ALTER TABLE cambridge_ways_intersections DROP COLUMN cnt; -ALTER TABLE cambridge_ways_intersections DROP COLUMN chk; -ALTER TABLE cambridge_ways_intersections DROP COLUMN ein; -ALTER TABLE cambridge_ways_intersections DROP COLUMN eout; -ALTER TABLE cambridge_ways_intersections DROP COLUMN lon; -ALTER TABLE cambridge_ways_intersections DROP COLUMN lat; - --- change column names -ALTER TABLE cambridge_ways RENAME COLUMN gid TO road_id; -ALTER TABLE cambridge_ways RENAME COLUMN the_geom TO geom; -ALTER TABLE cambridge_ways RENAME COLUMN source TO intersection_from; -ALTER TABLE cambridge_ways RENAME COLUMN target TO intersection_to; - -ALTER TABLE cambridge_ways_intersections RENAME COLUMN id TO int_id; -ALTER TABLE cambridge_ways_intersections RENAME COLUMN the_geom TO geom; - --- reproject -ALTER TABLE cambridge_ways ALTER COLUMN geom TYPE geometry(linestring,2249) -USING ST_Transform(geom,2249); -ALTER TABLE cambridge_cycwys_ways ALTER COLUMN the_geom TYPE geometry(linestring,2249) -USING ST_Transform(the_geom,2249); -ALTER TABLE cambridge_ways_intersections ALTER COLUMN geom TYPE geometry(point,2249) -USING ST_Transform(geom,2249); - --- add columns -ALTER TABLE cambridge_ways ADD COLUMN functional_class TEXT; -ALTER TABLE cambridge_ways ADD COLUMN path_id INTEGER; -ALTER TABLE cambridge_ways ADD COLUMN speed_limit INT; -ALTER TABLE cambridge_ways ADD COLUMN one_way_car VARCHAR(2); -ALTER TABLE cambridge_ways ADD COLUMN one_way VARCHAR(2); -ALTER TABLE cambridge_ways ADD COLUMN width_ft INT; -ALTER TABLE cambridge_ways ADD COLUMN ft_bike_infra TEXT; -ALTER TABLE cambridge_ways ADD COLUMN tf_bike_infra TEXT; -ALTER TABLE cambridge_ways ADD COLUMN ft_lanes INT; -ALTER TABLE cambridge_ways ADD COLUMN tf_lanes INT; -ALTER TABLE cambridge_ways ADD COLUMN ft_park INT; -ALTER TABLE cambridge_ways ADD COLUMN tf_park INT; -ALTER TABLE cambridge_ways ADD COLUMN ft_seg_stress INT; -ALTER TABLE cambridge_ways ADD COLUMN ft_int_stress INT; -ALTER TABLE cambridge_ways ADD COLUMN tf_seg_stress INT; -ALTER TABLE cambridge_ways ADD COLUMN tf_int_stress INT; - --- indexes -CREATE INDEX idx_cambridge_ways_osm ON cambridge_ways (osm_id); -CREATE INDEX idx_cambridge_ways_ints_osm ON cambridge_ways_intersections (osm_id); -CREATE INDEX idx_cambridge_fullways ON cambridge_osm_full_line (osm_id); -CREATE INDEX idx_cambridge_fullpoints ON cambridge_osm_full_point (osm_id); -ANALYZE cambridge_ways (osm_id,geom); -ANALYZE cambridge_cycwys_ways (the_geom); -ANALYZE cambridge_ways_intersections (osm_id); -ANALYZE cambridge_osm_full_line (osm_id); -ANALYZE cambridge_osm_full_point (osm_id); - --- add in cycleway data that is missing from first osm2pgrouting call -INSERT INTO cambridge_ways ( - name, intersection_from, intersection_to, osm_id, geom -) -SELECT name, - (SELECT i.int_id - FROM cambridge_ways_intersections i - WHERE i.geom <#> cambridge_cycwys_ways.the_geom < 20 - ORDER BY ST_Distance(ST_StartPoint(cambridge_cycwys_ways.the_geom),i.geom) ASC - LIMIT 1), - (SELECT i.int_id - FROM cambridge_ways_intersections i - WHERE i.geom <#> cambridge_cycwys_ways.the_geom < 20 - ORDER BY ST_Distance(ST_EndPoint(cambridge_cycwys_ways.the_geom),i.geom) ASC - LIMIT 1), - osm_id, - the_geom -FROM cambridge_cycwys_ways -WHERE NOT EXISTS ( - SELECT 1 - FROM cambridge_ways w2 - WHERE w2.osm_id = cambridge_cycwys_ways.osm_id -); - --- setup intersection table -ALTER TABLE cambridge_ways_intersections ADD COLUMN legs INT; -ALTER TABLE cambridge_ways_intersections ADD COLUMN signalized BOOLEAN; -ALTER TABLE cambridge_ways_intersections ADD COLUMN stops BOOLEAN; -CREATE INDEX idx_cambridge_ints_stop ON cambridge_ways_intersections (signalized,stops); +---------------------------------------- +-- INPUTS +-- location: neighborhood +-- proj: 2249 +---------------------------------------- + +-- add tdg_id field to roads +ALTER TABLE neighborhood_ways ADD COLUMN tdg_id TEXT DEFAULT uuid_generate_v4(); + +-- drop unnecessary columns +ALTER TABLE neighborhood_ways DROP COLUMN class_id; +ALTER TABLE neighborhood_ways DROP COLUMN length; +ALTER TABLE neighborhood_ways DROP COLUMN length_m; +ALTER TABLE neighborhood_ways DROP COLUMN x1; +ALTER TABLE neighborhood_ways DROP COLUMN y1; +ALTER TABLE neighborhood_ways DROP COLUMN x2; +ALTER TABLE neighborhood_ways DROP COLUMN y2; +ALTER TABLE neighborhood_ways DROP COLUMN cost; +ALTER TABLE neighborhood_ways DROP COLUMN reverse_cost; +ALTER TABLE neighborhood_ways DROP COLUMN cost_s; +ALTER TABLE neighborhood_ways DROP COLUMN reverse_cost_s; +ALTER TABLE neighborhood_ways DROP COLUMN rule; +ALTER TABLE neighborhood_ways DROP COLUMN maxspeed_forward; +ALTER TABLE neighborhood_ways DROP COLUMN maxspeed_backward; +ALTER TABLE neighborhood_ways DROP COLUMN source_osm; +ALTER TABLE neighborhood_ways DROP COLUMN target_osm; +ALTER TABLE neighborhood_ways DROP COLUMN priority; +ALTER TABLE neighborhood_ways DROP COLUMN one_way; + +ALTER TABLE neighborhood_ways_intersections DROP COLUMN cnt; +ALTER TABLE neighborhood_ways_intersections DROP COLUMN chk; +ALTER TABLE neighborhood_ways_intersections DROP COLUMN ein; +ALTER TABLE neighborhood_ways_intersections DROP COLUMN eout; +ALTER TABLE neighborhood_ways_intersections DROP COLUMN lon; +ALTER TABLE neighborhood_ways_intersections DROP COLUMN lat; + +-- change column names +ALTER TABLE neighborhood_ways RENAME COLUMN gid TO road_id; +ALTER TABLE neighborhood_ways RENAME COLUMN the_geom TO geom; +ALTER TABLE neighborhood_ways RENAME COLUMN source TO intersection_from; +ALTER TABLE neighborhood_ways RENAME COLUMN target TO intersection_to; + +ALTER TABLE neighborhood_ways_intersections RENAME COLUMN id TO int_id; +ALTER TABLE neighborhood_ways_intersections RENAME COLUMN the_geom TO geom; + +-- reproject +ALTER TABLE neighborhood_ways ALTER COLUMN geom TYPE geometry(linestring,2249) +USING ST_Transform(geom,2249); +ALTER TABLE neighborhood_cycwys_ways ALTER COLUMN the_geom TYPE geometry(linestring,2249) +USING ST_Transform(the_geom,2249); +ALTER TABLE neighborhood_ways_intersections ALTER COLUMN geom TYPE geometry(point,2249) +USING ST_Transform(geom,2249); + +-- add columns +ALTER TABLE neighborhood_ways ADD COLUMN functional_class TEXT; +ALTER TABLE neighborhood_ways ADD COLUMN path_id INTEGER; +ALTER TABLE neighborhood_ways ADD COLUMN speed_limit INT; +ALTER TABLE neighborhood_ways ADD COLUMN one_way_car VARCHAR(2); +ALTER TABLE neighborhood_ways ADD COLUMN one_way VARCHAR(2); +ALTER TABLE neighborhood_ways ADD COLUMN width_ft INT; +ALTER TABLE neighborhood_ways ADD COLUMN ft_bike_infra TEXT; +ALTER TABLE neighborhood_ways ADD COLUMN tf_bike_infra TEXT; +ALTER TABLE neighborhood_ways ADD COLUMN ft_lanes INT; +ALTER TABLE neighborhood_ways ADD COLUMN tf_lanes INT; +ALTER TABLE neighborhood_ways ADD COLUMN ft_park INT; +ALTER TABLE neighborhood_ways ADD COLUMN tf_park INT; +ALTER TABLE neighborhood_ways ADD COLUMN ft_seg_stress INT; +ALTER TABLE neighborhood_ways ADD COLUMN ft_int_stress INT; +ALTER TABLE neighborhood_ways ADD COLUMN tf_seg_stress INT; +ALTER TABLE neighborhood_ways ADD COLUMN tf_int_stress INT; + +-- indexes +CREATE INDEX idx_neighborhood_ways_osm ON neighborhood_ways (osm_id); +CREATE INDEX idx_neighborhood_ways_ints_osm ON neighborhood_ways_intersections (osm_id); +CREATE INDEX idx_neighborhood_fullways ON neighborhood_osm_full_line (osm_id); +CREATE INDEX idx_neighborhood_fullpoints ON neighborhood_osm_full_point (osm_id); +ANALYZE neighborhood_ways (osm_id,geom); +ANALYZE neighborhood_cycwys_ways (the_geom); +ANALYZE neighborhood_ways_intersections (osm_id); +ANALYZE neighborhood_osm_full_line (osm_id); +ANALYZE neighborhood_osm_full_point (osm_id); + +-- add in cycleway data that is missing from first osm2pgrouting call +INSERT INTO neighborhood_ways ( + name, intersection_from, intersection_to, osm_id, geom +) +SELECT name, + (SELECT i.int_id + FROM neighborhood_ways_intersections i + WHERE i.geom <#> neighborhood_cycwys_ways.the_geom < 20 + ORDER BY ST_Distance(ST_StartPoint(neighborhood_cycwys_ways.the_geom),i.geom) ASC + LIMIT 1), + (SELECT i.int_id + FROM neighborhood_ways_intersections i + WHERE i.geom <#> neighborhood_cycwys_ways.the_geom < 20 + ORDER BY ST_Distance(ST_EndPoint(neighborhood_cycwys_ways.the_geom),i.geom) ASC + LIMIT 1), + osm_id, + the_geom +FROM neighborhood_cycwys_ways +WHERE NOT EXISTS ( + SELECT 1 + FROM neighborhood_ways w2 + WHERE w2.osm_id = neighborhood_cycwys_ways.osm_id +); + +-- setup intersection table +ALTER TABLE neighborhood_ways_intersections ADD COLUMN legs INT; +ALTER TABLE neighborhood_ways_intersections ADD COLUMN signalized BOOLEAN; +ALTER TABLE neighborhood_ways_intersections ADD COLUMN stops BOOLEAN; +CREATE INDEX idx_neighborhood_ints_stop ON neighborhood_ways_intersections (signalized,stops); diff --git a/run_connectivity.sh b/run_connectivity.sh index c38bc8e8..46951c0d 100755 --- a/run_connectivity.sh +++ b/run_connectivity.sh @@ -2,51 +2,52 @@ cd `dirname $0` -DBHOST='127.0.0.1' -DBNAME='pfb' -OSMPREFIX='cambridge' +NB_POSTGRESQL_HOST="${NB_POSTGRESQL_HOST:-127.0.0.1}" +NB_POSTGRESQL_DB="${NB_POSTGRESQL_DB:-pfb}" +NB_POSTGRESQL_USER="${NB_POSTGRESQL_USER:-gis}" +NB_POSTGRESQL_PASSWORD="${NB_POSTGRESQL_PASSWORD:-gis}" -# psql -h "${DBHOST}" -U gis -d "${DBNAME}" \ -# -c "SELECT tdgMakeNetwork('${OSMPREFIX}_ways');" +psql -h "${DBHOST}" -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_DB}" \ + -c "SELECT tdgMakeNetwork('neighborhood_ways');" -# psql -h "${DBHOST}" -U gis -d "${DBNAME}" \ -# -c "SELECT tdgNetworkCostFromDistance('${OSMPREFIX}_ways');" +psql -h "${NB_POSTGRESQL_HOST}" -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_DB}" \ + -c "SELECT tdgNetworkCostFromDistance('neighborhood_ways');" -/usr/bin/time -v psql -h "${DBHOST}" -U gis -d "${DBNAME}" \ +/usr/bin/time -v psql -h "${NB_POSTGRESQL_HOST}" -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_DB}" \ -f connectivity/census_blocks.sql -/usr/bin/time -v psql -h "${DBHOST}" -U gis -d "${DBNAME}" \ +/usr/bin/time -v psql -h "${NB_POSTGRESQL_HOST}" -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_DB}" \ -f connectivity/census_block_roads.sql -/usr/bin/time -v psql -h "${DBHOST}" -U gis -d "${DBNAME}" \ +/usr/bin/time -v psql -h "${NB_POSTGRESQL_HOST}" -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_DB}" \ -f connectivity/reachable_roads_high_stress.sql -/usr/bin/time -v psql -h "${DBHOST}" -U gis -d "${DBNAME}" \ +/usr/bin/time -v psql -h "${NB_POSTGRESQL_HOST}" -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_DB}" \ -f connectivity/reachable_roads_low_stress.sql -/usr/bin/time -v psql -h "${DBHOST}" -U gis -d "${DBNAME}" \ +/usr/bin/time -v psql -h "${NB_POSTGRESQL_HOST}" -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_DB}" \ -f connectivity/connected_census_blocks.sql -/usr/bin/time -v psql -h "${DBHOST}" -U gis -d "${DBNAME}" \ +/usr/bin/time -v psql -h "${NB_POSTGRESQL_HOST}" -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_DB}" \ -f connectivity/access_population.sql -/usr/bin/time -v psql -h "${DBHOST}" -U gis -d "${DBNAME}" \ +/usr/bin/time -v psql -h "${NB_POSTGRESQL_HOST}" -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_DB}" \ -f connectivity/census_block_jobs.sql -/usr/bin/time -v psql -h "${DBHOST}" -U gis -d "${DBNAME}" \ +/usr/bin/time -v psql -h "${NB_POSTGRESQL_HOST}" -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_DB}" \ -f connectivity/access_jobs.sql -/usr/bin/time -v psql -h "${DBHOST}" -U gis -d "${DBNAME}" \ +/usr/bin/time -v psql -h "${NB_POSTGRESQL_HOST}" -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_DB}" \ -f connectivity/schools.sql -/usr/bin/time -v psql -h "${DBHOST}" -U gis -d "${DBNAME}" \ +/usr/bin/time -v psql -h "${NB_POSTGRESQL_HOST}" -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_DB}" \ -f connectivity/school_roads.sql -/usr/bin/time -v psql -h "${DBHOST}" -U gis -d "${DBNAME}" \ +/usr/bin/time -v psql -h "${NB_POSTGRESQL_HOST}" -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_DB}" \ -f connectivity/connected_census_blocks_schools.sql -/usr/bin/time -v psql -h "${DBHOST}" -U gis -d "${DBNAME}" \ +/usr/bin/time -v psql -h "${NB_POSTGRESQL_HOST}" -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_DB}" \ -f connectivity/access_schools.sql -/usr/bin/time -v psql -h "${DBHOST}" -U gis -d "${DBNAME}" \ +/usr/bin/time -v psql -h "${NB_POSTGRESQL_HOST}" -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_DB}" \ -f connectivity/overall_scores.sql diff --git a/signalized.sql b/signalized.sql index f0ebcd13..8205ef67 100644 --- a/signalized.sql +++ b/signalized.sql @@ -1,27 +1,27 @@ ----------------------------------------- --- INPUTS --- location: cambridge ----------------------------------------- -UPDATE cambridge_ways_intersections SET signalized = 'f'; - -UPDATE cambridge_ways_intersections -SET signalized = 't' -FROM cambridge_osm_full_point osm -WHERE cambridge_ways_intersections.osm_id = osm.osm_id -AND osm.highway = 'traffic_signals'; - -UPDATE cambridge_ways_intersections -SET signalized = 't' -FROM cambridge_ways, - cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id -AND int_id = cambridge_ways.intersection_to -AND osm."traffic_signals:direction" = 'forward'; - -UPDATE cambridge_ways_intersections -SET signalized = 't' -FROM cambridge_ways, - cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id -AND int_id = cambridge_ways.intersection_from -AND osm."traffic_signals:direction" = 'backward'; +---------------------------------------- +-- INPUTS +-- location: neighborhood +---------------------------------------- +UPDATE neighborhood_ways_intersections SET signalized = 'f'; + +UPDATE neighborhood_ways_intersections +SET signalized = 't' +FROM neighborhood_osm_full_point osm +WHERE neighborhood_ways_intersections.osm_id = osm.osm_id +AND osm.highway = 'traffic_signals'; + +UPDATE neighborhood_ways_intersections +SET signalized = 't' +FROM neighborhood_ways, + neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id +AND int_id = neighborhood_ways.intersection_to +AND osm."traffic_signals:direction" = 'forward'; + +UPDATE neighborhood_ways_intersections +SET signalized = 't' +FROM neighborhood_ways, + neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id +AND int_id = neighborhood_ways.intersection_from +AND osm."traffic_signals:direction" = 'backward'; diff --git a/speed_limit.sql b/speed_limit.sql index 35e1803b..975ed480 100644 --- a/speed_limit.sql +++ b/speed_limit.sql @@ -1,11 +1,11 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -UPDATE cambridge_ways SET speed_limit = NULL; +UPDATE neighborhood_ways SET speed_limit = NULL; -UPDATE cambridge_ways +UPDATE neighborhood_ways SET speed_limit = substring(osm.maxspeed from '\d+')::INT -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id AND osm.maxspeed LIKE '% mph'; diff --git a/stops.sql b/stops.sql index bdee62b7..2138c62c 100644 --- a/stops.sql +++ b/stops.sql @@ -1,12 +1,12 @@ ----------------------------------------- --- INPUTS --- location: cambridge ----------------------------------------- -UPDATE cambridge_ways_intersections SET stops = 'f'; - -UPDATE cambridge_ways_intersections -SET stops = 't' -FROM cambridge_osm_full_point osm -WHERE cambridge_ways_intersections.osm_id = osm.osm_id -AND osm.highway = 'stop' -AND osm.stop = 'all'; +---------------------------------------- +-- INPUTS +-- location: neighborhood +---------------------------------------- +UPDATE neighborhood_ways_intersections SET stops = 'f'; + +UPDATE neighborhood_ways_intersections +SET stops = 't' +FROM neighborhood_osm_full_point osm +WHERE neighborhood_ways_intersections.osm_id = osm.osm_id +AND osm.highway = 'stop' +AND osm.stop = 'all'; diff --git a/stress_lesser_ints.sql b/stress_lesser_ints.sql index 1fa83798..b291ef1f 100644 --- a/stress_lesser_ints.sql +++ b/stress_lesser_ints.sql @@ -1,19 +1,19 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -UPDATE cambridge_ways SET ft_int_stress = 1, tf_int_stress = 1 +UPDATE neighborhood_ways SET ft_int_stress = 1, tf_int_stress = 1 WHERE functional_class IN ('residential','living_street','track','path'); -- ft -UPDATE cambridge_ways +UPDATE neighborhood_ways SET ft_int_stress = 3 WHERE functional_class IN ('residential','living_street','track','path') AND EXISTS ( SELECT 1 - FROM cambridge_ways w - WHERE cambridge_ways.intersection_to IN (w.intersection_to,w.intersection_from) - AND COALESCE(cambridge_ways.name,'a') != COALESCE(w.name,'b') + FROM neighborhood_ways w + WHERE neighborhood_ways.intersection_to IN (w.intersection_to,w.intersection_from) + AND COALESCE(neighborhood_ways.name,'a') != COALESCE(w.name,'b') AND CASE WHEN w.functional_class IN ('motorway','trunk','primary') THEN CASE @@ -62,14 +62,14 @@ AND EXISTS ( ); -- tf -UPDATE cambridge_ways +UPDATE neighborhood_ways SET tf_int_stress = 3 WHERE functional_class IN ('residential','living_street','track','path') AND EXISTS ( SELECT 1 - FROM cambridge_ways w - WHERE cambridge_ways.intersection_from IN (w.intersection_to,w.intersection_from) - AND COALESCE(cambridge_ways.name,'a') != COALESCE(w.name,'b') + FROM neighborhood_ways w + WHERE neighborhood_ways.intersection_from IN (w.intersection_to,w.intersection_from) + AND COALESCE(neighborhood_ways.name,'a') != COALESCE(w.name,'b') AND CASE WHEN w.functional_class IN ('motorway','trunk','primary') THEN CASE diff --git a/stress_link_ints.sql b/stress_link_ints.sql index 16c1addb..26e536ee 100644 --- a/stress_link_ints.sql +++ b/stress_link_ints.sql @@ -1,6 +1,6 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -UPDATE cambridge_ways SET ft_int_stress = 1, tf_int_stress = 1 +UPDATE neighborhood_ways SET ft_int_stress = 1, tf_int_stress = 1 WHERE functional_class LIKE '%_link'; diff --git a/stress_living_street.sql b/stress_living_street.sql index 7be738be..f1947739 100644 --- a/stress_living_street.sql +++ b/stress_living_street.sql @@ -1,11 +1,11 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -UPDATE cambridge_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL +UPDATE neighborhood_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL WHERE functional_class = 'living_street'; -UPDATE cambridge_ways +UPDATE neighborhood_ways SET ft_seg_stress = 1, tf_seg_stress = 1 WHERE functional_class = 'living_street'; diff --git a/stress_motorway-trunk.sql b/stress_motorway-trunk.sql index 1da735a7..35a6a48b 100644 --- a/stress_motorway-trunk.sql +++ b/stress_motorway-trunk.sql @@ -1,9 +1,9 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -UPDATE cambridge_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL +UPDATE neighborhood_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL WHERE functional_class IN ('motorway','motorway_link','trunk','trunk_link'); -UPDATE cambridge_ways SET ft_seg_stress = 3, tf_seg_stress = 3 +UPDATE neighborhood_ways SET ft_seg_stress = 3, tf_seg_stress = 3 WHERE functional_class IN ('motorway','motorway_link','trunk','trunk_link'); diff --git a/stress_motorway-trunk_ints.sql b/stress_motorway-trunk_ints.sql index 12fd8edb..e16e0b0d 100644 --- a/stress_motorway-trunk_ints.sql +++ b/stress_motorway-trunk_ints.sql @@ -1,7 +1,7 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -- assume low stress, since these juncions would always be controlled or free flowing -UPDATE cambridge_ways SET ft_int_stress = 1, tf_int_stress = 1 +UPDATE neighborhood_ways SET ft_int_stress = 1, tf_int_stress = 1 WHERE functional_class IN ('motorway','trunk'); diff --git a/stress_one_way_reset.sql b/stress_one_way_reset.sql index a08a4498..67130224 100644 --- a/stress_one_way_reset.sql +++ b/stress_one_way_reset.sql @@ -1,7 +1,7 @@ -- reset opposite stress for one-way -UPDATE cambridge_ways +UPDATE neighborhood_ways SET ft_seg_stress = NULL WHERE one_way = 'tf'; -UPDATE cambridge_ways +UPDATE neighborhood_ways SET tf_seg_stress = NULL WHERE one_way = 'ft'; diff --git a/stress_path.sql b/stress_path.sql index 19057fdd..cce9fd0b 100644 --- a/stress_path.sql +++ b/stress_path.sql @@ -1,11 +1,11 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -UPDATE cambridge_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL +UPDATE neighborhood_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL WHERE functional_class = 'path'; -UPDATE cambridge_ways +UPDATE neighborhood_ways SET ft_seg_stress = 1, tf_seg_stress = 1 WHERE functional_class = 'path'; diff --git a/stress_primary.sql b/stress_primary.sql index aa8f269e..e1b1d9b1 100644 --- a/stress_primary.sql +++ b/stress_primary.sql @@ -1,12 +1,12 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -UPDATE cambridge_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL +UPDATE neighborhood_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL WHERE functional_class IN ('primary','primary_link'); -- ft direction -UPDATE cambridge_ways +UPDATE neighborhood_ways SET ft_seg_stress = CASE WHEN ft_bike_infra = 'track' THEN 1 @@ -51,7 +51,7 @@ SET ft_seg_stress = WHERE functional_class IN ('primary','primary_link'); -- tf direction -UPDATE cambridge_ways +UPDATE neighborhood_ways SET tf_seg_stress = CASE WHEN tf_bike_infra = 'track' THEN 1 diff --git a/stress_primary_ints.sql b/stress_primary_ints.sql index 986db734..86621d04 100644 --- a/stress_primary_ints.sql +++ b/stress_primary_ints.sql @@ -1,7 +1,7 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -- assume low stress, since these juncions would always be controlled or free flowing -UPDATE cambridge_ways SET ft_int_stress = 1, tf_int_stress = 1 +UPDATE neighborhood_ways SET ft_int_stress = 1, tf_int_stress = 1 WHERE functional_class = 'primary'; diff --git a/stress_residential.sql b/stress_residential.sql index cdd51522..0d8eb8e5 100644 --- a/stress_residential.sql +++ b/stress_residential.sql @@ -1,43 +1,43 @@ ----------------------------------------- --- INPUTS --- location: cambridge --- notes: residential streets with bike lanes of any type --- are scored as tertiary streets ----------------------------------------- -UPDATE cambridge_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL -WHERE functional_class = 'residential' -AND (ft_bike_infra IS NULL OR ft_bike_infra NOT IN ('track','buffered_lane','lane')) -AND (tf_bike_infra IS NULL OR tf_bike_infra NOT IN ('track','buffered_lane','lane')); - --- no additional information -UPDATE cambridge_ways -SET ft_seg_stress = 1, - tf_seg_stress = 1 -WHERE functional_class = 'residential' -AND (ft_bike_infra IS NULL OR ft_bike_infra NOT IN ('track','buffered_lane','lane')) -AND (tf_bike_infra IS NULL OR tf_bike_infra NOT IN ('track','buffered_lane','lane')); - --- stress increase for multiple lanes or high speeds -UPDATE cambridge_ways -SET ft_seg_stress = 3 -WHERE functional_class = 'residential' -AND (ft_bike_infra IS NULL OR ft_bike_infra NOT IN ('track','buffered_lane','lane')) -AND (tf_bike_infra IS NULL OR tf_bike_infra NOT IN ('track','buffered_lane','lane')) -AND (ft_lanes > 1 OR speed_limit > 30); -UPDATE cambridge_ways -SET tf_seg_stress = 3 -WHERE functional_class = 'residential' -AND (ft_bike_infra IS NULL OR ft_bike_infra NOT IN ('track','buffered_lane','lane')) -AND (tf_bike_infra IS NULL OR tf_bike_infra NOT IN ('track','buffered_lane','lane')) -AND (tf_lanes > 1 OR speed_limit > 30); - --- stress increase for narrow one way and parking on both sides -UPDATE cambridge_ways -SET ft_seg_stress = 2, - tf_seg_stress = 2 -WHERE functional_class = 'residential' -AND (ft_bike_infra IS NULL OR ft_bike_infra NOT IN ('track','buffered_lane','lane')) -AND (tf_bike_infra IS NULL OR tf_bike_infra NOT IN ('track','buffered_lane','lane')) -AND width_ft <= 26 -AND ft_park = 1 -AND tf_park = 1; +---------------------------------------- +-- INPUTS +-- location: neighborhood +-- notes: residential streets with bike lanes of any type +-- are scored as tertiary streets +---------------------------------------- +UPDATE neighborhood_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL +WHERE functional_class = 'residential' +AND (ft_bike_infra IS NULL OR ft_bike_infra NOT IN ('track','buffered_lane','lane')) +AND (tf_bike_infra IS NULL OR tf_bike_infra NOT IN ('track','buffered_lane','lane')); + +-- no additional information +UPDATE neighborhood_ways +SET ft_seg_stress = 1, + tf_seg_stress = 1 +WHERE functional_class = 'residential' +AND (ft_bike_infra IS NULL OR ft_bike_infra NOT IN ('track','buffered_lane','lane')) +AND (tf_bike_infra IS NULL OR tf_bike_infra NOT IN ('track','buffered_lane','lane')); + +-- stress increase for multiple lanes or high speeds +UPDATE neighborhood_ways +SET ft_seg_stress = 3 +WHERE functional_class = 'residential' +AND (ft_bike_infra IS NULL OR ft_bike_infra NOT IN ('track','buffered_lane','lane')) +AND (tf_bike_infra IS NULL OR tf_bike_infra NOT IN ('track','buffered_lane','lane')) +AND (ft_lanes > 1 OR speed_limit > 30); +UPDATE neighborhood_ways +SET tf_seg_stress = 3 +WHERE functional_class = 'residential' +AND (ft_bike_infra IS NULL OR ft_bike_infra NOT IN ('track','buffered_lane','lane')) +AND (tf_bike_infra IS NULL OR tf_bike_infra NOT IN ('track','buffered_lane','lane')) +AND (tf_lanes > 1 OR speed_limit > 30); + +-- stress increase for narrow one way and parking on both sides +UPDATE neighborhood_ways +SET ft_seg_stress = 2, + tf_seg_stress = 2 +WHERE functional_class = 'residential' +AND (ft_bike_infra IS NULL OR ft_bike_infra NOT IN ('track','buffered_lane','lane')) +AND (tf_bike_infra IS NULL OR tf_bike_infra NOT IN ('track','buffered_lane','lane')) +AND width_ft <= 26 +AND ft_park = 1 +AND tf_park = 1; diff --git a/stress_secondary.sql b/stress_secondary.sql index 4975d28c..5cb6971a 100644 --- a/stress_secondary.sql +++ b/stress_secondary.sql @@ -1,12 +1,12 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -UPDATE cambridge_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL +UPDATE neighborhood_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL WHERE functional_class IN ('secondary','secondary_link'); -- ft direction -UPDATE cambridge_ways +UPDATE neighborhood_ways SET ft_seg_stress = CASE WHEN ft_bike_infra = 'track' THEN 1 @@ -51,7 +51,7 @@ SET ft_seg_stress = WHERE functional_class IN ('secondary','secondary_link'); -- tf direction -UPDATE cambridge_ways +UPDATE neighborhood_ways SET tf_seg_stress = CASE WHEN tf_bike_infra = 'track' THEN 1 diff --git a/stress_secondary_ints.sql b/stress_secondary_ints.sql index 9e42a555..8b976dad 100644 --- a/stress_secondary_ints.sql +++ b/stress_secondary_ints.sql @@ -1,19 +1,19 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -UPDATE cambridge_ways SET ft_int_stress = 1, tf_int_stress = 1 +UPDATE neighborhood_ways SET ft_int_stress = 1, tf_int_stress = 1 WHERE functional_class = 'secondary'; -- ft -UPDATE cambridge_ways +UPDATE neighborhood_ways SET ft_int_stress = 3 WHERE functional_class = 'secondary' AND EXISTS ( SELECT 1 - FROM cambridge_ways w - WHERE cambridge_ways.intersection_to IN (w.intersection_to,w.intersection_from) - AND COALESCE(cambridge_ways.name,'a') != COALESCE(w.name,'b') + FROM neighborhood_ways w + WHERE neighborhood_ways.intersection_to IN (w.intersection_to,w.intersection_from) + AND COALESCE(neighborhood_ways.name,'a') != COALESCE(w.name,'b') AND CASE WHEN w.functional_class IN ('motorway','trunk','primary') THEN CASE @@ -48,14 +48,14 @@ AND EXISTS ( ); -- tf -UPDATE cambridge_ways +UPDATE neighborhood_ways SET tf_int_stress = 3 WHERE functional_class = 'secondary' AND EXISTS ( SELECT 1 - FROM cambridge_ways w - WHERE cambridge_ways.intersection_from IN (w.intersection_to,w.intersection_from) - AND COALESCE(cambridge_ways.name,'a') != COALESCE(w.name,'b') + FROM neighborhood_ways w + WHERE neighborhood_ways.intersection_from IN (w.intersection_to,w.intersection_from) + AND COALESCE(neighborhood_ways.name,'a') != COALESCE(w.name,'b') AND CASE WHEN w.functional_class IN ('motorway','trunk','primary') THEN CASE diff --git a/stress_tertiary.sql b/stress_tertiary.sql index 0855b7ce..ea64f7ce 100644 --- a/stress_tertiary.sql +++ b/stress_tertiary.sql @@ -1,122 +1,122 @@ ----------------------------------------- --- INPUTS --- location: cambridge --- notes: this includes residential streets that have bike lanes --- of any type ----------------------------------------- -UPDATE cambridge_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL -WHERE functional_class IN ('tertiary','tertiary_link') -OR (functional_class = 'residential' AND ft_bike_infra IN ('track','buffered_lane','lane')) -OR (functional_class = 'residential' AND tf_bike_infra IN ('track','buffered_lane','lane')); - --- ft direction -UPDATE cambridge_ways -SET ft_seg_stress = - CASE - WHEN ft_bike_infra = 'track' THEN 1 - WHEN ft_bike_infra = 'buffered_lane' - THEN CASE - WHEN speed_limit > 35 THEN 3 - WHEN speed_limit = 35 THEN CASE - WHEN ft_lanes = 1 THEN 2 - ELSE 3 - END - ELSE CASE - WHEN ft_lanes > 1 THEN 3 - ELSE 1 - END - END - WHEN ft_bike_infra = 'lane' - THEN CASE - WHEN speed_limit > 30 THEN 3 - WHEN speed_limit <= 25 - THEN CASE - WHEN ft_lanes > 2 THEN 3 - WHEN ft_lanes = 1 THEN CASE - WHEN ft_park = 1 THEN 2 - ELSE 2 - END - ELSE CASE - WHEN ft_park = 0 THEN 1 - ELSE 2 - END - END - ELSE CASE - WHEN ft_lanes > 1 THEN 3 - ELSE CASE - WHEN ft_park = 0 THEN 1 - ELSE 2 - END - END - END - ELSE CASE - WHEN speed_limit = 30 - THEN CASE - WHEN ft_lanes = 1 THEN 2 - ELSE 3 - END - WHEN speed_limit = 25 - THEN CASE - WHEN ft_lanes = 1 THEN 1 - ELSE 3 - END - ELSE 3 - END - END -WHERE functional_class IN ('tertiary','tertiary_link') -OR (functional_class = 'residential' AND ft_bike_infra IN ('track','buffered_lane','lane')) -OR (functional_class = 'residential' AND tf_bike_infra IN ('track','buffered_lane','lane')); - --- tf direction -UPDATE cambridge_ways -SET tf_seg_stress = - CASE - WHEN tf_bike_infra = 'track' THEN 1 - WHEN tf_bike_infra = 'buffered_lane' - THEN CASE - WHEN speed_limit > 30 THEN 3 - ELSE CASE - WHEN tf_lanes > 1 THEN 3 - ELSE 1 - END - END - WHEN tf_bike_infra = 'lane' - THEN CASE - WHEN speed_limit > 30 THEN 3 - WHEN speed_limit <= 25 - THEN CASE - WHEN tf_lanes > 2 THEN 3 - WHEN tf_lanes = 1 THEN CASE - WHEN tf_park = 1 THEN 2 - ELSE 2 - END - ELSE CASE - WHEN tf_park = 0 THEN 1 - ELSE 2 - END - END - ELSE CASE - WHEN tf_lanes > 1 THEN 3 - ELSE CASE - WHEN tf_park = 0 THEN 1 - ELSE 2 - END - END - END - ELSE CASE - WHEN speed_limit = 30 - THEN CASE - WHEN tf_lanes = 1 THEN 2 - ELSE 3 - END - WHEN speed_limit = 25 - THEN CASE - WHEN tf_lanes = 1 THEN 1 - ELSE 3 - END - ELSE 3 - END - END -WHERE functional_class IN ('tertiary','tertiary_link') -OR (functional_class = 'residential' AND ft_bike_infra IN ('track','buffered_lane','lane')) -OR (functional_class = 'residential' AND tf_bike_infra IN ('track','buffered_lane','lane')); +---------------------------------------- +-- INPUTS +-- location: neighborhood +-- notes: this includes residential streets that have bike lanes +-- of any type +---------------------------------------- +UPDATE neighborhood_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL +WHERE functional_class IN ('tertiary','tertiary_link') +OR (functional_class = 'residential' AND ft_bike_infra IN ('track','buffered_lane','lane')) +OR (functional_class = 'residential' AND tf_bike_infra IN ('track','buffered_lane','lane')); + +-- ft direction +UPDATE neighborhood_ways +SET ft_seg_stress = + CASE + WHEN ft_bike_infra = 'track' THEN 1 + WHEN ft_bike_infra = 'buffered_lane' + THEN CASE + WHEN speed_limit > 35 THEN 3 + WHEN speed_limit = 35 THEN CASE + WHEN ft_lanes = 1 THEN 2 + ELSE 3 + END + ELSE CASE + WHEN ft_lanes > 1 THEN 3 + ELSE 1 + END + END + WHEN ft_bike_infra = 'lane' + THEN CASE + WHEN speed_limit > 30 THEN 3 + WHEN speed_limit <= 25 + THEN CASE + WHEN ft_lanes > 2 THEN 3 + WHEN ft_lanes = 1 THEN CASE + WHEN ft_park = 1 THEN 2 + ELSE 2 + END + ELSE CASE + WHEN ft_park = 0 THEN 1 + ELSE 2 + END + END + ELSE CASE + WHEN ft_lanes > 1 THEN 3 + ELSE CASE + WHEN ft_park = 0 THEN 1 + ELSE 2 + END + END + END + ELSE CASE + WHEN speed_limit = 30 + THEN CASE + WHEN ft_lanes = 1 THEN 2 + ELSE 3 + END + WHEN speed_limit = 25 + THEN CASE + WHEN ft_lanes = 1 THEN 1 + ELSE 3 + END + ELSE 3 + END + END +WHERE functional_class IN ('tertiary','tertiary_link') +OR (functional_class = 'residential' AND ft_bike_infra IN ('track','buffered_lane','lane')) +OR (functional_class = 'residential' AND tf_bike_infra IN ('track','buffered_lane','lane')); + +-- tf direction +UPDATE neighborhood_ways +SET tf_seg_stress = + CASE + WHEN tf_bike_infra = 'track' THEN 1 + WHEN tf_bike_infra = 'buffered_lane' + THEN CASE + WHEN speed_limit > 30 THEN 3 + ELSE CASE + WHEN tf_lanes > 1 THEN 3 + ELSE 1 + END + END + WHEN tf_bike_infra = 'lane' + THEN CASE + WHEN speed_limit > 30 THEN 3 + WHEN speed_limit <= 25 + THEN CASE + WHEN tf_lanes > 2 THEN 3 + WHEN tf_lanes = 1 THEN CASE + WHEN tf_park = 1 THEN 2 + ELSE 2 + END + ELSE CASE + WHEN tf_park = 0 THEN 1 + ELSE 2 + END + END + ELSE CASE + WHEN tf_lanes > 1 THEN 3 + ELSE CASE + WHEN tf_park = 0 THEN 1 + ELSE 2 + END + END + END + ELSE CASE + WHEN speed_limit = 30 + THEN CASE + WHEN tf_lanes = 1 THEN 2 + ELSE 3 + END + WHEN speed_limit = 25 + THEN CASE + WHEN tf_lanes = 1 THEN 1 + ELSE 3 + END + ELSE 3 + END + END +WHERE functional_class IN ('tertiary','tertiary_link') +OR (functional_class = 'residential' AND ft_bike_infra IN ('track','buffered_lane','lane')) +OR (functional_class = 'residential' AND tf_bike_infra IN ('track','buffered_lane','lane')); diff --git a/stress_tertiary_ints.sql b/stress_tertiary_ints.sql index feb754de..9e6aa309 100644 --- a/stress_tertiary_ints.sql +++ b/stress_tertiary_ints.sql @@ -1,19 +1,19 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -UPDATE cambridge_ways SET ft_int_stress = 1, tf_int_stress = 1 +UPDATE neighborhood_ways SET ft_int_stress = 1, tf_int_stress = 1 WHERE functional_class = 'tertiary'; -- ft -UPDATE cambridge_ways +UPDATE neighborhood_ways SET ft_int_stress = 3 WHERE functional_class = 'tertiary' AND EXISTS ( SELECT 1 - FROM cambridge_ways w - WHERE cambridge_ways.intersection_to IN (w.intersection_to,w.intersection_from) - AND COALESCE(cambridge_ways.name,'a') != COALESCE(w.name,'b') + FROM neighborhood_ways w + WHERE neighborhood_ways.intersection_to IN (w.intersection_to,w.intersection_from) + AND COALESCE(neighborhood_ways.name,'a') != COALESCE(w.name,'b') AND CASE WHEN w.functional_class IN ('motorway','trunk','primary') THEN CASE @@ -62,14 +62,14 @@ AND EXISTS ( ); -- tf -UPDATE cambridge_ways +UPDATE neighborhood_ways SET tf_int_stress = 3 WHERE functional_class = 'tertiary' AND EXISTS ( SELECT 1 - FROM cambridge_ways w - WHERE cambridge_ways.intersection_from IN (w.intersection_to,w.intersection_from) - AND COALESCE(cambridge_ways.name,'a') != COALESCE(w.name,'b') + FROM neighborhood_ways w + WHERE neighborhood_ways.intersection_from IN (w.intersection_to,w.intersection_from) + AND COALESCE(neighborhood_ways.name,'a') != COALESCE(w.name,'b') AND CASE WHEN w.functional_class IN ('motorway','trunk','primary') THEN CASE diff --git a/stress_track.sql b/stress_track.sql index bdc75261..2aaf2b54 100644 --- a/stress_track.sql +++ b/stress_track.sql @@ -1,11 +1,11 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -UPDATE cambridge_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL +UPDATE neighborhood_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL WHERE functional_class = 'track'; -UPDATE cambridge_ways +UPDATE neighborhood_ways SET ft_seg_stress = 1, tf_seg_stress = 1 WHERE functional_class = 'track'; diff --git a/width_ft.sql b/width_ft.sql index 69710209..24333b53 100644 --- a/width_ft.sql +++ b/width_ft.sql @@ -1,31 +1,31 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -UPDATE cambridge_ways SET width_ft = NULL; +UPDATE neighborhood_ways SET width_ft = NULL; -- feet -UPDATE cambridge_ways +UPDATE neighborhood_ways SET width_ft = substring(osm.width from '\d+\.?\d?\d?')::FLOAT -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id AND osm.width IS NOT NULL AND osm.width LIKE '% ft'; -- meters -UPDATE cambridge_ways +UPDATE neighborhood_ways SET width_ft = 3.28084 * substring(osm.width from '\d+\.?\d?\d?')::FLOAT -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id AND osm.width IS NOT NULL AND osm.width LIKE '% m'; -- no units (default=meters) -- N.B. we weed out anything more than 20, since that's likely either bogus -- or not in meters -UPDATE cambridge_ways +UPDATE neighborhood_ways SET width_ft = 3.28084 * substring(osm.width from '\d+\.?\d?\d?')::FLOAT -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id AND osm.width IS NOT NULL AND substring(osm.width from '\d+\.?\d?\d?')::FLOAT < 20; From a58ecf30df8daa5bc9563728e294fe260421befd Mon Sep 17 00:00:00 2001 From: CloudNiner Date: Thu, 27 Oct 2016 10:03:11 -0400 Subject: [PATCH 50/94] Make connectivity scripts idempotent --- connectivity/access_jobs.sql | 2 ++ connectivity/access_population.sql | 2 ++ connectivity/access_schools.sql | 4 ++++ connectivity/census_block_jobs.sql | 11 ++++------- connectivity/census_block_roads.sql | 2 +- connectivity/census_blocks.sql | 18 +++++++++--------- connectivity/connected_census_blocks.sql | 4 ++-- .../connected_census_blocks_schools.sql | 6 +++--- connectivity/reachable_roads_high_stress.sql | 4 ++-- connectivity/reachable_roads_low_stress.sql | 4 ++-- connectivity/school_roads.sql | 4 ++-- 11 files changed, 33 insertions(+), 28 deletions(-) diff --git a/connectivity/access_jobs.sql b/connectivity/access_jobs.sql index 8924744b..3988c8e0 100644 --- a/connectivity/access_jobs.sql +++ b/connectivity/access_jobs.sql @@ -3,6 +3,7 @@ -- location: neighborhood ---------------------------------------- -- low stress access +UPDATE neighborhood_census_blocks SET emp_low_stress = NULL; UPDATE neighborhood_census_blocks SET emp_low_stress = ( SELECT SUM(blocks2.jobs) @@ -22,6 +23,7 @@ WHERE EXISTS ( ); -- high stress access +UPDATE neighborhood_census_blocks SET emp_high_stress = NULL; UPDATE neighborhood_census_blocks SET emp_high_stress = ( SELECT SUM(blocks2.jobs) diff --git a/connectivity/access_population.sql b/connectivity/access_population.sql index 86f6e397..1bf47ceb 100644 --- a/connectivity/access_population.sql +++ b/connectivity/access_population.sql @@ -3,6 +3,7 @@ -- location: neighborhood ---------------------------------------- -- low stress access +UPDATE neighborhood_census_blocks SET pop_low_stress = NULL; UPDATE neighborhood_census_blocks SET pop_low_stress = ( SELECT SUM(blocks2.pop10) @@ -22,6 +23,7 @@ WHERE EXISTS ( ); -- high stress access +UPDATE neighborhood_census_blocks SET pop_high_stress = NULL; UPDATE neighborhood_census_blocks SET pop_high_stress = ( SELECT SUM(blocks2.pop10) diff --git a/connectivity/access_schools.sql b/connectivity/access_schools.sql index d584ccd3..852c8bcd 100644 --- a/connectivity/access_schools.sql +++ b/connectivity/access_schools.sql @@ -3,6 +3,7 @@ -- location: neighborhood ---------------------------------------- -- low stress access +UPDATE neighborhood_census_blocks SET schools_low_stress = NULL; UPDATE neighborhood_census_blocks SET schools_low_stress = ( SELECT COUNT(cbs.id) @@ -17,6 +18,7 @@ WHERE EXISTS ( ); -- high stress access +UPDATE neighborhood_census_blocks SET schools_high_stress = NULL; UPDATE neighborhood_census_blocks SET schools_high_stress = ( SELECT COUNT(cbs.id) @@ -30,6 +32,7 @@ WHERE EXISTS ( ); -- low stress population shed for schools in neighborhood +UPDATE neighborhood_schools SET pop_low_stress = NULL; UPDATE neighborhood_schools SET pop_low_stress = ( SELECT SUM(cb.pop10) @@ -46,6 +49,7 @@ WHERE EXISTS ( ); -- high stress population shed for schools in neighborhood +UPDATE neighborhood_schools SET pop_high_stress = NULL; UPDATE neighborhood_schools SET pop_high_stress = ( SELECT SUM(cb.pop10) diff --git a/connectivity/census_block_jobs.sql b/connectivity/census_block_jobs.sql index bffd8994..813f2138 100644 --- a/connectivity/census_block_jobs.sql +++ b/connectivity/census_block_jobs.sql @@ -18,12 +18,13 @@ ALTER TABLE "state_od_main_JT00_2014" ALTER COLUMN w_geocode TYPE VARCHAR(15); UPDATE "state_od_main_JT00_2014" SET w_geocode = rpad(w_geocode,15,'0'); --just in case we lost any trailing zeros -- indexes -CREATE INDEX tidx_auxjtw ON "state_od_aux_JT00_2014" (w_geocode); -CREATE INDEX tidx_mainjtw ON "state_od_main_JT00_2014" (w_geocode); +CREATE INDEX IF NOT EXISTS tidx_auxjtw ON "state_od_aux_JT00_2014" (w_geocode); +CREATE INDEX IF NOT EXISTS tidx_mainjtw ON "state_od_main_JT00_2014" (w_geocode); ANALYZE "state_od_aux_JT00_2014" (w_geocode); ANALYZE "state_od_main_JT00_2014" (w_geocode); -- create combined table +DROP TABLE IF EXISTS generated.neighborhood_census_block_jobs; CREATE TABLE generated.neighborhood_census_block_jobs ( id SERIAL PRIMARY KEY, blockid10 VARCHAR(15), @@ -53,9 +54,5 @@ SET jobs = jobs + ),0); -- indexes -CREATE INDEX idx_neighborhood_blkjobs ON neighborhood_census_block_jobs (blockid10); +CREATE INDEX IF NOT EXISTS idx_neighborhood_blkjobs ON neighborhood_census_block_jobs (blockid10); ANALYZE neighborhood_census_block_jobs (blockid10); - --- drop import tables --- DROP TABLE IF EXISTS "state_od_aux_JT00_2014"; --- DROP TABLE IF EXISTS "state_od_main_JT00_2014"; diff --git a/connectivity/census_block_roads.sql b/connectivity/census_block_roads.sql index f17cc004..fa4b5e17 100644 --- a/connectivity/census_block_roads.sql +++ b/connectivity/census_block_roads.sql @@ -20,6 +20,6 @@ FROM neighborhood_census_blocks blocks, neighborhood_ways ways WHERE ST_DWithin(blocks.geom,ways.geom,50); -CREATE INDEX idx_neighborhood_censblkrds +CREATE INDEX IF NOT EXISTS idx_neighborhood_censblkrds ON generated.neighborhood_census_block_roads (blockid10,road_id); ANALYZE generated.neighborhood_census_block_roads; diff --git a/connectivity/census_blocks.sql b/connectivity/census_blocks.sql index 3f2a1456..e327dc05 100644 --- a/connectivity/census_blocks.sql +++ b/connectivity/census_blocks.sql @@ -6,14 +6,14 @@ -- blkpophu file ---------------------------------------- -ALTER TABLE neighborhood_census_blocks ADD COLUMN pop_low_stress INT; -ALTER TABLE neighborhood_census_blocks ADD COLUMN pop_high_stress INT; -ALTER TABLE neighborhood_census_blocks ADD COLUMN emp_low_stress INT; -ALTER TABLE neighborhood_census_blocks ADD COLUMN emp_high_stress INT; -ALTER TABLE neighborhood_census_blocks ADD COLUMN schools_low_stress INT; -ALTER TABLE neighborhood_census_blocks ADD COLUMN schools_high_stress INT; -ALTER TABLE neighborhood_census_blocks ADD COLUMN rec_low_stress INT; -ALTER TABLE neighborhood_census_blocks ADD COLUMN rec_high_stress INT; +ALTER TABLE neighborhood_census_blocks ADD COLUMN IF NOT EXISTS pop_low_stress INT; +ALTER TABLE neighborhood_census_blocks ADD COLUMN IF NOT EXISTS pop_high_stress INT; +ALTER TABLE neighborhood_census_blocks ADD COLUMN IF NOT EXISTS emp_low_stress INT; +ALTER TABLE neighborhood_census_blocks ADD COLUMN IF NOT EXISTS emp_high_stress INT; +ALTER TABLE neighborhood_census_blocks ADD COLUMN IF NOT EXISTS schools_low_stress INT; +ALTER TABLE neighborhood_census_blocks ADD COLUMN IF NOT EXISTS schools_high_stress INT; +ALTER TABLE neighborhood_census_blocks ADD COLUMN IF NOT EXISTS rec_low_stress INT; +ALTER TABLE neighborhood_census_blocks ADD COLUMN IF NOT EXISTS rec_high_stress INT; -CREATE INDEX idx_neighborhood_blocks10 ON neighborhood_census_blocks (blockid10); +CREATE INDEX IF NOT EXISTS idx_neighborhood_blocks10 ON neighborhood_census_blocks (blockid10); ANALYZE neighborhood_census_blocks (blockid10); diff --git a/connectivity/connected_census_blocks.sql b/connectivity/connected_census_blocks.sql index 842d5601..ac13fed6 100644 --- a/connectivity/connected_census_blocks.sql +++ b/connectivity/connected_census_blocks.sql @@ -80,6 +80,6 @@ AND ( ),11000) <= 1.3; -- stress index -CREATE INDEX idx_neighborhood_blockpairs_lstress ON neighborhood_connected_census_blocks (low_stress); -CREATE INDEX idx_neighborhood_blockpairs_hstress ON neighborhood_connected_census_blocks (high_stress); +CREATE INDEX IF NOT EXISTS idx_neighborhood_blockpairs_lstress ON neighborhood_connected_census_blocks (low_stress); +CREATE INDEX IF NOT EXISTS idx_neighborhood_blockpairs_hstress ON neighborhood_connected_census_blocks (high_stress); ANALYZE neighborhood_connected_census_blocks (low_stress,high_stress); diff --git a/connectivity/connected_census_blocks_schools.sql b/connectivity/connected_census_blocks_schools.sql index 5f6fee53..2c1c3185 100644 --- a/connectivity/connected_census_blocks_schools.sql +++ b/connectivity/connected_census_blocks_schools.sql @@ -41,7 +41,7 @@ AND EXISTS ( ); -- block pair index -CREATE INDEX idx_neighborhood_blockschoolpairs +CREATE INDEX IF NOT EXISTS idx_neighborhood_blockschoolpairs ON neighborhood_connected_census_blocks_schools (source_blockid10,target_school_id); ANALYZE neighborhood_connected_census_blocks_schools (source_blockid10,target_school_id); @@ -80,6 +80,6 @@ AND ( ),11000) <= 1.3; -- stress index -CREATE INDEX idx_neighborhood_blockschl_lstress ON neighborhood_connected_census_blocks_schools (low_stress); -CREATE INDEX idx_neighborhood_blockschl_hstress ON neighborhood_connected_census_blocks_schools (high_stress); +CREATE INDEX IF NOT EXISTS idx_neighborhood_blockschl_lstress ON neighborhood_connected_census_blocks_schools (low_stress); +CREATE INDEX IF NOT EXISTS idx_neighborhood_blockschl_hstress ON neighborhood_connected_census_blocks_schools (high_stress); ANALYZE neighborhood_connected_census_blocks_schools (low_stress,high_stress); diff --git a/connectivity/reachable_roads_high_stress.sql b/connectivity/reachable_roads_high_stress.sql index 14ef6849..2d3fd249 100644 --- a/connectivity/reachable_roads_high_stress.sql +++ b/connectivity/reachable_roads_high_stress.sql @@ -41,6 +41,6 @@ WHERE EXISTS ( AND r1.road_id = v1.road_id AND v2.vert_id = sheds.node; -CREATE INDEX idx_neighborhood_rchblrdshistrss_b ON generated.neighborhood_reachable_roads_high_stress (base_road); -CREATE INDEX idx_neighborhood_rchblrdshistrss_t ON generated.neighborhood_reachable_roads_high_stress (target_road); +CREATE INDEX IF NOT EXISTS idx_neighborhood_rchblrdshistrss_b ON generated.neighborhood_reachable_roads_high_stress (base_road); +CREATE INDEX IF NOT EXISTS idx_neighborhood_rchblrdshistrss_t ON generated.neighborhood_reachable_roads_high_stress (target_road); ANALYZE generated.neighborhood_reachable_roads_high_stress (base_road,target_road); diff --git a/connectivity/reachable_roads_low_stress.sql b/connectivity/reachable_roads_low_stress.sql index e134b1ae..4690cf3a 100644 --- a/connectivity/reachable_roads_low_stress.sql +++ b/connectivity/reachable_roads_low_stress.sql @@ -42,6 +42,6 @@ WHERE EXISTS ( AND r1.road_id = v1.road_id AND v2.vert_id = sheds.node; -CREATE INDEX idx_neighborhood_rchblrdslowstrss_b ON generated.neighborhood_reachable_roads_low_stress (base_road); -CREATE INDEX idx_neighborhood_rchblrdslowstrss_t ON generated.neighborhood_reachable_roads_low_stress (target_road); +CREATE INDEX IF NOT EXISTS idx_neighborhood_rchblrdslowstrss_b ON generated.neighborhood_reachable_roads_low_stress (base_road); +CREATE INDEX IF NOT EXISTS idx_neighborhood_rchblrdslowstrss_t ON generated.neighborhood_reachable_roads_low_stress (target_road); ANALYZE generated.neighborhood_reachable_roads_low_stress (base_road,target_road); diff --git a/connectivity/school_roads.sql b/connectivity/school_roads.sql index 8aac9875..3141f9e5 100644 --- a/connectivity/school_roads.sql +++ b/connectivity/school_roads.sql @@ -51,6 +51,6 @@ AND NOT EXISTS ( WHERE schools.id = r.school_id ); -CREATE INDEX idx_neighborhood_schlrds_schlid ON generated.neighborhood_school_roads (school_id); -CREATE INDEX idx_neighborhood_schlrds_rdid ON generated.neighborhood_school_roads (road_id); +CREATE INDEX IF NOT EXISTS idx_neighborhood_schlrds_schlid ON generated.neighborhood_school_roads (school_id); +CREATE INDEX IF NOT EXISTS idx_neighborhood_schlrds_rdid ON generated.neighborhood_school_roads (road_id); ANALYZE generated.neighborhood_school_roads (school_id, road_id); From 872134df2db502a7bed60b9df053393889581ba7 Mon Sep 17 00:00:00 2001 From: CloudNiner Date: Thu, 27 Oct 2016 11:36:25 -0400 Subject: [PATCH 51/94] Update default name of osm file --- import_osm.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/import_osm.sh b/import_osm.sh index 13612694..00a9843b 100755 --- a/import_osm.sh +++ b/import_osm.sh @@ -6,7 +6,7 @@ NB_POSTGRESQL_HOST="${NB_POSTGRESQL_HOST:-127.0.0.1}" NB_POSTGRESQL_DB="${NB_POSTGRESQL_DB:-pfb}" NB_POSTGRESQL_USER="${NB_POSTGRESQL_USER:-gis}" NB_POSTGRESQL_PASSWORD="${NB_POSTGRESQL_PASSWORD:-gis}" -NB_OSMFILE="${NB_OSMFILE:-/vagrant/data/cambridge.osm}" +NB_OSMFILE="${NB_OSMFILE:-/vagrant/data/neighborhood.osm}" # drop old tables echo 'Dropping old tables' From e9867eb4024a46dc13446b416ed6434f05581f08 Mon Sep 17 00:00:00 2001 From: CloudNiner Date: Thu, 27 Oct 2016 11:36:39 -0400 Subject: [PATCH 52/94] Add wrapper import script --- import.sh | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100755 import.sh diff --git a/import.sh b/import.sh new file mode 100755 index 00000000..6785f2be --- /dev/null +++ b/import.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +set -e + +cd `dirname "${0}"` + +if [[ -n "${PFB_DEBUG}" ]]; then + set -x +fi + +function usage() { + echo -n \ +" +Usage: $(basename "$0") + +Import all necessary files to run the analysis. See the scripts this calls for specific +ENV configuration options. + +" +} + +if [ "${BASH_SOURCE[0]}" = "${0}" ] +then + if [ "${1:-}" = "--help" ] || [ -z "${1:-}" ] + then + usage + else + ./import_neighborhood.sh "${1}" "${3}" + ./import_jobs.sh "${2}" + ./import_osm.sh + fi +fi From 543e88b80c47258ff9f837a55b1668e844c63fc1 Mon Sep 17 00:00:00 2001 From: CloudNiner Date: Tue, 1 Nov 2016 10:08:11 -0400 Subject: [PATCH 53/94] Parametrize analysis SRID in all scripts --- connectivity/schools.sql | 6 ++++-- import_osm.sh | 9 ++++++--- paths.sql | 8 +++++--- prepare_tables.sql | 15 ++++++++------- run_connectivity.sh | 3 ++- 5 files changed, 25 insertions(+), 16 deletions(-) diff --git a/connectivity/schools.sql b/connectivity/schools.sql index 275bd4a4..07ee52cc 100644 --- a/connectivity/schools.sql +++ b/connectivity/schools.sql @@ -1,6 +1,8 @@ ---------------------------------------- -- INPUTS -- location: neighborhood +-- proj: :nb_output_srid psql var must be set before running this script, +-- e.g. psql -v nb_output_srid=4326 -f schools.sql ---------------------------------------- DROP TABLE IF EXISTS generated.neighborhood_schools; @@ -10,8 +12,8 @@ CREATE TABLE generated.neighborhood_schools ( school_name TEXT, pop_low_stress INT, pop_high_stress INT, - geom_pt geometry(point,2249), - geom_poly geometry(polygon,2249) + geom_pt geometry(point, :nb_output_srid), + geom_poly geometry(polygon, :nb_output_srid) ); CREATE INDEX sidx_neighborhood_schools_geompt ON neighborhood_schools USING GIST (geom_pt); CREATE INDEX sidx_neighborhood_schools_geomply ON neighborhood_schools USING GIST (geom_poly); diff --git a/import_osm.sh b/import_osm.sh index 00a9843b..3db1fe8c 100755 --- a/import_osm.sh +++ b/import_osm.sh @@ -7,6 +7,7 @@ NB_POSTGRESQL_DB="${NB_POSTGRESQL_DB:-pfb}" NB_POSTGRESQL_USER="${NB_POSTGRESQL_USER:-gis}" NB_POSTGRESQL_PASSWORD="${NB_POSTGRESQL_PASSWORD:-gis}" NB_OSMFILE="${NB_OSMFILE:-/vagrant/data/neighborhood.osm}" +NB_OUTPUT_SRID="${NB_OUTPUT_SRID:-4326}" # drop old tables echo 'Dropping old tables' @@ -128,7 +129,7 @@ osm2pgsql \ --create \ --database "${NB_POSTGRESQL_DB}" \ --prefix "neighborhood_osm_full" \ - --proj 2249 \ + --proj "${NB_OUTPUT_SRID}" \ --style ./pfb.style \ "${NB_OSMFILE}" @@ -145,11 +146,13 @@ psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ # process tables echo 'Updating field names' -psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./prepare_tables.sql +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ + -v nb_output_srid="${NB_OUTPUT_SRID}" -f ./prepare_tables.sql echo 'Setting values on road segments' psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./one_way.sql psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./functional_class.sql -psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./paths.sql +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ + -v nb_output_srid="${NB_OUTPUT_SRID}" -f ./paths.sql psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./speed_limit.sql psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./width_ft.sql psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./lanes.sql diff --git a/paths.sql b/paths.sql index b413d1f3..c1d9f5f1 100644 --- a/paths.sql +++ b/paths.sql @@ -1,13 +1,15 @@ ---------------------------------------- -- INPUTS -- location: neighborhood +-- proj: :nb_output_srid psql var must be set before running this script, +-- e.g. psql -v nb_output_srid=4326 -f paths.sql ---------------------------------------- DROP TABLE IF EXISTS generated.neighborhood_paths; DROP INDEX IF EXISTS idx_neighborhood_ways_path_id; CREATE TABLE generated.neighborhood_paths ( path_id SERIAL PRIMARY KEY, - geom geometry(multilinestring,2249), + geom geometry(multilinestring, :nb_output_srid), path_length INTEGER, bbox_length INTEGER ); @@ -17,7 +19,7 @@ INSERT INTO neighborhood_paths (geom) SELECT ST_CollectionExtract( ST_SetSRID( unnest(ST_ClusterIntersecting(geom)), - 2249 + :nb_output_srid ), 2 --linestrings ) @@ -36,7 +38,7 @@ SET bbox_length = ST_Length( ST_MakePoint(ST_XMin(geom), ST_YMin(geom)), ST_MakePoint(ST_XMax(geom), ST_YMax(geom)) ), - 2249 + :nb_output_srid ) ); diff --git a/prepare_tables.sql b/prepare_tables.sql index 335a7421..f15a372d 100644 --- a/prepare_tables.sql +++ b/prepare_tables.sql @@ -1,7 +1,8 @@ ---------------------------------------- -- INPUTS -- location: neighborhood --- proj: 2249 +-- proj: :nb_output_srid psql var must be set before running this script, +-- e.g. psql -v nb_output_srid=4326 -f prepare_tables.sql ---------------------------------------- -- add tdg_id field to roads @@ -44,12 +45,12 @@ ALTER TABLE neighborhood_ways_intersections RENAME COLUMN id TO int_id; ALTER TABLE neighborhood_ways_intersections RENAME COLUMN the_geom TO geom; -- reproject -ALTER TABLE neighborhood_ways ALTER COLUMN geom TYPE geometry(linestring,2249) -USING ST_Transform(geom,2249); -ALTER TABLE neighborhood_cycwys_ways ALTER COLUMN the_geom TYPE geometry(linestring,2249) -USING ST_Transform(the_geom,2249); -ALTER TABLE neighborhood_ways_intersections ALTER COLUMN geom TYPE geometry(point,2249) -USING ST_Transform(geom,2249); +ALTER TABLE neighborhood_ways ALTER COLUMN geom TYPE geometry(linestring,:nb_output_srid) +USING ST_Transform(geom,:nb_output_srid); +ALTER TABLE neighborhood_cycwys_ways ALTER COLUMN the_geom TYPE geometry(linestring,:nb_output_srid) +USING ST_Transform(the_geom,:nb_output_srid); +ALTER TABLE neighborhood_ways_intersections ALTER COLUMN geom TYPE geometry(point,:nb_output_srid) +USING ST_Transform(geom,:nb_output_srid); -- add columns ALTER TABLE neighborhood_ways ADD COLUMN functional_class TEXT; diff --git a/run_connectivity.sh b/run_connectivity.sh index 46951c0d..1bbf68db 100755 --- a/run_connectivity.sh +++ b/run_connectivity.sh @@ -6,6 +6,7 @@ NB_POSTGRESQL_HOST="${NB_POSTGRESQL_HOST:-127.0.0.1}" NB_POSTGRESQL_DB="${NB_POSTGRESQL_DB:-pfb}" NB_POSTGRESQL_USER="${NB_POSTGRESQL_USER:-gis}" NB_POSTGRESQL_PASSWORD="${NB_POSTGRESQL_PASSWORD:-gis}" +NB_OUTPUT_SRID="${NB_OUTPUT_SRID:-4326}" psql -h "${DBHOST}" -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_DB}" \ -c "SELECT tdgMakeNetwork('neighborhood_ways');" @@ -38,7 +39,7 @@ psql -h "${NB_POSTGRESQL_HOST}" -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_D -f connectivity/access_jobs.sql /usr/bin/time -v psql -h "${NB_POSTGRESQL_HOST}" -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_DB}" \ - -f connectivity/schools.sql + -v nb_output_srid="${NB_OUTPUT_SRID}" -f connectivity/schools.sql /usr/bin/time -v psql -h "${NB_POSTGRESQL_HOST}" -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_DB}" \ -f connectivity/school_roads.sql From d9dbcdfd8fef8dd23f3a63e700c62cedc08085cc Mon Sep 17 00:00:00 2001 From: Reed Martz Date: Mon, 31 Oct 2016 14:19:35 -0400 Subject: [PATCH 54/94] Add indexes and tweak INSERT query performance Testing indicates Census Connected Blocks insert query should successfully run in < 10 minutes (Compared to 2.5 hours previously). --- connectivity/census_blocks.sql | 3 +- connectivity/connected_census_blocks.sql | 41 +++++++++----------- connectivity/reachable_roads_high_stress.sql | 4 +- 3 files changed, 22 insertions(+), 26 deletions(-) diff --git a/connectivity/census_blocks.sql b/connectivity/census_blocks.sql index e327dc05..99a2e574 100644 --- a/connectivity/census_blocks.sql +++ b/connectivity/census_blocks.sql @@ -16,4 +16,5 @@ ALTER TABLE neighborhood_census_blocks ADD COLUMN IF NOT EXISTS rec_low_stress I ALTER TABLE neighborhood_census_blocks ADD COLUMN IF NOT EXISTS rec_high_stress INT; CREATE INDEX IF NOT EXISTS idx_neighborhood_blocks10 ON neighborhood_census_blocks (blockid10); -ANALYZE neighborhood_census_blocks (blockid10); +CREATE INDEX IF NOT EXISTS idx_neighborhood_geom ON neighborhood_census_blocks USING GIST (geom); +ANALYZE neighborhood_census_blocks; diff --git a/connectivity/connected_census_blocks.sql b/connectivity/connected_census_blocks.sql index ac13fed6..bef73144 100644 --- a/connectivity/connected_census_blocks.sql +++ b/connectivity/connected_census_blocks.sql @@ -14,36 +14,31 @@ CREATE TABLE generated.neighborhood_connected_census_blocks ( high_stress_cost INT ); -INSERT INTO generated.neighborhood_connected_census_blocks ( -- took 2 hrs on the server +INSERT INTO generated.neighborhood_connected_census_blocks ( source_blockid10, target_blockid10, low_stress, high_stress ) SELECT source_block.blockid10, target_block.blockid10, 'f'::BOOLEAN, 't'::BOOLEAN -FROM neighborhood_census_blocks source_block, - neighborhood_census_blocks target_block -WHERE EXISTS ( - SELECT 1 - FROM neighborhood_boundary AS b - WHERE ST_Intersects(source_block.geom,b.geom) - ) -AND source_block.geom <#> target_block.geom < 11000 -AND EXISTS ( - SELECT 1 - FROM neighborhood_census_block_roads source_br, - neighborhood_census_block_roads target_br, - neighborhood_reachable_roads_high_stress hs - WHERE source_block.blockid10 = source_br.blockid10 - AND target_block.blockid10 = target_br.blockid10 - AND hs.base_road = source_br.road_id - AND hs.target_road = target_br.road_id - ); +FROM neighborhood_boundary b +JOIN neighborhood_census_blocks source_block + ON ST_Intersects(source_block.geom,b.geom) +JOIN neighborhood_census_blocks target_block + ON source_block.geom <#> target_block.geom < 11000 +JOIN neighborhood_census_block_roads source_br + ON source_block.blockid10 = source_br.blockid10 +JOIN neighborhood_census_block_roads target_br + ON target_block.blockid10 = target_br.blockid10 +JOIN neighborhood_reachable_roads_high_stress hs + ON hs.base_road = source_br.road_id + AND hs.target_road = target_br.road_id +GROUP BY source_block.blockid10, target_block.blockid10 +; -- block pair index -CREATE INDEX idx_neighborhood_blockpairs -ON neighborhood_connected_census_blocks (source_blockid10,target_blockid10); -ANALYZE neighborhood_connected_census_blocks (source_blockid10,target_blockid10); +CREATE UNIQUE INDEX idx_neighborhood_blockpairs ON neighborhood_connected_census_blocks (source_blockid10,target_blockid10); +ANALYZE neighborhood_connected_census_blocks; -- low stress UPDATE neighborhood_connected_census_blocks @@ -82,4 +77,4 @@ AND ( -- stress index CREATE INDEX IF NOT EXISTS idx_neighborhood_blockpairs_lstress ON neighborhood_connected_census_blocks (low_stress); CREATE INDEX IF NOT EXISTS idx_neighborhood_blockpairs_hstress ON neighborhood_connected_census_blocks (high_stress); -ANALYZE neighborhood_connected_census_blocks (low_stress,high_stress); +ANALYZE neighborhood_connected_census_blocks; diff --git a/connectivity/reachable_roads_high_stress.sql b/connectivity/reachable_roads_high_stress.sql index 2d3fd249..d6c17b44 100644 --- a/connectivity/reachable_roads_high_stress.sql +++ b/connectivity/reachable_roads_high_stress.sql @@ -41,6 +41,6 @@ WHERE EXISTS ( AND r1.road_id = v1.road_id AND v2.vert_id = sheds.node; -CREATE INDEX IF NOT EXISTS idx_neighborhood_rchblrdshistrss_b ON generated.neighborhood_reachable_roads_high_stress (base_road); +CREATE UNIQUE INDEX IF NOT EXISTS idx_neighborhood_rchblrdshistrss_b ON generated.neighborhood_reachable_roads_high_stress (base_road, target_road); CREATE INDEX IF NOT EXISTS idx_neighborhood_rchblrdshistrss_t ON generated.neighborhood_reachable_roads_high_stress (target_road); -ANALYZE generated.neighborhood_reachable_roads_high_stress (base_road,target_road); +ANALYZE generated.neighborhood_reachable_roads_high_stress; From 743f048d2641d16793a39fa443f76b942b315b50 Mon Sep 17 00:00:00 2001 From: CloudNiner Date: Wed, 9 Nov 2016 13:57:20 -0500 Subject: [PATCH 55/94] Closes #11: Parameterize buffer distance Ensures that the census block distance comparisons are consistent across the entire analysis. However, the analysis still requires an NB_OUTPUT_SRID where the projection units are feet since there are other hardcoded comparisons of other quantities. --- connectivity/connected_census_blocks.sql | 6 ++++-- connectivity/connected_census_blocks_recreation.sql | 6 ++++-- connectivity/connected_census_blocks_schools.sql | 6 ++++-- connectivity/school_roads.sql | 6 ++++-- import_neighborhood.sh | 3 ++- run_connectivity.sh | 4 ++++ 6 files changed, 22 insertions(+), 9 deletions(-) diff --git a/connectivity/connected_census_blocks.sql b/connectivity/connected_census_blocks.sql index bef73144..61d52bcd 100644 --- a/connectivity/connected_census_blocks.sql +++ b/connectivity/connected_census_blocks.sql @@ -1,6 +1,8 @@ ---------------------------------------- -- INPUTS -- location: neighborhood +-- :nb_boundary_buffer psql var must be set before running this script, +-- e.g. psql -v nb_boundary_buffer=11000 -f connected_census_blocks.sql ---------------------------------------- DROP TABLE IF EXISTS generated.neighborhood_connected_census_blocks; @@ -25,7 +27,7 @@ FROM neighborhood_boundary b JOIN neighborhood_census_blocks source_block ON ST_Intersects(source_block.geom,b.geom) JOIN neighborhood_census_blocks target_block - ON source_block.geom <#> target_block.geom < 11000 + ON source_block.geom <#> target_block.geom < :nb_boundary_buffer JOIN neighborhood_census_block_roads source_br ON source_block.blockid10 = source_br.blockid10 JOIN neighborhood_census_block_roads target_br @@ -72,7 +74,7 @@ AND ( AND target_blockid10 = target_br.blockid10 AND hs.base_road = source_br.road_id AND hs.target_road = target_br.road_id - ),11000) <= 1.3; + ), :nb_boundary_buffer) <= 1.3; -- stress index CREATE INDEX IF NOT EXISTS idx_neighborhood_blockpairs_lstress ON neighborhood_connected_census_blocks (low_stress); diff --git a/connectivity/connected_census_blocks_recreation.sql b/connectivity/connected_census_blocks_recreation.sql index cff8b0b1..11ccea20 100644 --- a/connectivity/connected_census_blocks_recreation.sql +++ b/connectivity/connected_census_blocks_recreation.sql @@ -1,6 +1,8 @@ ---------------------------------------- -- INPUTS -- location: neighborhood +-- :nb_boundary_buffer psql var must be set before running this script, +-- e.g. psql -v nb_boundary_buffer=11000 -f connected_census_blocks_recreation.sql ---------------------------------------- DROP TABLE IF EXISTS generated.neighborhood_connected_census_blocks_recreation; @@ -29,7 +31,7 @@ WHERE EXISTS ( WHERE ST_Intersects(blocks.geom,zips.geom) AND zips.zip_code = '02138' ) -AND blocks.geom <#> paths.geom < 11000 +AND blocks.geom <#> paths.geom < :nb_boundary_buffer AND EXISTS ( SELECT 1 FROM neighborhood_census_block_roads source_br, @@ -84,7 +86,7 @@ AND ( AND target_school_id = target_sr.school_id AND hs.base_road = source_br.road_id AND hs.target_road = target_sr.road_id - ),11000) <= 1.3; + ), :nb_boundary_buffer) <= 1.3; -- stress index CREATE INDEX idx_neighborhood_blockschl_lstress ON neighborhood_connected_census_blocks_recreation (low_stress); diff --git a/connectivity/connected_census_blocks_schools.sql b/connectivity/connected_census_blocks_schools.sql index 2c1c3185..6423af65 100644 --- a/connectivity/connected_census_blocks_schools.sql +++ b/connectivity/connected_census_blocks_schools.sql @@ -1,6 +1,8 @@ ---------------------------------------- -- INPUTS -- location: neighborhood +-- :nb_boundary_buffer psql var must be set before running this script, +-- e.g. psql -v nb_boundary_buffer=11000 -f connected_census_blocks_schools.sql ---------------------------------------- DROP TABLE IF EXISTS generated.neighborhood_connected_census_blocks_schools; @@ -28,7 +30,7 @@ WHERE EXISTS ( FROM neighborhood_boundary AS b WHERE ST_Intersects(blocks.geom,b.geom) ) -AND blocks.geom <#> schools.geom_pt < 11000 +AND blocks.geom <#> schools.geom_pt < :nb_boundary_buffer AND EXISTS ( SELECT 1 FROM neighborhood_census_block_roads source_br, @@ -77,7 +79,7 @@ AND ( AND target_school_id = target_sr.school_id AND hs.base_road = source_br.road_id AND hs.target_road = target_sr.road_id - ),11000) <= 1.3; + ), :nb_boundary_buffer) <= 1.3; -- stress index CREATE INDEX IF NOT EXISTS idx_neighborhood_blockschl_lstress ON neighborhood_connected_census_blocks_schools (low_stress); diff --git a/connectivity/school_roads.sql b/connectivity/school_roads.sql index 3141f9e5..eafb6a79 100644 --- a/connectivity/school_roads.sql +++ b/connectivity/school_roads.sql @@ -1,6 +1,8 @@ ---------------------------------------- -- INPUTS -- location: neighborhood +-- :nb_boundary_buffer psql var must be set before running this script, +-- e.g. psql -v nb_boundary_buffer=11000 -f school_roads.sql ---------------------------------------- DROP TABLE IF EXISTS generated.neighborhood_school_roads; @@ -22,7 +24,7 @@ FROM neighborhood_schools schools, WHERE EXISTS ( SELECT 1 FROM neighborhood_boundary AS b - WHERE ST_DWithin(b.geom, schools.geom_pt, 11000) + WHERE ST_DWithin(b.geom, schools.geom_pt, :nb_boundary_buffer) ) AND schools.geom_poly IS NOT NULL AND ST_DWithin(schools.geom_poly,ways.geom,50); @@ -43,7 +45,7 @@ FROM neighborhood_schools schools WHERE EXISTS ( SELECT 1 FROM neighborhood_boundary AS b - WHERE ST_DWithin(b.geom, schools.geom_pt, 11000) + WHERE ST_DWithin(b.geom, schools.geom_pt, :nb_boundary_buffer) ) AND NOT EXISTS ( SELECT 1 diff --git a/import_neighborhood.sh b/import_neighborhood.sh index bd87b351..d248e6e9 100755 --- a/import_neighborhood.sh +++ b/import_neighborhood.sh @@ -30,7 +30,8 @@ Requires passing the state FIPS ID that the neighborhood boundary is found in. e Optional ENV vars: NB_INPUT_SRID - Default: 4326 -NB_OUTPUT_SRID - Default: 4326 +NB_OUTPUT_SRID - Default: 4326 (Should have units of 'ft', otherwise some portions of the + analysis will not work correctly) NB_BOUNDARY_BUFFER - Default: 0 (Units is units of NB_OUTPUT_SRID) NB_POSTGRESQL_HOST - Default: 127.0.0.1 NB_POSTGRESQL_DB - Default: pfb diff --git a/run_connectivity.sh b/run_connectivity.sh index 1bbf68db..757d431f 100755 --- a/run_connectivity.sh +++ b/run_connectivity.sh @@ -7,6 +7,7 @@ NB_POSTGRESQL_DB="${NB_POSTGRESQL_DB:-pfb}" NB_POSTGRESQL_USER="${NB_POSTGRESQL_USER:-gis}" NB_POSTGRESQL_PASSWORD="${NB_POSTGRESQL_PASSWORD:-gis}" NB_OUTPUT_SRID="${NB_OUTPUT_SRID:-4326}" +NB_BOUNDARY_BUFFER="${NB_BOUNDARY_BUFFER:-0}" psql -h "${DBHOST}" -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_DB}" \ -c "SELECT tdgMakeNetwork('neighborhood_ways');" @@ -27,6 +28,7 @@ psql -h "${NB_POSTGRESQL_HOST}" -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_D -f connectivity/reachable_roads_low_stress.sql /usr/bin/time -v psql -h "${NB_POSTGRESQL_HOST}" -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_DB}" \ + -v nb_boundary_buffer="${NB_BOUNDARY_BUFFER}" \ -f connectivity/connected_census_blocks.sql /usr/bin/time -v psql -h "${NB_POSTGRESQL_HOST}" -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_DB}" \ @@ -42,9 +44,11 @@ psql -h "${NB_POSTGRESQL_HOST}" -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_D -v nb_output_srid="${NB_OUTPUT_SRID}" -f connectivity/schools.sql /usr/bin/time -v psql -h "${NB_POSTGRESQL_HOST}" -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_DB}" \ + -v nb_boundary_buffer="${NB_BOUNDARY_BUFFER}" \ -f connectivity/school_roads.sql /usr/bin/time -v psql -h "${NB_POSTGRESQL_HOST}" -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_DB}" \ + -v nb_boundary_buffer="${NB_BOUNDARY_BUFFER}" \ -f connectivity/connected_census_blocks_schools.sql /usr/bin/time -v psql -h "${NB_POSTGRESQL_HOST}" -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_DB}" \ From c616504bc1b23253bf48607a35a96ccba8be8cbf Mon Sep 17 00:00:00 2001 From: CloudNiner Date: Thu, 10 Nov 2016 08:15:25 -0500 Subject: [PATCH 56/94] WIP: Download OSM data via shell script --- import_osm.sh | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/import_osm.sh b/import_osm.sh index 3db1fe8c..8a6b7210 100755 --- a/import_osm.sh +++ b/import_osm.sh @@ -6,7 +6,6 @@ NB_POSTGRESQL_HOST="${NB_POSTGRESQL_HOST:-127.0.0.1}" NB_POSTGRESQL_DB="${NB_POSTGRESQL_DB:-pfb}" NB_POSTGRESQL_USER="${NB_POSTGRESQL_USER:-gis}" NB_POSTGRESQL_PASSWORD="${NB_POSTGRESQL_PASSWORD:-gis}" -NB_OSMFILE="${NB_OSMFILE:-/vagrant/data/neighborhood.osm}" NB_OUTPUT_SRID="${NB_OUTPUT_SRID:-4326}" # drop old tables @@ -44,9 +43,28 @@ psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ -c "DROP TABLE IF EXISTS scratch.neighborhood_cycwys_osm_way_types;" + +# Get the neighborhood_boundary bbox +BBOX_SW_LNG=`psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -t -c "SELECT MIN(ST_Xmin(ST_Transform(geom, 4326))) FROM neighborhood_boundary;"` +BBOX_SW_LAT=`psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -t -c "SELECT MIN(ST_Ymin(ST_Transform(geom, 4326))) FROM neighborhood_boundary;"` +BBOX_NE_LNG=`psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -t -c "SELECT MAX(ST_Xmax(ST_Transform(geom, 4326))) FROM neighborhood_boundary;"` +BBOX_NE_LAT=`psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -t -c "SELECT MAX(ST_Ymax(ST_Transform(geom, 4326))) FROM neighborhood_boundary;"` +# Buffer it +LNG_DIFF=`bc <<< "$BBOX_NE_LNG - $BBOX_SW_LNG"` +LAT_DIFF=`bc <<< "$BBOX_NE_LAT - $BBOX_SW_LAT"` +BBOX_SW_LAT=`bc <<< "$BBOX_SW_LAT - $LAT_DIFF"` +BBOX_SW_LNG=`bc <<< "$BBOX_SW_LNG - $LNG_DIFF"` +BBOX_NE_LAT=`bc <<< "$BBOX_NE_LAT + $LAT_DIFF"` +BBOX_NE_LNG=`bc <<< "$BBOX_NE_LNG + $LNG_DIFF"` +# Download OSM data +OSM_API_URL="http://www.overpass-api.de/api/xapi?way[bbox=${BBOX_SW_LNG},${BBOX_SW_LAT},${BBOX_NE_LNG},${BBOX_NE_LAT}][highway=*]" +OSM_TEMPDIR=`mktemp -d` +OSM_DATA_FILE="${OSM_TEMPDIR}/overpass.osm" +wget -O "${OSM_DATA_FILE}" "${OSM_API_URL}" + # import the osm with highways osm2pgrouting \ - -f $NB_OSMFILE \ + -f $OSM_DATA_FILE \ -h $NB_POSTGRESQL_HOST \ --dbname ${NB_POSTGRESQL_DB} \ --username ${NB_POSTGRESQL_USER} \ @@ -57,7 +75,7 @@ osm2pgrouting \ # import the osm with cycleways that the above misses (bug in osm2pgrouting) osm2pgrouting \ - -f $NB_OSMFILE \ + -f $OSM_DATA_FILE \ -h $NB_POSTGRESQL_HOST \ --dbname ${NB_POSTGRESQL_DB} \ --username ${NB_POSTGRESQL_USER} \ @@ -131,7 +149,10 @@ osm2pgsql \ --prefix "neighborhood_osm_full" \ --proj "${NB_OUTPUT_SRID}" \ --style ./pfb.style \ - "${NB_OSMFILE}" + "${OSM_DATA_FILE}" + +# Delete downloaded temp OSM data +rm -rf "${OSM_TEMPDIR}" # move the full osm tables to the received schema echo 'Moving tables to received schema' From 2dc574992ec8913ab9de5a56f403545c855d449c Mon Sep 17 00:00:00 2001 From: CloudNiner Date: Thu, 10 Nov 2016 13:59:12 -0500 Subject: [PATCH 57/94] Add 'set -e' to analysis scripts that didn't have it set --- import_osm.sh | 2 ++ run_connectivity.sh | 2 ++ 2 files changed, 4 insertions(+) diff --git a/import_osm.sh b/import_osm.sh index 8a6b7210..619a86f6 100755 --- a/import_osm.sh +++ b/import_osm.sh @@ -1,5 +1,7 @@ #!/usr/bin/env bash +set -e + cd `dirname $0` NB_POSTGRESQL_HOST="${NB_POSTGRESQL_HOST:-127.0.0.1}" diff --git a/run_connectivity.sh b/run_connectivity.sh index 1bbf68db..3d425e15 100755 --- a/run_connectivity.sh +++ b/run_connectivity.sh @@ -1,5 +1,7 @@ #!/usr/bin/env bash +set -e + cd `dirname $0` NB_POSTGRESQL_HOST="${NB_POSTGRESQL_HOST:-127.0.0.1}" From 513665cced8f203ef472f7f07a81382bb57c5730 Mon Sep 17 00:00:00 2001 From: CloudNiner Date: Thu, 10 Nov 2016 14:56:02 -0500 Subject: [PATCH 58/94] Tweak OSM download to pull all data within bbox The analysis uses OSM data other than highways, such as amenity=school. For now, while in development, assume we need all the data within the bounding box. We can tighten up these parameters once the analysis finalizes and we deploy the application. As a point of reference, the center city philly bbox pulled 15mb of data in ~60s. According to the Overpass wiki page, we can continue to make requests to the API as long as we don't exceed these limits: - < 10,000 queries per day - < 5GB download per day http://wiki.openstreetmap.org/wiki/Overpass_API If we do start to get near these limits, we'll need to investigate other options for download. --- import_osm.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/import_osm.sh b/import_osm.sh index 619a86f6..11e02355 100755 --- a/import_osm.sh +++ b/import_osm.sh @@ -59,7 +59,7 @@ BBOX_SW_LNG=`bc <<< "$BBOX_SW_LNG - $LNG_DIFF"` BBOX_NE_LAT=`bc <<< "$BBOX_NE_LAT + $LAT_DIFF"` BBOX_NE_LNG=`bc <<< "$BBOX_NE_LNG + $LNG_DIFF"` # Download OSM data -OSM_API_URL="http://www.overpass-api.de/api/xapi?way[bbox=${BBOX_SW_LNG},${BBOX_SW_LAT},${BBOX_NE_LNG},${BBOX_NE_LAT}][highway=*]" +OSM_API_URL="http://www.overpass-api.de/api/xapi?*[bbox=${BBOX_SW_LNG},${BBOX_SW_LAT},${BBOX_NE_LNG},${BBOX_NE_LAT}]" OSM_TEMPDIR=`mktemp -d` OSM_DATA_FILE="${OSM_TEMPDIR}/overpass.osm" wget -O "${OSM_DATA_FILE}" "${OSM_API_URL}" From 7f8380e55f30cf6244bc2e03a077d6a4387fd4c3 Mon Sep 17 00:00:00 2001 From: Spencer Date: Mon, 14 Nov 2016 15:03:54 -0600 Subject: [PATCH 59/94] stress scoring changes: primary, secondary, tertiary --- stress_primary.sql | 48 ++++++++++++------ stress_secondary.sql | 46 +++++++++++++---- stress_tertiary.sql | 118 +++++++++++++++++++++++++++++-------------- 3 files changed, 149 insertions(+), 63 deletions(-) diff --git a/stress_primary.sql b/stress_primary.sql index aa8f269e..eed1c54c 100644 --- a/stress_primary.sql +++ b/stress_primary.sql @@ -2,7 +2,7 @@ -- INPUTS -- location: cambridge ---------------------------------------- -UPDATE cambridge_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL +UPDATE cambridge_ways SET tf_seg_stress = NULL, tf_seg_stress = NULL WHERE functional_class IN ('primary','primary_link'); -- ft direction @@ -14,21 +14,30 @@ SET ft_seg_stress = THEN CASE WHEN speed_limit = 35 THEN CASE WHEN ft_lanes = 1 THEN 2 - ELSE 3 + ELSE 3 -- assume more than 1 lane END WHEN speed_limit <= 30 THEN CASE WHEN ft_lanes = 1 THEN 1 - ELSE 3 + ELSE 2 -- assume more than 1 lane END - ELSE 3 + ELSE 3 -- assume higher than 35 END WHEN ft_bike_infra = 'lane' THEN CASE - WHEN speed_limit <= 25 + WHEN speed_limit <= 20 THEN CASE + WHEN ft_lanes = 1 THEN + CASE + WHEN ft_park = 0 THEN 1 + ELSE 2 -- assume parking + END + WHEN ft_lanes > 2 THEN 3 + ELSE 2 -- assume 2 lanes + END + WHEN speed_limit = 25 THEN CASE WHEN ft_lanes = 1 THEN CASE WHEN ft_park = 0 THEN 1 - ELSE 2 + ELSE 2 -- assume parking END WHEN ft_lanes > 2 THEN 3 ELSE CASE @@ -39,8 +48,8 @@ SET ft_seg_stress = WHEN speed_limit = 30 THEN CASE WHEN ft_lanes = 1 THEN CASE - WHEN ft_park = 0 THEN 1 - ELSE 2 + WHEN ft_park = 0 THEN 2 + ELSE 3 END ELSE 3 END @@ -59,21 +68,30 @@ SET tf_seg_stress = THEN CASE WHEN speed_limit = 35 THEN CASE WHEN tf_lanes = 1 THEN 2 - ELSE 3 + ELSE 3 -- assume more than 1 lane END WHEN speed_limit <= 30 THEN CASE WHEN tf_lanes = 1 THEN 1 - ELSE 3 + ELSE 2 -- assume more than 1 lane END - ELSE 3 + ELSE 3 -- assume higher than 35 END WHEN tf_bike_infra = 'lane' THEN CASE - WHEN speed_limit <= 25 + WHEN speed_limit <= 20 THEN CASE + WHEN tf_lanes = 1 THEN + CASE + WHEN tf_park = 0 THEN 1 + ELSE 2 -- assume parking + END + WHEN tf_lanes > 2 THEN 3 + ELSE 2 -- assume 2 lanes + END + WHEN speed_limit = 25 THEN CASE WHEN tf_lanes = 1 THEN CASE WHEN tf_park = 0 THEN 1 - ELSE 2 + ELSE 2 -- assume parking END WHEN tf_lanes > 2 THEN 3 ELSE CASE @@ -84,8 +102,8 @@ SET tf_seg_stress = WHEN speed_limit = 30 THEN CASE WHEN tf_lanes = 1 THEN CASE - WHEN tf_park = 0 THEN 1 - ELSE 2 + WHEN tf_park = 0 THEN 2 + ELSE 3 END ELSE 3 END diff --git a/stress_secondary.sql b/stress_secondary.sql index 4975d28c..58322d07 100644 --- a/stress_secondary.sql +++ b/stress_secondary.sql @@ -18,16 +18,29 @@ SET ft_seg_stress = END WHEN speed_limit <= 30 THEN CASE WHEN ft_lanes = 1 THEN 1 - ELSE 3 + ELSE 2 END ELSE 3 END WHEN ft_bike_infra = 'lane' THEN CASE - WHEN speed_limit <= 25 + WHEN speed_limit <= 20 THEN CASE + WHEN ft_lanes = 1 THEN + CASE + WHEN ft_park = 0 THEN 1 + ELSE 2 + END + WHEN ft_lanes = 2 THEN + CASE + WHEN ft_park = 0 THEN 2 + ELSE 2 + END + ELSE 3 + END + WHEN speed_limit = 25 THEN CASE WHEN ft_lanes = 1 THEN CASE - WHEN ft_park = 0 THEN 1 + WHEN ft_park = 0 THEN 2 ELSE 2 END WHEN ft_lanes > 2 THEN 3 @@ -39,8 +52,8 @@ SET ft_seg_stress = WHEN speed_limit = 30 THEN CASE WHEN ft_lanes = 1 THEN CASE - WHEN ft_park = 0 THEN 1 - ELSE 2 + WHEN ft_park = 0 THEN 2 + ELSE 3 END ELSE 3 END @@ -63,16 +76,29 @@ SET tf_seg_stress = END WHEN speed_limit <= 30 THEN CASE WHEN tf_lanes = 1 THEN 1 - ELSE 3 + ELSE 2 END ELSE 3 END WHEN tf_bike_infra = 'lane' THEN CASE - WHEN speed_limit <= 25 + WHEN speed_limit <= 20 THEN CASE + WHEN tf_lanes = 1 THEN + CASE + WHEN tf_park = 0 THEN 1 + ELSE 2 + END + WHEN tf_lanes = 2 THEN + CASE + WHEN tf_park = 0 THEN 2 + ELSE 2 + END + ELSE 3 + END + WHEN speed_limit = 25 THEN CASE WHEN tf_lanes = 1 THEN CASE - WHEN tf_park = 0 THEN 1 + WHEN tf_park = 0 THEN 2 ELSE 2 END WHEN tf_lanes > 2 THEN 3 @@ -84,8 +110,8 @@ SET tf_seg_stress = WHEN speed_limit = 30 THEN CASE WHEN tf_lanes = 1 THEN CASE - WHEN tf_park = 0 THEN 1 - ELSE 2 + WHEN tf_park = 0 THEN 2 + ELSE 3 END ELSE 3 END diff --git a/stress_tertiary.sql b/stress_tertiary.sql index 0855b7ce..6f727538 100644 --- a/stress_tertiary.sql +++ b/stress_tertiary.sql @@ -16,36 +16,55 @@ SET ft_seg_stress = WHEN ft_bike_infra = 'track' THEN 1 WHEN ft_bike_infra = 'buffered_lane' THEN CASE - WHEN speed_limit > 35 THEN 3 - WHEN speed_limit = 35 THEN CASE - WHEN ft_lanes = 1 THEN 2 - ELSE 3 - END - ELSE CASE - WHEN ft_lanes > 1 THEN 3 - ELSE 1 + WHEN speed_limit = 35 + THEN CASE + WHEN ft_lanes > 1 THEN 3 + ELSE 2 -- assume 1 lane + END + WHEN speed_limit > 35 + THEN CASE + WHEN ft_lanes > 1 THEN 3 + ELSE 2 -- assume 1 lane + END + ELSE CASE -- assume speed 30 + WHEN ft_lanes > 1 THEN 2 + ELSE 1 -- assume 1 lane END END WHEN ft_bike_infra = 'lane' THEN CASE WHEN speed_limit > 30 THEN 3 - WHEN speed_limit <= 25 + WHEN speed_limit <= 20 THEN CASE WHEN ft_lanes > 2 THEN 3 - WHEN ft_lanes = 1 THEN CASE - WHEN ft_park = 1 THEN 2 - ELSE 2 - END - ELSE CASE + WHEN ft_lanes = 2 + THEN CASE + WHEN ft_park = 0 THEN 2 + ELSE 2 -- assume parking + END + ELSE CASE -- assume 1 lane WHEN ft_park = 0 THEN 1 - ELSE 2 + ELSE 2 -- assume parking END END - ELSE CASE + WHEN speed_limit = 25 + THEN CASE + WHEN ft_lanes > 2 THEN 3 + WHEN ft_lanes = 2 + THEN CASE + WHEN ft_park = 0 THEN 2 + ELSE 3 -- assume parking + END + ELSE CASE -- assume 1 lane + WHEN ft_park = 0 THEN 1 + ELSE 2 -- assume parking + END + END + ELSE CASE -- assume 30 mph speed limit WHEN ft_lanes > 1 THEN 3 - ELSE CASE + ELSE CASE -- assume 1 lane WHEN ft_park = 0 THEN 1 - ELSE 2 + ELSE 2 -- assume parking END END END @@ -53,12 +72,12 @@ SET ft_seg_stress = WHEN speed_limit = 30 THEN CASE WHEN ft_lanes = 1 THEN 2 - ELSE 3 + ELSE 3 -- assumee more than 1 lane END - WHEN speed_limit = 25 + WHEN speed_limit <= 25 THEN CASE WHEN ft_lanes = 1 THEN 1 - ELSE 3 + ELSE 3 -- assumee more than 1 lane END ELSE 3 END @@ -74,32 +93,55 @@ SET tf_seg_stress = WHEN tf_bike_infra = 'track' THEN 1 WHEN tf_bike_infra = 'buffered_lane' THEN CASE - WHEN speed_limit > 30 THEN 3 - ELSE CASE - WHEN tf_lanes > 1 THEN 3 - ELSE 1 + WHEN speed_limit = 35 + THEN CASE + WHEN tf_lanes > 1 THEN 3 + ELSE 2 -- assume 1 lane + END + WHEN speed_limit > 35 + THEN CASE + WHEN tf_lanes > 1 THEN 3 + ELSE 2 -- assume 1 lane + END + ELSE CASE -- assume speed 30 + WHEN tf_lanes > 1 THEN 2 + ELSE 1 -- assume 1 lane END END WHEN tf_bike_infra = 'lane' THEN CASE WHEN speed_limit > 30 THEN 3 - WHEN speed_limit <= 25 + WHEN speed_limit <= 20 + THEN CASE + WHEN tf_lanes > 2 THEN 3 + WHEN tf_lanes = 2 + THEN CASE + WHEN tf_park = 0 THEN 2 + ELSE 2 -- assume parking + END + ELSE CASE -- assume 1 lane + WHEN tf_park = 0 THEN 1 + ELSE 2 -- assume parking + END + END + WHEN speed_limit = 25 THEN CASE WHEN tf_lanes > 2 THEN 3 - WHEN tf_lanes = 1 THEN CASE - WHEN tf_park = 1 THEN 2 - ELSE 2 - END - ELSE CASE + WHEN tf_lanes = 2 + THEN CASE + WHEN tf_park = 0 THEN 2 + ELSE 3 -- assume parking + END + ELSE CASE -- assume 1 lane WHEN tf_park = 0 THEN 1 - ELSE 2 + ELSE 2 -- assume parking END END - ELSE CASE + ELSE CASE -- assume 30 mph speed limit WHEN tf_lanes > 1 THEN 3 - ELSE CASE + ELSE CASE -- assume 1 lane WHEN tf_park = 0 THEN 1 - ELSE 2 + ELSE 2 -- assume parking END END END @@ -107,12 +149,12 @@ SET tf_seg_stress = WHEN speed_limit = 30 THEN CASE WHEN tf_lanes = 1 THEN 2 - ELSE 3 + ELSE 3 -- assumee more than 1 lane END - WHEN speed_limit = 25 + WHEN speed_limit <= 25 THEN CASE WHEN tf_lanes = 1 THEN 1 - ELSE 3 + ELSE 3 -- assumee more than 1 lane END ELSE 3 END From 6142ada102e1a66ac568e45f8841eaed8e8d99d7 Mon Sep 17 00:00:00 2001 From: Spencer Date: Mon, 14 Nov 2016 15:06:19 -0600 Subject: [PATCH 60/94] treat residential with multiple lanes or high speeds as tertiary --- stress_residential.sql | 14 -------------- stress_tertiary.sql | 15 ++++++++++++--- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/stress_residential.sql b/stress_residential.sql index cdd51522..a3636425 100644 --- a/stress_residential.sql +++ b/stress_residential.sql @@ -17,20 +17,6 @@ WHERE functional_class = 'residential' AND (ft_bike_infra IS NULL OR ft_bike_infra NOT IN ('track','buffered_lane','lane')) AND (tf_bike_infra IS NULL OR tf_bike_infra NOT IN ('track','buffered_lane','lane')); --- stress increase for multiple lanes or high speeds -UPDATE cambridge_ways -SET ft_seg_stress = 3 -WHERE functional_class = 'residential' -AND (ft_bike_infra IS NULL OR ft_bike_infra NOT IN ('track','buffered_lane','lane')) -AND (tf_bike_infra IS NULL OR tf_bike_infra NOT IN ('track','buffered_lane','lane')) -AND (ft_lanes > 1 OR speed_limit > 30); -UPDATE cambridge_ways -SET tf_seg_stress = 3 -WHERE functional_class = 'residential' -AND (ft_bike_infra IS NULL OR ft_bike_infra NOT IN ('track','buffered_lane','lane')) -AND (tf_bike_infra IS NULL OR tf_bike_infra NOT IN ('track','buffered_lane','lane')) -AND (tf_lanes > 1 OR speed_limit > 30); - -- stress increase for narrow one way and parking on both sides UPDATE cambridge_ways SET ft_seg_stress = 2, diff --git a/stress_tertiary.sql b/stress_tertiary.sql index 6f727538..54866961 100644 --- a/stress_tertiary.sql +++ b/stress_tertiary.sql @@ -7,7 +7,10 @@ UPDATE cambridge_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL WHERE functional_class IN ('tertiary','tertiary_link') OR (functional_class = 'residential' AND ft_bike_infra IN ('track','buffered_lane','lane')) -OR (functional_class = 'residential' AND tf_bike_infra IN ('track','buffered_lane','lane')); +OR (functional_class = 'residential' AND tf_bike_infra IN ('track','buffered_lane','lane')) +OR (functional_class = 'residential' AND ft_lanes > 1) +OR (functional_class = 'residential' AND tf_lanes > 1) +OR (functional_class = 'residential' AND speed_limit > 30); -- ft direction UPDATE cambridge_ways @@ -84,7 +87,10 @@ SET ft_seg_stress = END WHERE functional_class IN ('tertiary','tertiary_link') OR (functional_class = 'residential' AND ft_bike_infra IN ('track','buffered_lane','lane')) -OR (functional_class = 'residential' AND tf_bike_infra IN ('track','buffered_lane','lane')); +OR (functional_class = 'residential' AND tf_bike_infra IN ('track','buffered_lane','lane')) +OR (functional_class = 'residential' AND ft_lanes > 1) +OR (functional_class = 'residential' AND tf_lanes > 1) +OR (functional_class = 'residential' AND speed_limit > 30); -- tf direction UPDATE cambridge_ways @@ -161,4 +167,7 @@ SET tf_seg_stress = END WHERE functional_class IN ('tertiary','tertiary_link') OR (functional_class = 'residential' AND ft_bike_infra IN ('track','buffered_lane','lane')) -OR (functional_class = 'residential' AND tf_bike_infra IN ('track','buffered_lane','lane')); +OR (functional_class = 'residential' AND tf_bike_infra IN ('track','buffered_lane','lane')) +OR (functional_class = 'residential' AND ft_lanes > 1) +OR (functional_class = 'residential' AND tf_lanes > 1) +OR (functional_class = 'residential' AND speed_limit > 30); From 7f14cdd6a999841cb21248996fd4a738b1e1088f Mon Sep 17 00:00:00 2001 From: Spencer Date: Tue, 15 Nov 2016 10:41:44 -0600 Subject: [PATCH 61/94] residential scoring tweaks to treat like tertiary if multiple lanes or high speed --- stress_residential.sql | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/stress_residential.sql b/stress_residential.sql index a3636425..391672bf 100644 --- a/stress_residential.sql +++ b/stress_residential.sql @@ -7,7 +7,10 @@ UPDATE cambridge_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL WHERE functional_class = 'residential' AND (ft_bike_infra IS NULL OR ft_bike_infra NOT IN ('track','buffered_lane','lane')) -AND (tf_bike_infra IS NULL OR tf_bike_infra NOT IN ('track','buffered_lane','lane')); +AND (tf_bike_infra IS NULL OR tf_bike_infra NOT IN ('track','buffered_lane','lane')) +AND (ft_lanes IS NULL OR ft_lanes = 1) +AND (ft_lanes IS NULL OR tf_lanes = 1) +AND (speed_limit IS NULL OR speed_limit <= 30); -- no additional information UPDATE cambridge_ways @@ -15,7 +18,10 @@ SET ft_seg_stress = 1, tf_seg_stress = 1 WHERE functional_class = 'residential' AND (ft_bike_infra IS NULL OR ft_bike_infra NOT IN ('track','buffered_lane','lane')) -AND (tf_bike_infra IS NULL OR tf_bike_infra NOT IN ('track','buffered_lane','lane')); +AND (tf_bike_infra IS NULL OR tf_bike_infra NOT IN ('track','buffered_lane','lane')) +AND (ft_lanes IS NULL OR ft_lanes = 1) +AND (ft_lanes IS NULL OR tf_lanes = 1) +AND (speed_limit IS NULL OR speed_limit <= 30); -- stress increase for narrow one way and parking on both sides UPDATE cambridge_ways @@ -24,6 +30,9 @@ SET ft_seg_stress = 2, WHERE functional_class = 'residential' AND (ft_bike_infra IS NULL OR ft_bike_infra NOT IN ('track','buffered_lane','lane')) AND (tf_bike_infra IS NULL OR tf_bike_infra NOT IN ('track','buffered_lane','lane')) +AND (ft_lanes IS NULL OR ft_lanes = 1) +AND (ft_lanes IS NULL OR tf_lanes = 1) +AND (speed_limit IS NULL OR speed_limit <= 30) AND width_ft <= 26 AND ft_park = 1 AND tf_park = 1; From 2a421a90ae51ad3af46135cdcadbf090c6960866 Mon Sep 17 00:00:00 2001 From: Spencer Date: Wed, 16 Nov 2016 10:46:30 -0600 Subject: [PATCH 62/94] better matching of census blocks and roads to only keep roads on or within perimeter --- connectivity/census_block_roads.sql | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/connectivity/census_block_roads.sql b/connectivity/census_block_roads.sql index b69a6cf7..46428321 100644 --- a/connectivity/census_block_roads.sql +++ b/connectivity/census_block_roads.sql @@ -10,13 +10,26 @@ CREATE TABLE generated.cambridge_census_block_roads ( road_id INT ); +-- build a temporary table with buffered geoms to efficiently get +-- containing roads +CREATE TEMP TABLE tmp_block_buffers ( + id INTEGER PRIMARY KEY, + blockid10 VARCHAR(15), + geom geometry(multipolygon,2249) +) ON COMMIT DROP; +INSERT INTO tmp_block_buffers +SELECT id, blockid10, ST_Multi(ST_Buffer(geom,50)) FROM cambridge_census_blocks; +CREATE INDEX tidx_cambridge_blockgeoms ON tmp_block_buffers USING GIST (geom); +ANALYZE tmp_block_buffers; + +-- insert blocks and roads INSERT INTO generated.cambridge_census_block_roads ( blockid10, road_id ) SELECT blocks.blockid10, ways.road_id -FROM cambridge_census_blocks blocks, +FROM tmp_block_buffers blocks, cambridge_ways ways WHERE EXISTS ( SELECT 1 @@ -24,7 +37,13 @@ WHERE EXISTS ( WHERE ST_DWithin(zips.geom, blocks.geom, 11000) AND zips.zip_code = '02138' ) -AND ST_DWithin(blocks.geom,ways.geom,50); +AND ST_Intersects(blocks.geom,ways.geom) +AND ( + ST_Contains(blocks.geom,ways.geom) + OR ST_Length( + ST_Intersection(blocks.geom,ways.geom) + ) > 100 + ); CREATE INDEX idx_cambridge_censblkrds ON generated.cambridge_census_block_roads (blockid10,road_id); From 5357fe2eadadf48b3cbe7c4af20c4f975a7d15a6 Mon Sep 17 00:00:00 2001 From: Spencer Date: Fri, 18 Nov 2016 13:31:48 -0600 Subject: [PATCH 63/94] add designated bike access for pedestrian ways --- functional_class.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/functional_class.sql b/functional_class.sql index b0d8fd53..56e58875 100644 --- a/functional_class.sql +++ b/functional_class.sql @@ -47,7 +47,7 @@ SET functional_class = 'path' FROM cambridge_osm_full_line osm WHERE cambridge_ways.osm_id = osm.osm_id AND osm.highway = 'footway' -AND osm.bicycle IN ('yes','permissive') +AND osm.bicycle IN ('yes','permissive','designated') AND (osm.access IS NULL OR osm.access NOT IN ('no','private')); UPDATE cambridge_ways @@ -55,7 +55,7 @@ SET functional_class = 'living_street' FROM cambridge_osm_full_line osm WHERE cambridge_ways.osm_id = osm.osm_id AND osm.highway = 'pedestrian' -AND osm.bicycle IN ('yes','permissive') +AND osm.bicycle IN ('yes','permissive','designated') AND (osm.access IS NULL OR osm.access NOT IN ('no','private')); -- remove stuff that we don't want to route over From 06cdb09c5aecb90ae7bfeb360ec6adee050461db Mon Sep 17 00:00:00 2001 From: Spencer Date: Fri, 18 Nov 2016 13:48:13 -0600 Subject: [PATCH 64/94] add footway and service tags --- pfb.style | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pfb.style b/pfb.style index b91839e0..3c90765d 100644 --- a/pfb.style +++ b/pfb.style @@ -96,6 +96,7 @@ way cycleway:left:buffer text linear way cycleway:right:buffer text linear way cycleway:both:buffer text linear node,way foot text linear +way footway text linear node,way highway text linear node,way junction text linear way lanes text linear @@ -114,6 +115,7 @@ way parking:lane:right text linear way parking:lane:left text linear way parking:lane:both text linear node,way segregated text linear +way service text linear node,way stop text linear node,way surface text linear way tracktype text linear From 09ff41ee741ca688853b281d16615140bba74c71 Mon Sep 17 00:00:00 2001 From: Spencer Date: Fri, 18 Nov 2016 16:18:27 -0600 Subject: [PATCH 65/94] move width calcs before functional class. add sidewalk routes and designated service roads to network --- functional_class.sql | 19 +++++++++++++++++-- import_osm.sh | 2 +- process.txt | 2 +- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/functional_class.sql b/functional_class.sql index 56e58875..7a501e85 100644 --- a/functional_class.sql +++ b/functional_class.sql @@ -47,8 +47,23 @@ SET functional_class = 'path' FROM cambridge_osm_full_line osm WHERE cambridge_ways.osm_id = osm.osm_id AND osm.highway = 'footway' -AND osm.bicycle IN ('yes','permissive','designated') -AND (osm.access IS NULL OR osm.access NOT IN ('no','private')); +AND osm.footway = 'crossing'; + +UPDATE cambridge_ways +SET functional_class = 'path' +FROM cambridge_osm_full_line osm +WHERE cambridge_ways.osm_id = osm.osm_id +AND osm.highway = 'footway' +AND osm.bicycle = 'designated' +AND (osm.access IS NULL OR osm.access NOT IN ('no','private')) +AND COALESCE(width_ft,0) >= 8; + +UPDATE cambridge_ways +SET functional_class = 'path' +FROM cambridge_osm_full_line osm +WHERE cambridge_ways.osm_id = osm.osm_id +AND osm.highway='service' +AND osm.bicycle='designated'; UPDATE cambridge_ways SET functional_class = 'living_street' diff --git a/import_osm.sh b/import_osm.sh index c6a9c49e..e91e253c 100644 --- a/import_osm.sh +++ b/import_osm.sh @@ -146,10 +146,10 @@ echo 'Updating field names' psql -h $DBHOST -U gis -d ${DBNAME} -f ./prepare_tables.sql echo 'Setting values on road segments' psql -h $DBHOST -U gis -d ${DBNAME} -f ./one_way.sql +psql -h $DBHOST -U gis -d ${DBNAME} -f ./width_ft.sql psql -h $DBHOST -U gis -d ${DBNAME} -f ./functional_class.sql psql -h $DBHOST -U gis -d ${DBNAME} -f ./paths.sql psql -h $DBHOST -U gis -d ${DBNAME} -f ./speed_limit.sql -psql -h $DBHOST -U gis -d ${DBNAME} -f ./width_ft.sql psql -h $DBHOST -U gis -d ${DBNAME} -f ./lanes.sql psql -h $DBHOST -U gis -d ${DBNAME} -f ./park.sql psql -h $DBHOST -U gis -d ${DBNAME} -f ./bike_infra.sql diff --git a/process.txt b/process.txt index 9d08fbb8..d5e0e4ea 100644 --- a/process.txt +++ b/process.txt @@ -5,10 +5,10 @@ import_osm.sh (runs the following automatically) - prepare_tables.sql - one_way.sql + - width_ft.sql - functional_class.sql - paths.sql - speed_limit.sql - - width_ft.sql - lanes.sql - park.sql - bike_infra.sql From aef58328b7337889794dde30dd37871d611cd09f Mon Sep 17 00:00:00 2001 From: CloudNiner Date: Mon, 21 Nov 2016 16:15:27 -0500 Subject: [PATCH 66/94] Revert files to unix line endings --- functional_class.sql | 200 ++++++++++++------------- stress_tertiary.sql | 346 +++++++++++++++++++++---------------------- 2 files changed, 273 insertions(+), 273 deletions(-) diff --git a/functional_class.sql b/functional_class.sql index 7785f010..69147700 100644 --- a/functional_class.sql +++ b/functional_class.sql @@ -1,100 +1,100 @@ ----------------------------------------- --- INPUTS --- location: neighborhood ----------------------------------------- -UPDATE neighborhood_ways SET functional_class = NULL; - -UPDATE neighborhood_ways -SET functional_class = osm.highway -FROM neighborhood_osm_full_line osm -WHERE neighborhood_ways.osm_id = osm.osm_id -AND osm.highway IN ( - 'motorway', - 'tertiary', - 'trunk', - 'tertiary_link', - 'motorway_link', - 'secondary_link', - 'primary_link', - 'trunk_link', - 'residential', - 'secondary', - 'primary', - 'living_street' -); -- note that we're leaving out "road" - -UPDATE neighborhood_ways -SET functional_class = 'tertiary' -FROM neighborhood_osm_full_line osm -WHERE neighborhood_ways.osm_id = osm.osm_id -AND osm.highway = 'unclassified'; - -UPDATE neighborhood_ways -SET functional_class = 'track' -FROM neighborhood_osm_full_line osm -WHERE neighborhood_ways.osm_id = osm.osm_id -AND osm.highway = 'track' -AND osm.tracktype = 'grade1'; - -UPDATE neighborhood_ways -SET functional_class = 'path' -FROM neighborhood_osm_full_line osm -WHERE neighborhood_ways.osm_id = osm.osm_id -AND osm.highway IN ('cycleway','path'); - -UPDATE neighborhood_ways -SET functional_class = 'path' -FROM neighborhood_osm_full_line osm -WHERE neighborhood_ways.osm_id = osm.osm_id -AND osm.highway = 'footway' -AND osm.footway = 'crossing'; - -UPDATE cambridge_ways -SET functional_class = 'path' -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id -AND osm.highway = 'footway' -AND osm.bicycle = 'designated' -AND (osm.access IS NULL OR osm.access NOT IN ('no','private')) -AND COALESCE(width_ft,0) >= 8; - -UPDATE cambridge_ways -SET functional_class = 'path' -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id -AND osm.highway='service' -AND osm.bicycle='designated'; - -UPDATE neighborhood_ways -SET functional_class = 'living_street' -FROM neighborhood_osm_full_line osm -WHERE neighborhood_ways.osm_id = osm.osm_id -AND osm.highway = 'pedestrian' -AND osm.bicycle IN ('yes','permissive', 'designated') -AND (osm.access IS NULL OR osm.access NOT IN ('no','private')); - --- remove stuff that we don't want to route over -DELETE FROM neighborhood_ways WHERE functional_class IS NULL; - --- remove orphans -DELETE FROM neighborhood_ways -WHERE NOT EXISTS ( - SELECT 1 - FROM neighborhood_ways w - WHERE neighborhood_ways.intersection_to IN (w.intersection_to,w.intersection_from) - AND w.road_id != neighborhood_ways.road_id -) -AND NOT EXISTS ( - SELECT 1 - FROM neighborhood_ways w - WHERE neighborhood_ways.intersection_from IN (w.intersection_to,w.intersection_from) - AND w.road_id != neighborhood_ways.road_id -); - --- remove obsolete intersections -DELETE FROM neighborhood_ways_intersections -WHERE NOT EXISTS ( - SELECT 1 - FROM neighborhood_ways w - WHERE int_id IN (w.intersection_to,w.intersection_from) -); +---------------------------------------- +-- INPUTS +-- location: neighborhood +---------------------------------------- +UPDATE neighborhood_ways SET functional_class = NULL; + +UPDATE neighborhood_ways +SET functional_class = osm.highway +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id +AND osm.highway IN ( + 'motorway', + 'tertiary', + 'trunk', + 'tertiary_link', + 'motorway_link', + 'secondary_link', + 'primary_link', + 'trunk_link', + 'residential', + 'secondary', + 'primary', + 'living_street' +); -- note that we're leaving out "road" + +UPDATE neighborhood_ways +SET functional_class = 'tertiary' +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id +AND osm.highway = 'unclassified'; + +UPDATE neighborhood_ways +SET functional_class = 'track' +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id +AND osm.highway = 'track' +AND osm.tracktype = 'grade1'; + +UPDATE neighborhood_ways +SET functional_class = 'path' +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id +AND osm.highway IN ('cycleway','path'); + +UPDATE neighborhood_ways +SET functional_class = 'path' +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id +AND osm.highway = 'footway' +AND osm.footway = 'crossing'; + +UPDATE cambridge_ways +SET functional_class = 'path' +FROM cambridge_osm_full_line osm +WHERE cambridge_ways.osm_id = osm.osm_id +AND osm.highway = 'footway' +AND osm.bicycle = 'designated' +AND (osm.access IS NULL OR osm.access NOT IN ('no','private')) +AND COALESCE(width_ft,0) >= 8; + +UPDATE cambridge_ways +SET functional_class = 'path' +FROM cambridge_osm_full_line osm +WHERE cambridge_ways.osm_id = osm.osm_id +AND osm.highway='service' +AND osm.bicycle='designated'; + +UPDATE neighborhood_ways +SET functional_class = 'living_street' +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id +AND osm.highway = 'pedestrian' +AND osm.bicycle IN ('yes','permissive', 'designated') +AND (osm.access IS NULL OR osm.access NOT IN ('no','private')); + +-- remove stuff that we don't want to route over +DELETE FROM neighborhood_ways WHERE functional_class IS NULL; + +-- remove orphans +DELETE FROM neighborhood_ways +WHERE NOT EXISTS ( + SELECT 1 + FROM neighborhood_ways w + WHERE neighborhood_ways.intersection_to IN (w.intersection_to,w.intersection_from) + AND w.road_id != neighborhood_ways.road_id +) +AND NOT EXISTS ( + SELECT 1 + FROM neighborhood_ways w + WHERE neighborhood_ways.intersection_from IN (w.intersection_to,w.intersection_from) + AND w.road_id != neighborhood_ways.road_id +); + +-- remove obsolete intersections +DELETE FROM neighborhood_ways_intersections +WHERE NOT EXISTS ( + SELECT 1 + FROM neighborhood_ways w + WHERE int_id IN (w.intersection_to,w.intersection_from) +); diff --git a/stress_tertiary.sql b/stress_tertiary.sql index cdcf11ef..2755010b 100644 --- a/stress_tertiary.sql +++ b/stress_tertiary.sql @@ -1,173 +1,173 @@ ----------------------------------------- --- INPUTS --- location: neighborhood --- notes: this includes residential streets that have bike lanes --- of any type ----------------------------------------- -UPDATE neighborhood_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL -WHERE functional_class IN ('tertiary','tertiary_link') -OR (functional_class = 'residential' AND ft_bike_infra IN ('track','buffered_lane','lane')) -OR (functional_class = 'residential' AND tf_bike_infra IN ('track','buffered_lane','lane')) -OR (functional_class = 'residential' AND ft_lanes > 1) -OR (functional_class = 'residential' AND tf_lanes > 1) -OR (functional_class = 'residential' AND speed_limit > 30); - --- ft direction -UPDATE neighborhood_ways -SET ft_seg_stress = - CASE - WHEN ft_bike_infra = 'track' THEN 1 - WHEN ft_bike_infra = 'buffered_lane' - THEN CASE - WHEN speed_limit = 35 - THEN CASE - WHEN ft_lanes > 1 THEN 3 - ELSE 2 -- assume 1 lane - END - WHEN speed_limit > 35 - THEN CASE - WHEN ft_lanes > 1 THEN 3 - ELSE 2 -- assume 1 lane - END - ELSE CASE -- assume speed 30 - WHEN ft_lanes > 1 THEN 2 - ELSE 1 -- assume 1 lane - END - END - WHEN ft_bike_infra = 'lane' - THEN CASE - WHEN speed_limit > 30 THEN 3 - WHEN speed_limit <= 20 - THEN CASE - WHEN ft_lanes > 2 THEN 3 - WHEN ft_lanes = 2 - THEN CASE - WHEN ft_park = 0 THEN 2 - ELSE 2 -- assume parking - END - ELSE CASE -- assume 1 lane - WHEN ft_park = 0 THEN 1 - ELSE 2 -- assume parking - END - END - WHEN speed_limit = 25 - THEN CASE - WHEN ft_lanes > 2 THEN 3 - WHEN ft_lanes = 2 - THEN CASE - WHEN ft_park = 0 THEN 2 - ELSE 3 -- assume parking - END - ELSE CASE -- assume 1 lane - WHEN ft_park = 0 THEN 1 - ELSE 2 -- assume parking - END - END - ELSE CASE -- assume 30 mph speed limit - WHEN ft_lanes > 1 THEN 3 - ELSE CASE -- assume 1 lane - WHEN ft_park = 0 THEN 1 - ELSE 2 -- assume parking - END - END - END - ELSE CASE - WHEN speed_limit = 30 - THEN CASE - WHEN ft_lanes = 1 THEN 2 - ELSE 3 -- assumee more than 1 lane - END - WHEN speed_limit <= 25 - THEN CASE - WHEN ft_lanes = 1 THEN 1 - ELSE 3 -- assumee more than 1 lane - END - ELSE 3 - END - END -WHERE functional_class IN ('tertiary','tertiary_link') -OR (functional_class = 'residential' AND ft_bike_infra IN ('track','buffered_lane','lane')) -OR (functional_class = 'residential' AND tf_bike_infra IN ('track','buffered_lane','lane')) -OR (functional_class = 'residential' AND ft_lanes > 1) -OR (functional_class = 'residential' AND tf_lanes > 1) -OR (functional_class = 'residential' AND speed_limit > 30); - --- tf direction -UPDATE neighborhood_ways -SET tf_seg_stress = - CASE - WHEN tf_bike_infra = 'track' THEN 1 - WHEN tf_bike_infra = 'buffered_lane' - THEN CASE - WHEN speed_limit = 35 - THEN CASE - WHEN tf_lanes > 1 THEN 3 - ELSE 2 -- assume 1 lane - END - WHEN speed_limit > 35 - THEN CASE - WHEN tf_lanes > 1 THEN 3 - ELSE 2 -- assume 1 lane - END - ELSE CASE -- assume speed 30 - WHEN tf_lanes > 1 THEN 2 - ELSE 1 -- assume 1 lane - END - END - WHEN tf_bike_infra = 'lane' - THEN CASE - WHEN speed_limit > 30 THEN 3 - WHEN speed_limit <= 20 - THEN CASE - WHEN tf_lanes > 2 THEN 3 - WHEN tf_lanes = 2 - THEN CASE - WHEN tf_park = 0 THEN 2 - ELSE 2 -- assume parking - END - ELSE CASE -- assume 1 lane - WHEN tf_park = 0 THEN 1 - ELSE 2 -- assume parking - END - END - WHEN speed_limit = 25 - THEN CASE - WHEN tf_lanes > 2 THEN 3 - WHEN tf_lanes = 2 - THEN CASE - WHEN tf_park = 0 THEN 2 - ELSE 3 -- assume parking - END - ELSE CASE -- assume 1 lane - WHEN tf_park = 0 THEN 1 - ELSE 2 -- assume parking - END - END - ELSE CASE -- assume 30 mph speed limit - WHEN tf_lanes > 1 THEN 3 - ELSE CASE -- assume 1 lane - WHEN tf_park = 0 THEN 1 - ELSE 2 -- assume parking - END - END - END - ELSE CASE - WHEN speed_limit = 30 - THEN CASE - WHEN tf_lanes = 1 THEN 2 - ELSE 3 -- assumee more than 1 lane - END - WHEN speed_limit <= 25 - THEN CASE - WHEN tf_lanes = 1 THEN 1 - ELSE 3 -- assumee more than 1 lane - END - ELSE 3 - END - END -WHERE functional_class IN ('tertiary','tertiary_link') -OR (functional_class = 'residential' AND ft_bike_infra IN ('track','buffered_lane','lane')) -OR (functional_class = 'residential' AND tf_bike_infra IN ('track','buffered_lane','lane')) -OR (functional_class = 'residential' AND ft_lanes > 1) -OR (functional_class = 'residential' AND tf_lanes > 1) -OR (functional_class = 'residential' AND speed_limit > 30); +---------------------------------------- +-- INPUTS +-- location: neighborhood +-- notes: this includes residential streets that have bike lanes +-- of any type +---------------------------------------- +UPDATE neighborhood_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL +WHERE functional_class IN ('tertiary','tertiary_link') +OR (functional_class = 'residential' AND ft_bike_infra IN ('track','buffered_lane','lane')) +OR (functional_class = 'residential' AND tf_bike_infra IN ('track','buffered_lane','lane')) +OR (functional_class = 'residential' AND ft_lanes > 1) +OR (functional_class = 'residential' AND tf_lanes > 1) +OR (functional_class = 'residential' AND speed_limit > 30); + +-- ft direction +UPDATE neighborhood_ways +SET ft_seg_stress = + CASE + WHEN ft_bike_infra = 'track' THEN 1 + WHEN ft_bike_infra = 'buffered_lane' + THEN CASE + WHEN speed_limit = 35 + THEN CASE + WHEN ft_lanes > 1 THEN 3 + ELSE 2 -- assume 1 lane + END + WHEN speed_limit > 35 + THEN CASE + WHEN ft_lanes > 1 THEN 3 + ELSE 2 -- assume 1 lane + END + ELSE CASE -- assume speed 30 + WHEN ft_lanes > 1 THEN 2 + ELSE 1 -- assume 1 lane + END + END + WHEN ft_bike_infra = 'lane' + THEN CASE + WHEN speed_limit > 30 THEN 3 + WHEN speed_limit <= 20 + THEN CASE + WHEN ft_lanes > 2 THEN 3 + WHEN ft_lanes = 2 + THEN CASE + WHEN ft_park = 0 THEN 2 + ELSE 2 -- assume parking + END + ELSE CASE -- assume 1 lane + WHEN ft_park = 0 THEN 1 + ELSE 2 -- assume parking + END + END + WHEN speed_limit = 25 + THEN CASE + WHEN ft_lanes > 2 THEN 3 + WHEN ft_lanes = 2 + THEN CASE + WHEN ft_park = 0 THEN 2 + ELSE 3 -- assume parking + END + ELSE CASE -- assume 1 lane + WHEN ft_park = 0 THEN 1 + ELSE 2 -- assume parking + END + END + ELSE CASE -- assume 30 mph speed limit + WHEN ft_lanes > 1 THEN 3 + ELSE CASE -- assume 1 lane + WHEN ft_park = 0 THEN 1 + ELSE 2 -- assume parking + END + END + END + ELSE CASE + WHEN speed_limit = 30 + THEN CASE + WHEN ft_lanes = 1 THEN 2 + ELSE 3 -- assumee more than 1 lane + END + WHEN speed_limit <= 25 + THEN CASE + WHEN ft_lanes = 1 THEN 1 + ELSE 3 -- assumee more than 1 lane + END + ELSE 3 + END + END +WHERE functional_class IN ('tertiary','tertiary_link') +OR (functional_class = 'residential' AND ft_bike_infra IN ('track','buffered_lane','lane')) +OR (functional_class = 'residential' AND tf_bike_infra IN ('track','buffered_lane','lane')) +OR (functional_class = 'residential' AND ft_lanes > 1) +OR (functional_class = 'residential' AND tf_lanes > 1) +OR (functional_class = 'residential' AND speed_limit > 30); + +-- tf direction +UPDATE neighborhood_ways +SET tf_seg_stress = + CASE + WHEN tf_bike_infra = 'track' THEN 1 + WHEN tf_bike_infra = 'buffered_lane' + THEN CASE + WHEN speed_limit = 35 + THEN CASE + WHEN tf_lanes > 1 THEN 3 + ELSE 2 -- assume 1 lane + END + WHEN speed_limit > 35 + THEN CASE + WHEN tf_lanes > 1 THEN 3 + ELSE 2 -- assume 1 lane + END + ELSE CASE -- assume speed 30 + WHEN tf_lanes > 1 THEN 2 + ELSE 1 -- assume 1 lane + END + END + WHEN tf_bike_infra = 'lane' + THEN CASE + WHEN speed_limit > 30 THEN 3 + WHEN speed_limit <= 20 + THEN CASE + WHEN tf_lanes > 2 THEN 3 + WHEN tf_lanes = 2 + THEN CASE + WHEN tf_park = 0 THEN 2 + ELSE 2 -- assume parking + END + ELSE CASE -- assume 1 lane + WHEN tf_park = 0 THEN 1 + ELSE 2 -- assume parking + END + END + WHEN speed_limit = 25 + THEN CASE + WHEN tf_lanes > 2 THEN 3 + WHEN tf_lanes = 2 + THEN CASE + WHEN tf_park = 0 THEN 2 + ELSE 3 -- assume parking + END + ELSE CASE -- assume 1 lane + WHEN tf_park = 0 THEN 1 + ELSE 2 -- assume parking + END + END + ELSE CASE -- assume 30 mph speed limit + WHEN tf_lanes > 1 THEN 3 + ELSE CASE -- assume 1 lane + WHEN tf_park = 0 THEN 1 + ELSE 2 -- assume parking + END + END + END + ELSE CASE + WHEN speed_limit = 30 + THEN CASE + WHEN tf_lanes = 1 THEN 2 + ELSE 3 -- assumee more than 1 lane + END + WHEN speed_limit <= 25 + THEN CASE + WHEN tf_lanes = 1 THEN 1 + ELSE 3 -- assumee more than 1 lane + END + ELSE 3 + END + END +WHERE functional_class IN ('tertiary','tertiary_link') +OR (functional_class = 'residential' AND ft_bike_infra IN ('track','buffered_lane','lane')) +OR (functional_class = 'residential' AND tf_bike_infra IN ('track','buffered_lane','lane')) +OR (functional_class = 'residential' AND ft_lanes > 1) +OR (functional_class = 'residential' AND tf_lanes > 1) +OR (functional_class = 'residential' AND speed_limit > 30); From b181bc4889a8f4b51873b1ecf9ecee33e9df94fd Mon Sep 17 00:00:00 2001 From: Spencer Date: Mon, 21 Nov 2016 16:19:52 -0600 Subject: [PATCH 67/94] fix incorrect ft/tf column reference --- stress_primary.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stress_primary.sql b/stress_primary.sql index eed1c54c..a3c23557 100644 --- a/stress_primary.sql +++ b/stress_primary.sql @@ -2,7 +2,7 @@ -- INPUTS -- location: cambridge ---------------------------------------- -UPDATE cambridge_ways SET tf_seg_stress = NULL, tf_seg_stress = NULL +UPDATE cambridge_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL WHERE functional_class IN ('primary','primary_link'); -- ft direction From a93caef2aba7750ddb55e9213b7f6bdc8a9074e3 Mon Sep 17 00:00:00 2001 From: CloudNiner Date: Tue, 22 Nov 2016 08:00:14 -0500 Subject: [PATCH 68/94] Fixup remaining merge issues: - Fix incorrect stress_primary column ref, same fix as: https://github.com/spencerrecneps/pfb/commit/b181bc4889a8f4b51873b1ecf9ecee33e9df94fd - Fix missed references to cambridge table prefix - Fix census_block_roads temp table creation, ON COMMIT DROP no good since it drops itself immediately after creation --- connectivity/census_block_roads.sql | 8 ++++---- functional_class.sql | 12 ++++++------ stress_primary.sql | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/connectivity/census_block_roads.sql b/connectivity/census_block_roads.sql index 168aef2b..8bc100b4 100644 --- a/connectivity/census_block_roads.sql +++ b/connectivity/census_block_roads.sql @@ -19,10 +19,10 @@ CREATE TEMP TABLE tmp_block_buffers ( id INTEGER PRIMARY KEY, blockid10 VARCHAR(15), geom geometry(multipolygon, :nb_output_srid) -) ON COMMIT DROP; +); INSERT INTO tmp_block_buffers -SELECT id, blockid10, ST_Multi(ST_Buffer(geom,50)) FROM neighborhood_census_blocks; -CREATE INDEX tidx_cambridge_blockgeoms ON tmp_block_buffers USING GIST (geom); +SELECT gid, blockid10, ST_Multi(ST_Buffer(geom,50)) FROM neighborhood_census_blocks; +CREATE INDEX tidx_neighborhood_blockgeoms ON tmp_block_buffers USING GIST (geom); ANALYZE tmp_block_buffers; -- insert blocks and roads @@ -33,7 +33,7 @@ INSERT INTO generated.neighborhood_census_block_roads ( SELECT blocks.blockid10, ways.road_id FROM tmp_block_buffers blocks, - cambridge_ways ways + neighborhood_ways ways WHERE EXISTS ( SELECT 1 FROM neighborhood_boundary AS b diff --git a/functional_class.sql b/functional_class.sql index 69147700..7e5f32be 100644 --- a/functional_class.sql +++ b/functional_class.sql @@ -49,19 +49,19 @@ WHERE neighborhood_ways.osm_id = osm.osm_id AND osm.highway = 'footway' AND osm.footway = 'crossing'; -UPDATE cambridge_ways +UPDATE neighborhood_ways SET functional_class = 'path' -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id AND osm.highway = 'footway' AND osm.bicycle = 'designated' AND (osm.access IS NULL OR osm.access NOT IN ('no','private')) AND COALESCE(width_ft,0) >= 8; -UPDATE cambridge_ways +UPDATE neighborhood_ways SET functional_class = 'path' -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id AND osm.highway='service' AND osm.bicycle='designated'; diff --git a/stress_primary.sql b/stress_primary.sql index 7a3aa803..12df9514 100644 --- a/stress_primary.sql +++ b/stress_primary.sql @@ -2,7 +2,7 @@ -- INPUTS -- location: neighborhood ---------------------------------------- -UPDATE neighborhood_ways SET tf_seg_stress = NULL, tf_seg_stress = NULL +UPDATE neighborhood_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL WHERE functional_class IN ('primary','primary_link'); -- ft direction From e884e06db78ed9db1d1540746b88358ca02813b2 Mon Sep 17 00:00:00 2001 From: CloudNiner Date: Tue, 22 Nov 2016 08:39:04 -0500 Subject: [PATCH 69/94] Parameterize streetlight_gates.sql --- streetlight/streetlight_gates.sql | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/streetlight/streetlight_gates.sql b/streetlight/streetlight_gates.sql index 0a1468be..4244e168 100644 --- a/streetlight/streetlight_gates.sql +++ b/streetlight/streetlight_gates.sql @@ -1,19 +1,21 @@ ---------------------------------------- -- INPUTS --- location: cambridge --- proj: 2249 +-- location: neighborhood +-- :nb_boundary_buffer psql var must be set before running this script, +-- :nb_output_srid psql var must be set before running this script, +-- e.g. psql -v nb_boundary_buffer=11000 -v nb_output_srid=2249 -f streetlight_gates.sql ---------------------------------------- -DROP TABLE IF EXISTS cambridge_streetlight_gates; -CREATE TABLE generated.cambridge_streetlight_gates ( +DROP TABLE IF EXISTS neighborhood_streetlight_gates; +CREATE TABLE generated.neighborhood_streetlight_gates ( id SERIAL PRIMARY KEY, - geom geometry(polygon,2249), + geom geometry(polygon, :nb_output_srid), road_id BIGINT, functional_class TEXT, direction INT, is_pass INT ); -INSERT INTO cambridge_streetlight_gates ( +INSERT INTO neighborhood_streetlight_gates ( road_id, functional_class, geom, @@ -28,7 +30,7 @@ SELECT road_id, ST_LineInterpolatePoint(geom,0.5), ST_LineInterpolatePoint(geom,0.55) ), - 2249 + :nb_output_srid ), 100, 'endcap=flat' @@ -38,13 +40,12 @@ SELECT road_id, ST_LineInterpolatePoint(geom,0.55) )), 1 -FROM cambridge_ways +FROM neighborhood_ways WHERE functional_class IN ('primary','secondary','tertiary','residential') AND EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_DWithin(cambridge_ways.geom,zips.geom,11000) - AND zips.zip_code = '02138' + FROM neighborhood_boundary AS nb + WHERE ST_DWithin(neighborhood_ways.geom,nb.geom, :nb_boundary_buffer) ); -- formatting for upload to SLD @@ -53,4 +54,4 @@ SELECT road_id AS id, is_pass, direction, geom -FROM cambridge_streetlight_gates; +FROM neighborhood_streetlight_gates; From d33c0db526d66e1f59c551ea719b47dfa97babac Mon Sep 17 00:00:00 2001 From: CloudNiner Date: Thu, 10 Nov 2016 14:56:02 -0500 Subject: [PATCH 70/94] Tweak OSM download to pull all data within bbox The analysis uses OSM data other than highways, such as amenity=school. For now, while in development, assume we need all the data within the bounding box. We can tighten up these parameters once the analysis finalizes and we deploy the application. As a point of reference, the center city philly bbox pulled 15mb of data in ~60s. According to the Overpass wiki page, we can continue to make requests to the API as long as we don't exceed these limits: - < 10,000 queries per day - < 5GB download per day http://wiki.openstreetmap.org/wiki/Overpass_API If we do start to get near these limits, we'll need to investigate other options for download. --- import_osm.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/import_osm.sh b/import_osm.sh index 98da1075..92f72062 100755 --- a/import_osm.sh +++ b/import_osm.sh @@ -59,7 +59,7 @@ BBOX_SW_LNG=`bc <<< "$BBOX_SW_LNG - $LNG_DIFF"` BBOX_NE_LAT=`bc <<< "$BBOX_NE_LAT + $LAT_DIFF"` BBOX_NE_LNG=`bc <<< "$BBOX_NE_LNG + $LNG_DIFF"` # Download OSM data -OSM_API_URL="http://www.overpass-api.de/api/xapi?way[bbox=${BBOX_SW_LNG},${BBOX_SW_LAT},${BBOX_NE_LNG},${BBOX_NE_LAT}][highway=*]" +OSM_API_URL="http://www.overpass-api.de/api/xapi?*[bbox=${BBOX_SW_LNG},${BBOX_SW_LAT},${BBOX_NE_LNG},${BBOX_NE_LAT}]" OSM_TEMPDIR=`mktemp -d` OSM_DATA_FILE="${OSM_TEMPDIR}/overpass.osm" wget -O "${OSM_DATA_FILE}" "${OSM_API_URL}" From ee4badd6cc4eba84314c0bcf80665fe8c850544e Mon Sep 17 00:00:00 2001 From: Spencer Date: Mon, 5 Dec 2016 17:19:47 -0600 Subject: [PATCH 71/94] prep destinations layer for streetlightdata --- streetlight/streetlight_destinations.sql | 28 ++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 streetlight/streetlight_destinations.sql diff --git a/streetlight/streetlight_destinations.sql b/streetlight/streetlight_destinations.sql new file mode 100644 index 00000000..b88e5842 --- /dev/null +++ b/streetlight/streetlight_destinations.sql @@ -0,0 +1,28 @@ +---------------------------------------- +-- INPUTS +-- location: cambridge +-- proj: 2249 +---------------------------------------- +DROP TABLE IF EXISTS cambridge_streetlight_destinations; +CREATE TABLE generated.cambridge_streetlight_destinations ( + id SERIAL PRIMARY KEY, + geom geometry(multipolygon,4326), + name TEXT, + blockid10 TEXT, + is_pass INT +); + +INSERT INTO cambridge_streetlight_destinations ( + blockid10, + name, + geom, + is_pass +) +SELECT blocks.blockid10, + blocks.blockid10, + ST_Transform(blocks.geom,4326), + 0 +FROM cambridge_census_blocks blocks, + cambridge_zip_codes zips +WHERE zips.zip_code = '02138' +AND ST_Intersects(blocks.geom,zips.geom); From 43e41ff20e8c35b9b7d0f184e6949a37ec6b327d Mon Sep 17 00:00:00 2001 From: Spencer Date: Tue, 6 Dec 2016 16:50:22 -0600 Subject: [PATCH 72/94] add rules for better handling of lane data --- pfb.style | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pfb.style b/pfb.style index 3c90765d..b13f330b 100644 --- a/pfb.style +++ b/pfb.style @@ -102,6 +102,7 @@ node,way junction text linear way lanes text linear way lanes:forward text linear way lanes:backward text linear +way lanes:both_ways text linear node,way leisure text linear,polygon way maxspeed text linear node,way motorcar text linear @@ -123,6 +124,10 @@ node,way traffic_sign text linear node traffic_signals text linear way traffic_signals:direction text linear node,way tunnel text linear +way turn:lanes text linear +way turn:lanes:both_ways text linear +way turn:lanes:backward text linear +way turn:lanes:forward text linear node,way width text linear From 9dd294c2262ae56e83782dd0ea4545833680fa20 Mon Sep 17 00:00:00 2001 From: Spencer Date: Tue, 20 Dec 2016 13:24:59 -0600 Subject: [PATCH 73/94] add cross lanes and rework lane assignment --- lanes.sql | 201 +++++++++++++++++++++++++++++++++++---------- prepare_tables.sql | 1 + 2 files changed, 159 insertions(+), 43 deletions(-) diff --git a/lanes.sql b/lanes.sql index 4ef36e1c..0479ebe8 100644 --- a/lanes.sql +++ b/lanes.sql @@ -2,49 +2,164 @@ -- INPUTS -- location: cambridge ---------------------------------------- -UPDATE cambridge_ways SET ft_lanes = NULL, tf_lanes = NULL; +UPDATE cambridge_ways SET ft_lanes = NULL, tf_lanes = NULL, cross_lanes; --- forward UPDATE cambridge_ways -SET ft_lanes = substring(osm."lanes:forward" FROM '\d+')::INT -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id -AND ft_lanes IS NULL -AND osm."lanes:forward" IS NOT NULL; +SET ft_lanes = + CASE WHEN osm."turn:lanes:forward" IS NOT NULL + THEN array_length( + regexp_split_to_array( + osm."turn:lanes:forward", + '\|' + ), + 1 -- only one dimension + ) + WHEN osm."turn:lanes" IS NOT NULL AND one_way = 'ft' + THEN array_length( + regexp_split_to_array( + osm."turn:lanes", + '\|' + ), + 1 -- only one dimension + ) + WHEN osm."lanes:forward" IS NOT NULL + THEN substring(osm."lanes:forward" FROM '\d+')::INT + WHEN osm."lanes" IS NOT NULL AND one_way = 'ft' + THEN substring(osm."lanes" FROM '\d+')::INT + WHEN osm."lanes" IS NOT NULL AND one_way IS NULL + THEN ceil(substring(osm."lanes" FROM '\d+')::FLOAT) + END, + tf_lanes = + CASE WHEN osm."turn:lanes:backward" IS NOT NULL + THEN array_length( + regexp_split_to_array( + osm."turn:lanes:backward", + '\|' + ), + 1 -- only one dimension + ) + WHEN osm."turn:lanes" IS NOT NULL AND one_way = 'tf' + THEN array_length( + regexp_split_to_array( + osm."turn:lanes", + '\|' + ), + 1 -- only one dimension + ) + WHEN osm."lanes:backward" IS NOT NULL + THEN substring(osm."lanes:backward" FROM '\d+')::INT + WHEN osm."lanes" IS NOT NULL AND one_way = 'tf' + THEN substring(osm."lanes" FROM '\d+')::INT + WHEN osm."lanes" IS NOT NULL AND one_way IS NULL + THEN ceil(substring(osm."lanes" FROM '\d+')::FLOAT) + END, + cross_lanes = + CASE WHEN osm."turn:lanes:forward" IS NOT NULL AND one_way = 'ft' + THEN array_length( + array_remove( + regexp_split_to_array( + osm."turn:lanes:forward", + '\|' + ), + 'right' -- don't consider right-only lanes for crossing stress + ), + 1 -- only one dimension + ) + WHEN osm."turn:lanes:backward" IS NOT NULL AND one_way = 'tf' + THEN array_length( + array_remove( + regexp_split_to_array( + osm."turn:lanes:backward", + '\|' + ), + 'right' -- don't consider right-only lanes for crossing stress + ), + 1 -- only one dimension + ) + WHEN osm."turn:lanes:forward" IS NOT NULL AND osm."turn:lanes:backward" IS NOT NULL + THEN array_length( + array_remove( + regexp_split_to_array( + osm."turn:lanes:forward", + '\|' + ), + 'right' -- don't consider right-only lanes for crossing stress + ), + 1 -- only one dimension + ) + + array_length( + array_remove( + regexp_split_to_array( + osm."turn:lanes:backward", + '\|' + ), + 'right' -- don't consider right-only lanes for crossing stress + ), + 1 -- only one dimension + ) + WHEN osm."turn:lanes" IS NOT NULL + THEN array_length( + array_remove( + regexp_split_to_array( + osm."turn:lanes", + '\|' + ), + 'right' -- don't consider right-only lanes for crossing stress + ), + 1 -- only one dimension + ) + WHEN osm."lanes:forward" IS NOT NULL AND one_way = 'ft' + THEN substring(osm."lanes:forward" FROM '\d+')::INT + WHEN osm."lanes:backward" IS NOT NULL AND one_way = 'tf' + THEN substring(osm."lanes:backward" FROM '\d+')::INT + WHEN osm."lanes:forward" IS NOT NULL AND osm."lanes:backward" IS NOT NULL + THEN substring(osm."lanes:forward" FROM '\d+')::INT + + substring(osm."lanes:backward" FROM '\d+')::INT + WHEN osm."lanes" IS NOT NULL + THEN substring(osm."lanes" FROM '\d+')::INT + END --- backward -UPDATE cambridge_ways -SET tf_lanes = substring(osm."lanes:backward" FROM '\d+')::INT -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id -AND tf_lanes IS NULL -AND osm."lanes:backward" IS NOT NULL; - --- all lanes (no direction given) --- two way -UPDATE cambridge_ways -SET ft_lanes = floor(substring(osm.lanes FROM '\d+')::FLOAT / 2), - tf_lanes = floor(substring(osm.lanes FROM '\d+')::FLOAT / 2) -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id -AND tf_lanes IS NULL -AND ft_lanes IS NULL -AND one_way_car NOT IN ('ft','tf') -AND osm.lanes IS NOT NULL; - --- all lanes (no direction given) --- one way -UPDATE cambridge_ways -SET ft_lanes = substring(osm.lanes FROM '\d+')::INT -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id -AND one_way_car = 'ft' -AND ft_lanes IS NULL -AND osm.lanes IS NOT NULL; -UPDATE cambridge_ways -SET tf_lanes = substring(osm.lanes FROM '\d+')::INT -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id -AND one_way_car = 'tf' -AND tf_lanes IS NULL -AND osm.lanes IS NOT NULL; +-- -- forward +-- UPDATE cambridge_ways +-- SET ft_lanes = substring(osm."lanes:forward" FROM '\d+')::INT +-- FROM cambridge_osm_full_line osm +-- WHERE cambridge_ways.osm_id = osm.osm_id +-- AND ft_lanes IS NULL +-- AND osm."lanes:forward" IS NOT NULL; +-- +-- -- backward +-- UPDATE cambridge_ways +-- SET tf_lanes = substring(osm."lanes:backward" FROM '\d+')::INT +-- FROM cambridge_osm_full_line osm +-- WHERE cambridge_ways.osm_id = osm.osm_id +-- AND tf_lanes IS NULL +-- AND osm."lanes:backward" IS NOT NULL; +-- +-- -- all lanes (no direction given) +-- -- two way +-- UPDATE cambridge_ways +-- SET ft_lanes = floor(substring(osm.lanes FROM '\d+')::FLOAT / 2), +-- tf_lanes = floor(substring(osm.lanes FROM '\d+')::FLOAT / 2) +-- FROM cambridge_osm_full_line osm +-- WHERE cambridge_ways.osm_id = osm.osm_id +-- AND tf_lanes IS NULL +-- AND ft_lanes IS NULL +-- AND one_way_car NOT IN ('ft','tf') +-- AND osm.lanes IS NOT NULL; +-- +-- -- all lanes (no direction given) +-- -- one way +-- UPDATE cambridge_ways +-- SET ft_lanes = substring(osm.lanes FROM '\d+')::INT +-- FROM cambridge_osm_full_line osm +-- WHERE cambridge_ways.osm_id = osm.osm_id +-- AND one_way_car = 'ft' +-- AND ft_lanes IS NULL +-- AND osm.lanes IS NOT NULL; +-- UPDATE cambridge_ways +-- SET tf_lanes = substring(osm.lanes FROM '\d+')::INT +-- FROM cambridge_osm_full_line osm +-- WHERE cambridge_ways.osm_id = osm.osm_id +-- AND one_way_car = 'tf' +-- AND tf_lanes IS NULL +-- AND osm.lanes IS NOT NULL; diff --git a/prepare_tables.sql b/prepare_tables.sql index de8b87a8..ae650bc2 100644 --- a/prepare_tables.sql +++ b/prepare_tables.sql @@ -62,6 +62,7 @@ ALTER TABLE cambridge_ways ADD COLUMN ft_bike_infra TEXT; ALTER TABLE cambridge_ways ADD COLUMN tf_bike_infra TEXT; ALTER TABLE cambridge_ways ADD COLUMN ft_lanes INT; ALTER TABLE cambridge_ways ADD COLUMN tf_lanes INT; +ALTER TABLE cambridge_ways ADD COLUMN cross_lanes INT; ALTER TABLE cambridge_ways ADD COLUMN ft_park INT; ALTER TABLE cambridge_ways ADD COLUMN tf_park INT; ALTER TABLE cambridge_ways ADD COLUMN ft_seg_stress INT; From 1b6014067a49584550243d86af9fce94ab15fbd2 Mon Sep 17 00:00:00 2001 From: Spencer Date: Tue, 20 Dec 2016 16:33:32 -0600 Subject: [PATCH 74/94] refine handling of cross lanes --- lanes.sql | 59 ++++++++++++++++++++++++---------------------- prepare_tables.sql | 4 +++- 2 files changed, 34 insertions(+), 29 deletions(-) diff --git a/lanes.sql b/lanes.sql index 0479ebe8..b6097ed7 100644 --- a/lanes.sql +++ b/lanes.sql @@ -2,7 +2,8 @@ -- INPUTS -- location: cambridge ---------------------------------------- -UPDATE cambridge_ways SET ft_lanes = NULL, tf_lanes = NULL, cross_lanes; +UPDATE cambridge_ways +SET ft_lanes = NULL, tf_lanes = NULL, ft_cross_lanes = NULL, tf_cross_lanes = NULL; UPDATE cambridge_ways SET ft_lanes = @@ -26,8 +27,8 @@ SET ft_lanes = THEN substring(osm."lanes:forward" FROM '\d+')::INT WHEN osm."lanes" IS NOT NULL AND one_way = 'ft' THEN substring(osm."lanes" FROM '\d+')::INT - WHEN osm."lanes" IS NOT NULL AND one_way IS NULL - THEN ceil(substring(osm."lanes" FROM '\d+')::FLOAT) + WHEN osm."lanes" IS NOT NULL + THEN ceil(substring(osm."lanes" FROM '\d+')::FLOAT / 2) END, tf_lanes = CASE WHEN osm."turn:lanes:backward" IS NOT NULL @@ -50,11 +51,11 @@ SET ft_lanes = THEN substring(osm."lanes:backward" FROM '\d+')::INT WHEN osm."lanes" IS NOT NULL AND one_way = 'tf' THEN substring(osm."lanes" FROM '\d+')::INT - WHEN osm."lanes" IS NOT NULL AND one_way IS NULL - THEN ceil(substring(osm."lanes" FROM '\d+')::FLOAT) + WHEN osm."lanes" IS NOT NULL + THEN ceil(substring(osm."lanes" FROM '\d+')::FLOAT / 2) END, - cross_lanes = - CASE WHEN osm."turn:lanes:forward" IS NOT NULL AND one_way = 'ft' + ft_cross_lanes = + CASE WHEN osm."turn:lanes:forward" IS NOT NULL THEN array_length( array_remove( regexp_split_to_array( @@ -65,29 +66,27 @@ SET ft_lanes = ), 1 -- only one dimension ) - WHEN osm."turn:lanes:backward" IS NOT NULL AND one_way = 'tf' + WHEN osm."turn:lanes" IS NOT NULL AND one_way = 'ft' THEN array_length( array_remove( regexp_split_to_array( - osm."turn:lanes:backward", + osm."turn:lanes", '\|' ), 'right' -- don't consider right-only lanes for crossing stress ), 1 -- only one dimension ) - WHEN osm."turn:lanes:forward" IS NOT NULL AND osm."turn:lanes:backward" IS NOT NULL + WHEN osm."lanes:forward" IS NOT NULL + THEN substring(osm."lanes:forward" FROM '\d+')::INT + WHEN osm."lanes" IS NOT NULL AND one_way = 'ft' + THEN substring(osm."lanes" FROM '\d+')::INT + WHEN osm."lanes" IS NOT NULL + THEN ceil(substring(osm."lanes" FROM '\d+')::FLOAT / 2) + END, + tf_cross_lanes = + CASE WHEN osm."turn:lanes:backward" IS NOT NULL THEN array_length( - array_remove( - regexp_split_to_array( - osm."turn:lanes:forward", - '\|' - ), - 'right' -- don't consider right-only lanes for crossing stress - ), - 1 -- only one dimension - ) + - array_length( array_remove( regexp_split_to_array( osm."turn:lanes:backward", @@ -97,7 +96,7 @@ SET ft_lanes = ), 1 -- only one dimension ) - WHEN osm."turn:lanes" IS NOT NULL + WHEN osm."turn:lanes" IS NOT NULL AND one_way = 'tf' THEN array_length( array_remove( regexp_split_to_array( @@ -108,16 +107,20 @@ SET ft_lanes = ), 1 -- only one dimension ) - WHEN osm."lanes:forward" IS NOT NULL AND one_way = 'ft' - THEN substring(osm."lanes:forward" FROM '\d+')::INT - WHEN osm."lanes:backward" IS NOT NULL AND one_way = 'tf' + WHEN osm."lanes:backward" IS NOT NULL THEN substring(osm."lanes:backward" FROM '\d+')::INT - WHEN osm."lanes:forward" IS NOT NULL AND osm."lanes:backward" IS NOT NULL - THEN substring(osm."lanes:forward" FROM '\d+')::INT + - substring(osm."lanes:backward" FROM '\d+')::INT - WHEN osm."lanes" IS NOT NULL + WHEN osm."lanes" IS NOT NULL AND one_way = 'tf' THEN substring(osm."lanes" FROM '\d+')::INT + WHEN osm."lanes" IS NOT NULL + THEN ceil(substring(osm."lanes" FROM '\d+')::FLOAT / 2) + END, + twltl_cross_lanes = + CASE WHEN osm."lanes:both_ways" IS NOT NULL THEN 1 + WHEN osm."turn:lanes:both_ways" IS NOT NULL THEN 1 + ELSE NULL END +FROM cambridge_osm_full_line osm +WHERE cambridge_ways.osm_id = osm.osm_id; -- -- forward -- UPDATE cambridge_ways diff --git a/prepare_tables.sql b/prepare_tables.sql index ae650bc2..98876513 100644 --- a/prepare_tables.sql +++ b/prepare_tables.sql @@ -62,7 +62,9 @@ ALTER TABLE cambridge_ways ADD COLUMN ft_bike_infra TEXT; ALTER TABLE cambridge_ways ADD COLUMN tf_bike_infra TEXT; ALTER TABLE cambridge_ways ADD COLUMN ft_lanes INT; ALTER TABLE cambridge_ways ADD COLUMN tf_lanes INT; -ALTER TABLE cambridge_ways ADD COLUMN cross_lanes INT; +ALTER TABLE cambridge_ways ADD COLUMN ft_cross_lanes INT; +ALTER TABLE cambridge_ways ADD COLUMN tf_cross_lanes INT; +ALTER TABLE cambridge_ways ADD COLUMN twltl_cross_lanes INT; ALTER TABLE cambridge_ways ADD COLUMN ft_park INT; ALTER TABLE cambridge_ways ADD COLUMN tf_park INT; ALTER TABLE cambridge_ways ADD COLUMN ft_seg_stress INT; From 860417ab268069857a6592e34b9f30d4f7d126fc Mon Sep 17 00:00:00 2001 From: Spencer Date: Wed, 21 Dec 2016 09:59:00 -0600 Subject: [PATCH 75/94] change references to cambridge into neighborhood --- bike_infra.sql | 66 ++++---- connectivity/access_jobs.sql | 26 +-- connectivity/access_population.sql | 26 +-- connectivity/access_recreation.sql | 20 +-- connectivity/access_schools.sql | 46 +++--- connectivity/census_block_jobs.sql | 20 +-- connectivity/census_block_roads.sql | 22 +-- connectivity/census_blocks.sql | 22 +-- connectivity/connected_census_blocks.sql | 52 +++--- .../connected_census_blocks_recreation.sql | 52 +++--- .../connected_census_blocks_schools.sql | 52 +++--- connectivity/coverage.sql | 10 +- connectivity/cycles.py | 2 +- connectivity/overall_scores.sql | 126 +++++++------- connectivity/reachable_roads_high_stress.sql | 24 +-- connectivity/reachable_roads_low_stress.sql | 24 +-- connectivity/school_roads.sql | 30 ++-- connectivity/schools.sql | 30 ++-- drop_tables.sh | 2 +- functional_class.sql | 72 ++++---- import_osm.sh | 4 +- lanes.sql | 40 ++--- legs.sql | 8 +- one_way.sql | 16 +- park.sql | 22 +-- paths.sql | 40 ++--- prepare_tables.sql | 154 +++++++++--------- process.txt | 4 +- signalized.sql | 30 ++-- speed_limit.sql | 10 +- stops.sql | 10 +- streetlight/streetlight_destinations.sql | 12 +- streetlight/streetlight_gates.sql | 16 +- stress_lesser_ints.sql | 20 +-- stress_link_ints.sql | 4 +- stress_living_street.sql | 6 +- stress_motorway-trunk.sql | 6 +- stress_motorway-trunk_ints.sql | 4 +- stress_one_way_reset.sql | 4 +- stress_path.sql | 6 +- stress_primary.sql | 8 +- stress_primary_ints.sql | 4 +- stress_residential.sql | 8 +- stress_secondary.sql | 8 +- stress_secondary_ints.sql | 20 +-- stress_tertiary.sql | 8 +- stress_tertiary_ints.sql | 20 +-- stress_track.sql | 6 +- width_ft.sql | 22 +-- 49 files changed, 622 insertions(+), 622 deletions(-) diff --git a/bike_infra.sql b/bike_infra.sql index e3b82947..dde91a1a 100644 --- a/bike_infra.sql +++ b/bike_infra.sql @@ -1,17 +1,17 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -UPDATE cambridge_ways SET ft_bike_infra = NULL, tf_bike_infra = NULL; +UPDATE neighborhood_ways SET ft_bike_infra = NULL, tf_bike_infra = NULL; ---------------------- -- ft direction ---------------------- -- sharrow -UPDATE cambridge_ways +UPDATE neighborhood_ways SET ft_bike_infra = 'sharrow' -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id AND ( osm."cycleway:both" = 'shared_lane' OR (COALESCE(one_way_car,'ft') = 'ft' AND osm.cycleway = 'shared_lane') @@ -20,10 +20,10 @@ AND ( ); -- lane -UPDATE cambridge_ways +UPDATE neighborhood_ways SET ft_bike_infra = 'lane' -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id AND ( osm."cycleway:both" = 'lane' OR (COALESCE(one_way_car,'ft') = 'ft' AND osm.cycleway = 'lane') @@ -34,10 +34,10 @@ AND ( ); -- buffered lane -UPDATE cambridge_ways +UPDATE neighborhood_ways SET ft_bike_infra = 'buffered_lane' -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id AND ( osm."cycleway:both" = 'buffered_lane' OR (COALESCE(one_way_car,'ft') = 'ft' AND osm.cycleway = 'buffered_lane') @@ -53,10 +53,10 @@ AND ( ); -- track -UPDATE cambridge_ways +UPDATE neighborhood_ways SET ft_bike_infra = 'track' -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id AND ( osm."cycleway:both" = 'track' OR (osm."cycleway:right" = 'track' AND osm."oneway:bicycle" = 'no') @@ -74,10 +74,10 @@ AND ( -- tf direction ---------------------- -- sharrow -UPDATE cambridge_ways +UPDATE neighborhood_ways SET tf_bike_infra = 'sharrow' -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id AND ( osm."cycleway:both" = 'shared_lane' OR (COALESCE(one_way_car,'tf') = 'tf' AND osm.cycleway = 'shared_lane') @@ -86,10 +86,10 @@ AND ( ); -- lane -UPDATE cambridge_ways +UPDATE neighborhood_ways SET tf_bike_infra = 'lane' -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id AND ( osm."cycleway:both" = 'lane' OR (COALESCE(one_way_car,'tf') = 'tf' AND osm.cycleway = 'lane') @@ -100,10 +100,10 @@ AND ( ); -- buffered lane -UPDATE cambridge_ways +UPDATE neighborhood_ways SET tf_bike_infra = 'buffered_lane' -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id AND ( osm."cycleway:both" = 'buffered_lane' OR (COALESCE(one_way_car,'tf') = 'tf' AND osm.cycleway = 'buffered_lane') @@ -119,10 +119,10 @@ AND ( ); -- track -UPDATE cambridge_ways +UPDATE neighborhood_ways SET tf_bike_infra = 'track' -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id AND ( osm."cycleway:both" = 'track' OR (osm."cycleway:left" = 'track' AND osm."oneway:bicycle" = 'no') @@ -136,17 +136,17 @@ AND ( ); -- update one_way based on bike infra -UPDATE cambridge_ways +UPDATE neighborhood_ways SET one_way = NULL; -UPDATE cambridge_ways +UPDATE neighborhood_ways SET one_way = one_way_car -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id AND one_way_car = 'ft' AND NOT (tf_bike_infra IS NOT NULL OR COALESCE(osm."oneway:bicycle",'yes') = 'no'); -UPDATE cambridge_ways +UPDATE neighborhood_ways SET one_way = one_way_car -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id AND one_way_car = 'tf' AND NOT (ft_bike_infra IS NOT NULL OR COALESCE(osm."oneway:bicycle",'yes') = 'no'); diff --git a/connectivity/access_jobs.sql b/connectivity/access_jobs.sql index b30bebf2..54ca919a 100644 --- a/connectivity/access_jobs.sql +++ b/connectivity/access_jobs.sql @@ -1,42 +1,42 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -- low stress access -UPDATE cambridge_census_blocks +UPDATE neighborhood_census_blocks SET emp_low_stress = ( SELECT SUM(blocks2.jobs) - FROM cambridge_census_block_jobs blocks2 + FROM neighborhood_census_block_jobs blocks2 WHERE EXISTS ( SELECT 1 - FROM cambridge_connected_census_blocks cb - WHERE cb.source_blockid10 = cambridge_census_blocks.blockid10 + FROM neighborhood_connected_census_blocks cb + WHERE cb.source_blockid10 = neighborhood_census_blocks.blockid10 AND cb.target_blockid10 = blocks2.blockid10 AND cb.low_stress ) ) WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) + FROM neighborhood_zip_codes zips + WHERE ST_Intersects(neighborhood_census_blocks.geom,zips.geom) AND zips.zip_code = '02138' ); -- high stress access -UPDATE cambridge_census_blocks +UPDATE neighborhood_census_blocks SET emp_high_stress = ( SELECT SUM(blocks2.jobs) - FROM cambridge_census_block_jobs blocks2 + FROM neighborhood_census_block_jobs blocks2 WHERE EXISTS ( SELECT 1 - FROM cambridge_connected_census_blocks cb - WHERE cb.source_blockid10 = cambridge_census_blocks.blockid10 + FROM neighborhood_connected_census_blocks cb + WHERE cb.source_blockid10 = neighborhood_census_blocks.blockid10 AND cb.target_blockid10 = blocks2.blockid10 ) ) WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) + FROM neighborhood_zip_codes zips + WHERE ST_Intersects(neighborhood_census_blocks.geom,zips.geom) AND zips.zip_code = '02138' ); diff --git a/connectivity/access_population.sql b/connectivity/access_population.sql index 1163c6e2..da51698a 100644 --- a/connectivity/access_population.sql +++ b/connectivity/access_population.sql @@ -1,42 +1,42 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -- low stress access -UPDATE cambridge_census_blocks +UPDATE neighborhood_census_blocks SET pop_low_stress = ( SELECT SUM(blocks2.pop10) - FROM cambridge_census_blocks blocks2 + FROM neighborhood_census_blocks blocks2 WHERE EXISTS ( SELECT 1 - FROM cambridge_connected_census_blocks cb - WHERE cb.source_blockid10 = cambridge_census_blocks.blockid10 + FROM neighborhood_connected_census_blocks cb + WHERE cb.source_blockid10 = neighborhood_census_blocks.blockid10 AND cb.target_blockid10 = blocks2.blockid10 AND cb.low_stress ) ) WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) + FROM neighborhood_zip_codes zips + WHERE ST_Intersects(neighborhood_census_blocks.geom,zips.geom) AND zips.zip_code = '02138' ); -- high stress access -UPDATE cambridge_census_blocks +UPDATE neighborhood_census_blocks SET pop_high_stress = ( SELECT SUM(blocks2.pop10) - FROM cambridge_census_blocks blocks2 + FROM neighborhood_census_blocks blocks2 WHERE EXISTS ( SELECT 1 - FROM cambridge_connected_census_blocks cb - WHERE cb.source_blockid10 = cambridge_census_blocks.blockid10 + FROM neighborhood_connected_census_blocks cb + WHERE cb.source_blockid10 = neighborhood_census_blocks.blockid10 AND cb.target_blockid10 = blocks2.blockid10 ) ) WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) + FROM neighborhood_zip_codes zips + WHERE ST_Intersects(neighborhood_census_blocks.geom,zips.geom) AND zips.zip_code = '02138' ); diff --git a/connectivity/access_recreation.sql b/connectivity/access_recreation.sql index 8129e5b7..8846c648 100644 --- a/connectivity/access_recreation.sql +++ b/connectivity/access_recreation.sql @@ -1,26 +1,26 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -- low stress access -UPDATE cambridge_census_blocks +UPDATE neighborhood_census_blocks SET rec_low_stress = ( SELECT COUNT(path_id) - FROM cambridge_paths + FROM neighborhood_paths WHERE EXISTS ( SELECT 1 - FROM cambridge_census_block_roads cbr, - cambridge_reachable_roads_low_stress ls, - cambridge_ways, - cambridge_paths - WHERE cb.source_blockid10 = cambridge_census_blocks.blockid10 + FROM neighborhood_census_block_roads cbr, + neighborhood_reachable_roads_low_stress ls, + neighborhood_ways, + neighborhood_paths + WHERE cb.source_blockid10 = neighborhood_census_blocks.blockid10 AND cb.target_blockid10 = blocks2.blockid10 AND cb.low_stress ) ) WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) + FROM neighborhood_zip_codes zips + WHERE ST_Intersects(neighborhood_census_blocks.geom,zips.geom) AND zips.zip_code = '02138' ); diff --git a/connectivity/access_schools.sql b/connectivity/access_schools.sql index 58cf950f..a5cd20a6 100644 --- a/connectivity/access_schools.sql +++ b/connectivity/access_schools.sql @@ -1,65 +1,65 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -- low stress access -UPDATE cambridge_census_blocks +UPDATE neighborhood_census_blocks SET schools_low_stress = ( SELECT COUNT(cbs.id) - FROM cambridge_connected_census_blocks_schools cbs - WHERE cbs.source_blockid10 = cambridge_census_blocks.blockid10 + FROM neighborhood_connected_census_blocks_schools cbs + WHERE cbs.source_blockid10 = neighborhood_census_blocks.blockid10 AND cbs.low_stress ) WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) + FROM neighborhood_zip_codes zips + WHERE ST_Intersects(neighborhood_census_blocks.geom,zips.geom) AND zips.zip_code = '02138' ); -- high stress access -UPDATE cambridge_census_blocks +UPDATE neighborhood_census_blocks SET schools_high_stress = ( SELECT COUNT(cbs.id) - FROM cambridge_connected_census_blocks_schools cbs - WHERE cbs.source_blockid10 = cambridge_census_blocks.blockid10 + FROM neighborhood_connected_census_blocks_schools cbs + WHERE cbs.source_blockid10 = neighborhood_census_blocks.blockid10 ) WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) + FROM neighborhood_zip_codes zips + WHERE ST_Intersects(neighborhood_census_blocks.geom,zips.geom) AND zips.zip_code = '02138' ); -- low stress population shed for schools in neighborhood -UPDATE cambridge_schools +UPDATE neighborhood_schools SET pop_low_stress = ( SELECT SUM(cb.pop10) - FROM cambridge_census_blocks cb, - cambridge_connected_census_blocks_schools cbs + FROM neighborhood_census_blocks cb, + neighborhood_connected_census_blocks_schools cbs WHERE cb.blockid10 = cbs.source_blockid10 - AND cambridge_schools.id = cbs.target_school_id + AND neighborhood_schools.id = cbs.target_school_id AND cbs.low_stress ) WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_Intersects(cambridge_schools.geom_pt,zips.geom) + FROM neighborhood_zip_codes zips + WHERE ST_Intersects(neighborhood_schools.geom_pt,zips.geom) AND zips.zip_code = '02138' ); -- high stress population shed for schools in neighborhood -UPDATE cambridge_schools +UPDATE neighborhood_schools SET pop_high_stress = ( SELECT SUM(cb.pop10) - FROM cambridge_census_blocks cb, - cambridge_connected_census_blocks_schools cbs + FROM neighborhood_census_blocks cb, + neighborhood_connected_census_blocks_schools cbs WHERE cb.blockid10 = cbs.source_blockid10 - AND cambridge_schools.id = cbs.target_school_id + AND neighborhood_schools.id = cbs.target_school_id ) WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_Intersects(cambridge_schools.geom_pt,zips.geom) + FROM neighborhood_zip_codes zips + WHERE ST_Intersects(neighborhood_schools.geom_pt,zips.geom) AND zips.zip_code = '02138' ); diff --git a/connectivity/census_block_jobs.sql b/connectivity/census_block_jobs.sql index e7148585..d877dd4e 100644 --- a/connectivity/census_block_jobs.sql +++ b/connectivity/census_block_jobs.sql @@ -1,6 +1,6 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood -- data downloaded from http://lehd.ces.census.gov/data/ -- or http://lehd.ces.census.gov/data/lodes/LODES7/ -- "ma_od_main_JT00_2014".csv @@ -24,37 +24,37 @@ ANALYZE "ma_od_aux_JT00_2014" (w_geocode); ANALYZE "ma_od_main_JT00_2014" (w_geocode); -- create combined table -CREATE TABLE generated.cambridge_census_block_jobs ( +CREATE TABLE generated.neighborhood_census_block_jobs ( id SERIAL PRIMARY KEY, blockid10 VARCHAR(15), jobs INT ); -- add blocks of interest -INSERT INTO generated.cambridge_census_block_jobs (blockid10) +INSERT INTO generated.neighborhood_census_block_jobs (blockid10) SELECT blocks.blockid10 -FROM cambridge_census_blocks blocks; +FROM neighborhood_census_blocks blocks; -- add main data -UPDATE generated.cambridge_census_block_jobs +UPDATE generated.neighborhood_census_block_jobs SET jobs = COALESCE(( SELECT SUM(j."S000") FROM "ma_od_main_JT00_2014" j - WHERE j.w_geocode = cambridge_census_block_jobs.blockid10 + WHERE j.w_geocode = neighborhood_census_block_jobs.blockid10 ),0); -- add aux data -UPDATE generated.cambridge_census_block_jobs +UPDATE generated.neighborhood_census_block_jobs SET jobs = jobs + COALESCE(( SELECT SUM(j."S000") FROM "ma_od_aux_JT00_2014" j - WHERE j.w_geocode = cambridge_census_block_jobs.blockid10 + WHERE j.w_geocode = neighborhood_census_block_jobs.blockid10 ),0); -- indexes -CREATE INDEX idx_cambridge_blkjobs ON cambridge_census_block_jobs (blockid10); -ANALYZE cambridge_census_block_jobs (blockid10); +CREATE INDEX idx_neighborhood_blkjobs ON neighborhood_census_block_jobs (blockid10); +ANALYZE neighborhood_census_block_jobs (blockid10); -- drop import tables DROP TABLE IF EXISTS "ma_od_aux_JT00_2014"; diff --git a/connectivity/census_block_roads.sql b/connectivity/census_block_roads.sql index 46428321..54dfb0e5 100644 --- a/connectivity/census_block_roads.sql +++ b/connectivity/census_block_roads.sql @@ -1,10 +1,10 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -DROP TABLE IF EXISTS generated.cambridge_census_block_roads; +DROP TABLE IF EXISTS generated.neighborhood_census_block_roads; -CREATE TABLE generated.cambridge_census_block_roads ( +CREATE TABLE generated.neighborhood_census_block_roads ( id SERIAL PRIMARY KEY, blockid10 VARCHAR(15), road_id INT @@ -18,22 +18,22 @@ CREATE TEMP TABLE tmp_block_buffers ( geom geometry(multipolygon,2249) ) ON COMMIT DROP; INSERT INTO tmp_block_buffers -SELECT id, blockid10, ST_Multi(ST_Buffer(geom,50)) FROM cambridge_census_blocks; -CREATE INDEX tidx_cambridge_blockgeoms ON tmp_block_buffers USING GIST (geom); +SELECT id, blockid10, ST_Multi(ST_Buffer(geom,50)) FROM neighborhood_census_blocks; +CREATE INDEX tidx_neighborhood_blockgeoms ON tmp_block_buffers USING GIST (geom); ANALYZE tmp_block_buffers; -- insert blocks and roads -INSERT INTO generated.cambridge_census_block_roads ( +INSERT INTO generated.neighborhood_census_block_roads ( blockid10, road_id ) SELECT blocks.blockid10, ways.road_id FROM tmp_block_buffers blocks, - cambridge_ways ways + neighborhood_ways ways WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips + FROM neighborhood_zip_codes zips WHERE ST_DWithin(zips.geom, blocks.geom, 11000) AND zips.zip_code = '02138' ) @@ -45,6 +45,6 @@ AND ( ) > 100 ); -CREATE INDEX idx_cambridge_censblkrds -ON generated.cambridge_census_block_roads (blockid10,road_id); -ANALYZE generated.cambridge_census_block_roads; +CREATE INDEX idx_neighborhood_censblkrds +ON generated.neighborhood_census_block_roads (blockid10,road_id); +ANALYZE generated.neighborhood_census_block_roads; diff --git a/connectivity/census_blocks.sql b/connectivity/census_blocks.sql index 66041044..3f2a1456 100644 --- a/connectivity/census_blocks.sql +++ b/connectivity/census_blocks.sql @@ -1,19 +1,19 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood -- code to be run on table that has -- been imported directly from US Census -- blkpophu file ---------------------------------------- -ALTER TABLE cambridge_census_blocks ADD COLUMN pop_low_stress INT; -ALTER TABLE cambridge_census_blocks ADD COLUMN pop_high_stress INT; -ALTER TABLE cambridge_census_blocks ADD COLUMN emp_low_stress INT; -ALTER TABLE cambridge_census_blocks ADD COLUMN emp_high_stress INT; -ALTER TABLE cambridge_census_blocks ADD COLUMN schools_low_stress INT; -ALTER TABLE cambridge_census_blocks ADD COLUMN schools_high_stress INT; -ALTER TABLE cambridge_census_blocks ADD COLUMN rec_low_stress INT; -ALTER TABLE cambridge_census_blocks ADD COLUMN rec_high_stress INT; +ALTER TABLE neighborhood_census_blocks ADD COLUMN pop_low_stress INT; +ALTER TABLE neighborhood_census_blocks ADD COLUMN pop_high_stress INT; +ALTER TABLE neighborhood_census_blocks ADD COLUMN emp_low_stress INT; +ALTER TABLE neighborhood_census_blocks ADD COLUMN emp_high_stress INT; +ALTER TABLE neighborhood_census_blocks ADD COLUMN schools_low_stress INT; +ALTER TABLE neighborhood_census_blocks ADD COLUMN schools_high_stress INT; +ALTER TABLE neighborhood_census_blocks ADD COLUMN rec_low_stress INT; +ALTER TABLE neighborhood_census_blocks ADD COLUMN rec_high_stress INT; -CREATE INDEX idx_cambridge_blocks10 ON cambridge_census_blocks (blockid10); -ANALYZE cambridge_census_blocks (blockid10); +CREATE INDEX idx_neighborhood_blocks10 ON neighborhood_census_blocks (blockid10); +ANALYZE neighborhood_census_blocks (blockid10); diff --git a/connectivity/connected_census_blocks.sql b/connectivity/connected_census_blocks.sql index c7ff6119..d7094bbc 100644 --- a/connectivity/connected_census_blocks.sql +++ b/connectivity/connected_census_blocks.sql @@ -1,10 +1,10 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -DROP TABLE IF EXISTS generated.cambridge_connected_census_blocks; +DROP TABLE IF EXISTS generated.neighborhood_connected_census_blocks; -CREATE TABLE generated.cambridge_connected_census_blocks ( +CREATE TABLE generated.neighborhood_connected_census_blocks ( id SERIAL PRIMARY KEY, source_blockid10 VARCHAR(15), target_blockid10 VARCHAR(15), @@ -14,27 +14,27 @@ CREATE TABLE generated.cambridge_connected_census_blocks ( high_stress_cost INT ); -INSERT INTO generated.cambridge_connected_census_blocks ( -- took 2 hrs on the server +INSERT INTO generated.neighborhood_connected_census_blocks ( -- took 2 hrs on the server source_blockid10, target_blockid10, low_stress, high_stress ) SELECT source_block.blockid10, target_block.blockid10, 'f'::BOOLEAN, 't'::BOOLEAN -FROM cambridge_census_blocks source_block, - cambridge_census_blocks target_block +FROM neighborhood_census_blocks source_block, + neighborhood_census_blocks target_block WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips + FROM neighborhood_zip_codes zips WHERE ST_Intersects(source_block.geom,zips.geom) AND zips.zip_code = '02138' ) AND source_block.geom <#> target_block.geom < 11000 AND EXISTS ( SELECT 1 - FROM cambridge_census_block_roads source_br, - cambridge_census_block_roads target_br, - cambridge_reachable_roads_high_stress hs + FROM neighborhood_census_block_roads source_br, + neighborhood_census_block_roads target_br, + neighborhood_reachable_roads_high_stress hs WHERE source_block.blockid10 = source_br.blockid10 AND target_block.blockid10 = target_br.blockid10 AND hs.base_road = source_br.road_id @@ -42,18 +42,18 @@ AND EXISTS ( ); -- block pair index -CREATE INDEX idx_cambridge_blockpairs -ON cambridge_connected_census_blocks (source_blockid10,target_blockid10); -ANALYZE cambridge_connected_census_blocks (source_blockid10,target_blockid10); +CREATE INDEX idx_neighborhood_blockpairs +ON neighborhood_connected_census_blocks (source_blockid10,target_blockid10); +ANALYZE neighborhood_connected_census_blocks (source_blockid10,target_blockid10); -- low stress -UPDATE cambridge_connected_census_blocks +UPDATE neighborhood_connected_census_blocks SET low_stress = 't'::BOOLEAN WHERE EXISTS ( SELECT 1 - FROM cambridge_census_block_roads source_br, - cambridge_census_block_roads target_br, - cambridge_reachable_roads_low_stress ls + FROM neighborhood_census_block_roads source_br, + neighborhood_census_block_roads target_br, + neighborhood_reachable_roads_low_stress ls WHERE source_blockid10 = source_br.blockid10 AND target_blockid10 = target_br.blockid10 AND ls.base_road = source_br.road_id @@ -61,9 +61,9 @@ WHERE EXISTS ( ) AND ( SELECT MIN(total_cost) - FROM cambridge_census_block_roads source_br, - cambridge_census_block_roads target_br, - cambridge_reachable_roads_low_stress ls + FROM neighborhood_census_block_roads source_br, + neighborhood_census_block_roads target_br, + neighborhood_reachable_roads_low_stress ls WHERE source_blockid10 = source_br.blockid10 AND target_blockid10 = target_br.blockid10 AND ls.base_road = source_br.road_id @@ -71,9 +71,9 @@ AND ( )::FLOAT / COALESCE(( SELECT MIN(total_cost) + 1 - FROM cambridge_census_block_roads source_br, - cambridge_census_block_roads target_br, - cambridge_reachable_roads_high_stress hs + FROM neighborhood_census_block_roads source_br, + neighborhood_census_block_roads target_br, + neighborhood_reachable_roads_high_stress hs WHERE source_blockid10 = source_br.blockid10 AND target_blockid10 = target_br.blockid10 AND hs.base_road = source_br.road_id @@ -81,6 +81,6 @@ AND ( ),11000) <= 1.3; -- stress index -CREATE INDEX idx_cambridge_blockpairs_lstress ON cambridge_connected_census_blocks (low_stress); -CREATE INDEX idx_cambridge_blockpairs_hstress ON cambridge_connected_census_blocks (high_stress); -ANALYZE cambridge_connected_census_blocks (low_stress,high_stress); +CREATE INDEX idx_neighborhood_blockpairs_lstress ON neighborhood_connected_census_blocks (low_stress); +CREATE INDEX idx_neighborhood_blockpairs_hstress ON neighborhood_connected_census_blocks (high_stress); +ANALYZE neighborhood_connected_census_blocks (low_stress,high_stress); diff --git a/connectivity/connected_census_blocks_recreation.sql b/connectivity/connected_census_blocks_recreation.sql index eba9c7ab..e8847fff 100644 --- a/connectivity/connected_census_blocks_recreation.sql +++ b/connectivity/connected_census_blocks_recreation.sql @@ -1,10 +1,10 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -DROP TABLE IF EXISTS generated.cambridge_connected_census_blocks_recreation; +DROP TABLE IF EXISTS generated.neighborhood_connected_census_blocks_recreation; -CREATE TABLE generated.cambridge_connected_census_blocks_recreation ( +CREATE TABLE generated.neighborhood_connected_census_blocks_recreation ( id SERIAL PRIMARY KEY, source_blockid10 VARCHAR(15), target_path_id INT, @@ -14,27 +14,27 @@ CREATE TABLE generated.cambridge_connected_census_blocks_recreation ( high_stress_cost INT ); -INSERT INTO generated.cambridge_connected_census_blocks_recreation ( +INSERT INTO generated.neighborhood_connected_census_blocks_recreation ( source_blockid10, target_school_id, low_stress, high_stress ) SELECT blocks.blockid10, paths.path_id, 'f'::BOOLEAN, 't'::BOOLEAN -FROM cambridge_census_blocks blocks, - cambridge_paths paths +FROM neighborhood_census_blocks blocks, + neighborhood_paths paths WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips + FROM neighborhood_zip_codes zips WHERE ST_Intersects(blocks.geom,zips.geom) AND zips.zip_code = '02138' ) AND blocks.geom <#> paths.geom < 11000 AND EXISTS ( SELECT 1 - FROM cambridge_census_block_roads source_br, - cambridge_ways target_r, - cambridge_reachable_roads_high_stress hs + FROM neighborhood_census_block_roads source_br, + neighborhood_ways target_r, + neighborhood_reachable_roads_high_stress hs WHERE blocks.blockid10 = source_br.blockid10 AND paths.path_id = target_r.path_id AND hs.base_road = source_br.road_id @@ -48,18 +48,18 @@ AND EXISTS ( -- block pair index -CREATE INDEX idx_cambridge_blockschoolpairs -ON cambridge_connected_census_blocks_recreation (source_blockid10,target_school_id); -ANALYZE cambridge_connected_census_blocks_recreation (source_blockid10,target_school_id); +CREATE INDEX idx_neighborhood_blockschoolpairs +ON neighborhood_connected_census_blocks_recreation (source_blockid10,target_school_id); +ANALYZE neighborhood_connected_census_blocks_recreation (source_blockid10,target_school_id); -- low stress -UPDATE cambridge_connected_census_blocks_recreation +UPDATE neighborhood_connected_census_blocks_recreation SET low_stress = 't'::BOOLEAN WHERE EXISTS ( SELECT 1 - FROM cambridge_census_block_roads source_br, - cambridge_school_roads target_sr, - cambridge_reachable_roads_low_stress ls + FROM neighborhood_census_block_roads source_br, + neighborhood_school_roads target_sr, + neighborhood_reachable_roads_low_stress ls WHERE source_blockid10 = source_br.blockid10 AND target_school_id = target_sr.school_id AND ls.base_road = source_br.road_id @@ -67,9 +67,9 @@ WHERE EXISTS ( ) AND ( SELECT MIN(total_cost) - FROM cambridge_census_block_roads source_br, - cambridge_school_roads target_sr, - cambridge_reachable_roads_low_stress ls + FROM neighborhood_census_block_roads source_br, + neighborhood_school_roads target_sr, + neighborhood_reachable_roads_low_stress ls WHERE source_blockid10 = source_br.blockid10 AND target_school_id = target_sr.school_id AND ls.base_road = source_br.road_id @@ -77,9 +77,9 @@ AND ( )::FLOAT / COALESCE(( SELECT MIN(total_cost) + 1 - FROM cambridge_census_block_roads source_br, - cambridge_school_roads target_sr, - cambridge_reachable_roads_high_stress hs + FROM neighborhood_census_block_roads source_br, + neighborhood_school_roads target_sr, + neighborhood_reachable_roads_high_stress hs WHERE source_blockid10 = source_br.blockid10 AND target_school_id = target_sr.school_id AND hs.base_road = source_br.road_id @@ -87,6 +87,6 @@ AND ( ),11000) <= 1.3; -- stress index -CREATE INDEX idx_cambridge_blockschl_lstress ON cambridge_connected_census_blocks_recreation (low_stress); -CREATE INDEX idx_cambridge_blockschl_hstress ON cambridge_connected_census_blocks_recreation (high_stress); -ANALYZE cambridge_connected_census_blocks_recreation (low_stress,high_stress); +CREATE INDEX idx_neighborhood_blockschl_lstress ON neighborhood_connected_census_blocks_recreation (low_stress); +CREATE INDEX idx_neighborhood_blockschl_hstress ON neighborhood_connected_census_blocks_recreation (high_stress); +ANALYZE neighborhood_connected_census_blocks_recreation (low_stress,high_stress); diff --git a/connectivity/connected_census_blocks_schools.sql b/connectivity/connected_census_blocks_schools.sql index 07913754..130415ba 100644 --- a/connectivity/connected_census_blocks_schools.sql +++ b/connectivity/connected_census_blocks_schools.sql @@ -1,10 +1,10 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -DROP TABLE IF EXISTS generated.cambridge_connected_census_blocks_schools; +DROP TABLE IF EXISTS generated.neighborhood_connected_census_blocks_schools; -CREATE TABLE generated.cambridge_connected_census_blocks_schools ( +CREATE TABLE generated.neighborhood_connected_census_blocks_schools ( id SERIAL PRIMARY KEY, source_blockid10 VARCHAR(15), target_school_id INT, @@ -14,27 +14,27 @@ CREATE TABLE generated.cambridge_connected_census_blocks_schools ( high_stress_cost INT ); -INSERT INTO generated.cambridge_connected_census_blocks_schools ( +INSERT INTO generated.neighborhood_connected_census_blocks_schools ( source_blockid10, target_school_id, low_stress, high_stress ) SELECT blocks.blockid10, schools.id, 'f'::BOOLEAN, 't'::BOOLEAN -FROM cambridge_census_blocks blocks, - cambridge_schools schools +FROM neighborhood_census_blocks blocks, + neighborhood_schools schools WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips + FROM neighborhood_zip_codes zips WHERE ST_Intersects(blocks.geom,zips.geom) AND zips.zip_code = '02138' ) AND blocks.geom <#> schools.geom_pt < 11000 AND EXISTS ( SELECT 1 - FROM cambridge_census_block_roads source_br, - cambridge_school_roads target_sr, - cambridge_reachable_roads_high_stress hs + FROM neighborhood_census_block_roads source_br, + neighborhood_school_roads target_sr, + neighborhood_reachable_roads_high_stress hs WHERE blocks.blockid10 = source_br.blockid10 AND schools.id = target_sr.school_id AND hs.base_road = source_br.road_id @@ -42,18 +42,18 @@ AND EXISTS ( ); -- block pair index -CREATE INDEX idx_cambridge_blockschoolpairs -ON cambridge_connected_census_blocks_schools (source_blockid10,target_school_id); -ANALYZE cambridge_connected_census_blocks_schools (source_blockid10,target_school_id); +CREATE INDEX idx_neighborhood_blockschoolpairs +ON neighborhood_connected_census_blocks_schools (source_blockid10,target_school_id); +ANALYZE neighborhood_connected_census_blocks_schools (source_blockid10,target_school_id); -- low stress -UPDATE cambridge_connected_census_blocks_schools +UPDATE neighborhood_connected_census_blocks_schools SET low_stress = 't'::BOOLEAN WHERE EXISTS ( SELECT 1 - FROM cambridge_census_block_roads source_br, - cambridge_school_roads target_sr, - cambridge_reachable_roads_low_stress ls + FROM neighborhood_census_block_roads source_br, + neighborhood_school_roads target_sr, + neighborhood_reachable_roads_low_stress ls WHERE source_blockid10 = source_br.blockid10 AND target_school_id = target_sr.school_id AND ls.base_road = source_br.road_id @@ -61,9 +61,9 @@ WHERE EXISTS ( ) AND ( SELECT MIN(total_cost) - FROM cambridge_census_block_roads source_br, - cambridge_school_roads target_sr, - cambridge_reachable_roads_low_stress ls + FROM neighborhood_census_block_roads source_br, + neighborhood_school_roads target_sr, + neighborhood_reachable_roads_low_stress ls WHERE source_blockid10 = source_br.blockid10 AND target_school_id = target_sr.school_id AND ls.base_road = source_br.road_id @@ -71,9 +71,9 @@ AND ( )::FLOAT / COALESCE(( SELECT MIN(total_cost) + 1 - FROM cambridge_census_block_roads source_br, - cambridge_school_roads target_sr, - cambridge_reachable_roads_high_stress hs + FROM neighborhood_census_block_roads source_br, + neighborhood_school_roads target_sr, + neighborhood_reachable_roads_high_stress hs WHERE source_blockid10 = source_br.blockid10 AND target_school_id = target_sr.school_id AND hs.base_road = source_br.road_id @@ -81,6 +81,6 @@ AND ( ),11000) <= 1.3; -- stress index -CREATE INDEX idx_cambridge_blockschl_lstress ON cambridge_connected_census_blocks_schools (low_stress); -CREATE INDEX idx_cambridge_blockschl_hstress ON cambridge_connected_census_blocks_schools (high_stress); -ANALYZE cambridge_connected_census_blocks_schools (low_stress,high_stress); +CREATE INDEX idx_neighborhood_blockschl_lstress ON neighborhood_connected_census_blocks_schools (low_stress); +CREATE INDEX idx_neighborhood_blockschl_hstress ON neighborhood_connected_census_blocks_schools (high_stress); +ANALYZE neighborhood_connected_census_blocks_schools (low_stress,high_stress); diff --git a/connectivity/coverage.sql b/connectivity/coverage.sql index 4d8fe048..5d472d44 100644 --- a/connectivity/coverage.sql +++ b/connectivity/coverage.sql @@ -1,21 +1,21 @@ SELECT r.road_id, r.geom, COUNT(sheds.node) AS ct -FROM cambridge_ways_net_vert v, - cambridge_ways r, - cambridge_boundary, +FROM neighborhood_ways_net_vert v, + neighborhood_ways r, + neighborhood_boundary, pgr_drivingDistance(' SELECT link_id AS id, source_vert AS source, target_vert AS target, link_cost AS cost - FROM cambridge_ways_net_link + FROM neighborhood_ways_net_link WHERE link_stress = 1', v.vert_id, 10560, directed := true ) sheds -WHERE ST_Intersects(r.geom,cambridge_boundary.geom) +WHERE ST_Intersects(r.geom,neighborhood_boundary.geom) AND v.road_id = r.road_id --and v.road_id = 1467 GROUP BY r.road_id, diff --git a/connectivity/cycles.py b/connectivity/cycles.py index 515f8c97..1eb8ecb1 100644 --- a/connectivity/cycles.py +++ b/connectivity/cycles.py @@ -2,7 +2,7 @@ import networkx as nx zipCode = '02138' -prefix = 'cambridge' +prefix = 'neighborhood' n = nxutils.NXUtils(prefix, zipCode) n.buildNetwork() diff --git a/connectivity/overall_scores.sql b/connectivity/overall_scores.sql index 7527b288..9da9b3c9 100644 --- a/connectivity/overall_scores.sql +++ b/connectivity/overall_scores.sql @@ -1,10 +1,10 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -DROP TABLE IF EXISTS generated.cambridge_overall_scores; +DROP TABLE IF EXISTS generated.neighborhood_overall_scores; -CREATE TABLE generated.cambridge_overall_scores ( +CREATE TABLE generated.neighborhood_overall_scores ( id SERIAL PRIMARY KEY, category TEXT, score_name TEXT, @@ -13,7 +13,7 @@ CREATE TABLE generated.cambridge_overall_scores ( ); -- median pop access low stress -INSERT INTO generated.cambridge_overall_scores ( +INSERT INTO generated.neighborhood_overall_scores ( category, score_name, score, notes ) SELECT 'Population', @@ -22,16 +22,16 @@ SELECT 'Population', regexp_replace('Total population accessible by low stress expressed as the median of all census blocks in the neighborhood','\n\s+',' ') -FROM cambridge_census_blocks +FROM neighborhood_census_blocks WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) + FROM neighborhood_zip_codes zips + WHERE ST_Intersects(neighborhood_census_blocks.geom,zips.geom) AND zips.zip_code = '02138' ); -- median pop access high stress -INSERT INTO generated.cambridge_overall_scores ( +INSERT INTO generated.neighborhood_overall_scores ( category, score_name, score, notes ) SELECT 'Population', @@ -40,16 +40,16 @@ SELECT 'Population', regexp_replace('Total population accessible by high stress expressed as the median of all census blocks in the neighborhood','\n\s+',' ') -FROM cambridge_census_blocks +FROM neighborhood_census_blocks WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) + FROM neighborhood_zip_codes zips + WHERE ST_Intersects(neighborhood_census_blocks.geom,zips.geom) AND zips.zip_code = '02138' ); -- median pop access ratio -INSERT INTO generated.cambridge_overall_scores ( +INSERT INTO generated.neighborhood_overall_scores ( category, score_name, score, notes ) SELECT 'Population', @@ -59,16 +59,16 @@ SELECT 'Population', to population accessible overall, expressed as the median of all census blocks in the neighborhood','\n\s+',' ') -FROM cambridge_census_blocks +FROM neighborhood_census_blocks WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) + FROM neighborhood_zip_codes zips + WHERE ST_Intersects(neighborhood_census_blocks.geom,zips.geom) AND zips.zip_code = '02138' ); -- 70th percentile pop access ratio -INSERT INTO generated.cambridge_overall_scores ( +INSERT INTO generated.neighborhood_overall_scores ( category, score_name, score, notes ) SELECT 'Population', @@ -78,16 +78,16 @@ SELECT 'Population', to population accessible overall, expressed as the 70th percentile of all census blocks in the neighborhood','\n\s+',' ') -FROM cambridge_census_blocks +FROM neighborhood_census_blocks WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) + FROM neighborhood_zip_codes zips + WHERE ST_Intersects(neighborhood_census_blocks.geom,zips.geom) AND zips.zip_code = '02138' ); -- avg pop access ratio -INSERT INTO generated.cambridge_overall_scores ( +INSERT INTO generated.neighborhood_overall_scores ( category, score_name, score, notes ) SELECT 'Population', @@ -97,16 +97,16 @@ SELECT 'Population', to population accessible overall, expressed as the average of all census blocks in the neighborhood','\n\s+',' ') -FROM cambridge_census_blocks +FROM neighborhood_census_blocks WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) + FROM neighborhood_zip_codes zips + WHERE ST_Intersects(neighborhood_census_blocks.geom,zips.geom) AND zips.zip_code = '02138' ); -- median jobs access low stress -INSERT INTO generated.cambridge_overall_scores ( +INSERT INTO generated.neighborhood_overall_scores ( category, score_name, score, notes ) SELECT 'Employment', @@ -115,16 +115,16 @@ SELECT 'Employment', regexp_replace('Total jobs accessible by low stress expressed as the median of all census blocks in the neighborhood','\n\s+',' ') -FROM cambridge_census_blocks +FROM neighborhood_census_blocks WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) + FROM neighborhood_zip_codes zips + WHERE ST_Intersects(neighborhood_census_blocks.geom,zips.geom) AND zips.zip_code = '02138' ); -- median jobs access high stress -INSERT INTO generated.cambridge_overall_scores ( +INSERT INTO generated.neighborhood_overall_scores ( category, score_name, score, notes ) SELECT 'Employment', @@ -133,16 +133,16 @@ SELECT 'Employment', regexp_replace('Total jobs accessible by high stress expressed as the median of all census blocks in the neighborhood','\n\s+',' ') -FROM cambridge_census_blocks +FROM neighborhood_census_blocks WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) + FROM neighborhood_zip_codes zips + WHERE ST_Intersects(neighborhood_census_blocks.geom,zips.geom) AND zips.zip_code = '02138' ); -- median jobs access ratio -INSERT INTO generated.cambridge_overall_scores ( +INSERT INTO generated.neighborhood_overall_scores ( category, score_name, score, notes ) SELECT 'Employment', @@ -152,16 +152,16 @@ SELECT 'Employment', to employment accessible overall, expressed as the median of all census blocks in the neighborhood','\n\s+',' ') -FROM cambridge_census_blocks +FROM neighborhood_census_blocks WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) + FROM neighborhood_zip_codes zips + WHERE ST_Intersects(neighborhood_census_blocks.geom,zips.geom) AND zips.zip_code = '02138' ); -- 70th percentile jobs access ratio -INSERT INTO generated.cambridge_overall_scores ( +INSERT INTO generated.neighborhood_overall_scores ( category, score_name, score, notes ) SELECT 'Employment', @@ -171,16 +171,16 @@ SELECT 'Employment', to employment accessible overall, expressed as the 70th percentile of all census blocks in the neighborhood','\n\s+',' ') -FROM cambridge_census_blocks +FROM neighborhood_census_blocks WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) + FROM neighborhood_zip_codes zips + WHERE ST_Intersects(neighborhood_census_blocks.geom,zips.geom) AND zips.zip_code = '02138' ); -- avg jobs access ratio -INSERT INTO generated.cambridge_overall_scores ( +INSERT INTO generated.neighborhood_overall_scores ( category, score_name, score, notes ) SELECT 'Employment', @@ -190,16 +190,16 @@ SELECT 'Employment', to employment accessible overall, expressed as the average of all census blocks in the neighborhood','\n\s+',' ') -FROM cambridge_census_blocks +FROM neighborhood_census_blocks WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) + FROM neighborhood_zip_codes zips + WHERE ST_Intersects(neighborhood_census_blocks.geom,zips.geom) AND zips.zip_code = '02138' ); -- median schools access low stress -INSERT INTO generated.cambridge_overall_scores ( +INSERT INTO generated.neighborhood_overall_scores ( category, score_name, score, notes ) SELECT 'Schools', @@ -208,16 +208,16 @@ SELECT 'Schools', regexp_replace('Number of schools accessible by low stress expressed as an average of all census blocks in the neighborhood','\n\s+',' ') -FROM cambridge_census_blocks +FROM neighborhood_census_blocks WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) + FROM neighborhood_zip_codes zips + WHERE ST_Intersects(neighborhood_census_blocks.geom,zips.geom) AND zips.zip_code = '02138' ); -- median schools access high stress -INSERT INTO generated.cambridge_overall_scores ( +INSERT INTO generated.neighborhood_overall_scores ( category, score_name, score, notes ) SELECT 'Schools', @@ -226,16 +226,16 @@ SELECT 'Schools', regexp_replace('Number of schools accessible by high stress expressed as an average of all census blocks in the neighborhood','\n\s+',' ') -FROM cambridge_census_blocks +FROM neighborhood_census_blocks WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_Intersects(cambridge_census_blocks.geom,zips.geom) + FROM neighborhood_zip_codes zips + WHERE ST_Intersects(neighborhood_census_blocks.geom,zips.geom) AND zips.zip_code = '02138' ); -- school low stress pop shed access -INSERT INTO generated.cambridge_overall_scores ( +INSERT INTO generated.neighborhood_overall_scores ( category, score_name, score, notes ) SELECT 'Schools', @@ -244,16 +244,16 @@ SELECT 'Schools', regexp_replace('Population with low stress access to schools in the neighborhood expressed as an average of all schools in the neighborhood','\n\s+',' ') -FROM cambridge_schools +FROM neighborhood_schools WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_Intersects(cambridge_schools.geom_pt,zips.geom) + FROM neighborhood_zip_codes zips + WHERE ST_Intersects(neighborhood_schools.geom_pt,zips.geom) AND zips.zip_code = '02138' ); -- school high stress pop shed access -INSERT INTO generated.cambridge_overall_scores ( +INSERT INTO generated.neighborhood_overall_scores ( category, score_name, score, notes ) SELECT 'Schools', @@ -262,16 +262,16 @@ SELECT 'Schools', regexp_replace('Population with high stress access to schools in the neighborhood expressed as an average of all schools in the neighborhood','\n\s+',' ') -FROM cambridge_schools +FROM neighborhood_schools WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_Intersects(cambridge_schools.geom_pt,zips.geom) + FROM neighborhood_zip_codes zips + WHERE ST_Intersects(neighborhood_schools.geom_pt,zips.geom) AND zips.zip_code = '02138' ); -- school pop shed access ratio -INSERT INTO generated.cambridge_overall_scores ( +INSERT INTO generated.neighborhood_overall_scores ( category, score_name, score, notes ) SELECT 'Schools', @@ -281,10 +281,10 @@ SELECT 'Schools', access to schools to population with high stress access in the neighborhood expressed as an average of all schools in the neighborhood','\n\s+',' ') -FROM cambridge_schools +FROM neighborhood_schools WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_Intersects(cambridge_schools.geom_pt,zips.geom) + FROM neighborhood_zip_codes zips + WHERE ST_Intersects(neighborhood_schools.geom_pt,zips.geom) AND zips.zip_code = '02138' ); diff --git a/connectivity/reachable_roads_high_stress.sql b/connectivity/reachable_roads_high_stress.sql index 9ecb37b3..c4188d31 100644 --- a/connectivity/reachable_roads_high_stress.sql +++ b/connectivity/reachable_roads_high_stress.sql @@ -1,18 +1,18 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood -- maximum network distsance: 10560 ft ---------------------------------------- -DROP TABLE IF EXISTS generated.cambridge_reachable_roads_high_stress; +DROP TABLE IF EXISTS generated.neighborhood_reachable_roads_high_stress; -CREATE TABLE generated.cambridge_reachable_roads_high_stress ( +CREATE TABLE generated.neighborhood_reachable_roads_high_stress ( id SERIAL PRIMARY KEY, base_road INT, target_road INT, total_cost FLOAT ); -INSERT INTO generated.cambridge_reachable_roads_high_stress ( +INSERT INTO generated.neighborhood_reachable_roads_high_stress ( base_road, target_road, total_cost @@ -20,28 +20,28 @@ INSERT INTO generated.cambridge_reachable_roads_high_stress ( SELECT r1.road_id, v2.road_id, sheds.agg_cost -FROM cambridge_ways r1, - cambridge_ways_net_vert v1, - cambridge_ways_net_vert v2, +FROM neighborhood_ways r1, + neighborhood_ways_net_vert v1, + neighborhood_ways_net_vert v2, pgr_drivingDistance(' SELECT link_id AS id, source_vert AS source, target_vert AS target, link_cost AS cost - FROM cambridge_ways_net_link', + FROM neighborhood_ways_net_link', v1.vert_id, 10560, directed := true ) sheds WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips + FROM neighborhood_zip_codes zips WHERE ST_Intersects(zips.geom,r1.geom) AND zips.zip_code = '02138' ) AND r1.road_id = v1.road_id AND v2.vert_id = sheds.node; -CREATE INDEX idx_cambridge_rchblrdshistrss_b ON generated.cambridge_reachable_roads_high_stress (base_road); -CREATE INDEX idx_cambridge_rchblrdshistrss_t ON generated.cambridge_reachable_roads_high_stress (target_road); -ANALYZE generated.cambridge_reachable_roads_high_stress (base_road,target_road); +CREATE INDEX idx_neighborhood_rchblrdshistrss_b ON generated.neighborhood_reachable_roads_high_stress (base_road); +CREATE INDEX idx_neighborhood_rchblrdshistrss_t ON generated.neighborhood_reachable_roads_high_stress (target_road); +ANALYZE generated.neighborhood_reachable_roads_high_stress (base_road,target_road); diff --git a/connectivity/reachable_roads_low_stress.sql b/connectivity/reachable_roads_low_stress.sql index 2c3510d6..13faca57 100644 --- a/connectivity/reachable_roads_low_stress.sql +++ b/connectivity/reachable_roads_low_stress.sql @@ -1,18 +1,18 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood -- maximum network distsance: 10560 ft ---------------------------------------- -DROP TABLE IF EXISTS generated.cambridge_reachable_roads_low_stress; +DROP TABLE IF EXISTS generated.neighborhood_reachable_roads_low_stress; -CREATE TABLE generated.cambridge_reachable_roads_low_stress ( +CREATE TABLE generated.neighborhood_reachable_roads_low_stress ( id SERIAL PRIMARY KEY, base_road INT, target_road INT, total_cost FLOAT ); -INSERT INTO generated.cambridge_reachable_roads_low_stress ( +INSERT INTO generated.neighborhood_reachable_roads_low_stress ( base_road, target_road, total_cost @@ -20,15 +20,15 @@ INSERT INTO generated.cambridge_reachable_roads_low_stress ( SELECT r1.road_id, v2.road_id, sheds.agg_cost -FROM cambridge_ways r1, - cambridge_ways_net_vert v1, - cambridge_ways_net_vert v2, +FROM neighborhood_ways r1, + neighborhood_ways_net_vert v1, + neighborhood_ways_net_vert v2, pgr_drivingDistance(' SELECT link_id AS id, source_vert AS source, target_vert AS target, link_cost AS cost - FROM cambridge_ways_net_link + FROM neighborhood_ways_net_link WHERE link_stress = 1', v1.vert_id, 10560, @@ -36,13 +36,13 @@ FROM cambridge_ways r1, ) sheds WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips + FROM neighborhood_zip_codes zips WHERE ST_Intersects(zips.geom,r1.geom) AND zips.zip_code = '02138' ) AND r1.road_id = v1.road_id AND v2.vert_id = sheds.node; -CREATE INDEX idx_cambridge_rchblrdslowstrss_b ON generated.cambridge_reachable_roads_low_stress (base_road); -CREATE INDEX idx_cambridge_rchblrdslowstrss_t ON generated.cambridge_reachable_roads_low_stress (target_road); -ANALYZE generated.cambridge_reachable_roads_low_stress (base_road,target_road); +CREATE INDEX idx_neighborhood_rchblrdslowstrss_b ON generated.neighborhood_reachable_roads_low_stress (base_road); +CREATE INDEX idx_neighborhood_rchblrdslowstrss_t ON generated.neighborhood_reachable_roads_low_stress (target_road); +ANALYZE generated.neighborhood_reachable_roads_low_stress (base_road,target_road); diff --git a/connectivity/school_roads.sql b/connectivity/school_roads.sql index fe65173d..9d3e24e8 100644 --- a/connectivity/school_roads.sql +++ b/connectivity/school_roads.sql @@ -1,27 +1,27 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -DROP TABLE IF EXISTS generated.cambridge_school_roads; +DROP TABLE IF EXISTS generated.neighborhood_school_roads; -CREATE TABLE generated.cambridge_school_roads ( +CREATE TABLE generated.neighborhood_school_roads ( id SERIAL PRIMARY KEY, school_id INT, road_id INT ); -- polygons take any road within 50 feet -INSERT INTO generated.cambridge_school_roads ( +INSERT INTO generated.neighborhood_school_roads ( school_id, road_id ) SELECT schools.id, ways.road_id -FROM cambridge_schools schools, - cambridge_ways ways +FROM neighborhood_schools schools, + neighborhood_ways ways WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips + FROM neighborhood_zip_codes zips WHERE ST_DWithin(zips.geom, schools.geom_pt, 11000) AND zips.zip_code = '02138' ) @@ -29,30 +29,30 @@ AND schools.geom_poly IS NOT NULL AND ST_DWithin(schools.geom_poly,ways.geom,50); -- points take the nearest road -INSERT INTO generated.cambridge_school_roads ( +INSERT INTO generated.neighborhood_school_roads ( school_id, road_id ) SELECT schools.id, ( SELECT ways.road_id - FROM cambridge_ways ways + FROM neighborhood_ways ways ORDER BY ST_Distance(ways.geom,schools.geom_pt) ASC LIMIT 1 ) -FROM cambridge_schools schools +FROM neighborhood_schools schools WHERE EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips + FROM neighborhood_zip_codes zips WHERE ST_DWithin(zips.geom, schools.geom_pt, 11000) AND zips.zip_code = '02138' ) AND NOT EXISTS ( SELECT 1 - FROM cambridge_school_roads r + FROM neighborhood_school_roads r WHERE schools.id = r.school_id ); -CREATE INDEX idx_cambridge_schlrds_schlid ON generated.cambridge_school_roads (school_id); -CREATE INDEX idx_cambridge_schlrds_rdid ON generated.cambridge_school_roads (road_id); -ANALYZE generated.cambridge_school_roads (school_id, road_id); +CREATE INDEX idx_neighborhood_schlrds_schlid ON generated.neighborhood_school_roads (school_id); +CREATE INDEX idx_neighborhood_schlrds_rdid ON generated.neighborhood_school_roads (road_id); +ANALYZE generated.neighborhood_school_roads (school_id, road_id); diff --git a/connectivity/schools.sql b/connectivity/schools.sql index da1648e6..275bd4a4 100644 --- a/connectivity/schools.sql +++ b/connectivity/schools.sql @@ -1,10 +1,10 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -DROP TABLE IF EXISTS generated.cambridge_schools; +DROP TABLE IF EXISTS generated.neighborhood_schools; -CREATE TABLE generated.cambridge_schools ( +CREATE TABLE generated.neighborhood_schools ( id SERIAL PRIMARY KEY, osm_id BIGINT, school_name TEXT, @@ -13,40 +13,40 @@ CREATE TABLE generated.cambridge_schools ( geom_pt geometry(point,2249), geom_poly geometry(polygon,2249) ); -CREATE INDEX sidx_cambridge_schools_geompt ON cambridge_schools USING GIST (geom_pt); -CREATE INDEX sidx_cambridge_schools_geomply ON cambridge_schools USING GIST (geom_poly); +CREATE INDEX sidx_neighborhood_schools_geompt ON neighborhood_schools USING GIST (geom_pt); +CREATE INDEX sidx_neighborhood_schools_geomply ON neighborhood_schools USING GIST (geom_poly); -- insert points from polygons -INSERT INTO generated.cambridge_schools ( +INSERT INTO generated.neighborhood_schools ( osm_id, school_name, geom_pt, geom_poly ) SELECT osm_id, name, ST_Centroid(way), way -FROM cambridge_osm_full_polygon +FROM neighborhood_osm_full_polygon WHERE amenity = 'school'; -- remove subareas that are mistakenly designated as amenity=school -DELETE FROM generated.cambridge_schools +DELETE FROM generated.neighborhood_schools WHERE EXISTS ( SELECT 1 - FROM generated.cambridge_schools s - WHERE ST_Contains(s.geom_poly,cambridge_schools.geom_poly) - AND s.id != generated.cambridge_schools.id + FROM generated.neighborhood_schools s + WHERE ST_Contains(s.geom_poly,neighborhood_schools.geom_poly) + AND s.id != generated.neighborhood_schools.id ); -- insert points -INSERT INTO generated.cambridge_schools ( +INSERT INTO generated.neighborhood_schools ( osm_id, school_name, geom_pt ) SELECT osm_id, name, way -FROM cambridge_osm_full_point +FROM neighborhood_osm_full_point WHERE amenity = 'school' AND NOT EXISTS ( SELECT 1 - FROM cambridge_schools s - WHERE ST_Intersects(s.geom_poly,cambridge_osm_full_point.way) + FROM neighborhood_schools s + WHERE ST_Intersects(s.geom_poly,neighborhood_osm_full_point.way) ); diff --git a/drop_tables.sh b/drop_tables.sh index bdd7ffd3..9ddbd822 100644 --- a/drop_tables.sh +++ b/drop_tables.sh @@ -3,7 +3,7 @@ # vars DBHOST='192.168.1.144' DBNAME='people_for_bikes' -OSMPREFIX='cambridge' +OSMPREFIX='neighborhood' # drop old tables echo 'Dropping old tables' diff --git a/functional_class.sql b/functional_class.sql index 7a501e85..b10cb135 100644 --- a/functional_class.sql +++ b/functional_class.sql @@ -1,13 +1,13 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -UPDATE cambridge_ways SET functional_class = NULL; +UPDATE neighborhood_ways SET functional_class = NULL; -UPDATE cambridge_ways +UPDATE neighborhood_ways SET functional_class = osm.highway -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id AND osm.highway IN ( 'motorway', 'tertiary', @@ -23,78 +23,78 @@ AND osm.highway IN ( 'living_street' ); -- note that we're leaving out "road" -UPDATE cambridge_ways +UPDATE neighborhood_ways SET functional_class = 'tertiary' -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id AND osm.highway = 'unclassified'; -UPDATE cambridge_ways +UPDATE neighborhood_ways SET functional_class = 'track' -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id AND osm.highway = 'track' AND osm.tracktype = 'grade1'; -UPDATE cambridge_ways +UPDATE neighborhood_ways SET functional_class = 'path' -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id AND osm.highway IN ('cycleway','path'); -UPDATE cambridge_ways +UPDATE neighborhood_ways SET functional_class = 'path' -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id AND osm.highway = 'footway' AND osm.footway = 'crossing'; -UPDATE cambridge_ways +UPDATE neighborhood_ways SET functional_class = 'path' -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id AND osm.highway = 'footway' AND osm.bicycle = 'designated' AND (osm.access IS NULL OR osm.access NOT IN ('no','private')) AND COALESCE(width_ft,0) >= 8; -UPDATE cambridge_ways +UPDATE neighborhood_ways SET functional_class = 'path' -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id AND osm.highway='service' AND osm.bicycle='designated'; -UPDATE cambridge_ways +UPDATE neighborhood_ways SET functional_class = 'living_street' -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id AND osm.highway = 'pedestrian' AND osm.bicycle IN ('yes','permissive','designated') AND (osm.access IS NULL OR osm.access NOT IN ('no','private')); -- remove stuff that we don't want to route over -DELETE FROM cambridge_ways WHERE functional_class IS NULL; +DELETE FROM neighborhood_ways WHERE functional_class IS NULL; -- remove orphans -DELETE FROM cambridge_ways +DELETE FROM neighborhood_ways WHERE NOT EXISTS ( SELECT 1 - FROM cambridge_ways w - WHERE cambridge_ways.intersection_to IN (w.intersection_to,w.intersection_from) - AND w.road_id != cambridge_ways.road_id + FROM neighborhood_ways w + WHERE neighborhood_ways.intersection_to IN (w.intersection_to,w.intersection_from) + AND w.road_id != neighborhood_ways.road_id ) AND NOT EXISTS ( SELECT 1 - FROM cambridge_ways w - WHERE cambridge_ways.intersection_from IN (w.intersection_to,w.intersection_from) - AND w.road_id != cambridge_ways.road_id + FROM neighborhood_ways w + WHERE neighborhood_ways.intersection_from IN (w.intersection_to,w.intersection_from) + AND w.road_id != neighborhood_ways.road_id ); -- remove obsolete intersections -DELETE FROM cambridge_ways_intersections +DELETE FROM neighborhood_ways_intersections WHERE NOT EXISTS ( SELECT 1 - FROM cambridge_ways w + FROM neighborhood_ways w WHERE int_id IN (w.intersection_to,w.intersection_from) ); diff --git a/import_osm.sh b/import_osm.sh index e91e253c..500803a3 100644 --- a/import_osm.sh +++ b/import_osm.sh @@ -3,8 +3,8 @@ # vars DBHOST='192.168.1.144' DBNAME='people_for_bikes' -OSMPREFIX='cambridge' -OSMFILE='/home/spencer/gis/cambridge.osm' +OSMPREFIX='neighborhood' +OSMFILE='/home/spencer/gis/neighborhood.osm' # drop old tables echo 'Dropping old tables' diff --git a/lanes.sql b/lanes.sql index b6097ed7..14f2cc2d 100644 --- a/lanes.sql +++ b/lanes.sql @@ -1,11 +1,11 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -UPDATE cambridge_ways +UPDATE neighborhood_ways SET ft_lanes = NULL, tf_lanes = NULL, ft_cross_lanes = NULL, tf_cross_lanes = NULL; -UPDATE cambridge_ways +UPDATE neighborhood_ways SET ft_lanes = CASE WHEN osm."turn:lanes:forward" IS NOT NULL THEN array_length( @@ -119,32 +119,32 @@ SET ft_lanes = WHEN osm."turn:lanes:both_ways" IS NOT NULL THEN 1 ELSE NULL END -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id; +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id; -- -- forward --- UPDATE cambridge_ways +-- UPDATE neighborhood_ways -- SET ft_lanes = substring(osm."lanes:forward" FROM '\d+')::INT --- FROM cambridge_osm_full_line osm --- WHERE cambridge_ways.osm_id = osm.osm_id +-- FROM neighborhood_osm_full_line osm +-- WHERE neighborhood_ways.osm_id = osm.osm_id -- AND ft_lanes IS NULL -- AND osm."lanes:forward" IS NOT NULL; -- -- -- backward --- UPDATE cambridge_ways +-- UPDATE neighborhood_ways -- SET tf_lanes = substring(osm."lanes:backward" FROM '\d+')::INT --- FROM cambridge_osm_full_line osm --- WHERE cambridge_ways.osm_id = osm.osm_id +-- FROM neighborhood_osm_full_line osm +-- WHERE neighborhood_ways.osm_id = osm.osm_id -- AND tf_lanes IS NULL -- AND osm."lanes:backward" IS NOT NULL; -- -- -- all lanes (no direction given) -- -- two way --- UPDATE cambridge_ways +-- UPDATE neighborhood_ways -- SET ft_lanes = floor(substring(osm.lanes FROM '\d+')::FLOAT / 2), -- tf_lanes = floor(substring(osm.lanes FROM '\d+')::FLOAT / 2) --- FROM cambridge_osm_full_line osm --- WHERE cambridge_ways.osm_id = osm.osm_id +-- FROM neighborhood_osm_full_line osm +-- WHERE neighborhood_ways.osm_id = osm.osm_id -- AND tf_lanes IS NULL -- AND ft_lanes IS NULL -- AND one_way_car NOT IN ('ft','tf') @@ -152,17 +152,17 @@ WHERE cambridge_ways.osm_id = osm.osm_id; -- -- -- all lanes (no direction given) -- -- one way --- UPDATE cambridge_ways +-- UPDATE neighborhood_ways -- SET ft_lanes = substring(osm.lanes FROM '\d+')::INT --- FROM cambridge_osm_full_line osm --- WHERE cambridge_ways.osm_id = osm.osm_id +-- FROM neighborhood_osm_full_line osm +-- WHERE neighborhood_ways.osm_id = osm.osm_id -- AND one_way_car = 'ft' -- AND ft_lanes IS NULL -- AND osm.lanes IS NOT NULL; --- UPDATE cambridge_ways +-- UPDATE neighborhood_ways -- SET tf_lanes = substring(osm.lanes FROM '\d+')::INT --- FROM cambridge_osm_full_line osm --- WHERE cambridge_ways.osm_id = osm.osm_id +-- FROM neighborhood_osm_full_line osm +-- WHERE neighborhood_ways.osm_id = osm.osm_id -- AND one_way_car = 'tf' -- AND tf_lanes IS NULL -- AND osm.lanes IS NOT NULL; diff --git a/legs.sql b/legs.sql index 93255a62..4cc93b2f 100644 --- a/legs.sql +++ b/legs.sql @@ -1,10 +1,10 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -UPDATE received.cambridge_ways_intersections +UPDATE received.neighborhood_ways_intersections SET legs = ( SELECT COUNT(road_id) - FROM cambridge_ways - WHERE cambridge_ways_intersections.int_id IN (intersection_from,intersection_to) + FROM neighborhood_ways + WHERE neighborhood_ways_intersections.int_id IN (intersection_from,intersection_to) ); diff --git a/one_way.sql b/one_way.sql index c3269a50..f2998258 100644 --- a/one_way.sql +++ b/one_way.sql @@ -1,19 +1,19 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -UPDATE cambridge_ways SET one_way_car = NULL; +UPDATE neighborhood_ways SET one_way_car = NULL; -- ft direction -UPDATE cambridge_ways +UPDATE neighborhood_ways SET one_way_car = 'ft' -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id AND trim(osm.oneway) IN ('1','yes'); -- tf direction -UPDATE cambridge_ways +UPDATE neighborhood_ways SET one_way_car = 'tf' -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id AND trim(osm.oneway) = '-1'; diff --git a/park.sql b/park.sql index e8dbf0d0..0f4b3063 100644 --- a/park.sql +++ b/park.sql @@ -1,11 +1,11 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -UPDATE cambridge_ways SET ft_park = NULL, tf_park = NULL; +UPDATE neighborhood_ways SET ft_park = NULL, tf_park = NULL; -- both -UPDATE cambridge_ways +UPDATE neighborhood_ways SET ft_park = CASE WHEN osm."parking:lane:both" = 'parallel' THEN 1 WHEN osm."parking:lane:both" = 'paralell' THEN 1 WHEN osm."parking:lane:both" = 'diagonal' THEN 1 @@ -20,11 +20,11 @@ SET ft_park = CASE WHEN osm."parking:lane:both" = 'parallel' THEN 1 WHEN osm."parking:lane:both" = 'no_parking' THEN 0 WHEN osm."parking:lane:both" = 'no_stopping' THEN 0 END -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id; +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id; -- right -UPDATE cambridge_ways +UPDATE neighborhood_ways SET ft_park = CASE WHEN osm."parking:lane:right" = 'parallel' THEN 1 WHEN osm."parking:lane:right" = 'paralell' THEN 1 WHEN osm."parking:lane:right" = 'diagonal' THEN 1 @@ -32,11 +32,11 @@ SET ft_park = CASE WHEN osm."parking:lane:right" = 'parallel' THEN 1 WHEN osm."parking:lane:right" = 'no_parking' THEN 0 WHEN osm."parking:lane:right" = 'no_stopping' THEN 0 END -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id; +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id; -- left -UPDATE cambridge_ways +UPDATE neighborhood_ways SET tf_park = CASE WHEN osm."parking:lane:left" = 'parallel' THEN 1 WHEN osm."parking:lane:left" = 'paralell' THEN 1 WHEN osm."parking:lane:left" = 'diagonal' THEN 1 @@ -44,5 +44,5 @@ SET tf_park = CASE WHEN osm."parking:lane:left" = 'parallel' THEN 1 WHEN osm."parking:lane:left" = 'no_parking' THEN 0 WHEN osm."parking:lane:left" = 'no_stopping' THEN 0 END -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id; +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id; diff --git a/paths.sql b/paths.sql index 70bb0646..b413d1f3 100644 --- a/paths.sql +++ b/paths.sql @@ -1,11 +1,11 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -DROP TABLE IF EXISTS generated.cambridge_paths; -DROP INDEX IF EXISTS idx_cambridge_ways_path_id; +DROP TABLE IF EXISTS generated.neighborhood_paths; +DROP INDEX IF EXISTS idx_neighborhood_ways_path_id; -CREATE TABLE generated.cambridge_paths ( +CREATE TABLE generated.neighborhood_paths ( path_id SERIAL PRIMARY KEY, geom geometry(multilinestring,2249), path_length INTEGER, @@ -13,7 +13,7 @@ CREATE TABLE generated.cambridge_paths ( ); -- combine contiguous paths -INSERT INTO cambridge_paths (geom) +INSERT INTO neighborhood_paths (geom) SELECT ST_CollectionExtract( ST_SetSRID( unnest(ST_ClusterIntersecting(geom)), @@ -21,15 +21,15 @@ SELECT ST_CollectionExtract( ), 2 --linestrings ) -FROM cambridge_ways +FROM neighborhood_ways WHERE functional_class = 'path'; -- get raw lengths -UPDATE cambridge_paths +UPDATE neighborhood_paths SET path_length = ST_Length(geom); -- get bounding box lengths -UPDATE cambridge_paths +UPDATE neighborhood_paths SET bbox_length = ST_Length( ST_SetSRID( ST_MakeLine( @@ -41,25 +41,25 @@ SET bbox_length = ST_Length( ); -- set path_id on each road segment (if path) -UPDATE cambridge_ways +UPDATE neighborhood_ways SET path_id = ( SELECT paths.path_id - FROM cambridge_paths paths - WHERE ST_Intersects(cambridge_ways.geom,paths.geom) - AND ST_CoveredBy(cambridge_ways.geom,paths.geom) + FROM neighborhood_paths paths + WHERE ST_Intersects(neighborhood_ways.geom,paths.geom) + AND ST_CoveredBy(neighborhood_ways.geom,paths.geom) LIMIT 1 ) WHERE functional_class = 'path'; -- get stragglers -UPDATE cambridge_ways +UPDATE neighborhood_ways SET path_id = paths.path_id -FROM cambridge_paths paths -WHERE cambridge_ways.functional_class = 'path' -AND cambridge_ways.path_id IS NULL -AND ST_Intersects(cambridge_ways.geom,paths.geom) -AND ST_CoveredBy(cambridge_ways.geom,ST_Buffer(paths.geom,1)); +FROM neighborhood_paths paths +WHERE neighborhood_ways.functional_class = 'path' +AND neighborhood_ways.path_id IS NULL +AND ST_Intersects(neighborhood_ways.geom,paths.geom) +AND ST_CoveredBy(neighborhood_ways.geom,ST_Buffer(paths.geom,1)); -- set index -CREATE INDEX idx_cambridge_ways_path_id ON cambridge_ways (path_id); -ANALYZE cambridge_ways (path_id); +CREATE INDEX idx_neighborhood_ways_path_id ON neighborhood_ways (path_id); +ANALYZE neighborhood_ways (path_id); diff --git a/prepare_tables.sql b/prepare_tables.sql index 98876513..d4aa55c3 100644 --- a/prepare_tables.sql +++ b/prepare_tables.sql @@ -1,114 +1,114 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood -- proj: 2249 ---------------------------------------- -- add tdg_id field to roads -ALTER TABLE cambridge_ways ADD COLUMN tdg_id TEXT DEFAULT uuid_generate_v4(); +ALTER TABLE neighborhood_ways ADD COLUMN tdg_id TEXT DEFAULT uuid_generate_v4(); -- drop unnecessary columns -ALTER TABLE cambridge_ways DROP COLUMN class_id; -ALTER TABLE cambridge_ways DROP COLUMN length; -ALTER TABLE cambridge_ways DROP COLUMN length_m; -ALTER TABLE cambridge_ways DROP COLUMN x1; -ALTER TABLE cambridge_ways DROP COLUMN y1; -ALTER TABLE cambridge_ways DROP COLUMN x2; -ALTER TABLE cambridge_ways DROP COLUMN y2; -ALTER TABLE cambridge_ways DROP COLUMN cost; -ALTER TABLE cambridge_ways DROP COLUMN reverse_cost; -ALTER TABLE cambridge_ways DROP COLUMN cost_s; -ALTER TABLE cambridge_ways DROP COLUMN reverse_cost_s; -ALTER TABLE cambridge_ways DROP COLUMN rule; -ALTER TABLE cambridge_ways DROP COLUMN maxspeed_forward; -ALTER TABLE cambridge_ways DROP COLUMN maxspeed_backward; -ALTER TABLE cambridge_ways DROP COLUMN source_osm; -ALTER TABLE cambridge_ways DROP COLUMN target_osm; -ALTER TABLE cambridge_ways DROP COLUMN priority; -ALTER TABLE cambridge_ways DROP COLUMN one_way; +ALTER TABLE neighborhood_ways DROP COLUMN class_id; +ALTER TABLE neighborhood_ways DROP COLUMN length; +ALTER TABLE neighborhood_ways DROP COLUMN length_m; +ALTER TABLE neighborhood_ways DROP COLUMN x1; +ALTER TABLE neighborhood_ways DROP COLUMN y1; +ALTER TABLE neighborhood_ways DROP COLUMN x2; +ALTER TABLE neighborhood_ways DROP COLUMN y2; +ALTER TABLE neighborhood_ways DROP COLUMN cost; +ALTER TABLE neighborhood_ways DROP COLUMN reverse_cost; +ALTER TABLE neighborhood_ways DROP COLUMN cost_s; +ALTER TABLE neighborhood_ways DROP COLUMN reverse_cost_s; +ALTER TABLE neighborhood_ways DROP COLUMN rule; +ALTER TABLE neighborhood_ways DROP COLUMN maxspeed_forward; +ALTER TABLE neighborhood_ways DROP COLUMN maxspeed_backward; +ALTER TABLE neighborhood_ways DROP COLUMN source_osm; +ALTER TABLE neighborhood_ways DROP COLUMN target_osm; +ALTER TABLE neighborhood_ways DROP COLUMN priority; +ALTER TABLE neighborhood_ways DROP COLUMN one_way; -ALTER TABLE cambridge_ways_intersections DROP COLUMN cnt; -ALTER TABLE cambridge_ways_intersections DROP COLUMN chk; -ALTER TABLE cambridge_ways_intersections DROP COLUMN ein; -ALTER TABLE cambridge_ways_intersections DROP COLUMN eout; -ALTER TABLE cambridge_ways_intersections DROP COLUMN lon; -ALTER TABLE cambridge_ways_intersections DROP COLUMN lat; +ALTER TABLE neighborhood_ways_intersections DROP COLUMN cnt; +ALTER TABLE neighborhood_ways_intersections DROP COLUMN chk; +ALTER TABLE neighborhood_ways_intersections DROP COLUMN ein; +ALTER TABLE neighborhood_ways_intersections DROP COLUMN eout; +ALTER TABLE neighborhood_ways_intersections DROP COLUMN lon; +ALTER TABLE neighborhood_ways_intersections DROP COLUMN lat; -- change column names -ALTER TABLE cambridge_ways RENAME COLUMN gid TO road_id; -ALTER TABLE cambridge_ways RENAME COLUMN the_geom TO geom; -ALTER TABLE cambridge_ways RENAME COLUMN source TO intersection_from; -ALTER TABLE cambridge_ways RENAME COLUMN target TO intersection_to; +ALTER TABLE neighborhood_ways RENAME COLUMN gid TO road_id; +ALTER TABLE neighborhood_ways RENAME COLUMN the_geom TO geom; +ALTER TABLE neighborhood_ways RENAME COLUMN source TO intersection_from; +ALTER TABLE neighborhood_ways RENAME COLUMN target TO intersection_to; -ALTER TABLE cambridge_ways_intersections RENAME COLUMN id TO int_id; -ALTER TABLE cambridge_ways_intersections RENAME COLUMN the_geom TO geom; +ALTER TABLE neighborhood_ways_intersections RENAME COLUMN id TO int_id; +ALTER TABLE neighborhood_ways_intersections RENAME COLUMN the_geom TO geom; -- reproject -ALTER TABLE cambridge_ways ALTER COLUMN geom TYPE geometry(linestring,2249) +ALTER TABLE neighborhood_ways ALTER COLUMN geom TYPE geometry(linestring,2249) USING ST_Transform(geom,2249); -ALTER TABLE cambridge_cycwys_ways ALTER COLUMN the_geom TYPE geometry(linestring,2249) +ALTER TABLE neighborhood_cycwys_ways ALTER COLUMN the_geom TYPE geometry(linestring,2249) USING ST_Transform(the_geom,2249); -ALTER TABLE cambridge_ways_intersections ALTER COLUMN geom TYPE geometry(point,2249) +ALTER TABLE neighborhood_ways_intersections ALTER COLUMN geom TYPE geometry(point,2249) USING ST_Transform(geom,2249); -- add columns -ALTER TABLE cambridge_ways ADD COLUMN functional_class TEXT; -ALTER TABLE cambridge_ways ADD COLUMN path_id INTEGER; -ALTER TABLE cambridge_ways ADD COLUMN speed_limit INT; -ALTER TABLE cambridge_ways ADD COLUMN one_way_car VARCHAR(2); -ALTER TABLE cambridge_ways ADD COLUMN one_way VARCHAR(2); -ALTER TABLE cambridge_ways ADD COLUMN width_ft INT; -ALTER TABLE cambridge_ways ADD COLUMN ft_bike_infra TEXT; -ALTER TABLE cambridge_ways ADD COLUMN tf_bike_infra TEXT; -ALTER TABLE cambridge_ways ADD COLUMN ft_lanes INT; -ALTER TABLE cambridge_ways ADD COLUMN tf_lanes INT; -ALTER TABLE cambridge_ways ADD COLUMN ft_cross_lanes INT; -ALTER TABLE cambridge_ways ADD COLUMN tf_cross_lanes INT; -ALTER TABLE cambridge_ways ADD COLUMN twltl_cross_lanes INT; -ALTER TABLE cambridge_ways ADD COLUMN ft_park INT; -ALTER TABLE cambridge_ways ADD COLUMN tf_park INT; -ALTER TABLE cambridge_ways ADD COLUMN ft_seg_stress INT; -ALTER TABLE cambridge_ways ADD COLUMN ft_int_stress INT; -ALTER TABLE cambridge_ways ADD COLUMN tf_seg_stress INT; -ALTER TABLE cambridge_ways ADD COLUMN tf_int_stress INT; +ALTER TABLE neighborhood_ways ADD COLUMN functional_class TEXT; +ALTER TABLE neighborhood_ways ADD COLUMN path_id INTEGER; +ALTER TABLE neighborhood_ways ADD COLUMN speed_limit INT; +ALTER TABLE neighborhood_ways ADD COLUMN one_way_car VARCHAR(2); +ALTER TABLE neighborhood_ways ADD COLUMN one_way VARCHAR(2); +ALTER TABLE neighborhood_ways ADD COLUMN width_ft INT; +ALTER TABLE neighborhood_ways ADD COLUMN ft_bike_infra TEXT; +ALTER TABLE neighborhood_ways ADD COLUMN tf_bike_infra TEXT; +ALTER TABLE neighborhood_ways ADD COLUMN ft_lanes INT; +ALTER TABLE neighborhood_ways ADD COLUMN tf_lanes INT; +ALTER TABLE neighborhood_ways ADD COLUMN ft_cross_lanes INT; +ALTER TABLE neighborhood_ways ADD COLUMN tf_cross_lanes INT; +ALTER TABLE neighborhood_ways ADD COLUMN twltl_cross_lanes INT; +ALTER TABLE neighborhood_ways ADD COLUMN ft_park INT; +ALTER TABLE neighborhood_ways ADD COLUMN tf_park INT; +ALTER TABLE neighborhood_ways ADD COLUMN ft_seg_stress INT; +ALTER TABLE neighborhood_ways ADD COLUMN ft_int_stress INT; +ALTER TABLE neighborhood_ways ADD COLUMN tf_seg_stress INT; +ALTER TABLE neighborhood_ways ADD COLUMN tf_int_stress INT; -- indexes -CREATE INDEX idx_cambridge_ways_osm ON cambridge_ways (osm_id); -CREATE INDEX idx_cambridge_ways_ints_osm ON cambridge_ways_intersections (osm_id); -CREATE INDEX idx_cambridge_fullways ON cambridge_osm_full_line (osm_id); -CREATE INDEX idx_cambridge_fullpoints ON cambridge_osm_full_point (osm_id); -ANALYZE cambridge_ways (osm_id,geom); -ANALYZE cambridge_cycwys_ways (the_geom); -ANALYZE cambridge_ways_intersections (osm_id); -ANALYZE cambridge_osm_full_line (osm_id); -ANALYZE cambridge_osm_full_point (osm_id); +CREATE INDEX idx_neighborhood_ways_osm ON neighborhood_ways (osm_id); +CREATE INDEX idx_neighborhood_ways_ints_osm ON neighborhood_ways_intersections (osm_id); +CREATE INDEX idx_neighborhood_fullways ON neighborhood_osm_full_line (osm_id); +CREATE INDEX idx_neighborhood_fullpoints ON neighborhood_osm_full_point (osm_id); +ANALYZE neighborhood_ways (osm_id,geom); +ANALYZE neighborhood_cycwys_ways (the_geom); +ANALYZE neighborhood_ways_intersections (osm_id); +ANALYZE neighborhood_osm_full_line (osm_id); +ANALYZE neighborhood_osm_full_point (osm_id); -- add in cycleway data that is missing from first osm2pgrouting call -INSERT INTO cambridge_ways ( +INSERT INTO neighborhood_ways ( name, intersection_from, intersection_to, osm_id, geom ) SELECT name, (SELECT i.int_id - FROM cambridge_ways_intersections i - WHERE i.geom <#> cambridge_cycwys_ways.the_geom < 20 - ORDER BY ST_Distance(ST_StartPoint(cambridge_cycwys_ways.the_geom),i.geom) ASC + FROM neighborhood_ways_intersections i + WHERE i.geom <#> neighborhood_cycwys_ways.the_geom < 20 + ORDER BY ST_Distance(ST_StartPoint(neighborhood_cycwys_ways.the_geom),i.geom) ASC LIMIT 1), (SELECT i.int_id - FROM cambridge_ways_intersections i - WHERE i.geom <#> cambridge_cycwys_ways.the_geom < 20 - ORDER BY ST_Distance(ST_EndPoint(cambridge_cycwys_ways.the_geom),i.geom) ASC + FROM neighborhood_ways_intersections i + WHERE i.geom <#> neighborhood_cycwys_ways.the_geom < 20 + ORDER BY ST_Distance(ST_EndPoint(neighborhood_cycwys_ways.the_geom),i.geom) ASC LIMIT 1), osm_id, the_geom -FROM cambridge_cycwys_ways +FROM neighborhood_cycwys_ways WHERE NOT EXISTS ( SELECT 1 - FROM cambridge_ways w2 - WHERE w2.osm_id = cambridge_cycwys_ways.osm_id + FROM neighborhood_ways w2 + WHERE w2.osm_id = neighborhood_cycwys_ways.osm_id ); -- setup intersection table -ALTER TABLE cambridge_ways_intersections ADD COLUMN legs INT; -ALTER TABLE cambridge_ways_intersections ADD COLUMN signalized BOOLEAN; -ALTER TABLE cambridge_ways_intersections ADD COLUMN stops BOOLEAN; -CREATE INDEX idx_cambridge_ints_stop ON cambridge_ways_intersections (signalized,stops); +ALTER TABLE neighborhood_ways_intersections ADD COLUMN legs INT; +ALTER TABLE neighborhood_ways_intersections ADD COLUMN signalized BOOLEAN; +ALTER TABLE neighborhood_ways_intersections ADD COLUMN stops BOOLEAN; +CREATE INDEX idx_neighborhood_ints_stop ON neighborhood_ways_intersections (signalized,stops); diff --git a/process.txt b/process.txt index d5e0e4ea..e9b23573 100644 --- a/process.txt +++ b/process.txt @@ -31,8 +31,8 @@ import_osm.sh (runs the following automatically) - stress_lesser_ints.sql - stress_link_ints.sql -SELECT tdgMakeNetwork('cambridge_ways'); -SELECT tdgNetworkCostFromDistance('cambridge_ways'); +SELECT tdgMakeNetwork('neighborhood_ways'); +SELECT tdgNetworkCostFromDistance('neighborhood_ways'); (import census blocks with pop from census blkpophu dataset) census_blocks.sql diff --git a/signalized.sql b/signalized.sql index f0ebcd13..aa70b55d 100644 --- a/signalized.sql +++ b/signalized.sql @@ -1,27 +1,27 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -UPDATE cambridge_ways_intersections SET signalized = 'f'; +UPDATE neighborhood_ways_intersections SET signalized = 'f'; -UPDATE cambridge_ways_intersections +UPDATE neighborhood_ways_intersections SET signalized = 't' -FROM cambridge_osm_full_point osm -WHERE cambridge_ways_intersections.osm_id = osm.osm_id +FROM neighborhood_osm_full_point osm +WHERE neighborhood_ways_intersections.osm_id = osm.osm_id AND osm.highway = 'traffic_signals'; -UPDATE cambridge_ways_intersections +UPDATE neighborhood_ways_intersections SET signalized = 't' -FROM cambridge_ways, - cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id -AND int_id = cambridge_ways.intersection_to +FROM neighborhood_ways, + neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id +AND int_id = neighborhood_ways.intersection_to AND osm."traffic_signals:direction" = 'forward'; -UPDATE cambridge_ways_intersections +UPDATE neighborhood_ways_intersections SET signalized = 't' -FROM cambridge_ways, - cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id -AND int_id = cambridge_ways.intersection_from +FROM neighborhood_ways, + neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id +AND int_id = neighborhood_ways.intersection_from AND osm."traffic_signals:direction" = 'backward'; diff --git a/speed_limit.sql b/speed_limit.sql index 35e1803b..975ed480 100644 --- a/speed_limit.sql +++ b/speed_limit.sql @@ -1,11 +1,11 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -UPDATE cambridge_ways SET speed_limit = NULL; +UPDATE neighborhood_ways SET speed_limit = NULL; -UPDATE cambridge_ways +UPDATE neighborhood_ways SET speed_limit = substring(osm.maxspeed from '\d+')::INT -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id AND osm.maxspeed LIKE '% mph'; diff --git a/stops.sql b/stops.sql index bdee62b7..1b6c6359 100644 --- a/stops.sql +++ b/stops.sql @@ -1,12 +1,12 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -UPDATE cambridge_ways_intersections SET stops = 'f'; +UPDATE neighborhood_ways_intersections SET stops = 'f'; -UPDATE cambridge_ways_intersections +UPDATE neighborhood_ways_intersections SET stops = 't' -FROM cambridge_osm_full_point osm -WHERE cambridge_ways_intersections.osm_id = osm.osm_id +FROM neighborhood_osm_full_point osm +WHERE neighborhood_ways_intersections.osm_id = osm.osm_id AND osm.highway = 'stop' AND osm.stop = 'all'; diff --git a/streetlight/streetlight_destinations.sql b/streetlight/streetlight_destinations.sql index b88e5842..3f6a8b8b 100644 --- a/streetlight/streetlight_destinations.sql +++ b/streetlight/streetlight_destinations.sql @@ -1,10 +1,10 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood -- proj: 2249 ---------------------------------------- -DROP TABLE IF EXISTS cambridge_streetlight_destinations; -CREATE TABLE generated.cambridge_streetlight_destinations ( +DROP TABLE IF EXISTS neighborhood_streetlight_destinations; +CREATE TABLE generated.neighborhood_streetlight_destinations ( id SERIAL PRIMARY KEY, geom geometry(multipolygon,4326), name TEXT, @@ -12,7 +12,7 @@ CREATE TABLE generated.cambridge_streetlight_destinations ( is_pass INT ); -INSERT INTO cambridge_streetlight_destinations ( +INSERT INTO neighborhood_streetlight_destinations ( blockid10, name, geom, @@ -22,7 +22,7 @@ SELECT blocks.blockid10, blocks.blockid10, ST_Transform(blocks.geom,4326), 0 -FROM cambridge_census_blocks blocks, - cambridge_zip_codes zips +FROM neighborhood_census_blocks blocks, + neighborhood_zip_codes zips WHERE zips.zip_code = '02138' AND ST_Intersects(blocks.geom,zips.geom); diff --git a/streetlight/streetlight_gates.sql b/streetlight/streetlight_gates.sql index 0a1468be..d5cbf651 100644 --- a/streetlight/streetlight_gates.sql +++ b/streetlight/streetlight_gates.sql @@ -1,10 +1,10 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood -- proj: 2249 ---------------------------------------- -DROP TABLE IF EXISTS cambridge_streetlight_gates; -CREATE TABLE generated.cambridge_streetlight_gates ( +DROP TABLE IF EXISTS neighborhood_streetlight_gates; +CREATE TABLE generated.neighborhood_streetlight_gates ( id SERIAL PRIMARY KEY, geom geometry(polygon,2249), road_id BIGINT, @@ -13,7 +13,7 @@ CREATE TABLE generated.cambridge_streetlight_gates ( is_pass INT ); -INSERT INTO cambridge_streetlight_gates ( +INSERT INTO neighborhood_streetlight_gates ( road_id, functional_class, geom, @@ -38,12 +38,12 @@ SELECT road_id, ST_LineInterpolatePoint(geom,0.55) )), 1 -FROM cambridge_ways +FROM neighborhood_ways WHERE functional_class IN ('primary','secondary','tertiary','residential') AND EXISTS ( SELECT 1 - FROM cambridge_zip_codes zips - WHERE ST_DWithin(cambridge_ways.geom,zips.geom,11000) + FROM neighborhood_zip_codes zips + WHERE ST_DWithin(neighborhood_ways.geom,zips.geom,11000) AND zips.zip_code = '02138' ); @@ -53,4 +53,4 @@ SELECT road_id AS id, is_pass, direction, geom -FROM cambridge_streetlight_gates; +FROM neighborhood_streetlight_gates; diff --git a/stress_lesser_ints.sql b/stress_lesser_ints.sql index 1fa83798..b291ef1f 100644 --- a/stress_lesser_ints.sql +++ b/stress_lesser_ints.sql @@ -1,19 +1,19 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -UPDATE cambridge_ways SET ft_int_stress = 1, tf_int_stress = 1 +UPDATE neighborhood_ways SET ft_int_stress = 1, tf_int_stress = 1 WHERE functional_class IN ('residential','living_street','track','path'); -- ft -UPDATE cambridge_ways +UPDATE neighborhood_ways SET ft_int_stress = 3 WHERE functional_class IN ('residential','living_street','track','path') AND EXISTS ( SELECT 1 - FROM cambridge_ways w - WHERE cambridge_ways.intersection_to IN (w.intersection_to,w.intersection_from) - AND COALESCE(cambridge_ways.name,'a') != COALESCE(w.name,'b') + FROM neighborhood_ways w + WHERE neighborhood_ways.intersection_to IN (w.intersection_to,w.intersection_from) + AND COALESCE(neighborhood_ways.name,'a') != COALESCE(w.name,'b') AND CASE WHEN w.functional_class IN ('motorway','trunk','primary') THEN CASE @@ -62,14 +62,14 @@ AND EXISTS ( ); -- tf -UPDATE cambridge_ways +UPDATE neighborhood_ways SET tf_int_stress = 3 WHERE functional_class IN ('residential','living_street','track','path') AND EXISTS ( SELECT 1 - FROM cambridge_ways w - WHERE cambridge_ways.intersection_from IN (w.intersection_to,w.intersection_from) - AND COALESCE(cambridge_ways.name,'a') != COALESCE(w.name,'b') + FROM neighborhood_ways w + WHERE neighborhood_ways.intersection_from IN (w.intersection_to,w.intersection_from) + AND COALESCE(neighborhood_ways.name,'a') != COALESCE(w.name,'b') AND CASE WHEN w.functional_class IN ('motorway','trunk','primary') THEN CASE diff --git a/stress_link_ints.sql b/stress_link_ints.sql index 16c1addb..26e536ee 100644 --- a/stress_link_ints.sql +++ b/stress_link_ints.sql @@ -1,6 +1,6 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -UPDATE cambridge_ways SET ft_int_stress = 1, tf_int_stress = 1 +UPDATE neighborhood_ways SET ft_int_stress = 1, tf_int_stress = 1 WHERE functional_class LIKE '%_link'; diff --git a/stress_living_street.sql b/stress_living_street.sql index 7be738be..f1947739 100644 --- a/stress_living_street.sql +++ b/stress_living_street.sql @@ -1,11 +1,11 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -UPDATE cambridge_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL +UPDATE neighborhood_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL WHERE functional_class = 'living_street'; -UPDATE cambridge_ways +UPDATE neighborhood_ways SET ft_seg_stress = 1, tf_seg_stress = 1 WHERE functional_class = 'living_street'; diff --git a/stress_motorway-trunk.sql b/stress_motorway-trunk.sql index 1da735a7..35a6a48b 100644 --- a/stress_motorway-trunk.sql +++ b/stress_motorway-trunk.sql @@ -1,9 +1,9 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -UPDATE cambridge_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL +UPDATE neighborhood_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL WHERE functional_class IN ('motorway','motorway_link','trunk','trunk_link'); -UPDATE cambridge_ways SET ft_seg_stress = 3, tf_seg_stress = 3 +UPDATE neighborhood_ways SET ft_seg_stress = 3, tf_seg_stress = 3 WHERE functional_class IN ('motorway','motorway_link','trunk','trunk_link'); diff --git a/stress_motorway-trunk_ints.sql b/stress_motorway-trunk_ints.sql index 12fd8edb..e16e0b0d 100644 --- a/stress_motorway-trunk_ints.sql +++ b/stress_motorway-trunk_ints.sql @@ -1,7 +1,7 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -- assume low stress, since these juncions would always be controlled or free flowing -UPDATE cambridge_ways SET ft_int_stress = 1, tf_int_stress = 1 +UPDATE neighborhood_ways SET ft_int_stress = 1, tf_int_stress = 1 WHERE functional_class IN ('motorway','trunk'); diff --git a/stress_one_way_reset.sql b/stress_one_way_reset.sql index a08a4498..67130224 100644 --- a/stress_one_way_reset.sql +++ b/stress_one_way_reset.sql @@ -1,7 +1,7 @@ -- reset opposite stress for one-way -UPDATE cambridge_ways +UPDATE neighborhood_ways SET ft_seg_stress = NULL WHERE one_way = 'tf'; -UPDATE cambridge_ways +UPDATE neighborhood_ways SET tf_seg_stress = NULL WHERE one_way = 'ft'; diff --git a/stress_path.sql b/stress_path.sql index 19057fdd..cce9fd0b 100644 --- a/stress_path.sql +++ b/stress_path.sql @@ -1,11 +1,11 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -UPDATE cambridge_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL +UPDATE neighborhood_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL WHERE functional_class = 'path'; -UPDATE cambridge_ways +UPDATE neighborhood_ways SET ft_seg_stress = 1, tf_seg_stress = 1 WHERE functional_class = 'path'; diff --git a/stress_primary.sql b/stress_primary.sql index a3c23557..12df9514 100644 --- a/stress_primary.sql +++ b/stress_primary.sql @@ -1,12 +1,12 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -UPDATE cambridge_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL +UPDATE neighborhood_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL WHERE functional_class IN ('primary','primary_link'); -- ft direction -UPDATE cambridge_ways +UPDATE neighborhood_ways SET ft_seg_stress = CASE WHEN ft_bike_infra = 'track' THEN 1 @@ -60,7 +60,7 @@ SET ft_seg_stress = WHERE functional_class IN ('primary','primary_link'); -- tf direction -UPDATE cambridge_ways +UPDATE neighborhood_ways SET tf_seg_stress = CASE WHEN tf_bike_infra = 'track' THEN 1 diff --git a/stress_primary_ints.sql b/stress_primary_ints.sql index 986db734..86621d04 100644 --- a/stress_primary_ints.sql +++ b/stress_primary_ints.sql @@ -1,7 +1,7 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -- assume low stress, since these juncions would always be controlled or free flowing -UPDATE cambridge_ways SET ft_int_stress = 1, tf_int_stress = 1 +UPDATE neighborhood_ways SET ft_int_stress = 1, tf_int_stress = 1 WHERE functional_class = 'primary'; diff --git a/stress_residential.sql b/stress_residential.sql index 391672bf..775f7d3a 100644 --- a/stress_residential.sql +++ b/stress_residential.sql @@ -1,10 +1,10 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood -- notes: residential streets with bike lanes of any type -- are scored as tertiary streets ---------------------------------------- -UPDATE cambridge_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL +UPDATE neighborhood_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL WHERE functional_class = 'residential' AND (ft_bike_infra IS NULL OR ft_bike_infra NOT IN ('track','buffered_lane','lane')) AND (tf_bike_infra IS NULL OR tf_bike_infra NOT IN ('track','buffered_lane','lane')) @@ -13,7 +13,7 @@ AND (ft_lanes IS NULL OR tf_lanes = 1) AND (speed_limit IS NULL OR speed_limit <= 30); -- no additional information -UPDATE cambridge_ways +UPDATE neighborhood_ways SET ft_seg_stress = 1, tf_seg_stress = 1 WHERE functional_class = 'residential' @@ -24,7 +24,7 @@ AND (ft_lanes IS NULL OR tf_lanes = 1) AND (speed_limit IS NULL OR speed_limit <= 30); -- stress increase for narrow one way and parking on both sides -UPDATE cambridge_ways +UPDATE neighborhood_ways SET ft_seg_stress = 2, tf_seg_stress = 2 WHERE functional_class = 'residential' diff --git a/stress_secondary.sql b/stress_secondary.sql index 58322d07..ca3f1c41 100644 --- a/stress_secondary.sql +++ b/stress_secondary.sql @@ -1,12 +1,12 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -UPDATE cambridge_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL +UPDATE neighborhood_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL WHERE functional_class IN ('secondary','secondary_link'); -- ft direction -UPDATE cambridge_ways +UPDATE neighborhood_ways SET ft_seg_stress = CASE WHEN ft_bike_infra = 'track' THEN 1 @@ -64,7 +64,7 @@ SET ft_seg_stress = WHERE functional_class IN ('secondary','secondary_link'); -- tf direction -UPDATE cambridge_ways +UPDATE neighborhood_ways SET tf_seg_stress = CASE WHEN tf_bike_infra = 'track' THEN 1 diff --git a/stress_secondary_ints.sql b/stress_secondary_ints.sql index 9e42a555..8b976dad 100644 --- a/stress_secondary_ints.sql +++ b/stress_secondary_ints.sql @@ -1,19 +1,19 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -UPDATE cambridge_ways SET ft_int_stress = 1, tf_int_stress = 1 +UPDATE neighborhood_ways SET ft_int_stress = 1, tf_int_stress = 1 WHERE functional_class = 'secondary'; -- ft -UPDATE cambridge_ways +UPDATE neighborhood_ways SET ft_int_stress = 3 WHERE functional_class = 'secondary' AND EXISTS ( SELECT 1 - FROM cambridge_ways w - WHERE cambridge_ways.intersection_to IN (w.intersection_to,w.intersection_from) - AND COALESCE(cambridge_ways.name,'a') != COALESCE(w.name,'b') + FROM neighborhood_ways w + WHERE neighborhood_ways.intersection_to IN (w.intersection_to,w.intersection_from) + AND COALESCE(neighborhood_ways.name,'a') != COALESCE(w.name,'b') AND CASE WHEN w.functional_class IN ('motorway','trunk','primary') THEN CASE @@ -48,14 +48,14 @@ AND EXISTS ( ); -- tf -UPDATE cambridge_ways +UPDATE neighborhood_ways SET tf_int_stress = 3 WHERE functional_class = 'secondary' AND EXISTS ( SELECT 1 - FROM cambridge_ways w - WHERE cambridge_ways.intersection_from IN (w.intersection_to,w.intersection_from) - AND COALESCE(cambridge_ways.name,'a') != COALESCE(w.name,'b') + FROM neighborhood_ways w + WHERE neighborhood_ways.intersection_from IN (w.intersection_to,w.intersection_from) + AND COALESCE(neighborhood_ways.name,'a') != COALESCE(w.name,'b') AND CASE WHEN w.functional_class IN ('motorway','trunk','primary') THEN CASE diff --git a/stress_tertiary.sql b/stress_tertiary.sql index 54866961..cdcf11ef 100644 --- a/stress_tertiary.sql +++ b/stress_tertiary.sql @@ -1,10 +1,10 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood -- notes: this includes residential streets that have bike lanes -- of any type ---------------------------------------- -UPDATE cambridge_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL +UPDATE neighborhood_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL WHERE functional_class IN ('tertiary','tertiary_link') OR (functional_class = 'residential' AND ft_bike_infra IN ('track','buffered_lane','lane')) OR (functional_class = 'residential' AND tf_bike_infra IN ('track','buffered_lane','lane')) @@ -13,7 +13,7 @@ OR (functional_class = 'residential' AND tf_lanes > 1) OR (functional_class = 'residential' AND speed_limit > 30); -- ft direction -UPDATE cambridge_ways +UPDATE neighborhood_ways SET ft_seg_stress = CASE WHEN ft_bike_infra = 'track' THEN 1 @@ -93,7 +93,7 @@ OR (functional_class = 'residential' AND tf_lanes > 1) OR (functional_class = 'residential' AND speed_limit > 30); -- tf direction -UPDATE cambridge_ways +UPDATE neighborhood_ways SET tf_seg_stress = CASE WHEN tf_bike_infra = 'track' THEN 1 diff --git a/stress_tertiary_ints.sql b/stress_tertiary_ints.sql index feb754de..9e6aa309 100644 --- a/stress_tertiary_ints.sql +++ b/stress_tertiary_ints.sql @@ -1,19 +1,19 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -UPDATE cambridge_ways SET ft_int_stress = 1, tf_int_stress = 1 +UPDATE neighborhood_ways SET ft_int_stress = 1, tf_int_stress = 1 WHERE functional_class = 'tertiary'; -- ft -UPDATE cambridge_ways +UPDATE neighborhood_ways SET ft_int_stress = 3 WHERE functional_class = 'tertiary' AND EXISTS ( SELECT 1 - FROM cambridge_ways w - WHERE cambridge_ways.intersection_to IN (w.intersection_to,w.intersection_from) - AND COALESCE(cambridge_ways.name,'a') != COALESCE(w.name,'b') + FROM neighborhood_ways w + WHERE neighborhood_ways.intersection_to IN (w.intersection_to,w.intersection_from) + AND COALESCE(neighborhood_ways.name,'a') != COALESCE(w.name,'b') AND CASE WHEN w.functional_class IN ('motorway','trunk','primary') THEN CASE @@ -62,14 +62,14 @@ AND EXISTS ( ); -- tf -UPDATE cambridge_ways +UPDATE neighborhood_ways SET tf_int_stress = 3 WHERE functional_class = 'tertiary' AND EXISTS ( SELECT 1 - FROM cambridge_ways w - WHERE cambridge_ways.intersection_from IN (w.intersection_to,w.intersection_from) - AND COALESCE(cambridge_ways.name,'a') != COALESCE(w.name,'b') + FROM neighborhood_ways w + WHERE neighborhood_ways.intersection_from IN (w.intersection_to,w.intersection_from) + AND COALESCE(neighborhood_ways.name,'a') != COALESCE(w.name,'b') AND CASE WHEN w.functional_class IN ('motorway','trunk','primary') THEN CASE diff --git a/stress_track.sql b/stress_track.sql index bdc75261..2aaf2b54 100644 --- a/stress_track.sql +++ b/stress_track.sql @@ -1,11 +1,11 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -UPDATE cambridge_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL +UPDATE neighborhood_ways SET ft_seg_stress = NULL, tf_seg_stress = NULL WHERE functional_class = 'track'; -UPDATE cambridge_ways +UPDATE neighborhood_ways SET ft_seg_stress = 1, tf_seg_stress = 1 WHERE functional_class = 'track'; diff --git a/width_ft.sql b/width_ft.sql index 69710209..24333b53 100644 --- a/width_ft.sql +++ b/width_ft.sql @@ -1,31 +1,31 @@ ---------------------------------------- -- INPUTS --- location: cambridge +-- location: neighborhood ---------------------------------------- -UPDATE cambridge_ways SET width_ft = NULL; +UPDATE neighborhood_ways SET width_ft = NULL; -- feet -UPDATE cambridge_ways +UPDATE neighborhood_ways SET width_ft = substring(osm.width from '\d+\.?\d?\d?')::FLOAT -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id AND osm.width IS NOT NULL AND osm.width LIKE '% ft'; -- meters -UPDATE cambridge_ways +UPDATE neighborhood_ways SET width_ft = 3.28084 * substring(osm.width from '\d+\.?\d?\d?')::FLOAT -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id AND osm.width IS NOT NULL AND osm.width LIKE '% m'; -- no units (default=meters) -- N.B. we weed out anything more than 20, since that's likely either bogus -- or not in meters -UPDATE cambridge_ways +UPDATE neighborhood_ways SET width_ft = 3.28084 * substring(osm.width from '\d+\.?\d?\d?')::FLOAT -FROM cambridge_osm_full_line osm -WHERE cambridge_ways.osm_id = osm.osm_id +FROM neighborhood_osm_full_line osm +WHERE neighborhood_ways.osm_id = osm.osm_id AND osm.width IS NOT NULL AND substring(osm.width from '\d+\.?\d?\d?')::FLOAT < 20; From e1c7d31100f73e68d29bcd72c8f31e7e40d19c8d Mon Sep 17 00:00:00 2001 From: Spencer Date: Wed, 21 Dec 2016 11:42:49 -0600 Subject: [PATCH 76/94] change srid to 3857, update spatial calculations to meters from feet --- connectivity/census_block_roads.sql | 8 ++++---- connectivity/connected_census_blocks.sql | 4 ++-- .../connected_census_blocks_recreation.sql | 10 +++++----- connectivity/connected_census_blocks_schools.sql | 4 ++-- connectivity/school_roads.sql | 6 +++--- connectivity/schools.sql | 4 ++-- import_osm.sh | 2 +- paths.sql | 8 ++++---- prepare_tables.sql | 14 +++++++------- streetlight/streetlight_destinations.sql | 2 +- streetlight/streetlight_gates.sql | 10 +++++----- 11 files changed, 36 insertions(+), 36 deletions(-) diff --git a/connectivity/census_block_roads.sql b/connectivity/census_block_roads.sql index 54dfb0e5..d2e449fe 100644 --- a/connectivity/census_block_roads.sql +++ b/connectivity/census_block_roads.sql @@ -15,10 +15,10 @@ CREATE TABLE generated.neighborhood_census_block_roads ( CREATE TEMP TABLE tmp_block_buffers ( id INTEGER PRIMARY KEY, blockid10 VARCHAR(15), - geom geometry(multipolygon,2249) + geom geometry(multipolygon,3857) ) ON COMMIT DROP; INSERT INTO tmp_block_buffers -SELECT id, blockid10, ST_Multi(ST_Buffer(geom,50)) FROM neighborhood_census_blocks; +SELECT id, blockid10, ST_Multi(ST_Buffer(geom,15)) FROM neighborhood_census_blocks; --15 meters ~~ 50 ft CREATE INDEX tidx_neighborhood_blockgeoms ON tmp_block_buffers USING GIST (geom); ANALYZE tmp_block_buffers; @@ -34,7 +34,7 @@ FROM tmp_block_buffers blocks, WHERE EXISTS ( SELECT 1 FROM neighborhood_zip_codes zips - WHERE ST_DWithin(zips.geom, blocks.geom, 11000) + WHERE ST_DWithin(zips.geom, blocks.geom, 3350) --3350 meters ~~ 11000 ft AND zips.zip_code = '02138' ) AND ST_Intersects(blocks.geom,ways.geom) @@ -42,7 +42,7 @@ AND ( ST_Contains(blocks.geom,ways.geom) OR ST_Length( ST_Intersection(blocks.geom,ways.geom) - ) > 100 + ) > 30 --30 meters ~~ 100 ft ); CREATE INDEX idx_neighborhood_censblkrds diff --git a/connectivity/connected_census_blocks.sql b/connectivity/connected_census_blocks.sql index d7094bbc..a0eaa986 100644 --- a/connectivity/connected_census_blocks.sql +++ b/connectivity/connected_census_blocks.sql @@ -29,7 +29,7 @@ WHERE EXISTS ( WHERE ST_Intersects(source_block.geom,zips.geom) AND zips.zip_code = '02138' ) -AND source_block.geom <#> target_block.geom < 11000 +AND source_block.geom <#> target_block.geom < 3350 --3350 meters ~~ 11000 ft AND EXISTS ( SELECT 1 FROM neighborhood_census_block_roads source_br, @@ -78,7 +78,7 @@ AND ( AND target_blockid10 = target_br.blockid10 AND hs.base_road = source_br.road_id AND hs.target_road = target_br.road_id - ),11000) <= 1.3; + ),3350) <= 1.3; --3350 meters ~~ 11000 ft -- stress index CREATE INDEX idx_neighborhood_blockpairs_lstress ON neighborhood_connected_census_blocks (low_stress); diff --git a/connectivity/connected_census_blocks_recreation.sql b/connectivity/connected_census_blocks_recreation.sql index e8847fff..779425bb 100644 --- a/connectivity/connected_census_blocks_recreation.sql +++ b/connectivity/connected_census_blocks_recreation.sql @@ -29,7 +29,7 @@ WHERE EXISTS ( WHERE ST_Intersects(blocks.geom,zips.geom) AND zips.zip_code = '02138' ) -AND blocks.geom <#> paths.geom < 11000 +AND blocks.geom <#> paths.geom < 3350 --3350 meters ~~ 11000 feet AND EXISTS ( SELECT 1 FROM neighborhood_census_block_roads source_br, @@ -39,13 +39,13 @@ AND EXISTS ( AND paths.path_id = target_r.path_id AND hs.base_road = source_br.road_id AND hs.target_road = target_r.road_id - AND paths.path_length > 15840 --path at least 3 mi long - AND paths.bbox_length > 10560 --extent of path at least 2 mi long + AND paths.path_length > 4500 --path at least 4.5 km long + AND paths.bbox_length > 3000 --extent of path at least 3 km long ); - + -- block pair index CREATE INDEX idx_neighborhood_blockschoolpairs @@ -84,7 +84,7 @@ AND ( AND target_school_id = target_sr.school_id AND hs.base_road = source_br.road_id AND hs.target_road = target_sr.road_id - ),11000) <= 1.3; + ),3350) <= 1.3; --3350 meters ~~ 11000 ft -- stress index CREATE INDEX idx_neighborhood_blockschl_lstress ON neighborhood_connected_census_blocks_recreation (low_stress); diff --git a/connectivity/connected_census_blocks_schools.sql b/connectivity/connected_census_blocks_schools.sql index 130415ba..65f94e9b 100644 --- a/connectivity/connected_census_blocks_schools.sql +++ b/connectivity/connected_census_blocks_schools.sql @@ -29,7 +29,7 @@ WHERE EXISTS ( WHERE ST_Intersects(blocks.geom,zips.geom) AND zips.zip_code = '02138' ) -AND blocks.geom <#> schools.geom_pt < 11000 +AND blocks.geom <#> schools.geom_pt < 3350 --3350 meters ~~ 11000 ft AND EXISTS ( SELECT 1 FROM neighborhood_census_block_roads source_br, @@ -78,7 +78,7 @@ AND ( AND target_school_id = target_sr.school_id AND hs.base_road = source_br.road_id AND hs.target_road = target_sr.road_id - ),11000) <= 1.3; + ),3350) <= 1.3; --3350 meters ~~ 11000 ft -- stress index CREATE INDEX idx_neighborhood_blockschl_lstress ON neighborhood_connected_census_blocks_schools (low_stress); diff --git a/connectivity/school_roads.sql b/connectivity/school_roads.sql index 9d3e24e8..7be484fd 100644 --- a/connectivity/school_roads.sql +++ b/connectivity/school_roads.sql @@ -22,11 +22,11 @@ FROM neighborhood_schools schools, WHERE EXISTS ( SELECT 1 FROM neighborhood_zip_codes zips - WHERE ST_DWithin(zips.geom, schools.geom_pt, 11000) + WHERE ST_DWithin(zips.geom, schools.geom_pt, 3350) --3350 meters ~~ 11000 ft AND zips.zip_code = '02138' ) AND schools.geom_poly IS NOT NULL -AND ST_DWithin(schools.geom_poly,ways.geom,50); +AND ST_DWithin(schools.geom_poly,ways.geom,15); --15 meters ~~ 50 ft -- points take the nearest road INSERT INTO generated.neighborhood_school_roads ( @@ -44,7 +44,7 @@ FROM neighborhood_schools schools WHERE EXISTS ( SELECT 1 FROM neighborhood_zip_codes zips - WHERE ST_DWithin(zips.geom, schools.geom_pt, 11000) + WHERE ST_DWithin(zips.geom, schools.geom_pt, 3350) --3350 meters ~~ 11000 ft AND zips.zip_code = '02138' ) AND NOT EXISTS ( diff --git a/connectivity/schools.sql b/connectivity/schools.sql index 275bd4a4..3e301e50 100644 --- a/connectivity/schools.sql +++ b/connectivity/schools.sql @@ -10,8 +10,8 @@ CREATE TABLE generated.neighborhood_schools ( school_name TEXT, pop_low_stress INT, pop_high_stress INT, - geom_pt geometry(point,2249), - geom_poly geometry(polygon,2249) + geom_pt geometry(point,3857), + geom_poly geometry(polygon,3857) ); CREATE INDEX sidx_neighborhood_schools_geompt ON neighborhood_schools USING GIST (geom_pt); CREATE INDEX sidx_neighborhood_schools_geomply ON neighborhood_schools USING GIST (geom_poly); diff --git a/import_osm.sh b/import_osm.sh index 500803a3..376df009 100644 --- a/import_osm.sh +++ b/import_osm.sh @@ -126,7 +126,7 @@ osm2pgsql \ --create \ --database ${DBNAME} \ --prefix ${OSMPREFIX}_osm_full \ - --proj 2249 \ + --proj 3857 \ --style /home/spencer/dev/pfb/pfb.style \ $OSMFILE diff --git a/paths.sql b/paths.sql index b413d1f3..c2bb7217 100644 --- a/paths.sql +++ b/paths.sql @@ -7,7 +7,7 @@ DROP INDEX IF EXISTS idx_neighborhood_ways_path_id; CREATE TABLE generated.neighborhood_paths ( path_id SERIAL PRIMARY KEY, - geom geometry(multilinestring,2249), + geom geometry(multilinestring,3857), path_length INTEGER, bbox_length INTEGER ); @@ -17,7 +17,7 @@ INSERT INTO neighborhood_paths (geom) SELECT ST_CollectionExtract( ST_SetSRID( unnest(ST_ClusterIntersecting(geom)), - 2249 + 3857 ), 2 --linestrings ) @@ -36,7 +36,7 @@ SET bbox_length = ST_Length( ST_MakePoint(ST_XMin(geom), ST_YMin(geom)), ST_MakePoint(ST_XMax(geom), ST_YMax(geom)) ), - 2249 + 3857 ) ); @@ -58,7 +58,7 @@ FROM neighborhood_paths paths WHERE neighborhood_ways.functional_class = 'path' AND neighborhood_ways.path_id IS NULL AND ST_Intersects(neighborhood_ways.geom,paths.geom) -AND ST_CoveredBy(neighborhood_ways.geom,ST_Buffer(paths.geom,1)); +AND ST_CoveredBy(neighborhood_ways.geom,ST_Buffer(paths.geom,0.3)); -- set index CREATE INDEX idx_neighborhood_ways_path_id ON neighborhood_ways (path_id); diff --git a/prepare_tables.sql b/prepare_tables.sql index d4aa55c3..12ba7c61 100644 --- a/prepare_tables.sql +++ b/prepare_tables.sql @@ -1,7 +1,7 @@ ---------------------------------------- -- INPUTS -- location: neighborhood --- proj: 2249 +-- proj: 3857 ---------------------------------------- -- add tdg_id field to roads @@ -44,12 +44,12 @@ ALTER TABLE neighborhood_ways_intersections RENAME COLUMN id TO int_id; ALTER TABLE neighborhood_ways_intersections RENAME COLUMN the_geom TO geom; -- reproject -ALTER TABLE neighborhood_ways ALTER COLUMN geom TYPE geometry(linestring,2249) -USING ST_Transform(geom,2249); -ALTER TABLE neighborhood_cycwys_ways ALTER COLUMN the_geom TYPE geometry(linestring,2249) -USING ST_Transform(the_geom,2249); -ALTER TABLE neighborhood_ways_intersections ALTER COLUMN geom TYPE geometry(point,2249) -USING ST_Transform(geom,2249); +ALTER TABLE neighborhood_ways ALTER COLUMN geom TYPE geometry(linestring,3857) +USING ST_Transform(geom,3857); +ALTER TABLE neighborhood_cycwys_ways ALTER COLUMN the_geom TYPE geometry(linestring,3857) +USING ST_Transform(the_geom,3857); +ALTER TABLE neighborhood_ways_intersections ALTER COLUMN geom TYPE geometry(point,3857) +USING ST_Transform(geom,3857); -- add columns ALTER TABLE neighborhood_ways ADD COLUMN functional_class TEXT; diff --git a/streetlight/streetlight_destinations.sql b/streetlight/streetlight_destinations.sql index 3f6a8b8b..aada9d96 100644 --- a/streetlight/streetlight_destinations.sql +++ b/streetlight/streetlight_destinations.sql @@ -1,7 +1,7 @@ ---------------------------------------- -- INPUTS -- location: neighborhood --- proj: 2249 +-- proj: 3857 ---------------------------------------- DROP TABLE IF EXISTS neighborhood_streetlight_destinations; CREATE TABLE generated.neighborhood_streetlight_destinations ( diff --git a/streetlight/streetlight_gates.sql b/streetlight/streetlight_gates.sql index d5cbf651..a7db5d6b 100644 --- a/streetlight/streetlight_gates.sql +++ b/streetlight/streetlight_gates.sql @@ -1,12 +1,12 @@ ---------------------------------------- -- INPUTS -- location: neighborhood --- proj: 2249 +-- proj: 3857 ---------------------------------------- DROP TABLE IF EXISTS neighborhood_streetlight_gates; CREATE TABLE generated.neighborhood_streetlight_gates ( id SERIAL PRIMARY KEY, - geom geometry(polygon,2249), + geom geometry(polygon,3857), road_id BIGINT, functional_class TEXT, direction INT, @@ -28,9 +28,9 @@ SELECT road_id, ST_LineInterpolatePoint(geom,0.5), ST_LineInterpolatePoint(geom,0.55) ), - 2249 + 3857 ), - 100, + 30, --30 meters ~~ 100 ft 'endcap=flat' ) AS geom, degrees(ST_Azimuth( @@ -43,7 +43,7 @@ WHERE functional_class IN ('primary','secondary','tertiary','residential') AND EXISTS ( SELECT 1 FROM neighborhood_zip_codes zips - WHERE ST_DWithin(neighborhood_ways.geom,zips.geom,11000) + WHERE ST_DWithin(neighborhood_ways.geom,zips.geom,3350) --3350 meters ~~ 11000 ft AND zips.zip_code = '02138' ); From 2a8cb7817b8d966a7d885f4f4ac56501d4bb7299 Mon Sep 17 00:00:00 2001 From: CloudNiner Date: Fri, 13 Jan 2017 14:19:27 -0500 Subject: [PATCH 77/94] Add Apache 2.0 License --- LICENSE | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..c6ed7a80 --- /dev/null +++ b/LICENSE @@ -0,0 +1,13 @@ +Copyright 2017 Azavea, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. From a1122423c808d6a51ab5ccd775080986ca9c75be Mon Sep 17 00:00:00 2001 From: CloudNiner Date: Wed, 18 Jan 2017 08:07:58 -0500 Subject: [PATCH 78/94] Add zipcode note in cycles.py --- connectivity/cycles.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/connectivity/cycles.py b/connectivity/cycles.py index 1eb8ecb1..2b55a3a8 100644 --- a/connectivity/cycles.py +++ b/connectivity/cycles.py @@ -1,6 +1,8 @@ import nxutils import networkx as nx +# TODO: Update this to remove dependency on static zipcode +# if we ever need to use this code zipCode = '02138' prefix = 'neighborhood' From ff1cc2ee34aa7f7fe98a62f3c65a3e7266c1411c Mon Sep 17 00:00:00 2001 From: CloudNiner Date: Wed, 18 Jan 2017 08:14:31 -0500 Subject: [PATCH 79/94] Fixup streetlight_destinations.sql - Continue to use SRID expected by StreetLightData - Support change from static zipcode boundary to custom user provided boundary --- streetlight/streetlight_destinations.sql | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/streetlight/streetlight_destinations.sql b/streetlight/streetlight_destinations.sql index aada9d96..a34fb466 100644 --- a/streetlight/streetlight_destinations.sql +++ b/streetlight/streetlight_destinations.sql @@ -1,7 +1,7 @@ ---------------------------------------- -- INPUTS -- location: neighborhood --- proj: 3857 +-- Prepares a table to be exported to StreetLightData ---------------------------------------- DROP TABLE IF EXISTS neighborhood_streetlight_destinations; CREATE TABLE generated.neighborhood_streetlight_destinations ( @@ -20,9 +20,9 @@ INSERT INTO neighborhood_streetlight_destinations ( ) SELECT blocks.blockid10, blocks.blockid10, + -- Transform to 4326, this is what StreetLightData expects ST_Transform(blocks.geom,4326), 0 FROM neighborhood_census_blocks blocks, - neighborhood_zip_codes zips -WHERE zips.zip_code = '02138' -AND ST_Intersects(blocks.geom,zips.geom); + neighborhood_boundary b +WHERE ST_Intersects(blocks.geom,b.geom); From 407d7bc9d331b54778e43ff763d684b53abc6a6d Mon Sep 17 00:00:00 2001 From: Sharp Hall Date: Wed, 1 Feb 2017 15:42:16 -0500 Subject: [PATCH 80/94] Change run_connectivity to parallelize in 8 threads --- ...l => reachable_roads_high_stress_calc.sql} | 16 ++-------- .../reachable_roads_high_stress_cleanup.sql | 3 ++ .../reachable_roads_high_stress_prep.sql | 13 ++++++++ ...ql => reachable_roads_low_stress_calc.sql} | 17 ++--------- .../reachable_roads_low_stress_cleanup.sql | 8 +++++ .../reachable_roads_low_stress_prep.sql | 13 ++++++++ run_connectivity.sh | 30 +++++++++++++++++-- 7 files changed, 71 insertions(+), 29 deletions(-) rename connectivity/{reachable_roads_high_stress.sql => reachable_roads_high_stress_calc.sql} (61%) create mode 100644 connectivity/reachable_roads_high_stress_cleanup.sql create mode 100644 connectivity/reachable_roads_high_stress_prep.sql rename connectivity/{reachable_roads_low_stress.sql => reachable_roads_low_stress_calc.sql} (62%) create mode 100644 connectivity/reachable_roads_low_stress_cleanup.sql create mode 100644 connectivity/reachable_roads_low_stress_prep.sql diff --git a/connectivity/reachable_roads_high_stress.sql b/connectivity/reachable_roads_high_stress_calc.sql similarity index 61% rename from connectivity/reachable_roads_high_stress.sql rename to connectivity/reachable_roads_high_stress_calc.sql index d6c17b44..f0cb7bed 100644 --- a/connectivity/reachable_roads_high_stress.sql +++ b/connectivity/reachable_roads_high_stress_calc.sql @@ -3,15 +3,6 @@ -- location: neighborhood -- maximum network distsance: 10560 ft ---------------------------------------- -DROP TABLE IF EXISTS generated.neighborhood_reachable_roads_high_stress; - -CREATE TABLE generated.neighborhood_reachable_roads_high_stress ( - id SERIAL PRIMARY KEY, - base_road INT, - target_road INT, - total_cost FLOAT -); - INSERT INTO generated.neighborhood_reachable_roads_high_stress ( base_road, target_road, @@ -33,7 +24,9 @@ FROM neighborhood_ways r1, 10560, directed := true ) sheds -WHERE EXISTS ( +WHERE r1.road_id % :thread_num = :thread_no +AND +EXISTS ( SELECT 1 FROM neighborhood_boundary AS b WHERE ST_Intersects(b.geom,r1.geom) @@ -41,6 +34,3 @@ WHERE EXISTS ( AND r1.road_id = v1.road_id AND v2.vert_id = sheds.node; -CREATE UNIQUE INDEX IF NOT EXISTS idx_neighborhood_rchblrdshistrss_b ON generated.neighborhood_reachable_roads_high_stress (base_road, target_road); -CREATE INDEX IF NOT EXISTS idx_neighborhood_rchblrdshistrss_t ON generated.neighborhood_reachable_roads_high_stress (target_road); -ANALYZE generated.neighborhood_reachable_roads_high_stress; diff --git a/connectivity/reachable_roads_high_stress_cleanup.sql b/connectivity/reachable_roads_high_stress_cleanup.sql new file mode 100644 index 00000000..c505edc6 --- /dev/null +++ b/connectivity/reachable_roads_high_stress_cleanup.sql @@ -0,0 +1,3 @@ +CREATE UNIQUE INDEX IF NOT EXISTS idx_neighborhood_rchblrdshistrss_b ON generated.neighborhood_reachable_roads_high_stress (base_road, target_road); +CREATE INDEX IF NOT EXISTS idx_neighborhood_rchblrdshistrss_t ON generated.neighborhood_reachable_roads_high_stress (target_road); +ANALYZE generated.neighborhood_reachable_roads_high_stress; diff --git a/connectivity/reachable_roads_high_stress_prep.sql b/connectivity/reachable_roads_high_stress_prep.sql new file mode 100644 index 00000000..b57a9e54 --- /dev/null +++ b/connectivity/reachable_roads_high_stress_prep.sql @@ -0,0 +1,13 @@ +---------------------------------------- +-- INPUTS +-- location: neighborhood +-- maximum network distsance: 10560 ft +---------------------------------------- +DROP TABLE IF EXISTS generated.neighborhood_reachable_roads_high_stress; + +CREATE TABLE generated.neighborhood_reachable_roads_high_stress ( + id SERIAL PRIMARY KEY, + base_road INT, + target_road INT, + total_cost FLOAT +); diff --git a/connectivity/reachable_roads_low_stress.sql b/connectivity/reachable_roads_low_stress_calc.sql similarity index 62% rename from connectivity/reachable_roads_low_stress.sql rename to connectivity/reachable_roads_low_stress_calc.sql index 4690cf3a..434a89dd 100644 --- a/connectivity/reachable_roads_low_stress.sql +++ b/connectivity/reachable_roads_low_stress_calc.sql @@ -3,15 +3,6 @@ -- location: neighborhood -- maximum network distsance: 10560 ft ---------------------------------------- -DROP TABLE IF EXISTS generated.neighborhood_reachable_roads_low_stress; - -CREATE TABLE generated.neighborhood_reachable_roads_low_stress ( - id SERIAL PRIMARY KEY, - base_road INT, - target_road INT, - total_cost FLOAT -); - INSERT INTO generated.neighborhood_reachable_roads_low_stress ( base_road, target_road, @@ -34,14 +25,12 @@ FROM neighborhood_ways r1, 10560, directed := true ) sheds -WHERE EXISTS ( +WHERE r1.road_id % :thread_num = :thread_no +AND +EXISTS ( SELECT 1 FROM neighborhood_boundary AS b WHERE ST_Intersects(b.geom,r1.geom) ) AND r1.road_id = v1.road_id AND v2.vert_id = sheds.node; - -CREATE INDEX IF NOT EXISTS idx_neighborhood_rchblrdslowstrss_b ON generated.neighborhood_reachable_roads_low_stress (base_road); -CREATE INDEX IF NOT EXISTS idx_neighborhood_rchblrdslowstrss_t ON generated.neighborhood_reachable_roads_low_stress (target_road); -ANALYZE generated.neighborhood_reachable_roads_low_stress (base_road,target_road); diff --git a/connectivity/reachable_roads_low_stress_cleanup.sql b/connectivity/reachable_roads_low_stress_cleanup.sql new file mode 100644 index 00000000..ea07d621 --- /dev/null +++ b/connectivity/reachable_roads_low_stress_cleanup.sql @@ -0,0 +1,8 @@ +---------------------------------------- +-- INPUTS +-- location: neighborhood +-- maximum network distsance: 10560 ft +---------------------------------------- +CREATE INDEX IF NOT EXISTS idx_neighborhood_rchblrdslowstrss_b ON generated.neighborhood_reachable_roads_low_stress (base_road); +CREATE INDEX IF NOT EXISTS idx_neighborhood_rchblrdslowstrss_t ON generated.neighborhood_reachable_roads_low_stress (target_road); +ANALYZE generated.neighborhood_reachable_roads_low_stress (base_road,target_road); diff --git a/connectivity/reachable_roads_low_stress_prep.sql b/connectivity/reachable_roads_low_stress_prep.sql new file mode 100644 index 00000000..535985d4 --- /dev/null +++ b/connectivity/reachable_roads_low_stress_prep.sql @@ -0,0 +1,13 @@ +---------------------------------------- +-- INPUTS +-- location: neighborhood +-- maximum network distsance: 10560 ft +---------------------------------------- +DROP TABLE IF EXISTS generated.neighborhood_reachable_roads_low_stress; + +CREATE TABLE generated.neighborhood_reachable_roads_low_stress ( + id SERIAL PRIMARY KEY, + base_road INT, + target_road INT, + total_cost FLOAT +); diff --git a/run_connectivity.sh b/run_connectivity.sh index a5a22130..378bb493 100755 --- a/run_connectivity.sh +++ b/run_connectivity.sh @@ -25,11 +25,37 @@ psql -h "${NB_POSTGRESQL_HOST}" -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_D -v nb_output_srid="${NB_OUTPUT_SRID}" \ -f connectivity/census_block_roads.sql +/usr/bin/time -v psql -h "${NB_POSTGRESQL_HOST}" -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_DB}" -f connectivity/reachable_roads_high_stress_prep.sql + +/usr/bin/time -v parallel< Date: Sat, 4 Feb 2017 17:07:05 -0500 Subject: [PATCH 81/94] Add script to export analysis data --- export_connectivity.sh | 87 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100755 export_connectivity.sh diff --git a/export_connectivity.sh b/export_connectivity.sh new file mode 100755 index 00000000..170830eb --- /dev/null +++ b/export_connectivity.sh @@ -0,0 +1,87 @@ +#!/usr/bin/env bash + +set -e + +cd `dirname $0` + +NB_POSTGRESQL_HOST="${NB_POSTGRESQL_HOST:-127.0.0.1}" +NB_POSTGRESQL_DB="${NB_POSTGRESQL_DB:-pfb}" +NB_POSTGRESQL_USER="${NB_POSTGRESQL_USER:-gis}" +NB_POSTGRESQL_PASSWORD="${NB_POSTGRESQL_PASSWORD:-gis}" +NB_POSTGRESQL_PORT="${NB_POSTGRESQL_PORT:-5432}" +NB_OUTPUT_FILE_PREFIX="${NB_OUTPUT_FILE_PREFIX:-analysis_}" + +NB_OUTPUT_DIR="${1}" + +function usage() { + echo -n \ +" +Usage: $(basename "$0") + +Export data from a successful run of the PeopleForBike Network Analysis to a directory on disk. + + must be an absolute path (pgsql COPY doesn't support relative paths) + +This script exports the following tables: + - neighborhood_ways as SHP + - neighborhood_ways as GeoJSON + - neighborhood_connected_census_blocks as SHP + - neighborhood_overall_scores as CSV + +Optional ENV vars: + +NB_OUTPUT_FILE_PREFIX - Default: 'analysis_' +NB_POSTGRESQL_HOST - Default: 127.0.0.1 +NB_POSTGRESQL_DB - Default: pfb +NB_POSTGRESQL_USER - Default: gis +NB_POSTGRESQL_PASSWORD - Default: gis +NB_POSTGRESQL_PORT - Default: 4326 + +" +} +if [ "${BASH_SOURCE[0]}" = "${0}" ] +then + if [ "${1:-}" = "--help" ] || [ -z "${1:-}" ] + then + usage + else + NB_OUTPUT_DIR="${1}" + + # Export neighborhood_ways as SHP + EXPORT_TABLENAME='neighborhood_ways' + FILETYPE='shp' + FILENAME="${NB_OUTPUT_DIR}/${NB_OUTPUT_FILE_PREFIX}${EXPORT_TABLENAME}.${FILETYPE}" + pgsql2shp -h "${NB_POSTGRESQL_HOST}" \ + -u "${NB_POSTGRESQL_USER}" \ + -p "${NB_POSTGRESQL_PORT}" \ + -P "${NB_POSTGRESQL_PASSWORD}" \ + -f "${FILENAME}" \ + "${NB_POSTGRESQL_DB}" \ + "${EXPORT_TABLENAME}" + + # Export neighborhood ways as GeoJSON + # TODO: Add ogr2ogr and try again + + # Export neighborhood_connected_census_blocks as SHP + EXPORT_TABLENAME='neighborhood_connected_census_blocks' + FILETYPE='shp' + FILENAME="${NB_OUTPUT_DIR}/${NB_OUTPUT_FILE_PREFIX}${EXPORT_TABLENAME}.${FILETYPE}" + pgsql2shp -h "${NB_POSTGRESQL_HOST}" \ + -u "${NB_POSTGRESQL_USER}" \ + -p "${NB_POSTGRESQL_PORT}" \ + -P "${NB_POSTGRESQL_PASSWORD}" \ + -f "${FILENAME}" \ + "${NB_POSTGRESQL_DB}" \ + "${EXPORT_TABLENAME}" + + # Export neighborhood_overall_scores as CSV + EXPORT_TABLENAME='neighborhood_overall_scores' + FILETYPE='csv' + FILENAME="${NB_OUTPUT_DIR}/${NB_OUTPUT_FILE_PREFIX}${EXPORT_TABLENAME}.${FILETYPE}" + psql -h "${NB_POSTGRESQL_HOST}" \ + -U "${NB_POSTGRESQL_USER}" \ + -p "${NB_POSTGRESQL_PORT}" \ + -d "${NB_POSTGRESQL_DB}" \ + -c "COPY ${EXPORT_TABLENAME} TO '${FILENAME}' WITH (FORMAT CSV, HEADER)" + fi +fi From 3be340c311d9e781c7b94be1f4d467b9a71af46e Mon Sep 17 00:00:00 2001 From: Sharp Hall Date: Mon, 6 Feb 2017 10:16:59 -0500 Subject: [PATCH 82/94] Dockerize --- Dockerfile | 17 +++++++++++++++++ README.md | 33 ++++++++++++++++++++++++++++++++- build_tools.sh | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ entrypoint.sh | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 145 insertions(+), 1 deletion(-) create mode 100644 Dockerfile create mode 100755 build_tools.sh create mode 100755 entrypoint.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..dc45062b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +FROM quay.io/azavea/postgis:latest +MAINTAINER Azavea + +RUN apt-get update && apt-get install -y unzip postgis \ + expat libexpat1-dev cmake libboost-all-dev make \ + g++ zlib1g-dev libbz2-dev libpq-dev libgeos-dev \ + libgeos++-dev libproj-dev lua5.2 liblua5.2-dev \ + git wget bc time parallel \ + postgresql-server-dev-$PG_MAJOR \ + postgresql-plpython-$PG_MAJOR \ + postgresql-$PG_MAJOR-pgrouting + +COPY ./ /pfb/ + +RUN /pfb/build_tools.sh + +ENTRYPOINT /pfb/entrypoint.sh diff --git a/README.md b/README.md index 6df70deb..cee9c154 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,33 @@ # pfb -osm2pgrouting mapconfig file + +## Docker + +To run the analysis in docker, first build the docker image: + +```bash +docker build -t pfb . +``` + +Then run the analysis as follows: + +```bash +docker run \ + -e PFB_SHPFILE=/data/neighborhood_boundary.shp \ + -e PFB_STATE=ma \ + -e PFB_STATE_FIPS=25 \ + -e NB_INPUT_SRID=2249 \ + -e NB_OUTPUT_SRID=2249 \ + -e NB_BOUNDARY_BUFFER=11000 \ + -v /home/user/projects/pfb-network-connectivity/data/:/data/ \ + pfb +``` + +The `-e` in this example sets environment variables, which will depend on the +analysis you are running. + +The `-v` in this example mounts a local directory inside the docker container +under `/data/`. The `PFB_SHPFILE` environment variable specifies the `.shp` +file under this directory to use. + +This process of mounting a data directory with the input shapefile will be +removed in favor of an import process. diff --git a/build_tools.sh b/build_tools.sh new file mode 100755 index 00000000..1327a014 --- /dev/null +++ b/build_tools.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +set -e + +cd /tmp/ + +# osm2pgrouting + +git clone --branch 'osm2pgrouting-2.1.0' https://github.com/pgRouting/osm2pgrouting.git + +pushd osm2pgrouting + mkdir build + cmake -H. -Bbuild + pushd build + make + make install + popd +popd + +# osm2pgsql + +git clone --branch '0.90.1' https://github.com/openstreetmap/osm2pgsql.git + +pushd osm2pgsql + mkdir build + pushd build + cmake ../ + make + make install + popd +popd + +# quantile + +git clone --branch master https://github.com/tvondra/quantile.git + +pushd quantile + make install +popd + +git clone --branch nodes https://github.com/spencerrecneps/TDG-Tools.git + +# TDG tools + +pushd TDG-Tools + pushd TDG\ SQL\ Tools + make clean + make install + popd +popd diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 00000000..461a21ef --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,46 @@ +set -e + +NB_POSTGRESQL_DB=pfb +NB_POSTGRESQL_USER=gis +NB_POSTGRESQL_PASSWORD=gis + +# start postgres and capture the PID +/docker-entrypoint.sh postgres & +POSTGRES_PROC=$! + +# sleep while db comes up +sleep 10 + +# set up database +su postgres bash -c psql < Date: Mon, 6 Feb 2017 11:37:27 -0700 Subject: [PATCH 83/94] Cleanup from PR review --- export_connectivity.sh | 68 ++++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 32 deletions(-) diff --git a/export_connectivity.sh b/export_connectivity.sh index 170830eb..adde626c 100755 --- a/export_connectivity.sh +++ b/export_connectivity.sh @@ -1,8 +1,10 @@ #!/usr/bin/env bash +# ec prefix stands for 'export connectivity' + set -e -cd `dirname $0` +cd $(dirname "$0") NB_POSTGRESQL_HOST="${NB_POSTGRESQL_HOST:-127.0.0.1}" NB_POSTGRESQL_DB="${NB_POSTGRESQL_DB:-pfb}" @@ -13,7 +15,7 @@ NB_OUTPUT_FILE_PREFIX="${NB_OUTPUT_FILE_PREFIX:-analysis_}" NB_OUTPUT_DIR="${1}" -function usage() { +function ec_usage() { echo -n \ " Usage: $(basename "$0") @@ -24,7 +26,7 @@ Export data from a successful run of the PeopleForBike Network Analysis to a dir This script exports the following tables: - neighborhood_ways as SHP - - neighborhood_ways as GeoJSON + - neighborhood_ways as GeoJSON (TODO) - neighborhood_connected_census_blocks as SHP - neighborhood_overall_scores as CSV @@ -39,49 +41,51 @@ NB_POSTGRESQL_PORT - Default: 4326 " } + +function ec_export_table_shp() { + OUTPUT_DIR="$1" + EXPORT_TABLENAME="$2" + + FILENAME="${OUTPUT_DIR}/${NB_OUTPUT_FILE_PREFIX}${EXPORT_TABLENAME}.shp" + pgsql2shp -h "${NB_POSTGRESQL_HOST}" \ + -u "${NB_POSTGRESQL_USER}" \ + -p "${NB_POSTGRESQL_PORT}" \ + -P "${NB_POSTGRESQL_PASSWORD}" \ + -f "${FILENAME}" \ + "${NB_POSTGRESQL_DB}" \ + "${EXPORT_TABLENAME}" +} + +function ec_export_table_csv() { + OUTPUT_DIR="$1" + EXPORT_TABLENAME="$2" + + FILENAME="${OUTPUT_DIR}/${NB_OUTPUT_FILE_PREFIX}${EXPORT_TABLENAME}.csv" + psql -h "${NB_POSTGRESQL_HOST}" \ + -U "${NB_POSTGRESQL_USER}" \ + -p "${NB_POSTGRESQL_PORT}" \ + -d "${NB_POSTGRESQL_DB}" \ + -c "COPY ${EXPORT_TABLENAME} TO '${FILENAME}' WITH (FORMAT CSV, HEADER)" +} + if [ "${BASH_SOURCE[0]}" = "${0}" ] then if [ "${1:-}" = "--help" ] || [ -z "${1:-}" ] then - usage + ec_usage else NB_OUTPUT_DIR="${1}" # Export neighborhood_ways as SHP - EXPORT_TABLENAME='neighborhood_ways' - FILETYPE='shp' - FILENAME="${NB_OUTPUT_DIR}/${NB_OUTPUT_FILE_PREFIX}${EXPORT_TABLENAME}.${FILETYPE}" - pgsql2shp -h "${NB_POSTGRESQL_HOST}" \ - -u "${NB_POSTGRESQL_USER}" \ - -p "${NB_POSTGRESQL_PORT}" \ - -P "${NB_POSTGRESQL_PASSWORD}" \ - -f "${FILENAME}" \ - "${NB_POSTGRESQL_DB}" \ - "${EXPORT_TABLENAME}" + ec_export_table_shp "${NB_OUTPUT_DIR}" "neighborhood_ways" # Export neighborhood ways as GeoJSON # TODO: Add ogr2ogr and try again # Export neighborhood_connected_census_blocks as SHP - EXPORT_TABLENAME='neighborhood_connected_census_blocks' - FILETYPE='shp' - FILENAME="${NB_OUTPUT_DIR}/${NB_OUTPUT_FILE_PREFIX}${EXPORT_TABLENAME}.${FILETYPE}" - pgsql2shp -h "${NB_POSTGRESQL_HOST}" \ - -u "${NB_POSTGRESQL_USER}" \ - -p "${NB_POSTGRESQL_PORT}" \ - -P "${NB_POSTGRESQL_PASSWORD}" \ - -f "${FILENAME}" \ - "${NB_POSTGRESQL_DB}" \ - "${EXPORT_TABLENAME}" + ec_export_table_shp "${NB_OUTPUT_DIR}" "neighborhood_connected_census_blocks" # Export neighborhood_overall_scores as CSV - EXPORT_TABLENAME='neighborhood_overall_scores' - FILETYPE='csv' - FILENAME="${NB_OUTPUT_DIR}/${NB_OUTPUT_FILE_PREFIX}${EXPORT_TABLENAME}.${FILETYPE}" - psql -h "${NB_POSTGRESQL_HOST}" \ - -U "${NB_POSTGRESQL_USER}" \ - -p "${NB_POSTGRESQL_PORT}" \ - -d "${NB_POSTGRESQL_DB}" \ - -c "COPY ${EXPORT_TABLENAME} TO '${FILENAME}' WITH (FORMAT CSV, HEADER)" + ec_export_table_csv "${NB_OUTPUT_DIR}" "neighborhood_overall_scores" fi fi From 63aeaf1f26162a38d0f18987670e4f6e88f32a59 Mon Sep 17 00:00:00 2001 From: Sharp Hall Date: Wed, 8 Feb 2017 10:54:42 -0500 Subject: [PATCH 84/94] Consolidate build inside of Dockerfile Move database initialization to /docker-entrypoint-initdb.d/ --- Dockerfile | 53 +++++++++++++++++++++++++++++++++++++++-------- build_tools.sh | 50 -------------------------------------------- entrypoint.sh | 19 ----------------- setup_database.sh | 26 +++++++++++++++++++++++ 4 files changed, 70 insertions(+), 78 deletions(-) delete mode 100755 build_tools.sh create mode 100755 setup_database.sh diff --git a/Dockerfile b/Dockerfile index dc45062b..b23b5c6b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,52 @@ -FROM quay.io/azavea/postgis:latest +FROM quay.io/azavea/postgis:postgres9.6-postgis2.3 MAINTAINER Azavea -RUN apt-get update && apt-get install -y unzip postgis \ - expat libexpat1-dev cmake libboost-all-dev make \ - g++ zlib1g-dev libbz2-dev libpq-dev libgeos-dev \ - libgeos++-dev libproj-dev lua5.2 liblua5.2-dev \ - git wget bc time parallel \ +ENV GIT_BRANCH_OSM2PGROUTING osm2pgrouting-2.1.0 +ENV GIT_BRANCH_OSM2PGSQL 0.90.1 +ENV GIT_BRANCH_QUANTILE master +ENV GIT_BRANCH_TDGTOOLS nodes + +RUN set -xe && \ + BUILD_DEPS=" \ postgresql-server-dev-$PG_MAJOR \ + libexpat1-dev \ + cmake \ + libboost-all-dev make \ + g++ \ + zlib1g-dev \ + libbz2-dev \ + libpq-dev \ + libgeos-dev \ + libgeos++-dev \ + libproj-dev \ + git" \ + DEPS=" \ + ca-certificates \ + liblua5.2-dev \ + lua5.2 \ + expat \ + wget \ + bc \ + time \ + parallel \ postgresql-plpython-$PG_MAJOR \ - postgresql-$PG_MAJOR-pgrouting + postgresql-$PG_MAJOR-pgrouting \ + unzip \ + postgis" && \ + apt-get update && apt-get install -y ${BUILD_DEPS} ${DEPS} --no-install-recommends && \ + mkdir /tmp/build/ && cd /tmp/build && \ + git clone --branch $GIT_BRANCH_OSM2PGROUTING https://github.com/pgRouting/osm2pgrouting.git && \ + (cd osm2pgrouting && mkdir build && cmake -H. -Bbuild && cd build && make install) && \ + git clone --branch $GIT_BRANCH_OSM2PGSQL https://github.com/openstreetmap/osm2pgsql.git && \ + (cd osm2pgsql && mkdir build && cd build && cmake ../ && make install) && \ + git clone --branch $GIT_BRANCH_QUANTILE https://github.com/tvondra/quantile.git && \ + (cd quantile && make install) && \ + git clone --branch $GIT_BRANCH_TDGTOOLS https://github.com/spencerrecneps/TDG-Tools.git && \ + (cd TDG-Tools/TDG\ SQL\ Tools && make clean && make install) && \ + cd /tmp/ && rm -rf /tmp/build/ /var/lib/apt/lists/* && \ + apt-get purge -y --auto-remove ${BUILD_DEPS} +COPY setup_database.sh /docker-entrypoint-initdb.d/setup_database.sh COPY ./ /pfb/ -RUN /pfb/build_tools.sh - ENTRYPOINT /pfb/entrypoint.sh diff --git a/build_tools.sh b/build_tools.sh deleted file mode 100755 index 1327a014..00000000 --- a/build_tools.sh +++ /dev/null @@ -1,50 +0,0 @@ -#!/bin/bash - -set -e - -cd /tmp/ - -# osm2pgrouting - -git clone --branch 'osm2pgrouting-2.1.0' https://github.com/pgRouting/osm2pgrouting.git - -pushd osm2pgrouting - mkdir build - cmake -H. -Bbuild - pushd build - make - make install - popd -popd - -# osm2pgsql - -git clone --branch '0.90.1' https://github.com/openstreetmap/osm2pgsql.git - -pushd osm2pgsql - mkdir build - pushd build - cmake ../ - make - make install - popd -popd - -# quantile - -git clone --branch master https://github.com/tvondra/quantile.git - -pushd quantile - make install -popd - -git clone --branch nodes https://github.com/spencerrecneps/TDG-Tools.git - -# TDG tools - -pushd TDG-Tools - pushd TDG\ SQL\ Tools - make clean - make install - popd -popd diff --git a/entrypoint.sh b/entrypoint.sh index 461a21ef..452a541b 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -11,25 +11,6 @@ POSTGRES_PROC=$! # sleep while db comes up sleep 10 -# set up database -su postgres bash -c psql < Date: Wed, 8 Feb 2017 11:54:27 -0500 Subject: [PATCH 85/94] Add intelligent wait for database --- entrypoint.sh | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 452a541b..05fa1097 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,3 +1,5 @@ +#!/bin/bash + set -e NB_POSTGRESQL_DB=pfb @@ -5,11 +7,36 @@ NB_POSTGRESQL_USER=gis NB_POSTGRESQL_PASSWORD=gis # start postgres and capture the PID -/docker-entrypoint.sh postgres & +/docker-entrypoint.sh postgres | tee /tmp/postgres_stdout.txt & POSTGRES_PROC=$! -# sleep while db comes up -sleep 10 +MAX_TRIES=30 +counter=1 + +# wait for database to become available +while true +do + echo waiting for database, try ${counter} + sleep 3 + # don't check if postgres is up until docker-entrypoint gives us the signal + if grep 'PostgreSQL init process complete' /tmp/postgres_stdout.txt > /dev/null + then + set +e + psql -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_DB}" -c "SELECT 1" &> /dev/null + postgresql_status=$? + set -e + if [ "$postgresql_status" == "0" ] + then + break + fi + fi + if [ "$counter" == "$MAX_TRIES" ]; then + echo database did not come up successfully + kill $POSTGRES_PROC + exit 1 + fi + ((counter++)) +done # run job cd /pfb From b6115bb9d6055c2ca853f915f658e36caac70dcb Mon Sep 17 00:00:00 2001 From: Sharp Hall Date: Wed, 8 Feb 2017 12:00:38 -0500 Subject: [PATCH 86/94] Change example to match data path inside of Vagrant VM --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cee9c154..1ba2e364 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ docker run \ -e NB_INPUT_SRID=2249 \ -e NB_OUTPUT_SRID=2249 \ -e NB_BOUNDARY_BUFFER=11000 \ - -v /home/user/projects/pfb-network-connectivity/data/:/data/ \ + -v /vagrant/data/:/data/ \ pfb ``` From 912e9ab83f2df1efb71b3f1fdeb69d78a33131b8 Mon Sep 17 00:00:00 2001 From: Kathryn Killebrew Date: Mon, 6 Feb 2017 17:20:28 -0500 Subject: [PATCH 87/94] Detect SRID from input shapefile Detect UTM zone from input shapefile and set matching SRID on environment. To use: ``` source set_srid.sh ``` Depends on python and python-gdal. --- detect_utm_zone.py | 86 ++++++++++++++++++++++++++++++++++++++++++++++ set_srid.sh | 29 ++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100755 detect_utm_zone.py create mode 100755 set_srid.sh diff --git a/detect_utm_zone.py b/detect_utm_zone.py new file mode 100755 index 00000000..420e2e48 --- /dev/null +++ b/detect_utm_zone.py @@ -0,0 +1,86 @@ +#!/usr/bin/env python + +""" +Accepts a polygon shapefile in WGS84 and finds the SRID for the UTM zone +Based on https://github.com/jbranigan/geo-scripts-python/blob/master/latlng2utm/detect-utm-zone.py +""" + +from osgeo import ogr +import math +import argparse + + +def check_latlng(check_bbox): + ''' Checks to see if the file coordinates are in lat/lng ''' + for i in check_bbox: + if i < -180 or i > 180: + failure('This file is already projected.') + return True + + +def check_width(check_bbox): + ''' Checsk to see if the bounding box fits in a UTM zone ''' + wide = check_bbox[1] - check_bbox[0] + if wide > 3: + failure('This file is too many degrees wide for UTM') + return True + + +def get_zone(coord): + ''' Finds the UTM zone of the coordinate ''' + # There are 60 longitudinal projection zones numbered 1 to 60 starting at 180W + # So that's -180 = 1, -174 = 2, -168 = 3 + zone = ((coord - -180) / 6.0) + return int(math.ceil(zone)) + + +def get_bbox(shapefile): + ''' Gets the bounding box of a shapefile input ''' + driver = ogr.GetDriverByName('ESRI Shapefile') + # 0 means read, 1 means write + data_source = driver.Open(shapefile, 0) + # Check to see if shapefile is found. + if data_source is None: + failure('Could not open %s' % (shapefile)) + else: + layer = data_source.GetLayer() + shape_bbox = layer.GetExtent() + return shape_bbox + + +def failure(why): + ''' Quits the script with an exit message ''' + print why + raise SystemExit + + +def get_srid(filename): + bbox = get_bbox(filename) + check_latlng(bbox) + check_width(bbox) + + avg_longitude = ((bbox[1] - bbox[0]) / 2) + bbox[0] + utm_zone = get_zone(avg_longitude) + + avg_latitude = ((bbox[3] - bbox[2]) / 2) + bbox[2] + + # convert UTM zone to SRID + # SRID for a given UTM ZONE: 32[6 if N|7 if S] + srid = '32' + if avg_latitude < 0: + srid += '7' + else: + srid += '6' + + srid += str(utm_zone) + print(srid) + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("filename", help="the path to the input shapefile") + args = parser.parse_args() + + get_srid(args.filename) + +main() diff --git a/set_srid.sh b/set_srid.sh new file mode 100755 index 00000000..b78bb6ad --- /dev/null +++ b/set_srid.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +set -e + +if [[ -n "${PFB_DEBUG}" ]]; then + set -x +fi + +# determine current working directory in a way that works with `source` +DIR="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +function usage() { + echo -n \ +" +Usage: set_srid.sh + +Autodetect the UTM zone for the given boundary file and set the SRID in ENV NB_OUTPUT_SRID + +" +} + +if [ "${1:-}" = "--help" ] || [ -z "${1:-}" ] +then + usage +else + SRID=`python ${DIR}/detect_utm_zone.py "${1}"` + echo "Detected SRID ${SRID}" + export NB_OUTPUT_SRID=$SRID +fi From 45e297e99af541e48f93b98aacab1923d35f69de Mon Sep 17 00:00:00 2001 From: Kathryn Killebrew Date: Tue, 7 Feb 2017 12:59:05 -0500 Subject: [PATCH 88/94] Convert bounds to WGS84 Handle arbitrary input projections; tidy formatting. --- detect_utm_zone.py | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/detect_utm_zone.py b/detect_utm_zone.py index 420e2e48..2468758a 100755 --- a/detect_utm_zone.py +++ b/detect_utm_zone.py @@ -1,17 +1,18 @@ #!/usr/bin/env python """ -Accepts a polygon shapefile in WGS84 and finds the SRID for the UTM zone +Accepts a polygon shapefile and finds the SRID for the UTM zone Based on https://github.com/jbranigan/geo-scripts-python/blob/master/latlng2utm/detect-utm-zone.py """ -from osgeo import ogr -import math import argparse +import math +from osgeo import ogr, osr +import sys def check_latlng(check_bbox): - ''' Checks to see if the file coordinates are in lat/lng ''' + """ Checks to see if the file coordinates are in lat/lng """ for i in check_bbox: if i < -180 or i > 180: failure('This file is already projected.') @@ -19,7 +20,7 @@ def check_latlng(check_bbox): def check_width(check_bbox): - ''' Checsk to see if the bounding box fits in a UTM zone ''' + """ Checks to see if the bounding box fits in a UTM zone """ wide = check_bbox[1] - check_bbox[0] if wide > 3: failure('This file is too many degrees wide for UTM') @@ -27,7 +28,7 @@ def check_width(check_bbox): def get_zone(coord): - ''' Finds the UTM zone of the coordinate ''' + """ Finds the UTM zone of a WGS84 coordinate """ # There are 60 longitudinal projection zones numbered 1 to 60 starting at 180W # So that's -180 = 1, -174 = 2, -168 = 3 zone = ((coord - -180) / 6.0) @@ -35,7 +36,9 @@ def get_zone(coord): def get_bbox(shapefile): - ''' Gets the bounding box of a shapefile input ''' + """ Gets the bounding box of a shapefile in EPSG 4326. + If shapefile is not in WGS84, bounds are reprojected. + """ driver = ogr.GetDriverByName('ESRI Shapefile') # 0 means read, 1 means write data_source = driver.Open(shapefile, 0) @@ -45,13 +48,29 @@ def get_bbox(shapefile): else: layer = data_source.GetLayer() shape_bbox = layer.GetExtent() + + spatialRef = layer.GetSpatialRef() + target = osr.SpatialReference() + target.ImportFromEPSG(4326) + + # this check for non-WGS84 projections gets some false positives, but that's okay + if target.ExportToProj4() != spatialRef.ExportToProj4(): + transform = osr.CoordinateTransformation(spatialRef, target) + point1 = ogr.Geometry(ogr.wkbPoint) + point1.AddPoint(shape_bbox[0], shape_bbox[2]) + point2 = ogr.Geometry(ogr.wkbPoint) + point2.AddPoint(shape_bbox[1], shape_bbox[3]) + point1.Transform(transform) + point2.Transform(transform) + shape_bbox = [point1.GetX(), point2.GetX(), point1.GetY(), point2.GetY()] + return shape_bbox def failure(why): - ''' Quits the script with an exit message ''' - print why - raise SystemExit + """ Quits the script with an exit message """ + print(why) + sys.exit(1) def get_srid(filename): From 5855a206c417bd988044effef06589cf1057995f Mon Sep 17 00:00:00 2001 From: Kathryn Killebrew Date: Tue, 7 Feb 2017 12:59:47 -0500 Subject: [PATCH 89/94] Handle UTM zone detection error Unset environment variable if failed to detect UTM zone. --- set_srid.sh | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/set_srid.sh b/set_srid.sh index b78bb6ad..aabc90d7 100755 --- a/set_srid.sh +++ b/set_srid.sh @@ -1,7 +1,5 @@ #!/bin/bash -set -e - if [[ -n "${PFB_DEBUG}" ]]; then set -x fi @@ -24,6 +22,11 @@ then usage else SRID=`python ${DIR}/detect_utm_zone.py "${1}"` - echo "Detected SRID ${SRID}" - export NB_OUTPUT_SRID=$SRID + if [ $? -eq 0 ]; then + echo "Detected SRID ${SRID}" + export NB_OUTPUT_SRID=$SRID + else + echo "Failed to determine UTM Zone SRID" + unset NB_OUTPUT_SRID + fi fi From 49bd8c51df5097f1ac59b75eab2c6a83173ea614 Mon Sep 17 00:00:00 2001 From: Kathryn Killebrew Date: Mon, 13 Feb 2017 12:47:41 -0500 Subject: [PATCH 90/94] Set SRID before import In Docker run, set output SRID by detecting it from UTM zone for shapefile. --- Dockerfile | 1 + README.md | 1 - entrypoint.sh | 3 +++ set_srid.sh | 32 -------------------------------- 4 files changed, 4 insertions(+), 33 deletions(-) delete mode 100755 set_srid.sh diff --git a/Dockerfile b/Dockerfile index b23b5c6b..a9e28d4d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -31,6 +31,7 @@ RUN set -xe && \ parallel \ postgresql-plpython-$PG_MAJOR \ postgresql-$PG_MAJOR-pgrouting \ + python-gdal \ unzip \ postgis" && \ apt-get update && apt-get install -y ${BUILD_DEPS} ${DEPS} --no-install-recommends && \ diff --git a/README.md b/README.md index 1ba2e364..98dc18f0 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,6 @@ docker run \ -e PFB_STATE=ma \ -e PFB_STATE_FIPS=25 \ -e NB_INPUT_SRID=2249 \ - -e NB_OUTPUT_SRID=2249 \ -e NB_BOUNDARY_BUFFER=11000 \ -v /vagrant/data/:/data/ \ pfb diff --git a/entrypoint.sh b/entrypoint.sh index 05fa1097..73e993a1 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -41,6 +41,9 @@ done # run job cd /pfb +# determine coordinate reference system based on input shapefile UTM zone +NB_OUTPUT_SRID="$(./detect_utm_zone.py $PFB_SHPFILE)" + ./import.sh $PFB_SHPFILE $PFB_STATE $PFB_STATE_FIPS ./run_connectivity.sh diff --git a/set_srid.sh b/set_srid.sh deleted file mode 100755 index aabc90d7..00000000 --- a/set_srid.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash - -if [[ -n "${PFB_DEBUG}" ]]; then - set -x -fi - -# determine current working directory in a way that works with `source` -DIR="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)" - -function usage() { - echo -n \ -" -Usage: set_srid.sh - -Autodetect the UTM zone for the given boundary file and set the SRID in ENV NB_OUTPUT_SRID - -" -} - -if [ "${1:-}" = "--help" ] || [ -z "${1:-}" ] -then - usage -else - SRID=`python ${DIR}/detect_utm_zone.py "${1}"` - if [ $? -eq 0 ]; then - echo "Detected SRID ${SRID}" - export NB_OUTPUT_SRID=$SRID - else - echo "Failed to determine UTM Zone SRID" - unset NB_OUTPUT_SRID - fi -fi From dfe51f7066b7b80e92143061d1d3570503aac566 Mon Sep 17 00:00:00 2001 From: Klaas Hoekema Date: Wed, 15 Feb 2017 08:35:03 -0500 Subject: [PATCH 91/94] Small README fixes - 's' in `scripts` - pushd/popd around the docker build command --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 467e0456..91923992 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Requirements: - VirtualBox 4.3+ - Ansible 2.0+ -Run `./script/setup` to install project dependencies and prepare the development environment. Then, SSH into the VM: +Run `./scripts/setup` to install project dependencies and prepare the development environment. Then, SSH into the VM: ``` vagrant ssh ``` @@ -59,7 +59,9 @@ In this example, we configure the analysis to be run for Cambridge MA. Run: ``` +pushd pfb-analysis docker build -t pfb . +popd docker run \ -e PFB_SHPFILE=/data/neighborhood_boundary.shp \ From c9bf699dfac629180181d87c0a56b331a63614c6 Mon Sep 17 00:00:00 2001 From: Klaas Hoekema Date: Wed, 15 Feb 2017 00:47:28 -0500 Subject: [PATCH 92/94] Move files into directories Moves stuff out of the root directory and into directories that loosely group related pieces. No other changes except file path references. --- pfb-analysis/Dockerfile | 4 +- pfb-analysis/{ => features}/bike_infra.sql | 0 .../{ => features}/functional_class.sql | 0 pfb-analysis/{ => features}/lanes.sql | 0 pfb-analysis/{ => features}/legs.sql | 0 pfb-analysis/{ => features}/one_way.sql | 0 pfb-analysis/{ => features}/park.sql | 0 pfb-analysis/{ => features}/paths.sql | 0 pfb-analysis/{ => features}/signalized.sql | 0 pfb-analysis/{ => features}/speed_limit.sql | 0 pfb-analysis/{ => features}/stops.sql | 0 .../streetlight/streetlight_destinations.sql | 0 .../streetlight/streetlight_gates.sql | 0 pfb-analysis/{ => features}/width_ft.sql | 0 pfb-analysis/{ => import}/import_jobs.sh | 0 .../{ => import}/import_neighborhood.sh | 0 pfb-analysis/{ => import}/import_osm.sh | 54 ++++++++-------- .../{ => import}/mapconfig_cycleway.xml | 0 .../{ => import}/mapconfig_highway.xml | 0 pfb-analysis/{ => import}/pfb.style | 0 pfb-analysis/{ => import}/prepare_tables.sql | 0 pfb-analysis/{ => scripts}/detect_utm_zone.py | 0 pfb-analysis/{ => scripts}/drop_tables.sh | 0 pfb-analysis/{ => scripts}/entrypoint.sh | 6 +- .../{ => scripts}/export_connectivity.sh | 0 pfb-analysis/{ => scripts}/import.sh | 6 +- .../{ => scripts}/run_connectivity.sh | 62 +++++++++---------- pfb-analysis/{ => scripts}/setup_database.sh | 0 .../{ => stress}/stress_lesser_ints.sql | 0 .../{ => stress}/stress_link_ints.sql | 0 .../{ => stress}/stress_living_street.sql | 0 .../{ => stress}/stress_motorway-trunk.sql | 0 .../stress_motorway-trunk_ints.sql | 0 .../{ => stress}/stress_one_way_reset.sql | 0 pfb-analysis/{ => stress}/stress_path.sql | 0 pfb-analysis/{ => stress}/stress_primary.sql | 0 .../{ => stress}/stress_primary_ints.sql | 0 .../{ => stress}/stress_residential.sql | 0 .../{ => stress}/stress_secondary.sql | 0 .../{ => stress}/stress_secondary_ints.sql | 0 pfb-analysis/{ => stress}/stress_tertiary.sql | 0 .../{ => stress}/stress_tertiary_ints.sql | 0 pfb-analysis/{ => stress}/stress_track.sql | 0 .../stress_validation.sql} | 0 44 files changed, 66 insertions(+), 66 deletions(-) rename pfb-analysis/{ => features}/bike_infra.sql (100%) rename pfb-analysis/{ => features}/functional_class.sql (100%) rename pfb-analysis/{ => features}/lanes.sql (100%) rename pfb-analysis/{ => features}/legs.sql (100%) rename pfb-analysis/{ => features}/one_way.sql (100%) rename pfb-analysis/{ => features}/park.sql (100%) rename pfb-analysis/{ => features}/paths.sql (100%) rename pfb-analysis/{ => features}/signalized.sql (100%) rename pfb-analysis/{ => features}/speed_limit.sql (100%) rename pfb-analysis/{ => features}/stops.sql (100%) rename pfb-analysis/{ => features}/streetlight/streetlight_destinations.sql (100%) rename pfb-analysis/{ => features}/streetlight/streetlight_gates.sql (100%) rename pfb-analysis/{ => features}/width_ft.sql (100%) rename pfb-analysis/{ => import}/import_jobs.sh (100%) rename pfb-analysis/{ => import}/import_neighborhood.sh (100%) rename pfb-analysis/{ => import}/import_osm.sh (90%) rename pfb-analysis/{ => import}/mapconfig_cycleway.xml (100%) rename pfb-analysis/{ => import}/mapconfig_highway.xml (100%) rename pfb-analysis/{ => import}/pfb.style (100%) rename pfb-analysis/{ => import}/prepare_tables.sql (100%) rename pfb-analysis/{ => scripts}/detect_utm_zone.py (100%) rename pfb-analysis/{ => scripts}/drop_tables.sh (100%) rename pfb-analysis/{ => scripts}/entrypoint.sh (89%) rename pfb-analysis/{ => scripts}/export_connectivity.sh (100%) rename pfb-analysis/{ => scripts}/import.sh (79%) rename pfb-analysis/{ => scripts}/run_connectivity.sh (58%) rename pfb-analysis/{ => scripts}/setup_database.sh (100%) rename pfb-analysis/{ => stress}/stress_lesser_ints.sql (100%) rename pfb-analysis/{ => stress}/stress_link_ints.sql (100%) rename pfb-analysis/{ => stress}/stress_living_street.sql (100%) rename pfb-analysis/{ => stress}/stress_motorway-trunk.sql (100%) rename pfb-analysis/{ => stress}/stress_motorway-trunk_ints.sql (100%) rename pfb-analysis/{ => stress}/stress_one_way_reset.sql (100%) rename pfb-analysis/{ => stress}/stress_path.sql (100%) rename pfb-analysis/{ => stress}/stress_primary.sql (100%) rename pfb-analysis/{ => stress}/stress_primary_ints.sql (100%) rename pfb-analysis/{ => stress}/stress_residential.sql (100%) rename pfb-analysis/{ => stress}/stress_secondary.sql (100%) rename pfb-analysis/{ => stress}/stress_secondary_ints.sql (100%) rename pfb-analysis/{ => stress}/stress_tertiary.sql (100%) rename pfb-analysis/{ => stress}/stress_tertiary_ints.sql (100%) rename pfb-analysis/{ => stress}/stress_track.sql (100%) rename pfb-analysis/{stress validation.sql => stress/stress_validation.sql} (100%) diff --git a/pfb-analysis/Dockerfile b/pfb-analysis/Dockerfile index a9e28d4d..6df375fe 100644 --- a/pfb-analysis/Dockerfile +++ b/pfb-analysis/Dockerfile @@ -47,7 +47,7 @@ RUN set -xe && \ cd /tmp/ && rm -rf /tmp/build/ /var/lib/apt/lists/* && \ apt-get purge -y --auto-remove ${BUILD_DEPS} -COPY setup_database.sh /docker-entrypoint-initdb.d/setup_database.sh +COPY scripts/setup_database.sh /docker-entrypoint-initdb.d/setup_database.sh COPY ./ /pfb/ -ENTRYPOINT /pfb/entrypoint.sh +ENTRYPOINT /pfb/scripts/entrypoint.sh diff --git a/pfb-analysis/bike_infra.sql b/pfb-analysis/features/bike_infra.sql similarity index 100% rename from pfb-analysis/bike_infra.sql rename to pfb-analysis/features/bike_infra.sql diff --git a/pfb-analysis/functional_class.sql b/pfb-analysis/features/functional_class.sql similarity index 100% rename from pfb-analysis/functional_class.sql rename to pfb-analysis/features/functional_class.sql diff --git a/pfb-analysis/lanes.sql b/pfb-analysis/features/lanes.sql similarity index 100% rename from pfb-analysis/lanes.sql rename to pfb-analysis/features/lanes.sql diff --git a/pfb-analysis/legs.sql b/pfb-analysis/features/legs.sql similarity index 100% rename from pfb-analysis/legs.sql rename to pfb-analysis/features/legs.sql diff --git a/pfb-analysis/one_way.sql b/pfb-analysis/features/one_way.sql similarity index 100% rename from pfb-analysis/one_way.sql rename to pfb-analysis/features/one_way.sql diff --git a/pfb-analysis/park.sql b/pfb-analysis/features/park.sql similarity index 100% rename from pfb-analysis/park.sql rename to pfb-analysis/features/park.sql diff --git a/pfb-analysis/paths.sql b/pfb-analysis/features/paths.sql similarity index 100% rename from pfb-analysis/paths.sql rename to pfb-analysis/features/paths.sql diff --git a/pfb-analysis/signalized.sql b/pfb-analysis/features/signalized.sql similarity index 100% rename from pfb-analysis/signalized.sql rename to pfb-analysis/features/signalized.sql diff --git a/pfb-analysis/speed_limit.sql b/pfb-analysis/features/speed_limit.sql similarity index 100% rename from pfb-analysis/speed_limit.sql rename to pfb-analysis/features/speed_limit.sql diff --git a/pfb-analysis/stops.sql b/pfb-analysis/features/stops.sql similarity index 100% rename from pfb-analysis/stops.sql rename to pfb-analysis/features/stops.sql diff --git a/pfb-analysis/streetlight/streetlight_destinations.sql b/pfb-analysis/features/streetlight/streetlight_destinations.sql similarity index 100% rename from pfb-analysis/streetlight/streetlight_destinations.sql rename to pfb-analysis/features/streetlight/streetlight_destinations.sql diff --git a/pfb-analysis/streetlight/streetlight_gates.sql b/pfb-analysis/features/streetlight/streetlight_gates.sql similarity index 100% rename from pfb-analysis/streetlight/streetlight_gates.sql rename to pfb-analysis/features/streetlight/streetlight_gates.sql diff --git a/pfb-analysis/width_ft.sql b/pfb-analysis/features/width_ft.sql similarity index 100% rename from pfb-analysis/width_ft.sql rename to pfb-analysis/features/width_ft.sql diff --git a/pfb-analysis/import_jobs.sh b/pfb-analysis/import/import_jobs.sh similarity index 100% rename from pfb-analysis/import_jobs.sh rename to pfb-analysis/import/import_jobs.sh diff --git a/pfb-analysis/import_neighborhood.sh b/pfb-analysis/import/import_neighborhood.sh similarity index 100% rename from pfb-analysis/import_neighborhood.sh rename to pfb-analysis/import/import_neighborhood.sh diff --git a/pfb-analysis/import_osm.sh b/pfb-analysis/import/import_osm.sh similarity index 90% rename from pfb-analysis/import_osm.sh rename to pfb-analysis/import/import_osm.sh index 92f72062..b7550741 100755 --- a/pfb-analysis/import_osm.sh +++ b/pfb-analysis/import/import_osm.sh @@ -172,32 +172,32 @@ echo 'Updating field names' psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ -v nb_output_srid="${NB_OUTPUT_SRID}" -f ./prepare_tables.sql echo 'Setting values on road segments' -psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./one_way.sql -psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./width_ft.sql -psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./functional_class.sql -psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ - -v nb_output_srid="${NB_OUTPUT_SRID}" -f ./paths.sql -psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./speed_limit.sql -psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./lanes.sql -psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./park.sql -psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./bike_infra.sql +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ../features/one_way.sql +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ../features/width_ft.sql +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ../features/functional_class.sql +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} \ + -v nb_output_srid="${NB_OUTPUT_SRID}" -f ../features/paths.sql +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ../features/speed_limit.sql +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ../features/lanes.sql +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ../features/park.sql +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ../features/bike_infra.sql echo 'Setting values on intersections' -psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./legs.sql -psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./signalized.sql -psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./stops.sql +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ../features/legs.sql +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ../features/signalized.sql +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ../features/stops.sql echo 'Calculating stress' -psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./stress_motorway-trunk.sql -psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./stress_primary.sql -psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./stress_secondary.sql -psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./stress_tertiary.sql -psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./stress_residential.sql -psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./stress_living_street.sql -psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./stress_track.sql -psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./stress_path.sql -psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./stress_one_way_reset.sql -psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./stress_motorway-trunk_ints.sql -psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./stress_primary_ints.sql -psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./stress_secondary_ints.sql -psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./stress_tertiary_ints.sql -psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./stress_lesser_ints.sql -psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ./stress_link_ints.sql +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ../stress/stress_motorway-trunk.sql +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ../stress/stress_primary.sql +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ../stress/stress_secondary.sql +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ../stress/stress_tertiary.sql +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ../stress/stress_residential.sql +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ../stress/stress_living_street.sql +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ../stress/stress_track.sql +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ../stress/stress_path.sql +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ../stress/stress_one_way_reset.sql +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ../stress/stress_motorway-trunk_ints.sql +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ../stress/stress_primary_ints.sql +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ../stress/stress_secondary_ints.sql +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ../stress/stress_tertiary_ints.sql +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ../stress/stress_lesser_ints.sql +psql -h $NB_POSTGRESQL_HOST -U ${NB_POSTGRESQL_USER} -d ${NB_POSTGRESQL_DB} -f ../stress/stress_link_ints.sql diff --git a/pfb-analysis/mapconfig_cycleway.xml b/pfb-analysis/import/mapconfig_cycleway.xml similarity index 100% rename from pfb-analysis/mapconfig_cycleway.xml rename to pfb-analysis/import/mapconfig_cycleway.xml diff --git a/pfb-analysis/mapconfig_highway.xml b/pfb-analysis/import/mapconfig_highway.xml similarity index 100% rename from pfb-analysis/mapconfig_highway.xml rename to pfb-analysis/import/mapconfig_highway.xml diff --git a/pfb-analysis/pfb.style b/pfb-analysis/import/pfb.style similarity index 100% rename from pfb-analysis/pfb.style rename to pfb-analysis/import/pfb.style diff --git a/pfb-analysis/prepare_tables.sql b/pfb-analysis/import/prepare_tables.sql similarity index 100% rename from pfb-analysis/prepare_tables.sql rename to pfb-analysis/import/prepare_tables.sql diff --git a/pfb-analysis/detect_utm_zone.py b/pfb-analysis/scripts/detect_utm_zone.py similarity index 100% rename from pfb-analysis/detect_utm_zone.py rename to pfb-analysis/scripts/detect_utm_zone.py diff --git a/pfb-analysis/drop_tables.sh b/pfb-analysis/scripts/drop_tables.sh similarity index 100% rename from pfb-analysis/drop_tables.sh rename to pfb-analysis/scripts/drop_tables.sh diff --git a/pfb-analysis/entrypoint.sh b/pfb-analysis/scripts/entrypoint.sh similarity index 89% rename from pfb-analysis/entrypoint.sh rename to pfb-analysis/scripts/entrypoint.sh index 73e993a1..1f607b4d 100755 --- a/pfb-analysis/entrypoint.sh +++ b/pfb-analysis/scripts/entrypoint.sh @@ -42,10 +42,10 @@ done cd /pfb # determine coordinate reference system based on input shapefile UTM zone -NB_OUTPUT_SRID="$(./detect_utm_zone.py $PFB_SHPFILE)" +NB_OUTPUT_SRID="$(./scripts/detect_utm_zone.py $PFB_SHPFILE)" -./import.sh $PFB_SHPFILE $PFB_STATE $PFB_STATE_FIPS -./run_connectivity.sh +./scripts/import.sh $PFB_SHPFILE $PFB_STATE $PFB_STATE_FIPS +./scripts/run_connectivity.sh # print scores (TODO: replace with export script) psql -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_DB}" < Date: Wed, 15 Feb 2017 10:00:18 -0500 Subject: [PATCH 93/94] Export variables from entrypoint.sh The import is in a sub-script so the calculated SRID needs to be exported to be available there. Also the NB_POSTGRESQL variables defined here won't act as overrides to the child scripts unless they're exported. --- pfb-analysis/scripts/entrypoint.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pfb-analysis/scripts/entrypoint.sh b/pfb-analysis/scripts/entrypoint.sh index 1f607b4d..35134392 100755 --- a/pfb-analysis/scripts/entrypoint.sh +++ b/pfb-analysis/scripts/entrypoint.sh @@ -2,9 +2,9 @@ set -e -NB_POSTGRESQL_DB=pfb -NB_POSTGRESQL_USER=gis -NB_POSTGRESQL_PASSWORD=gis +export NB_POSTGRESQL_DB=pfb +export NB_POSTGRESQL_USER=gis +export NB_POSTGRESQL_PASSWORD=gis # start postgres and capture the PID /docker-entrypoint.sh postgres | tee /tmp/postgres_stdout.txt & @@ -42,7 +42,7 @@ done cd /pfb # determine coordinate reference system based on input shapefile UTM zone -NB_OUTPUT_SRID="$(./scripts/detect_utm_zone.py $PFB_SHPFILE)" +export NB_OUTPUT_SRID="$(./scripts/detect_utm_zone.py $PFB_SHPFILE)" ./scripts/import.sh $PFB_SHPFILE $PFB_STATE $PFB_STATE_FIPS ./scripts/run_connectivity.sh From 52bad8b88ec873a20b55ed1e08f79b077bac1c9f Mon Sep 17 00:00:00 2001 From: Klaas Hoekema Date: Wed, 15 Feb 2017 10:11:21 -0500 Subject: [PATCH 94/94] Add `bash` to entrypoint.sh to preserve interactive containers --- pfb-analysis/scripts/entrypoint.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pfb-analysis/scripts/entrypoint.sh b/pfb-analysis/scripts/entrypoint.sh index 35134392..7e34a72f 100755 --- a/pfb-analysis/scripts/entrypoint.sh +++ b/pfb-analysis/scripts/entrypoint.sh @@ -52,6 +52,10 @@ psql -U "${NB_POSTGRESQL_USER}" -d "${NB_POSTGRESQL_DB}" <