If I want to find a list of neighboring countries for a particular list of countries I can do :

 counties=EntityList[sovereign states in Europe(countries)];

 neighbors = {#, 
 Intersection[CountryData[#, "BorderingCountries"], 
  countries]} & /@ countries;

 neighbors // TableForm 

For example; a list of neighbor countries for Albania is {Greece, Kosovo, Macedonia, Montenegro}.

We can do this because of the above attribute "BorderingCounties" that is available in Mathematica.

Imagine that we want something similar to the above but, using the state of Florida and its counties instead.

The list of counties in the State of Florida is given by :

 counties=EntityList[US counties in Florida (administrative divisions)];

If I now want a list of neighbor counties corresponding to each county in the State of Florida; I could try :

 countyneighbors = {#, 
 Intersection[CountryData[#, "BorderingCounties"], counties]} & /@

but, there is no such attribute "BorderingCounties" built in Mathematica. How an I get around this hurdle?

Thank you!

  • $\begingroup$ Correction: "We can do this because of the above attribute "BorderingCountries" that is available in Mathematica." (But, there is no "BorderingCounties" available in Mathematica.) $\endgroup$ – Gilmar Rodriguez Pierluissi Apr 18 '17 at 17:40
  • $\begingroup$ Please edit your post by clicking on the "edit" button below your question, instead of putting corrections in comments. $\endgroup$ – J. M. will be back soon Apr 18 '17 at 17:58

Each county has the property that you are looking for:

Mathematica graphics

In code my input is:

Entity["AdministrativeDivision", {"AlachuaCounty", "Florida", "UnitedStates"}][
 EntityProperty["AdministrativeDivision", "BorderingCounties"]]

And by the way, so do countries:

Mathematica graphics

You can find these properties by typing entity["Properties"]:

Mathematica graphics

  • $\begingroup$ Entity["AdministrativeDivision", {"AlachuaCounty", "Florida", "UnitedStates"}][ EntityProperty["AdministrativeDivision", "BorderingCounties"]] gives me: $\endgroup$ – Gilmar Rodriguez Pierluissi Apr 18 '17 at 20:47
  • $\begingroup$ Missing["UnknownEntity", {"AdministrativeDivision", {"AlachuaCounty", "Florida", "UnitedStates"}}] $\endgroup$ – Gilmar Rodriguez Pierluissi Apr 18 '17 at 20:47
  • $\begingroup$ @GilmarRodriguezPierluissi I asked someone else to try this and it worked for them too. We don't know what could cause it to not work. $\endgroup$ – C. E. Apr 18 '17 at 23:12
  • $\begingroup$ I can replicate an example found among the Mathematics examples located at: ref/GeoGraphics/NeatExamples where the 4-color theorem is applied to neighboring European countries with no problems. The lines of code in that example work fine when I activate them in Mathematica. But, when I modify the example applied to the State of Florida; the following: Alachua County, Florida, United States (administrative division)[Entity Property["AdministrativeDivision","BorderingCounties"]] give: Missing["UnknownEntity", {"AdministrativeDivision",{"AlachuaCounty", "Florida", "UnitedStates"}}]. Weird! $\endgroup$ – Gilmar Rodriguez Pierluissi Apr 19 '17 at 13:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.