If you ask Mathematica for a list of Mexican states via
CountryData["Mexico", "RegionNames"]
you will get a list of strings:
"Aguascalientes", "Baja California", ..., "Zacatecas"}
However, when you try to turn this into a list of objects representing these states via
states = Entity["AdministrativeDivision", {#, "Mexico"}] & /@ CountryData["Mexico", "RegionNames"]
something strange happens. Some items in the list are turned into useful objects, and some are uninterpreted symbols.
For example, Aguascalientes is recognized as an administrative division, but Baja California is not. It recognizes Oaxaca but not Nuevo León. The pattern is that states with a space are not recognized. There is an inconsistency in Mathematica: output names do not always match input names. To create the object representing Baja California, you need to pass in the string BajaCalifornia
with no space.
Entity["AdministrativeDivision", {"BajaCalifornia", "Mexico"}]
OK, so let’s remove spaces before we try to create a list of geographic objects.
names = StringReplace[#, " " -> ""] & /@ CountryData["Mexico", "RegionNames"]
This mostly works, but it trips up on Mexico City. The output name for the region is Ciudad de México, but Mathematica does not recognize CiudaddeMéxico
as an administrative division. Mathematica does recognize MexicoCity
as the name of a city but not as the name of an administrative division.
Changing CiudaddeMéxico
to MexicoCity
in the list of names did not fix the problem. But when I directly edited the list of state objects by replacing the uninterpreted value with the output running
Entity["AdministrativeDivision", {"MexicoCity", "Mexico"}]
by itself everything worked. Then I was able to find a Traveling Salesman tour as in earlier posts (Africa, Americas, Eurasia and Oceania, Canada).
Traveling Salesman tour of Mexico
The tour is
- Baja California
- Baja California Sur
- Sinaloa
- Durango
- Zacatecas
- Aguascalientes
- Nayarit
- Jalisco
- Colima
- Michoacán
- México
- Mexico City
- Morelos
- Guerrero
- Oaxaca
- Chiapas
- Tabasco
- Campeche
- Quintana Roo
- Yucatán
- Veracruz
- Puebla
- Tlaxcala
- Hidalgo
- Querétaro
- Guanajuato
- San Luis Potosí
- Tamaulipas
- Nuevo León
- Coahuila
- Chihuahua
- Sonora
The tour is 8,343 kilometers.