Last active
March 9, 2021 19:59
-
-
Save johntut/0ce47b16ed4af8dd1508 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
#!/bin/bash | |
#Iterate over a bunch of census shapefiles | |
#Extract only the fields of interest and reproject into | |
#wgs84 | |
for f in $(find . -name "*.shp"); do | |
p=$f | |
[[ "$p" == */* ]] || p="./$p" | |
fname="${p##*/}" | |
layer="${fname%%.*}" | |
outfile="./FixedShapefiles/$layer.shp" # Outfile name | |
/usr/bin/ogr2ogr -f "ESRI Shapefile" "$outfile" -t_srs EPSG:4326 \ | |
"$f" -sql "select GEOID,INTPTLAT10,INTPTLON10,B01001e2,B01001e26,B15002e14,B15002e15,B15002e16,B15002e17,B15002e18,B15002e32,B15002e33,B15002e34,B15002e35,B19001e1,B19001e2,B19001e3,B19001e4,B19001e5,B19001e6,B19001e7,B19001e8,B19001e9,B19001e10,B19001e11,B19001e12,B19001e13,B19001e14,B19001e15,B19001e16,B19001e17,B19013e1,C17002e1,C17002e2,C17002e3,C17002e4,C17002e5,C17002e6,C17002e7,C17002 e8 from $layer" | |
done |
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 | |
#Need to have ogr installed | |
#Downloads all the census data and converts it from | |
#geodatabases to shapefiles | |
/usr/bin/wget -r -np -nd -l 1 -A zip http://www2.census.gov/geo/tiger/TIGER_DP/2010ACS/ | |
for d in */; do | |
/usr/bin/ogr2ogr -f "ESRI Shapefile" "${d%%.*}" "$d" | |
done |
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 | |
#Combine all the shapefiles in a directory | |
#into one | |
file="./final/merge.shp" | |
for i in $(ls ./*.shp) | |
do | |
if [ -f "$file" ]; | |
then | |
ogr2ogr -f 'ESRI Shapefile' -update -append $file "$i" -nln merge | |
else | |
echo "merging……$i" | |
ogr2ogr -f 'ESRI Shapefile' $file "$i" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment