Last active
August 29, 2015 14:01
-
-
Save caged/d9b988485b813b14c69b to your computer and use it in GitHub Desktop.
Scoring buildings based on proximity to neighborhood features
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
drop table if exists target_homes; | |
with | |
supermarket_zones as (select st_expand(geom, 0.0045) as zone, 5 as score from osm_polygons where osm_polygons.shop='supermarket'), | |
rail_stop_zones as (select st_expand(geom, 0.0045) as zone, 5 as score from trimet_rail_stops), | |
park_zones as (select st_expand(geom, 0.0045) as zone, 2 as score from osm_polygons where osm_polygons.leisure='park'), | |
target_buildings as ( | |
select * from supermarket_zones inner join buildings on st_intersects(supermarket_zones.zone, buildings.geom) where buildings.subarea='City of Portland' | |
union select * from rail_stop_zones inner join buildings on st_intersects(rail_stop_zones.zone, buildings.geom) where buildings.subarea='City of Portland' | |
) | |
select sum(score) as rank, gid, geom into target_homes from target_buildings group by 2, 3; | |
create index target_homes_gix on target_homes using gist (geom); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment