Hi Jonathan! Each of these entities should have a property corresponding to location, and you can then use Select
to get what you want. Looking now (with EntityProperties["AstronomicalObservatory"]
), I see that there are a few different properties that relate to position, with one of them explicitly being "country". So:
observatories = EntityList["AstronomicalObservatory"];
observatoriesUS =
Select[observatories, #["Country"] ==
Entity["Country", "UnitedStates"] &]
This isn't super fast because we need to query this huge list of observatory entities (1407 of them) for their countries—and Select
does this one by one—but I expect that you could speed it up if you were doing something where speed is more important.
Get all of the countries at once, and extract their names as simple strings:
allCountries=EntityValue[EntityProperty[observatories,"Country"],"Name"];
Now, we can use Pick
to quickly pick out the elements according to a test value (in this case, the test is just: "is the element 'United States'?"):
observatoriesUS = Pick[observatories, allCountries, "United States"]
Confirm that this worked:
GeoListPlot[observatoriesUS,GeoRange->"World"]
EDIT: While trying this out, I realize that my initial answer with Select
actually doesn't work. While ==
works to compare most expressions, it doesn't work for entities exactly—basically, if you do have two equivalent entities, it will return True
—but if you try and compare, say, the US and Japan, it returns unevaluated. This causes problems for Select
, I think—so, using the lessons from the second solution, I think this is optimal in terms of simplicity and performance:
observatoriesUS2 =
Select[observatories,
EntityValue[#["Country"], "Name"] == "United States" &]
The key in either case is that it's very easy to compare two strings and instantly get back True
/False
!