Skip to content

pycensus.census.countries.mexico.geography

Boundary fetching shared by every Mexico census source.

Technical aspects

Boundaries come from INEGI's Marco Geoestadistico Nacional (MGN), a per-state shapefile bundle (see :data:pycensus.mexico.constants.MARCO_GEOESTADISTICO_URLS, verified 2026-08-19). Real boundaries are implemented for state, municipality, ageb (urban AGEB only, {state}a.shp), and block (urban manzana, {state}m.shp) -- the levels INEGI's per-state MGN zip covers cleanly and that pair with a real attribute-side source (ITER for state/municipality, RESAGEBURB for AGEB/block, see :mod:pycensus.mexico.api).

block pairing was live-verified end-to-end 2026-08-22 against Jalisco (state "14"): joining :func:pycensus.mexico.api.fetch_block_totals's GEOID (16-digit ENTIDAD+MUN+LOC+AGEB+MZA) against the real 14m.shp boundary's CVEGEO gives a 99.55% match rate restricted to AMBITO == "Urbana" boundary blocks (95,104 of 95,536 urban blocks matched) -- the only blocks RESAGEBURB, an urban-only source, can ever cover. The residual unmatched boundary blocks are almost entirely AMBITO == "Rural" (35,506 of 35,938 unmatched), exactly the documented RESAGEBURB urban-only gap, not a pairing bug. Summing POBTOT over every real block row for MUN "039" (Guadalajara) gives 1,385,621 -- identical to the already-verified AGEB-level total for the same municipality (see :func:pycensus.mexico.api.fetch_ageb_totals's docstring), confirming the attribute side is correct independent of the boundary join; only ~0.8% of that population sum (162 of 13,791 blocks) falls on blocks that don't match the 2018-vintage MGN boundary, an expected small vintage/edge-case gap. Rural AGEB ({state}ar.shp) is not wired up -- RESAGEBURB only covers urban AGEBs. nation/locality are not implemented (no exact INEGI national boundary shapefile URL was verified, and locality boundaries are polygon or point depending on population per INEGI's own documentation, which needs handling this module doesn't attempt).

Downloaded zips are cached under <data_dir>/raw/marco_geoestadistico/ (persistent across runs, independent of :mod:pycensus.cache's parquet cache) and extracted once per state.

Every boundary fetch here is stateless from :mod:pycensus.cache's point of view - persistence of the final merged (geometry + attribute) result is handled entirely by :mod:pycensus.cache, one level higher in the call stack (in inegi/loader.py), not by this module.

Source

https://www.inegi.org.mx/temas/mg/

states_in_aoi(aoi, year=2020)

Return the INEGI codes of every state that plausibly intersects aoi.

Note

A precise version of this would test against a real national state boundary layer; no cheap verified one is wired up (only the heavier per-state Marco Geoestadistico zips, see module docstring), so this instead does a bounding-box test against :data:pycensus.mexico.constants.STATE_BBOX (each state's approximate rectangular extent, padded by :data:pycensus.mexico.constants.STATE_BBOX_PADDING_DEG to stay safely over-inclusive). This is deliberately coarse -- for an AOI near a state border it may include a neighboring state that isn't actually needed -- but it reliably narrows a whole-country, 32-state candidate list (and the ~150s/state MGN + ITER download that goes with each one) down to the handful of states an AOI like a single city actually touches, without ever risking a false negative that would silently drop real data.

Parameters:

Name Type Description Default
aoi GeoDataFrame

Area of interest (GeoDataFrame).

required
year int

Boundary year.

2020

Returns:

Type Description
List[str]

State codes.

load_boundaries(level, state=None, year=2020, erase_water=None, data_dir=None)

Fetch real INEGI Marco Geoestadistico boundaries for one Mexico geography level.

Parameters:

Name Type Description Default
level str

Standard geometry level name, resolved through :data:pycensus.mexico.constants.LEVEL_FALLBACK. See :data:IMPLEMENTED_LEVELS and the module docstring for which levels have a real, verified boundary source.

required
state Optional[str]

State code, name, or abbreviation. Required (Marco Geoestadistico is distributed per-state).

None
year int

Vintage year. Only 2020 data is wired up; other values are accepted but ignored (INEGI's per-state MGN zip used here is a 2018-vintage boundary file, the geometry INEGI itself pairs with the 2020 census in its "descarga por entidad" catalog).

2020
erase_water Optional[bool]

Accepted for interface parity with usa.geography but not implemented (INEGI's MGN shapefiles are already land-only polygons).

None
data_dir Optional[str]

Base directory for the raw Marco Geoestadistico zip cache. Defaults to :data:pycensus.mexico.constants.DEFAULT_DATA_DIR.

None

Returns:

Type Description
GeoDataFrame

GeoDataFrame with a GEOID column (INEGI's CVEGEO) and

GeoDataFrame

geometry, reprojected to EPSG:4326.

Raises:

Type Description
KeyError

If level does not resolve to a known geography level.

ValueError

If state is not given, or level has no implemented boundary source yet.

load_boundaries_multi(level, states=None, year=2020, erase_water=None, aoi=None, data_dir=None)

Fetch and concatenate boundaries across one or more states, optionally clipped to an AOI.

Parameters:

Name Type Description Default
level str

Standard geometry level name.

required
states Optional[Union[str, List[str]]]

State code(s), name(s), or abbreviation(s). If None, uses every state (32 downloads -- slow; prefer passing aoi or explicit states for anything short of a full-country run).

None
year int

Vintage year (see :func:load_boundaries).

2020
erase_water Optional[bool]

Accepted for interface parity, not implemented.

None
aoi Optional[GeoDataFrame]

If given, the result is filtered to geometries intersecting it.

None
data_dir Optional[str]

Base directory for the raw Marco Geoestadistico zip cache.

None

Returns:

Type Description
GeoDataFrame

GeoDataFrame with a GEOID column, geometry, in EPSG:4326.