Skip to content

Instantly share code, notes, and snippets.

@diegovalle
Last active June 11, 2026 16:37
Show Gist options
  • Select an option

  • Save diegovalle/5129746 to your computer and use it in GitHub Desktop.

Select an option

Save diegovalle/5129746 to your computer and use it in GitHub Desktop.
Topojson of Mexican municipalities and states

How to create the topojson map:

curl -o estados.zip http://mapserver.inegi.org.mx/MGN/mge2010v5_0.zip
curl -o  municipios.zip http://mapserver.inegi.org.mx/MGN/mgm2010v5_0.zip
unzip estados.zip 
unzip municipios.zip
ogr2ogr states.shp Entidades_2010_5.shp -t_srs "+proj=longlat +ellps=WGS84 +no_defs +towgs84=0,0,0"
ogr2ogr municipalities.shp Municipios_2010_5.shp -t_srs "+proj=longlat +ellps=WGS84 +no_defs +towgs84=0,0,0"
topojson -o mx_tj.json -s 1e-7 -q 1e5 states.shp municipalities.shp -p state_code=+CVE_ENT,state_name=NOM_ENT,mun_code=+CVE_MUN,mun_name=NOM_MUN

Related: Projected Topojson of Mexican Municipalities

<!DOCTYPE html>
<meta charset="utf-8">
<title>Mexico Topojson</title>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/topojson.v0.min.js"></script>
<script>
var x = d3.scale.linear()
.domain([0, width])
.range([0, width]);
var y = d3.scale.linear()
.domain([0, height])
.range([height, 0]);
var width = 960,
height = 500;
var projection = d3.geo.mercator()
.scale(1200)
.center([-102.34034978813841, 24.012062015793]);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
var g = svg.append("g");
d3.json("mx_tj.json", function(error, mx) {
svg.selectAll("path")
.data(topojson.object(mx, mx.objects.municipalities).geometries)
.enter().append("path")
.attr("d", d3.geo.path().projection(projection))
.attr("fill", "transparent")
.style("stroke", "#333")
.style("stroke-width", ".2px")
.attr("class", "muns");
g.selectAll("path")
.data(topojson.object(mx, mx.objects.states).geometries)
.enter().append("path")
.attr("d", d3.geo.path().projection(projection))
.attr("fill", "transparent")
.style("stroke", "#333");
});
</script>
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

ghost commented Aug 3, 2017

Copy link
Copy Markdown

@diegovalle

I get the size of your files using this command instead:

ogr2ogr -f GeoJSON -lco COORDINATE_PRECISION=1 states.json Entidades_2010_5.shp -t_srs "+proj=longlat +ellps=WGS84 +no_defs +towgs84=0,0,0"
ogr2ogr -f GeoJSON -lco COORDINATE_PRECISION=1 municipalities.json Municipios_2010_5.shp -t_srs "+proj=longlat +ellps=WGS84 +no_defs +towgs84=0,0,0"

Thanks anyway...

@Vicroni

Vicroni commented Jan 24, 2018

Copy link
Copy Markdown

Hi, someone here knows how to do the same but without municipalities only states, please, save my life

@facita10

Copy link
Copy Markdown

Hola @diegovalle , ¿hay manera de extraer únicamente uno de los estados con todos sus municipios?

@IlyaOrson

Copy link
Copy Markdown

Here is a version that works similarly with later versions of the topojson ecosystem. Due to Mike Bostock, the origianl author of the libraries.

@Avzolem

Avzolem commented Aug 23, 2022

Copy link
Copy Markdown

https://github.com/Avzolem/alertaprensanext Aqui hay un proyecto que utiliza interactividad y el nombre de los estados encima del mapa :D

@MJChimal

MJChimal commented Jan 8, 2024

Copy link
Copy Markdown

👍 ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment