Created
March 31, 2020 13:15
-
-
Save nautilytics/1733621d8b3400963e42ffc0804fa6ac to your computer and use it in GitHub Desktop.
Instructions for getting Hurricane Sandy and US County shapefiles into a PostGIS database to identify affected counties
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
#!/bin/bash | |
createdb gis_db | |
psql -d gis_db -c "CREATE EXTENSION postgis" |
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
#!/bin/bash | |
# Add US County data to Postgis w/ GIST index | |
curl https://www2.census.gov/geo/tiger/TIGER2019/COUNTY/tl_2019_us_county.zip --output tl_2019_us_county.zip | |
unzip tl_2019_us_county.zip | |
shp2pgsql tl_2019_us_county/tl_2019_us_county.shp tl_2019_us_county | psql -d gis_db | |
psql -d gis_db -c "CREATE INDEX tl_2019_us_county_geom_gix ON tl_2019_us_county USING GIST (geom)" | |
# Add Hurricane Sandy Radii data to Postgis w/ GIST index | |
curl https://www.nhc.noaa.gov/gis/best_track/al182012_best_track.zip --output al182012_best_track.zip | |
unzip al182012_best_track.zip | |
shp2pgsql al182012_best_track/al182012_radii.shp al182012_radii| psql -d gis_db | |
psql -d gis_db -c "CREATE INDEX al182012_radii_geom_gix ON al182012_radii USING GIST (geom)" |
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 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