Article 64DDT Quirks in Mathematica’s administrative division data for Mexico

Quirks in Mathematica’s administrative division data for Mexico

by
John
from John D. Cook on (#64DDT)

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.

mmca_mexico.png

For example, Aguascalientes is recognized as an administrative division, but Baja California is not. It recognizes Oaxaca but not Nuevo Leon. 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 Mexico, but Mathematica does not recognize CiudaddeMexico as an administrative division. Mathematica does recognize MexicoCity as the name of a city but not as the name of an administrative division.

Changing CiudaddeMexico 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

mexico_tour.png

The tour is

  1. Baja California
  2. Baja California Sur
  3. Sinaloa
  4. Durango
  5. Zacatecas
  6. Aguascalientes
  7. Nayarit
  8. Jalisco
  9. Colima
  10. Michoacan
  11. Mexico
  12. Mexico City
  13. Morelos
  14. Guerrero
  15. Oaxaca
  16. Chiapas
  17. Tabasco
  18. Campeche
  19. Quintana Roo
  20. Yucatan
  21. Veracruz
  22. Puebla
  23. Tlaxcala
  24. Hidalgo
  25. Queretaro
  26. Guanajuato
  27. San Luis Potosi
  28. Tamaulipas
  29. Nuevo Leon
  30. Coahuila
  31. Chihuahua
  32. Sonora

The tour is 8,343 kilometers.

The post Quirks in Mathematica's administrative division data for Mexico first appeared on John D. Cook.
External Content
Source RSS or Atom Feed
Feed Location http://feeds.feedburner.com/TheEndeavour?format=xml
Feed Title John D. Cook
Feed Link https://www.johndcook.com/blog
Reply 0 comments