Posted on Mon 14 November 2022

Shapefiles from the 2020 INEGI Census

Streets of Mexico City

You can now download shapefiles of selected geographic areas from the latest INEGI SCINCE database. In addition to geospatial information on state and municipios, the files include AGEB and manzana boundaries. The files are available in shapefile format and include demographic data

If you don’t know how to run the script or prefer to simply download the data, you can subscribe to my newsletter (one email per post) and you’ll get the shapefile download links directly in your inbox as a bonus.




If you use linux you can use the following script (or if you’re unable to run the script you can always use the docker image)

1
docker run -v "$(pwd)/scince_2020":/scince_2020 diegovalle/scince_2020


# The directory from which the script is running
readonly LOCAL_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
TEMP_DIR="$(mktemp -d)"
# index starts at zero
declare -a states=("national" "ags" "bc" "bcs" "camp" "coah" "col"
"chis" "chih" "cdmx" "dgo" "gto" "gro" "hgo" "jal"
"mex" "mich" "mor" "nay" "nl" "oax" "pue" "qro"
"qroo" "slp" "sin" "son" "tab" "tamps" "tlax" "ver"
"yuc" "zac");
download_states() {
mkdir -p "$LOCAL_DIR"/scince_2020
for i in {0..32}
do
echo "Downloading ${states[$i]}..."
# The INEGI uses a leading zero for all one digit numbers
if [ "$i" -lt 10 ]
then
FILENUM="0$i"
else
FILENUM="$i"
fi
curl -sLo "$TEMP_DIR"/scince_$FILENUM.exe \
https://gaia.inegi.org.mx/scince2020desktop/$FILENUM/SCINCE2020_DATOS_$FILENUM.exe
(cd "$TEMP_DIR" && \
"$TEMP_DIR"/innoextract-1.9-linux/innoextract \
--lowercase \
--silent "$TEMP_DIR"/scince_$FILENUM.exe)
find "$TEMP_DIR"/app -depth -type f -regextype posix-extended \
-regex '.*\.(dbf|cpg|prj|shp|rtree|shx)' \
-execdir sh -c 'mv $1 "$2"_$(basename $1)' _ {} "${states[$i]}" \;
DIR=$(find "$TEMP_DIR"/app -mindepth 1 -maxdepth 1 -type d -name '[0-9]*' -print)
mv "$DIR" "$LOCAL_DIR/scince_2020/${states[$i]}"
rm -rf "$TEMP_DIR"/app "$TEMP_DIR"/tmp
done
}
main() {
# Download innoextract 1.9
curl -sLo "$TEMP_DIR"/inno.tar.xz https://constexpr.org/innoextract/files/innoextract-1.9/innoextract-1.9-linux.tar.xz
# Check checksum
echo "008efe5011476ccc4aae17c3e22038b5a1bc5c7aad2b9d4d869537bf3874d21f inno.tar.xz" | sha256sum --check --status
tar -xf "$TEMP_DIR"/inno.tar.xz --directory "$TEMP_DIR"
# Download shapefiles
download_states
rm -rf "$TEMP_DIR"
}
main
# -6 Datos reservados por confidencialidad
# -7 No disponible (cuando toda el área tiene viviendas pendientes)
# -8 No disponible (Cuando toda el área tiene sólo viviendas deshabitadas o de uso temporal)
# -9 No aplica (Cuando no es calculable)
view raw scince_2020.sh hosted with ❤ by GitHub

Streets of Mexico City




Unless otherwise stated, the content of this page is licensed under the Creative Commons Attribution 3.0 License, and code samples are licensed under the Apache 2.0 License. Privacy policy

Disclaimer: This website is not affiliated with any of the organizations or institutions to which Diego Valle-Jones belongs. All opinions are my own.

Special Projects:

Blogs I like: