Skip to content

Instantly share code, notes, and snippets.

@nautilytics
Last active April 14, 2020 19:02
Show Gist options
  • Save nautilytics/24194b51187a35caea06d899113bc0d0 to your computer and use it in GitHub Desktop.
Save nautilytics/24194b51187a35caea06d899113bc0d0 to your computer and use it in GitHub Desktop.
Retrieve a FeatureCollection of affected counties joined with wind speed data for Hurricane Sandy
SELECT ROW_TO_JSON(fc) AS json_out FROM (
SELECT 'FeatureCollection' AS type,
ARRAY_TO_JSON(ARRAY_AGG(f)) AS features
FROM (
SELECT 'Feature' AS type,
ST_AsGeoJSON(c.geom)::json AS geometry,
ROW_TO_JSON((
SELECT l FROM (
SELECT r.radii,
r.synoptime,
r.basin,
r.stormnum,
r.ne,
r.se,
r.sw,
r.nw,
r.gid AS id,
c.geoid AS fips
) AS l)) AS properties
FROM tl_2019_us_county AS c, al182012_radii AS r
WHERE ST_Intersects(c.geom, ST_MakeValid(r.geom))
) f
) fc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment