3
$\begingroup$

It seems to be an easy task as all the related functions GeoNearest and EntityList["City"] are close at hands.

However, for example, if we use

GeoNearest["City", Entity["Ocean", "PacificOcean"], 30]

to retrieve some cities, as the query size could be huge, we will always get such error: enter image description here

So, what would be the sensible/feasible approach to get a global list of coastal cities using the Entity framework?

$\endgroup$
4
  • $\begingroup$ I think that the first thing I would try if I was on a machine with Mathematica installed would be to get a list of cities with elevations less than some threshold, say 50m, and see what pops out. I suspect selecting cities on a simple criterion like the value of a property will be a lot less computationally burdensome than the GeoNearest[ ... theOcean] approach. $\endgroup$ Jan 6, 2022 at 17:08
  • $\begingroup$ Well, I just tried my previous suggestion in MMA online, got a list of ~28,000 cities! $\endgroup$ Jan 6, 2022 at 17:16
  • $\begingroup$ @HighPerformanceMark it would also be possible to filter those after the fact, since 28K is much easier to work with $\endgroup$
    – b3m2a1
    Jan 6, 2022 at 17:24
  • $\begingroup$ Yes, that's rather the way I was suggesting OP goes. $\endgroup$ Jan 6, 2022 at 18:53

1 Answer 1

4
$\begingroup$

As a workaround you can use the ocean polygon instead, e.g.:

GeoNearest[
    "City",
    Entity["Ocean","PacificOcean"]["Polygon"],
    30
]

{Entity["City", {"Avera", "Tubuai", "FrenchPolynesia"}], Entity["City", {"Niusuatia", "Tuamasaga", "Samoa"}], Entity["City", {"Uturoa", "IlesSousLeVent", "FrenchPolynesia"}], Entity["City", {"Fakahima", "TuamotuGambier", "FrenchPolynesia"}], Entity["City", {"Salesatele", "Atua", "Samoa"}], Entity["City", {"Sapulu", "FaAsaleleaga", "Samoa"}], Entity["City", {"Samamea", "VaAOFonoti", "Samoa"}], Entity["City", {"Tafagamanu", "AAna", "Samoa"}], Entity["City", {"Vailoa", "Tuamasaga", "Samoa"}], Entity["City", {"Anaa", "TuamotuGambier", "FrenchPolynesia"}], Entity["City", {"Ofu", "Manua", "AmericanSamoa"}], Entity["City", {"Papeete", "IlesDuVent", "FrenchPolynesia"}], Entity["City", {"SalelavaluTai", "FaAsaleleaga", "Samoa"}], Entity["City", {"Paepaeala", "AigaILeTai", "Samoa"}], Entity["City", {"Afega", "Tuamasaga", "Samoa"}], Entity["City", {"Faleu", "AigaILeTai", "Samoa"}], Entity["City", {"Taahuaia", "Tubuai", "FrenchPolynesia"}], Entity["City", {"Asaga", "FaAsaleleaga", "Samoa"}], Entity["City", {"Tufutafoe", "Vaisigano", "Samoa"}], Entity["City", {"ApolimaIsland", "AigaILeTai", "Samoa"}], Entity["City", {"SiumuUta", "Tuamasaga", "Samoa"}], Entity["City", {"Faleseela", "AAna", "Samoa"}], Entity["City", {"Maupiti", "IlesSousLeVent", "FrenchPolynesia"}], Entity["City", {"Mauga", "GagaEmauga", "Samoa"}], Entity["City", {"Apia", "Tuamasaga", "Samoa"}], Entity["City", {"IslandViewPiosBeach", "BayOfPlenty", "NewZealand"}], Entity["City", {"Mutis", "Choco", "Colombia"}], Entity["City", {"Kavieng", "NewIreland", "PapuaNewGuinea"}], Entity["City", {"Pimentel", "Lambayeque", "Peru"}], Entity["City", {"Palestina", "Guayas", "Ecuador"}]}

Since you're interested in the coastline, the following might be better:

GeoNearest[
    "City",
    Line @@ Entity["Ocean","PacificOcean"]["Polygon"],
    30
]

{Entity["City", {"IslandViewPiosBeach", "BayOfPlenty", "NewZealand"}], Entity["City", {"Mutis", "Choco", "Colombia"}], Entity["City", {"Kavieng", "NewIreland", "PapuaNewGuinea"}], Entity["City", {"Pimentel", "Lambayeque", "Peru"}], Entity["City", {"Palestina", "Guayas", "Ecuador"}], Entity["City", {"Cabra", "Panama", "Panama"}], Entity["City", {"Aberpura", "Papua", "Indonesia"}], Entity["City", {"AlvaroObregon", "Chiapas", "Mexico"}], Entity["City", {"Acacoyagua", "Chiapas", "Mexico"}], Entity["City", {"Santiago", "Veraguas", "Panama"}], Entity["City", {"BuenosAires", "Puntarenas", "CostaRica"}], Entity["City", {"Courtenay", "BritishColumbia", "Canada"}], Entity["City", {"Salem", "Oregon", "UnitedStates"}], Entity["City", {"Damascus", "Oregon", "UnitedStates"}], Entity["City", {"Roxana", "Limon", "CostaRica"}], Entity["City", {"LosChiles", "Alajuela", "CostaRica"}], Entity["City", {"Gizo", "Western", "SolomonIslands"}], Entity["City", {"Barranco", "BocasDelToro", "Panama"}], Entity["City", {"Limon", "Limon", "CostaRica"}], Entity["City", {"Karuizawa", "Nagano", "Japan"}], Entity["City", {"Cabanas", "Zacapa", "Guatemala"}], Entity["City", {"LeGrand", "California", "UnitedStates"}], Entity["City", {"Suwa", "Nagano", "Japan"}], Entity["City", {"WhiteRock", "BritishColumbia", "Canada"}], Entity["City", {"Ambato", "Tungurahua", "Ecuador"}], Entity["City", {"Buritica", "Antioquia", "Colombia"}], Entity["City", {"Oluta", "Veracruz", "Mexico"}], Entity["City", {"Abejorral", "Antioquia", "Colombia"}], Entity["City", {"Wasco", "Oregon", "UnitedStates"}], Entity["City", {"BarraDeSantaAna", "Tabasco", "Mexico"}]}

Since the Polygon and Line versions work, it might be worthwhile asking support why the plain Entity version doesn't work

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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