6
$\begingroup$

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]} & /@
 counties;

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

Thank you!

$\endgroup$
0
7
$\begingroup$

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

$\endgroup$
4
  • $\begingroup$ Entity["AdministrativeDivision", {"AlachuaCounty", "Florida", "UnitedStates"}][ EntityProperty["AdministrativeDivision", "BorderingCounties"]] gives me: $\endgroup$ Apr 18 '17 at 20:47
  • $\begingroup$ Missing["UnknownEntity", {"AdministrativeDivision", {"AlachuaCounty", "Florida", "UnitedStates"}}] $\endgroup$ 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$ 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.