Created
June 14, 2016 16:29
-
-
Save bertspaan/3674a0df31df6f6c4ce24fa003adf320 to your computer and use it in GitHub Desktop.
Maps by Decade
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
SELECT decade * 10 AS decade, | |
ST_AsGeoJSON(ST_Union(geometry))::json AS geometry, | |
COUNT(*) AS count | |
FROM ( | |
SELECT | |
geometry, (( | |
date_part('year', lower(validsince)) + | |
date_part('year', upper(validuntil)) | |
) / 2)::int / 10 AS decade | |
FROM | |
pits | |
WHERE | |
dataset = 'mapwarper' AND | |
ST_Contains(ST_Envelope( | |
ST_SetSRID(ST_MakeLine( | |
ST_MakePoint(-74.347229, 40.436495), ST_MakePoint(-73.424377, 41.155910)), 4326) | |
), geometry) AND | |
(data->>'masked')::boolean = true AND | |
daterange('1800-01-01', '1949-12-31') @> validsince AND | |
daterange('1800-01-01', '1949-12-31') @> validuntil AND | |
ST_Area(Geography(geometry)) < 1000000 -- 1 square km (250 acres) | |
) d | |
GROUP BY decade | |
ORDER BY decade |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment