Created
November 30, 2012 00:59
-
-
Save rywall/4173033 to your computer and use it in GitHub Desktop.
This file contains 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
[50, 100, 200, 500, 1000, 5000].each do |buffer| | |
puts "Calculating population within #{buffer} m of each shape_geometry" | |
Shape.find_each do |s| | |
execute "UPDATE shapes SET pop#{buffer}m = | |
(SELECT SUM((ST_SummaryStats(ST_Clip(rast,1,ST_Buffer(geom::geography, #{buffer})::geometry))).sum) | |
FROM shapes, population_tiles | |
WHERE id = #{s.id} AND ST_Intersects(ST_Buffer(geom::geography, #{buffer})::geometry,rast) | |
GROUP BY id) | |
WHERE id = #{s.id}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment