Diego Valle-Jones's Bloghttps://blog.diegovalle.net/2013-06-24T00:00:00+02:00Shapefiles 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>