Last active
May 8, 2018 16:52
-
-
Save GeoWill/880e0ee973f6e3b4faad96b72eed43d9 to your computer and use it in GitHub Desktop.
Simple shell script to merge shapefiles from INE
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 the layer you wish to combine: eg. $ merge-reproject.sh ENTIDAD | |
# LAYERS are 'SECCION' 'ENTIDAD' and 'DISTRITO' | |
LYR=$1 | |
#SET TO PATH WHERE YOU WANT THE SHP TO BE CREATED | |
FILE="/enter/path/here/${LYR}-wgs84.shp" # name of file to be merged to | |
LAYER="${LYR}-wgs84" # should be the same as | |
TSRS='EPSG:4326' # target CRS | |
BASE='/vsizip//vsicurl/http://cartografia.ife.org.mx/descargas/distritacion2017/federal' | |
for i in {01..32} | |
do | |
if [ $i = 06 ] #Hack because file number 6 is a different structure to the rest | |
then | |
SRC="$BASE/$i/$i.zip/${LYR}.shp" | |
else | |
SRC="$BASE/$i/$i.zip/$i/${LYR}.shp" | |
fi | |
if [ -f "$FILE" ] | |
then | |
echo "Reprojecting 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment