Diego Valle-Jones's Bloghttps://blog.diegovalle.net/2022-11-14T00:00:00+01:00Shapefiles from the 2020 INEGI Census2022-11-14T00:00:00+01:00Diego Valle-Jonestag:blog.diegovalle.net,2022-11-14:2022/11/inegi-mexico-2020-census-shapefiles.html<p><a href="/images/posts/inegi-census-shapefiles/mexico.jpg">
<img alt="Streets of Mexico City" class="image-process-article-image" src="/images/posts/inegi-census-shapefiles/derivatives/article-image/mexico.jpg"/>
</a></p>
<p>You can now download shapefiles of selected geographic areas from the
latest <span class="caps">INEGI</span> <a href="https://gaia.inegi.org.mx/scince2020/"><span class="caps">SCINCE</span></a>
database. In addition to geospatial information on state and
municipios, the files include <a href="https://www.inegi.org.mx/app/scitel/Default?ev=10"><span class="caps">AGEB</span> and
manzana</a>
boundaries. The files are available in shapefile format and include
demographic data</p>
<p>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.</p>
<p><br/>
</p><div id="envelope" style="border-color:#023F50;width:87%;margin:0;background-color:rgba(61, 121, 138, 1);padding:1em;font-family: 'PT Sans', sans-serif;">
<div class="mc_embed_signup" style="overflow: hidden;
text-align: left;">
<div class="form-top-left" style="float: left;
width: 75%;
padding-top: 25px;">
<h3 style="color:white;margin:0;font-family: 'PT Sans', sans-serif;">Subscribe to my <span class="free" style="color: #C7B720;">free</span> newsletter</h3>
<br/>
<p style="opacity:1;color:white;font-family: 'PT Sans', sans-serif;font-size:80%"><b>My email list is pretty simple: one email for each new post or project. If you join over 5,000 subscribers to my newsletter from Harvard, Stanford, Google, McKinsey, and many more, you’ll receive as a welcome gift the 100+ shapefiles described in this post (It’s more than <span class="caps"><span class="caps">7GB</span></span> of data and totally free)</b></p>
<p></p><ul style="opacity:1;color:white;font-family: 'PT Sans', sans-serif;font-size:80%">
<li>Shapefiles of Manzanas, AGEBs, Municipios, Estados, and more
</li>
<li>
The latest shapefiles from the 2020 Census
</li>
<li>Includes historical shapefiles from 2010 census</li>
<li><a href="https://www.diegovalle.net/privacy/">Privacy policy</a></li>
<li>Unsubscribe at any time</li>
<p></p></ul><p></p>
<!-- <p>Enter your email below to get instant access:</p> -->
</div>
<div class="form-top-right" style=" float: left;
width: 25%;
padding-top: 5px;
font-size: 66px;
color: #fff;
line-height: 100px;
text-align: right;
opacity: 0.3;">
<i class="fa fa-pencil"></i>
</div>
</div>
<div class="form-bottom">
<form action="https://www.diegovalle.net/api/newsletter" class="registration-form" id="Newsletter" method="post" novalidate="novalidate" role="form">
<!-- <div class="form-group">
<label class="sr-only" for="form-first-name">First name</label>
<input type="text" name="form-first-name" placeholder="First name..." class="form-first-name form-control" id="form-first-name">
</div>
<div class="form-group">
<label class="sr-only" for="form-last-name">Last name</label>
<input type="text" name="form-last-name" placeholder="Last name..." class="form-last-name form-control" id="form-last-name">
</div> -->
<div class="form-group">
<label for="email"><strong style="color:white;font-family: 'PT Sans', sans-serif;font-weight: 100;
font-size: 90%;">Where should I send the newsletter and shapefiles?</strong></label>
</div>
<div class="form-group">
<label class="sr-only" for="form-email" style=" position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0,0,0,0);
border: 0;">Email</label>
<input aria-required="true" class="form-email form-control" id="email" name="email" placeholder="Email..." required="" type="email"/>
</div>
<div style="position: absolute; left: -5000px;"><input name="website" style="height: 50px;margin: 0;padding: 0 20px;vertical-align: middle;background: #fff;border: 3px solid #fff;font-size: 16px;font-weight: 300;line-height: 50px;color: #888;-moz-border-radius: 4px;-webkit-border-radius: 4px;border-radius: 4px;-moz-box-shadow: none;-webkit-box-shadow: none;box-shadow: none;-o-transition: all .3s;-moz-transition: all .3s;-webkit-transition: all .3s;-ms-transition: all .3s;transition: all .3s;" tabindex="-1" type="text" value="fatcatseat2much"/>
<input name="referrer" tabindex="-1" type="text" value="2015shapefiles"/>
</div>
<input class="hiddenRecaptcha_post required" id="hiddenRecaptcha_post" name="hiddenRecaptcha_post" type="hidden"/>
<div class="g-recaptcha" data-sitekey="6LdhprAZAAAAAONu3rfxTPNGCIjjHbH06dqVerDd" id="recaptcha_post"></div><br/>
<button class="btn" style="height: 50px;margin: 0;padding: 0 20px;vertical-align: middle;border: 0;font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size: 16px;font-weight: 900;line-height: 50px;color: #fff;-moz-border-radius: 4px;-webkit-border-radius: 4px;border-radius: 4px;text-shadow: none;-moz-box-shadow: none;-webkit-box-shadow: none;box-shadow: none;-o-transition: all .3s;-moz-transition: all .3s;-webkit-transition: all .3s;-ms-transition: all .3s;transition: all .3s;" type="submit">Get your free newsletter</button>
</form>
</div>
</div>
<br/>
<p>If you use linux you can use the following script or if you’re unable to run the script you can always use the <a href="https://github.com/diegovalle/docker_scince_2020">docker</a> <a href="https://hub.docker.com/r/diegovalle/scince_2020">image</a></p>
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1</pre></div></td><td class="code"><div class="highlight"><pre>docker run -v <span class="s2">"</span><span class="k">$(</span><span class="nb">pwd</span><span class="k">)</span><span class="s2">/scince_2020"</span>:/scince_2020 diegovalle/scince_2020
</pre></div>
</td></tr></table>
<p><br/>
<style>
/<em> https://github.com/lonekorean/gist-syntax-themes </em>/
@import url('https://cdn.rawgit.com/lonekorean/gist-syntax-themes/d49b91b3/stylesheets/idle-fingers.css');</p>
<p>@import url('https://fonts.googleapis.com/css?family=Open+Sans');
body {
font: 16px 'Open Sans', sans-serif;
}
body .gist .gist-file {
border-color: #555 #555 #444
}
body .gist .gist-data {
border-color: #555
}
body .gist .gist-meta {
color: #ffffff;
background: #373737;
}
body .gist .gist-meta a {
color: #ffffff
}
body .gist .gist-data .pl-s .pl-s1 {
color: #a5c261
}
</style></p>
<script src="https://gist.github.com/diegovalle/af936552e0998174313154a2ea9e92a9.js"></script>
<p><a href="/images/posts/inegi-census-shapefiles/cdmx.jpg">
<img alt="Streets of Mexico City" class="image-process-article-image" src="/images/posts/inegi-census-shapefiles/derivatives/article-image/cdmx.jpg"/>
</a></p>Shapefiles from the 2015 Population Survey2016-01-27T00:00:00+01:00Diego Valle-Jonestag:blog.diegovalle.net,2016-01-27:2016/01/encuesta-intercensal-2015-shapefiles.html<p><a href="/images/posts/population-survey-shapefiles/df-streets.jpg">
<img alt="Streets and Services in the DF" class="image-process-article-image" src="/images/posts/population-survey-shapefiles/derivatives/article-image/df-streets.jpg"/>
</a></p>
<p>The <span class="caps">INEGI</span> just published the results of the latest <a href="http://www.inegi.org.mx/est/contenidos/proyectos/encuestas/hogares/especiales/ei2015/default.aspx">population survey</a>
along with updated shapefiles to reflect the changes to the
Mexican population. At the end of this post you’ll find a script to
download the updated manzanas (blocks), urban AGEBs, rural AGEBs, municipios,
streets (ejes viales), states, services, and localities
(localidades). It’s <span class="caps">7GB</span> of the latest shapefiles available for free!</p>
<p>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.
<br/>
</p><div id="envelope" style="border-color:#023F50;width:87%;margin:0;background-color:rgba(61, 121, 138, 1);padding:1em;font-family: 'PT Sans', sans-serif;">
<div class="mc_embed_signup" style="overflow: hidden;
text-align: left;">
<div class="form-top-left" style="float: left;
width: 75%;
padding-top: 25px;">
<h3 style="color:white;margin:0;font-family: 'PT Sans', sans-serif;">Subscribe to my <span class="free" style="color: #C7B720;">free</span> newsletter</h3>
<br/>
<p style="opacity:1;color:white;font-family: 'PT Sans', sans-serif;font-size:80%"><b>My email list is pretty simple: one email for each new post or project. If you join over 5,000 subscribers to my newsletter from Harvard, Stanford, Google, McKinsey, and many more, you’ll receive as a welcome gift the 100+ shapefiles described in this post (It’s more than <span class="caps"><span class="caps">7GB</span></span> of data and totally free)</b></p>
<p></p><ul style="opacity:1;color:white;font-family: 'PT Sans', sans-serif;font-size:80%">
<li>Shapefiles of Manzanas, AGEBs, Municipios, Estados, and more
</li>
<li>
The latest shapefiles from the 2020 Census
</li>
<li>Includes historical shapefiles from 2010 census</li>
<li><a href="https://www.diegovalle.net/privacy/">Privacy policy</a></li>
<li>Unsubscribe at any time</li>
<p></p></ul><p></p>
<!-- <p>Enter your email below to get instant access:</p> -->
</div>
<div class="form-top-right" style=" float: left;
width: 25%;
padding-top: 5px;
font-size: 66px;
color: #fff;
line-height: 100px;
text-align: right;
opacity: 0.3;">
<i class="fa fa-pencil"></i>
</div>
</div>
<div class="form-bottom">
<form action="https://www.diegovalle.net/api/newsletter" class="registration-form" id="Newsletter" method="post" novalidate="novalidate" role="form">
<!-- <div class="form-group">
<label class="sr-only" for="form-first-name">First name</label>
<input type="text" name="form-first-name" placeholder="First name..." class="form-first-name form-control" id="form-first-name">
</div>
<div class="form-group">
<label class="sr-only" for="form-last-name">Last name</label>
<input type="text" name="form-last-name" placeholder="Last name..." class="form-last-name form-control" id="form-last-name">
</div> -->
<div class="form-group">
<label for="email"><strong style="color:white;font-family: 'PT Sans', sans-serif;font-weight: 100;
font-size: 90%;">Where should I send the newsletter and shapefiles?</strong></label>
</div>
<div class="form-group">
<label class="sr-only" for="form-email" style=" position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0,0,0,0);
border: 0;">Email</label>
<input aria-required="true" class="form-email form-control" id="email" name="email" placeholder="Email..." required="" type="email"/>
</div>
<div style="position: absolute; left: -5000px;"><input name="website" style="height: 50px;margin: 0;padding: 0 20px;vertical-align: middle;background: #fff;border: 3px solid #fff;font-size: 16px;font-weight: 300;line-height: 50px;color: #888;-moz-border-radius: 4px;-webkit-border-radius: 4px;border-radius: 4px;-moz-box-shadow: none;-webkit-box-shadow: none;box-shadow: none;-o-transition: all .3s;-moz-transition: all .3s;-webkit-transition: all .3s;-ms-transition: all .3s;transition: all .3s;" tabindex="-1" type="text" value="fatcatseat2much"/>
<input name="referrer" tabindex="-1" type="text" value="2015shapefiles"/>
</div>
<input class="hiddenRecaptcha_post required" id="hiddenRecaptcha_post" name="hiddenRecaptcha_post" type="hidden"/>
<div class="g-recaptcha" data-sitekey="6LdhprAZAAAAAONu3rfxTPNGCIjjHbH06dqVerDd" id="recaptcha_post"></div><br/>
<button class="btn" style="height: 50px;margin: 0;padding: 0 20px;vertical-align: middle;border: 0;font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size: 16px;font-weight: 900;line-height: 50px;color: #fff;-moz-border-radius: 4px;-webkit-border-radius: 4px;border-radius: 4px;text-shadow: none;-moz-box-shadow: none;-webkit-box-shadow: none;box-shadow: none;-o-transition: all .3s;-moz-transition: all .3s;-webkit-transition: all .3s;-ms-transition: all .3s;transition: all .3s;" type="submit">Get your free newsletter</button>
</form>
</div>
</div>
<br/>
<p><a href="/images/posts/population-survey-shapefiles/muns.png">
<img alt="States and municipios of Mexico" class="image-process-article-image" src="/images/posts/population-survey-shapefiles/derivatives/article-image/muns.png"/>
</a></p>
<p>The script creates a directory for each of the 32 states and
Federal District where you’ll find all the shapefiles.</p>
<table>
<thead>
<tr>
<th>File</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>entidad</td>
<td>Entidad (states)</td>
</tr>
<tr>
<td>municipio</td>
<td>Municipio (counties)</td>
</tr>
<tr>
<td>localidad_urbana_y_rural_amanzanada</td>
<td>Localidad Urbana y Rural Amanzanada</td>
</tr>
<tr>
<td>localidad_rural_no_amanzanada</td>
<td>Localidad Rural</td>
</tr>
<tr>
<td>ageb_urbana</td>
<td>Área Geoestadística Básica (<span class="caps">AGEB</span>) [census tracts]</td>
</tr>
<tr>
<td>ageb_rural</td>
<td>Área Geoestadística Básica Rural (<span class="caps">AGEB</span>) [census tracts]</td>
</tr>
<tr>
<td>manzana</td>
<td>Polígonos de Manzanas (census blocks)</td>
</tr>
<tr>
<td>frentes_de_manazana</td>
<td>Frentes de Manzana (census blocks)</td>
</tr>
<tr>
<td>eje_vial</td>
<td>Ejes de vialidad (streets)</td>
</tr>
<tr>
<td>servicios_area</td>
<td>Servicios con Información complementaria de tipo Área (Áreas Verdes, Camellones, glorietas)</td>
</tr>
<tr>
<td>servicios_linea</td>
<td>Servicios con Información complementaria de tipo Línea (Ríos, Ferrocarriles)</td>
</tr>
<tr>
<td>servicios_puntual</td>
<td>Servicios con Información complementaria de tipo Puntual (Palacios Municipales o Ayudantías, Parques o Jardines)</td>
</tr>
<tr>
<td>territorio_insular</td>
<td>Territorio Insular (insular territory)</td>
</tr>
</tbody>
</table>
<p>The shapefiles didn’t change much from 2010 to 2015, but there were a few changes. Here’s and example of new services in Cancún (new ones are yellow):</p>
<p><a href="/images/posts/population-survey-shapefiles/cancun.jpg">
<img alt="Cancún" class="image-process-article-image" src="/images/posts/population-survey-shapefiles/derivatives/article-image/cancun.jpg"/>
</a></p>
<p><small></small></p>
<p>Like I said, there weren’t that many changes. Urban and rural AGEBs in Jalisco:</p>
<p><a href="/images/posts/population-survey-shapefiles/jal.jpg">
<img alt="Jalisco" class="image-process-article-image" src="/images/posts/population-survey-shapefiles/derivatives/article-image/jal.jpg"/>
</a></p>
<p>Urban AGEBs and roads in Baja California:</p>
<p><a href="/images/posts/population-survey-shapefiles/bc.jpg">
<img alt="Baja California AGEB" class="image-process-article-image" src="/images/posts/population-survey-shapefiles/derivatives/article-image/bc.jpg"/>
</a></p>
<p>Manzanas (blocks) in Morelos:</p>
<p><a href="/images/posts/population-survey-shapefiles/mor.jpg">
<img alt="Morelos" class="image-process-article-image" src="/images/posts/population-survey-shapefiles/derivatives/article-image/mor.jpg"/>
</a></p>
<p>Roads, localidades, rural and urban AGEBs in Acapulco:</p>
<p><a href="/images/posts/population-survey-shapefiles/gro.jpg">
<img alt="Acapulco" class="image-process-article-image" src="/images/posts/population-survey-shapefiles/derivatives/article-image/gro.jpg"/>
</a></p>
<p>Since the shapefiles are divided by state, you can use the bash code
below to merge all the individual state shapefiles into one big
national file.</p>
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18</pre></div></td><td class="code"><div class="highlight"><pre><span class="c">#! /bin/bash</span>
<span class="c"># The filename of the merged file</span>
<span class="nv">FILEOUT</span><span class="o">=</span><span class="s2">"municipio.shp"</span>
<span class="c"># The names of the files to merge, you can change this to</span>
<span class="c"># "*entidad.shp" or "*eje_vial.shp", etc</span>
<span class="nv">TYPE</span><span class="o">=</span><span class="s2">"*municipio.shp"</span>
<span class="k">for</span> i in <span class="k">$(</span>find . -maxdepth <span class="m">3</span> -name <span class="nv">$TYPE</span><span class="k">)</span>
<span class="k">do</span>
<span class="k">if</span> <span class="o">[</span> -f <span class="s2">"</span><span class="nv">$FILEOUT</span><span class="s2">"</span> <span class="o">]</span>
<span class="k">then</span>
<span class="nb">echo</span> <span class="s2">"adding state </span><span class="nv">$i</span><span class="s2"> to </span><span class="nv">$FILEOUT</span><span class="s2">"</span>
ogr2ogr -f <span class="s1">'ESRI Shapefile'</span> -update -append <span class="nv">$FILEOUT</span> <span class="nv">$i</span> -nln <span class="k">$(</span>basename -s .shp <span class="nv">$FILEOUT</span><span class="k">)</span>
<span class="k">else</span>
<span class="nb">echo</span> <span class="s2">"startin merge..."</span>
<span class="nb">echo</span> <span class="s2">"adding state </span><span class="nv">$i</span><span class="s2"> to </span><span class="nv">$FILEOUT</span><span class="s2">"</span>
ogr2ogr -f <span class="s1">'ESRI Shapefile'</span> <span class="nv">$FILEOUT</span> <span class="nv">$i</span>
<span class="k">fi</span>
<span class="k">done</span>
</pre></div>
</td></tr></table>
<p>All shapefiles come from the <span class="caps">INEGI</span>’s “Cartografía Geoestadística
Urbana y Rural Amanzanada. Cierre de la Encuesta Intercensal 2015.”
Here’s the code to download them:</p>
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111</pre></div></td><td class="code"><div class="highlight"><pre><span class="c">#! /bin/bash</span>
<span class="c"># Author: Diego Valle-Jones</span>
<span class="c"># Web: https://www.diegovalle.net</span>
<span class="c"># LICENSE: Apache 2.0</span>
<span class="c"># Purpose: Download shapefiles of manzanas (blocks), agebs (census areas), ejes</span>
<span class="c"># viales (streets), interesting areas and a whole bunch of other stuff from</span>
<span class="c"># the Encuesta Intercensal 2015</span>
<span class="c"># As of now, this script has not been tested on Windows,</span>
<span class="c"># only on Ubuntu and Macs. The script will create a directory</span>
<span class="c"># called 'shps' where all the shapefiles are located, if something</span>
<span class="c"># goes wrong when dowloading be sure to delete it and try again</span>
<span class="c">#Exit on error</span>
<span class="nb">set</span> -e
<span class="c"># Projection compatible with Google Maps</span>
<span class="nv">PROJECTION</span><span class="o">=</span><span class="s2">"+proj=longlat +ellps=WGS84 +no_defs +towgs84=0,0,0"</span>
<span class="c"># wget command</span>
<span class="nv">CURL</span><span class="o">=</span><span class="s2">"curl"</span>
<span class="c">#The way the INEGI download url starts</span>
<span class="nv">URL</span><span class="o">=</span><span class="s2">"http://internet.contenidos.inegi.org.mx/contenidos/productos//prod_serv/contenidos/espanol/bvinegi/productos/geografia/Cinter_2015/"</span>
<span class="c">#File ends in</span>
<span class="nv">SUFFIX</span><span class="o">=</span><span class="s2">"_s.zip"</span>
<span class="c">#States as numbers</span>
<span class="c">#I have no idea why the INEGI used these numbers to represent the states</span>
<span class="nb">declare</span> -a <span class="nv">states_numbers</span><span class="o">=(</span><span class="s2">"702825209025"</span> <span class="s2">"702825209032"</span> <span class="s2">"702825209049"</span> <span class="s2">"702825209056"</span> <span class="s2">"702825209087"</span> <span class="s2">"702825209094"</span> <span class="s2">"702825209063"</span> <span class="s2">"702825209070"</span> <span class="s2">"702825209100"</span> <span class="s2">"702825209117"</span> <span class="s2">"702825209124"</span> <span class="s2">"702825209131"</span> <span class="s2">"702825209148"</span> <span class="s2">"702825209155"</span> <span class="s2">"702825209162"</span> <span class="s2">"702825209179"</span> <span class="s2">"702825209186"</span> <span class="s2">"702825209193"</span> <span class="s2">"702825209209"</span> <span class="s2">"702825209216"</span> <span class="s2">"702825209223"</span> <span class="s2">"702825209230"</span> <span class="s2">"702825209247"</span> <span class="s2">"702825209254"</span> <span class="s2">"702825209261"</span> <span class="s2">"702825209278"</span> <span class="s2">"702825209285"</span> <span class="s2">"702825209292"</span> <span class="s2">"702825209308"</span> <span class="s2">"702825209315"</span> <span class="s2">"702825209322"</span> <span class="s2">"702825209339"</span><span class="o">)</span>
<span class="c">#State names in the URL</span>
<span class="nb">declare</span> -a <span class="nv">state_names</span><span class="o">=(</span><span class="s2">"Aguascalientes"</span> <span class="s2">"Baja_California"</span> <span class="s2">"Baja_California_Sur"</span> <span class="s2">"Campeche"</span> <span class="s2">"Coahuila_de_Zaragoza"</span> <span class="s2">"Colima"</span> <span class="s2">"Chiapas"</span> <span class="s2">"Chihuahua"</span> <span class="s2">"Distrito_Federal"</span> <span class="s2">"Durango"</span> <span class="s2">"Guanajuato"</span> <span class="s2">"Guerrero"</span> <span class="s2">"Hidalgo"</span> <span class="s2">"Jalisco"</span> <span class="s2">"Mexico"</span> <span class="s2">"Michoacan_de_Ocampo"</span> <span class="s2">"Morelos"</span> <span class="s2">"Nayarit"</span> <span class="s2">"Nuevo_Leon"</span> <span class="s2">"Oaxaca"</span> <span class="s2">"Puebla"</span> <span class="s2">"Queretaro"</span> <span class="s2">"Quintana_Roo"</span> <span class="s2">"San_Luis_Potosi"</span> <span class="s2">"Sinaloa"</span> <span class="s2">"Sonora"</span> <span class="s2">"Tabasco"</span> <span class="s2">"Tamaulipas"</span> <span class="s2">"Tlaxcala"</span> <span class="s2">"Veracruz_de_Ignacio_de_la_Llave"</span> <span class="s2">"Yucatan"</span> <span class="s2">"Zacatecas"</span> <span class="o">)</span>
<span class="c"># The list of shapefiles of manzanas, agebs, etc</span>
<span class="nb">declare</span> -a <span class="nv">files</span><span class="o">=(</span><span class="s2">"ar.shp"</span> <span class="s2">"ent.shp"</span> <span class="s2">"lpr.shp"</span> <span class="s2">"m.shp"</span> <span class="s2">"fm.shp"</span> <span class="s2">"sia.shp"</span> <span class="s2">"sip.shp"</span>
<span class="s2">"a.shp"</span> <span class="s2">"e.shp"</span> <span class="s2">"l.shp"</span> <span class="s2">"mun.shp"</span> <span class="s2">"sil.shp"</span> <span class="s2">"territorioinsular.shp"</span><span class="o">)</span><span class="p">;</span>
<span class="c">#The INEGI filenames are unreadable</span>
<span class="nb">declare</span> -a <span class="nv">files_nice</span><span class="o">=(</span><span class="s2">"ageb_rural.shp"</span> <span class="s2">"entidad.shp"</span> <span class="s2">"localidad_rural_no_amanzanada.shp"</span> <span class="s2">"manzana.shp"</span> <span class="s2">"frente_de_manzana.shp"</span> <span class="s2">"servicios_area.shp"</span> <span class="s2">"servicios_puntual.shp"</span>
<span class="s2">"ageb_urbana.shp"</span> <span class="s2">"eje_vial.shp"</span> <span class="s2">"localidad_urbana_y_rural_amanzanada.shp"</span> <span class="s2">"municipio.shp"</span> <span class="s2">"servicios_linea.shp"</span> <span class="s2">"territorio_insular.shp"</span><span class="o">)</span><span class="p">;</span>
<span class="c"># State abbreviations</span>
<span class="nb">declare</span> -a <span class="nv">states</span><span class="o">=(</span><span class="s2">"ags"</span> <span class="s2">"bc"</span> <span class="s2">"bcs"</span> <span class="s2">"camp"</span> <span class="s2">"coah"</span> <span class="s2">"col"</span> <span class="s2">"chis"</span> <span class="s2">"chih"</span>
<span class="s2">"df"</span> <span class="s2">"dgo"</span> <span class="s2">"gto"</span> <span class="s2">"gro"</span> <span class="s2">"hgo"</span> <span class="s2">"jal"</span> <span class="s2">"mex"</span> <span class="s2">"mich"</span> <span class="s2">"mor"</span> <span class="s2">"nay"</span> <span class="s2">"nl"</span> <span class="s2">"oax"</span>
<span class="s2">"pue"</span> <span class="s2">"qro"</span> <span class="s2">"qroo"</span> <span class="s2">"slp"</span> <span class="s2">"sin"</span> <span class="s2">"son"</span> <span class="s2">"tab"</span> <span class="s2">"tamps"</span> <span class="s2">"tlax"</span> <span class="s2">"ver"</span> <span class="s2">"yuc"</span>
<span class="s2">"zac"</span><span class="o">)</span><span class="p">;</span>
<span class="nb">declare</span> -a <span class="nv">state_num</span><span class="o">=(</span><span class="sb">`</span>seq -s <span class="s2">" "</span> -w <span class="m">1</span> 32<span class="sb">`</span><span class="o">)</span><span class="p">;</span>
<span class="c"># Use gdal to reproject, and then rename the shapefiles to include</span>
<span class="c"># a user friendly abbreviation instead of a number</span>
<span class="c"># First argument: directory of shapefiles shps/state_abbreviation</span>
<span class="c"># Second argument: the state abbreviation</span>
<span class="c"># Third argument: the shapefiles inside the zip file as an array</span>
<span class="c"># Fourth argument: the state number</span>
<span class="c"># TODO: convert the encoding from windows-1252 to utf-8</span>
<span class="k">function</span> reproject <span class="o">{</span>
<span class="nv">name</span><span class="o">=</span><span class="nv">$3</span><span class="o">[</span>@<span class="o">]</span>
<span class="nv">arr</span><span class="o">=(</span><span class="s2">"</span><span class="si">${</span><span class="p">!name</span><span class="si">}</span><span class="s2">"</span><span class="o">)</span>
<span class="nv">len</span><span class="o">=</span><span class="sb">`</span>expr <span class="si">${#</span><span class="nv">files</span><span class="p">[*]</span><span class="si">}</span> - 1<span class="sb">`</span>
<span class="c"># Has to match he number of files in the array</span>
<span class="k">for</span> i in <span class="sb">`</span>seq <span class="m">0</span> <span class="nv">$len</span><span class="sb">`</span>
<span class="k">do</span>
<span class="k">if</span> <span class="o">[</span> -f <span class="nv">$1</span>/conjunto_de_datos/<span class="nv">$4</span><span class="si">${</span><span class="nv">files</span><span class="p">[</span><span class="nv">$i</span><span class="p">]</span><span class="si">}</span> <span class="o">]</span><span class="p">;</span>
<span class="k">then</span>
<span class="nb">echo</span> <span class="s2">"Creating... "</span> <span class="s2">"</span><span class="nv">$1</span><span class="s2">"</span>/<span class="nv">$2_</span><span class="si">${</span><span class="nv">files_nice</span><span class="p">[</span><span class="nv">$i</span><span class="p">]</span><span class="si">}</span>
ogr2ogr <span class="s2">"</span><span class="nv">$1</span><span class="s2">"</span>/<span class="nv">$2_</span><span class="si">${</span><span class="nv">files_nice</span><span class="p">[</span><span class="nv">$i</span><span class="p">]</span><span class="si">}</span> <span class="nv">$1</span>/conjunto_de_datos/<span class="nv">$4</span><span class="si">${</span><span class="nv">files</span><span class="p">[</span><span class="nv">$i</span><span class="p">]</span><span class="si">}</span> -t_srs <span class="s2">"</span><span class="nv">$PROJECTION</span><span class="s2">"</span>
<span class="k">else</span>
<span class="nb">echo</span> <span class="s2">"No territorio insular in "</span> <span class="s2">"</span><span class="nv">$1</span><span class="s2">"</span>/<span class="nv">$2_</span><span class="si">${</span><span class="nv">files_nice</span><span class="p">[</span><span class="nv">$i</span><span class="p">]</span><span class="si">}</span>
<span class="k">fi</span>
<span class="k">done</span>
rm -rf <span class="s2">"</span><span class="nv">$1</span><span class="s2">"</span>/conjunto_de_datos
<span class="o">}</span>
<span class="nv">counter</span><span class="o">=</span>0
<span class="k">for</span> state_number in <span class="s2">"</span><span class="si">${</span><span class="nv">states_numbers</span><span class="p">[@]</span><span class="si">}</span><span class="s2">"</span>
<span class="k">do</span>
<span class="nv">FILENAME</span><span class="o">=</span><span class="s2">"</span><span class="nv">$URL</span><span class="si">${</span><span class="nv">state_names</span><span class="p">[</span><span class="nv">$counter</span><span class="p">]</span><span class="si">}</span><span class="s2">/</span><span class="nv">$state_number$SUFFIX</span><span class="s2">"</span>
<span class="c"># download the files from the inegi server.</span>
<span class="nv">$CURL</span> <span class="nv">$FILENAME</span> -o <span class="si">${</span><span class="nv">states</span><span class="p">[</span><span class="nv">$counter</span><span class="p">]</span><span class="si">}</span>.zip
<span class="c"># Extract the shapefiles from the zip file</span>
mkdir -p shps/<span class="si">${</span><span class="nv">states</span><span class="p">[</span><span class="nv">$counter</span><span class="p">]</span><span class="si">}</span>
unzip -o -L <span class="si">${</span><span class="nv">states</span><span class="p">[</span><span class="nv">$counter</span><span class="p">]</span><span class="si">}</span>.zip -d shps/<span class="si">${</span><span class="nv">states</span><span class="p">[</span><span class="nv">$counter</span><span class="p">]</span><span class="si">}</span>
reproject shps/<span class="si">${</span><span class="nv">states</span><span class="p">[</span><span class="nv">$counter</span><span class="p">]</span><span class="si">}</span> <span class="si">${</span><span class="nv">states</span><span class="p">[</span><span class="nv">$counter</span><span class="p">]</span><span class="si">}</span> files <span class="si">${</span><span class="nv">state_num</span><span class="p">[</span><span class="nv">$counter</span><span class="p">]</span><span class="si">}</span>
<span class="nv">counter</span><span class="o">=</span><span class="sb">`</span>expr <span class="nv">$counter</span> + 1<span class="sb">`</span>
<span class="k">done</span>
<span class="c"># Delete the downloaded zip files</span>
rm -rf *.zip
<span class="c"># You could use the code below to merge all the states into one giant</span>
<span class="c"># shapefile of Mexico. Change "*localidad_urbana.shp" to</span>
<span class="c"># '*ageb_urbana.shp' or '*eje_vial.shp' or whatever</span>
<span class="c">#</span>
<span class="c"># FILEOUT="municipio.shp"</span>
<span class="c"># TYPE="*municipio.shp"</span>
<span class="c"># for i in $(find . -maxdepth 3 -name $TYPE)</span>
<span class="c"># do</span>
<span class="c"># if [ -f "$FILEOUT" ]</span>
<span class="c"># then</span>
<span class="c"># echo "adding state $i to $FILEOUT"</span>
<span class="c"># ogr2ogr -f 'ESRI Shapefile' -update -append $FILEOUT $i -nln $(basename -s .shp $FILEOUT)</span>
<span class="c"># else</span>
<span class="c"># echo "startin merge..."</span>
<span class="c"># echo "adding state $i to $FILEOUT"</span>
<span class="c"># ogr2ogr -f 'ESRI Shapefile' $FILEOUT $i</span>
<span class="c"># fi</span>
<span class="c"># done</span>
</pre></div>
</td></tr></table>
<p><strong><span class="caps">P.S.</span></strong> The frente de manzana shapefile for Sonora contains an error
in its attribute table, hopefully the <span class="caps">INEGI</span> will fix it in a future version.</p>
<p><strong><span class="caps">P.P.S.</span></strong> Unlike the
<a href="https://blog.diegovalle.net/2013/06/shapefiles-of-mexico-agebs-manzanas-etc.html">2010 census shapefiles</a>,
these ones don’t contain demographic variables. (the Encuesta
Intercensal is valid for all municipios and the localidades with more
than 50,000 people)</p>Shapefiles of Mexico (AGEBs, Manzanas, etc)2013-06-24T00:00:00+02:00Diego Valle-Jonestag:blog.diegovalle.net,2013-06-24:2013/06/shapefiles-of-mexico-agebs-manzanas-etc.html<div class="post-body entry-content" itemprop="articleBody">
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/1.bp.blogspot.com_-FqW_5Q4FoYc_Ub5TFpkun5I_AAAAAAAAGVE_uimPXrWpJMI_s1600_df_localidades.png"><img border="0" height="297" src="/images/blogger_images/1.bp.blogspot.com_-FqW_5Q4FoYc_Ub5TFpkun5I_AAAAAAAAGVE_uimPXrWpJMI_s400_df_localidades.png" width="400"></a>
</div>
My post on how to <a href="http://blog.diegovalle.net/2013/02/download-shapefiles-of-mexico.html">download electoral shapefiles</a> proved to be very popular, so I decided to create <a href="https://gist.github.com/diegovalle/5843688">another script</a> to download shapefiles of census geographies. This is <b></b>all data that is freely available from the <span class="caps">INEGI</span> website, it’s just that they make it really hard to find, it’s only downloadable as a compressed windows executable, and the download links for the files tend to change every few months.<br>
<a id="more" name="more"></a><br>
The shapefiles are encoded as codepage 1252 and were reprojected to <span class="caps">WGS84</span>. All data corresponds to the 2010 census.<br>
<br>
<div id="envelope" style="border-color:#023F50;width:87%;margin:0;background-color:rgba(61, 121, 138, 1);padding:1em;font-family: 'PT Sans', sans-serif;">
<div class="mc_embed_signup" style="overflow: hidden; text-align: left;">
<div class="form-top-left" style="float: left; width: 75%; padding-top: 25px;">
<h3 style="color:white;margin:0;font-family: 'PT Sans', sans-serif;">Subscribe to my <span class="free" style="color: #C7B720;">free</span> newsletter</h3>
<br>
<img alt="Mexico Shapefiles - Manzanas, AGEB, Estados, Municipios" height="216" src="/images/free-shapefiles-box.png" width="147">
<p style="opacity:1;color:white;font-family: 'PT Sans', sans-serif;font-size:80%"><b>My email list is pretty simple: one email for each new post or project. If you join over 5,000 subscribers from Harvard, Stanford, Google, McKinsey… you’ll receive as a welcome gift the 100+ shapefiles of Mexico you will ever need (It’s more than <span class="caps">5GB</span> of data and totally free)</b></p>
<p></p>
<ul style="opacity:1;color:white;font-family: 'PT Sans', sans-serif;font-size:80%">
<li>Shapefiles of Manzanas, AGEBs, Municipios, Estados, and more</li>
<li>Secciones and Distritos in shapefile form</li>
<li>Database including population and a lot more variables from the 2010 census</li>
<li>Over 5.5 Gigabytes of shapefiles</li>
<li><a href="https://www.diegovalle.net/privacy/">Privacy policy</a></li>
<li>Unsubscribe at any time</li>
</ul>
<p></p>
<!-- <p>Enter your email below to get instant access:</p> -->
</div>
<div class="form-top-right" style=" float: left; width: 25%; padding-top: 5px; font-size: 66px; color: #fff; line-height: 100px; text-align: right; opacity: 0.3;">
<i class="fa fa-pencil"></i>
</div>
</div>
<div class="form-bottom">
<form action="https://www.diegovalle.net/api/newsletter" class="registration-form" id="Newsletter" method="post" name="Newsletter" novalidate="novalidate" role="form">
<div class="form-group">
<label for="email"><strong style="color:white;font-family: 'PT Sans', sans-serif;font-weight: 100; font-size: 90%;">Where should I send the newsletter and free shapefiles?</strong></label>
</div>
<div class="form-group">
<label class="sr-only" for="form-email" style=" position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0;">Email</label> <input aria-required="true" class="form-email form-control" id="email" name="email" placeholder="Email..." required="" type="email">
</div>
<div style="position: absolute; left: -5000px;">
<input name="website" style="height: 50px;margin: 0;padding: 0 20px;vertical-align: middle;background: #fff;border: 3px solid #fff;font-size: 16px;font-weight: 300;line-height: 50px;color: #888;-moz-border-radius: 4px;-webkit-border-radius: 4px;border-radius: 4px;-moz-box-shadow: none;-webkit-box-shadow: none;box-shadow: none;-o-transition: all .3s;-moz-transition: all .3s;-webkit-transition: all .3s;-ms-transition: all .3s;transition: all .3s;" tabindex="-1" type="text" value="fatcatseat2much"> <input name="referrer" tabindex="-1" type="text" value="shapefiles-of-mexico-ageb">
</div>
<input class="hiddenRecaptcha_post required" id="hiddenRecaptcha_post" name="hiddenRecaptcha_post" type="hidden">
<div class="g-recaptcha" data-sitekey="6LdhprAZAAAAAONu3rfxTPNGCIjjHbH06dqVerDd" id="recaptcha_post"></div>
<br>
<button class="btn" style="height: 50px;margin: 0;padding: 0 20px;vertical-align: middle;border: 0;font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size: 16px;font-weight: 900;line-height: 50px;color: #fff;-moz-border-radius: 4px;-webkit-border-radius: 4px;border-radius: 4px;text-shadow: none;-moz-box-shadow: none;-webkit-box-shadow: none;box-shadow: none;" type="submit">Send me the newsletter</button>
</form>
</div>
</div>
<br>
</div>
<p>Now for the ugly bits: You’ll need a recent version of <a href="http://constexpr.org/innoextract/">innoextract</a>, one that can work with files created by version 5.5 of Inno Setup (yes, the <span class="caps">INEGI</span> distributes shapefiles as windows installers), the one in Ubuntu universe is not recent enough. The version available from <a href="https://launchpad.net/~arx/+archive/release">this repository</a> should work.</p>
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
2
3
4</pre></div></td><td class="code"><div class="highlight"><pre>sudo add-apt-repository ppa:arx/release
sudo apt-get update
sudo apt-get install innoextract
chmod +x download-census-shp.sh
</pre></div>
</td></tr></table>
<p><strike>As of now, this script has not been tested on Windows and Mac systems, only on Ubuntu.</strike> This script has been tested on Ubuntu, on a Mac you should try and use ‘brew install wget’ and ‘brew install rename’ before running it, and on Windows use cygwin. </p>
<p>The script will create a directory called <code>shps</code> where all the shapefiles are located, if something goes wrong when downloading be sure to delete it and try again. Once you finish running the script you’ll end up with about 5.5 gigabytes of shapefiles containing all available levels of geographical granularity for the 2010 Mexican census.<br></p>
<h3>Census Geographies:</h3>
<p><i>States -> Municipios (Counties) -> Localidades (Polygon if urban otherwise point) -> <span class="caps">AGEB</span> (Census Areas - Urban only) -> Manzana (Census Blocks - Urban only)</i></p>
<p>Plus, you’ll also get a bunch of shapefiles of parks, rivers, schools, etc.</p>
<p><a href="/images/blogger_images/2.bp.blogspot.com_-0jvTTH6J9s4_Ub5UXd_70YI_AAAAAAAAGVc_Aj3P5T2Lctk_s1600_estados.png"><img border="0" height="297" src="/images/blogger_images/2.bp.blogspot.com_-0jvTTH6J9s4_Ub5UXd_70YI_AAAAAAAAGVc_Aj3P5T2Lctk_s400_estados.png" width="400"></a></p>
<p>Municipios (Counties)</p>
<p><a href="/images/blogger_images/3.bp.blogspot.com_-akm0LuNkMWw_Ub5Ua_AygHI_AAAAAAAAGVk_wc-K1bizeEQ_s1600_df_municipios.png"><img border="0" height="297" src="/images/blogger_images/3.bp.blogspot.com_-akm0LuNkMWw_Ub5Ua_AygHI_AAAAAAAAGVk_wc-K1bizeEQ_s400_df_municipios.png" width="400"></a></p>
<p>Localidades</span> (Urban Polygons and Rural Points)</p>
<p><a href="/images/blogger_images/4.bp.blogspot.com_-FqW_5Q4FoYc_Ub5TFpkun5I_AAAAAAAAGVI_V8c5AMgt_VU_s1600_df_localidades.png"><img border="0" height="297" src="/images/blogger_images/4.bp.blogspot.com_-FqW_5Q4FoYc_Ub5TFpkun5I_AAAAAAAAGVI_V8c5AMgt_VU_s400_df_localidades.png" width="400"></a></p>
<p><span class="caps">AGEB</span> (Census Areas)</p>
<p><a href="/images/blogger_images/3.bp.blogspot.com_-Lp1ib2NP6lI_Ub5UkaTjvEI_AAAAAAAAGVs_JFc1DE1xc90_s1600_df_ageb.png" style="margin-left: auto; margin-right: auto;"><img border="0" height="297" src="/images/blogger_images/3.bp.blogspot.com_-Lp1ib2NP6lI_Ub5UkaTjvEI_AAAAAAAAGVs_JFc1DE1xc90_s400_df_ageb.png" width="400"></a></p>
<p>Manzanas (Blocks)</p>
<p><a href="/images/blogger_images/4.bp.blogspot.com_-edZ6rWmRHCE_Ub5Uoq4OPZI_AAAAAAAAGV0_hn_CjZhvzh8_s1600_df_manazana.png" style="margin-left: auto; margin-right: auto;"><img border="0" height="297" src="/images/blogger_images/4.bp.blogspot.com_-edZ6rWmRHCE_Ub5Uoq4OPZI_AAAAAAAAGV0_hn_CjZhvzh8_s400_df_manazana.png" width="400"></a></p>
<p>Ejes viales (Streets)</p>
<p><a href="/images/blogger_images/4.bp.blogspot.com_-DHf-oy9VV8w_Ub5UsPc09II_AAAAAAAAGV8_4HFdGYzcngU_s1600_df_eje_vial.png" style="margin-left: auto; margin-right: auto;"><img border="0" height="238" src="/images/blogger_images/4.bp.blogspot.com_-DHf-oy9VV8w_Ub5UsPc09II_AAAAAAAAGV8_4HFdGYzcngU_s320_df_eje_vial.png" width="320"></a></p>
<h3>Servicios A (polygons and lines)</h3>
<p>Camellón, Metro Station, Hospitals, Parks, Schools, etc</p>
<p><a href="/images/blogger_images/1.bp.blogspot.com_-HKzr2CDRR0E_Ub5UwCOTBqI_AAAAAAAAGWE_u5Lc9uh0vgY_s1600_df_servicios_a.png" style="margin-left: auto; margin-right: auto;"><img border="0" height="297" src="/images/blogger_images/1.bp.blogspot.com_-HKzr2CDRR0E_Ub5UwCOTBqI_AAAAAAAAGWE_u5Lc9uh0vgY_s400_df_servicios_a.png" width="400"></a></p>
<h3>Servicios L (polygons and points)</h3>
<p>Bridges, Railways, Tren Metropolitano, Lindero, etc</p>
<p><a href="/images/blogger_images/1.bp.blogspot.com_-8_2yvfOSsPw_Ub5WSlOXiqI_AAAAAAAAGWs_T5tUgmGRkbs_s1600_df_servicios_l.png" style="margin-left: auto; margin-right: auto;"><img border="0" height="297" src="/images/blogger_images/1.bp.blogspot.com_-8_2yvfOSsPw_Ub5WSlOXiqI_AAAAAAAAGWs_T5tUgmGRkbs_s400_df_servicios_l.png" width="400"></a></p>
<h3>Servicios P (points)</h3>
<p>Churches, Schools, Hospitals, etc</p>
<p><a href="/images/blogger_images/2.bp.blogspot.com_-xGy74RIWEuM_Ub5U3iZ2zSI_AAAAAAAAGWM_YCPezZtix_o_s1600_df_servicios_p.png" style="margin-left: auto; margin-right: auto;"><img border="0" height="297" src="/images/blogger_images/2.bp.blogspot.com_-xGy74RIWEuM_Ub5U3iZ2zSI_AAAAAAAAGWM_YCPezZtix_o_s400_df_servicios_p.png" width="400"></a></p>
<p>Here’s the script you need to run to download the shapefiles:</p>
<script src="https://gist.github.com/diegovalle/5843688.js">
</script>
<p><br>
<span class="caps">P.S.</span> You can contact the <a href="https://twitter.com/INEGI_INFORMA"><span class="caps">INEGI</span></a> and tell them what you think of the way they distribute data.<br>
<span class="caps">P.P.S.</span> If you need shapefiles of elevation curves, archeological sites, rivers, etc, try this <a href="https://gist.github.com/diegovalle/5864549">other script</a></p>
<p><b><i>Update:</i></b> You can also use a docker image to run the script without having to install anything</p>
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
2
3
4
5
6</pre></div></td><td class="code"><div class="highlight"><pre>docker pull diegovalle/scince2010-docker
<span class="c"># shared directory to store the output</span>
mkdir /tmp/scince2010
<span class="c"># run ./download.sh within the container and the files should be ready</span>
<span class="c"># in /tmp/since2010</span>
docker run -v /tmp/scince2010:/shapefiles/shps -i -t diegovalle/scince2010-docker
</pre></div>
</td></tr></table>Download electoral shapefiles of Mexico (secciones, distritos, and colonias)2013-02-27T00:00:00+01:00Diego Valle-Jonestag:blog.diegovalle.net,2013-02-27:2013/02/download-shapefiles-of-mexico.html<div class="post-body entry-content" itemprop="articleBody">
<div id="envelope" style="border-color:#023F50;width:87%;margin:0;background-color:rgba(61, 121, 138, 1);padding:1em;font-family: 'PT Sans', sans-serif;">
<div class="mc_embed_signup" style="overflow: hidden;
text-align: left;">
<div class="form-top-left" style="float: left;
width: 75%;
padding-top: 25px;">
<h3 style="color:white;margin:0;font-family: 'PT Sans', sans-serif;"><span class="free" style="color: #C7B720;">Free</span> newsletter</h3>
<br><img src="/images/free-shapefiles-box.png" alt="Mexico Shapefiles - Manzanas, AGEB, Estados, Municipios" width="147" height="216">
<p style="opacity:1;color:white;font-family: 'PT Sans', sans-serif;font-size:80%"><b>My email list is pretty simple: one email for each new post or project. If you join over 5,000 subscribers from Harvard, Stanford, Google, McKinsey… you’ll receive as a welcome gift the 100+ shapefiles of Mexico mentioned in this post and any updates (It’s more than <span class="caps">5GB</span> of data and totally free)</b></p>
<p><ul style="opacity:1;color:white;font-family: 'PT Sans', sans-serif;font-size:80%">
<li>Secciones and Distritos in shapefile form</li>
<li>Shapefiles of Manzanas, AGEBs, Municipios, and Estados
</li>
<li>
Database including population and a lot more variables from the 2010 census
</li>
<li>Over 5.5 Gigabytes of shapefiles
</li>
<li><a href="https://gist.github.com/diegovalle/0ec566ad6f6b47dd450c">Política de privacidad</a></li>
<li>Unsubscribe at any time</li>
</ul></p>
<!-- <p>Enter your email below to get instant access:</p> -->
</div>
<div class="form-top-right" style=" float: left;
width: 25%;
padding-top: 5px;
font-size: 66px;
color: #fff;
line-height: 100px;
text-align: right;
opacity: 0.3;">
<i class="fa fa-pencil"></i>
</div>
</div>
<div class="form-bottom">
<form role="form" action="https://www.diegovalle.net/api/newsletter" method="post" class="registration-form" id="Newsletter" novalidate="novalidate">
<!-- <div class="form-group">
<label class="sr-only" for="form-first-name">First name</label>
<input type="text" name="form-first-name" placeholder="First name..." class="form-first-name form-control" id="form-first-name">
</div>
<div class="form-group">
<label class="sr-only" for="form-last-name">Last name</label>
<input type="text" name="form-last-name" placeholder="Last name..." class="form-last-name form-control" id="form-last-name">
</div> -->
<div class="form-group">
<label for="email"><strong style="color:white;font-family: 'PT Sans', sans-serif;font-weight: 100;
font-size: 90%;">Where should I send the newsletter and free shapefiles?</strong></label>
</div>
<div class="form-group">
<label class="sr-only" for="form-email" style=" position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0,0,0,0);
border: 0;">Email</label>
<input type="email" name="email" placeholder="Email..." class="form-email form-control" id="email" aria-required="true" required>
</div>
<div style="position: absolute; left: -5000px;"><input type="text" name="website" value="fatcatseat2much" tabindex="-1" style="height: 50px;margin: 0;padding: 0 20px;vertical-align: middle;background: #fff;border: 3px solid #fff;font-size: 16px;font-weight: 300;line-height: 50px;color: #888;-moz-border-radius: 4px;-webkit-border-radius: 4px;border-radius: 4px;-moz-box-shadow: none;-webkit-box-shadow: none;box-shadow: none;-o-transition: all .3s;-moz-transition: all .3s;-webkit-transition: all .3s;-ms-transition: all .3s;transition: all .3s;">
<input type="text" name="referrer" value="download-electoral-shapes" tabindex="-1">
</div>
<input type="hidden" class="hiddenRecaptcha_post required" name="hiddenRecaptcha_post" id="hiddenRecaptcha_post">
<div id="recaptcha_post" class="g-recaptcha" data-sitekey="6LdhprAZAAAAAONu3rfxTPNGCIjjHbH06dqVerDd"></div><br>
<button type="submit" class="btn" style="height: 50px;margin: 0;padding: 0 20px;vertical-align: middle;border: 0;font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size: 16px;font-weight: 900;line-height: 50px;color: #fff;-moz-border-radius: 4px;-webkit-border-radius: 4px;border-radius: 4px;text-shadow: none;-moz-box-shadow: none;-webkit-box-shadow: none;box-shadow: none;">Send me the newsletter</button>
</form>
</div>
</div>
<br>
<div class="separator" style="clear: both; text-align: center;">
<a href="/images/blogger_images/4.bp.blogspot.com_-WopLWoYlbZk_US4LELerTbI_AAAAAAAAGLs_T0GalJUhE4Q_s1600_res.png" imageanchor="1" ><img border="0" height="300" src="/images/blogger_images/4.bp.blogspot.com_-WopLWoYlbZk_US4LELerTbI_AAAAAAAAGLs_T0GalJUhE4Q_s400_res.png" width="400"/></a></div>
I’ve created a set of scripts to <a href="https://github.com/diegovalle/download-maps12">download and recode shapefiles</a> from the <span class="caps">IFE</span> and <span class="caps">INEGI</span>. Once you run the scripts you’ll find in the <i>map-out</i> directory:
<br/>
<br/>
<ul>
<li><b>distritos</b>: Shapefile of the electoral distritos (districts) </li>
<li><b>secciones-inegi</b>: Shapefile of electoral secciones (precincts) with both the ife and inegi codes for the municipalities each seccion belongs to </li>
<li><b>estados</b>: Shapefile of the Mexican states according to the <span class="caps">INEGI</span></li>
<li><b>localidades</b>: Shapefiles of the rural localities and the polygons of the urban ones </li>
<li><b>municipios</b>: Shapefile of the municipalities of Mexico according to the <span class="caps">INEGI</span></li>
<li><b>rdata-secciones</b>: serialized secciones (precincts) map as an R object </li>
</ul>
<div>
<div style="border: 0px; margin-bottom: 15px; margin-top: 15px; padding: 0px;">
<br/>
Since the <span class="caps">IFE</span> uses a different coding standard for the municipalities of Mexico than the <span class="caps">INEGI</span>, I’ve recoded the municipality codes so that they match the ones the <span class="caps">INEGI</span> uses.
</div>
<p><i><span style="background-color: #ffd966; font-family: Verdana, sans-serif;"><br/></span></i>
<i><span style="background-color: #ffd966; font-family: Verdana, sans-serif;">
</span></i>
<i><span style="background-color: #ffd966; font-family: Verdana, sans-serif;">Ecatepec, México according to the <span class="caps">INEGI</span> is <b>15 033</b>, while according to the <span class="caps">IFE</span> it’s <b>15 034</b> </span></i><br>
<i><span style="background-color: #ffd966; font-family: Verdana, sans-serif;">Guadalajara, Jalisco according to the <span class="caps">INEGI</span> is <b>14 039</b>, while according to the <span class="caps">IFE</span> it’s <b>14 041</b></span></i><br/>
<br/>
These codes are only available for the secciones electorales (precincts) shapefile and they are contained in the variables:
<br/>
<br/>
<ul>
<li><b>MUN_INEGI</b>: The inegi municipio codes </li>
<li><b>MUN_IFE</b>: The original ife municipio codes that came with the file</li>
</ul>
<br/>
The codebook for the the census data that comes with the distrito and sección shapefiles is in the <i>FD_SECC_IFE.pdf</i> file and the ife and inegi codes are in the <i>ife.to.inegi.csv</i> file. I also suggest you check out <a href="https://twitter.com/unRob">Rob Hidalgo’s</a> repository of <a href="https://github.com/unrob/informacion-publica/tree/master/ife/marco-geografico-nacional">public information</a> (from freedom of information requests) which includes a shapefile of the municipios of Mexico according to the <span class="caps">IFE</span> (my version comes from the <span class="caps">INEGI</span> and they differ by a few municipalities)<br/>
<br/>
<span class="caps">P.S.</span> Here’s the <a href="https://github.com/diegovalle/download-maps12">code</a></div>
<div style="clear: both;"></div>
</div></p>
<p><b><i>Update:</i></b> You can also use a docker image to run the program without installing anything
<br></p>
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
2
3
4
5</pre></div></td><td class="code"><div class="highlight"><pre>docker pull diegovalle/download-maps12
<span class="c"># shared directory to store the output</span>
mkdir -p /tmp/download-ine2010
<span class="c"># once the container is up run make</span>
docker run -v /tmp/download-ine2010:/download-maps12/map-out -i -t diegovalle/download-maps12
</pre></div>
</td></tr></table>