Created
April 19, 2018 15:11
-
-
Save GeoWill/49c7e8c36d8ff30d0660bfde1eef5c5b to your computer and use it in GitHub Desktop.
Scripts to merge local electoral districts in Mexico
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 | |
# To call the script open the terminal in the same folder as the script | |
# Ensure it is executable: $ chmod u+x merge-reproject.sh | |
# Call it with $ ./merge-distrito-local-reproject.sh | |
# SET TO PATH WHERE YOU WANT THE SHP TO BE CREATED | |
FILE='/enter/path/here/DISTRITO_LOCAL-wgs1984.shp' # name of file to be merged to | |
LAYER='DISTRITO_LOCAL' # should be the same as | |
TSRS='EPSG:4326' # target CRS | |
BASE='/vsizip//vsicurl/http://cartografia.ife.org.mx//descargas/distritacion2017/local' | |
for i in {01..32} | |
do | |
SRC="$BASE/$i/$i.zip/DISTRITO_LOCAL.shp" | |
if [ -f "$FILE" ] | |
then | |
echo "transforming and merging $SRC..." | |
ogr2ogr \ | |
-f 'ESRI Shapefile' \ | |
-t_srs $TSRS \ | |
-update -append $FILE $SRC \ | |
-nln $LAYER | |
else | |
echo "creating $FILE..." | |
ogr2ogr \ | |
-f 'ESRI Shapefile' \ | |
-t_srs $TSRS \ | |
$FILE $SRC | |
fi | |
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 | |
# To call the script open the terminal in the same folder as the script | |
# Ensure it is executable: $ chmod u+x merge-reproject.sh | |
# Call it with $ ./merge-distrito-local.sh | |
# SET TO PATH WHERE YOU WANT THE SHP TO BE CREATED | |
FILE='/home/will/data/concorde_data/mexico/source/INE/DISTRITO_LOCAL.shp' # name of file to be merged to | |
LAYER='DISTRITO_LOCAL' | |
BASE='/vsizip//vsicurl/http://cartografia.ife.org.mx//descargas/distritacion2017/local' | |
for i in {01..32} | |
do | |
SRC="$BASE/$i/$i.zip/DISTRITO_LOCAL.shp" | |
if [ -f "$FILE" ] | |
then | |
echo "merging $SRC..." | |
ogr2ogr \ | |
-f 'ESRI Shapefile' \ | |
-update -append $FILE $SRC \ | |
-nln $LAYER | |
else | |
echo "creating $FILE..." | |
ogr2ogr \ | |
-f 'ESRI Shapefile' \ | |
$FILE $SRC | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment