8
$\begingroup$

Given a GeoPosition, what is the recommended method to calculate its distance from the ocean?


EDIT

As an example, Atlanta is 350 km from the Atlantic ocean, but where is that actual location? It would be nice to not have to specify an ocean by name as well.

GeoDistance[Entity["City", {"Atlanta", "Georgia", "UnitedStates"}], 
 Entity["Ocean", "AtlanticOcean"]]

Quantity[349.84438296049916, "Kilometers"]

GeoGraphics[{Entity["Country", "UnitedStates"], 
  GeoMarker[Entity["City", {"Atlanta", "Georgia", "UnitedStates"}], 
   "Alignment" -> Bottom]}, 
 GeoCenter -> Entity["City", {"Atlanta", "Georgia", "UnitedStates"}], 
 GeoRange -> Quantity[600, "Kilometers"], 
 GeoBackground -> "Coastlines"]

enter image description here

Thanks for your help.

$\endgroup$

2 Answers 2

5
$\begingroup$

Probably can make this more elegant, but here's what I've got so far:

atlanta = Entity["City", {"Atlanta", "Georgia", "UnitedStates"}];
nearestOcean = First@GeoNearest[Entity["Ocean"], atlanta];
oceanPoints = Flatten[EntityValue[nearestOcean, "Polygon"][[1]]["Data"], 1];
nearestCoastalPoint = Nearest[oceanPoints, EntityValue[atlanta, "Coordinates"]]
(* {{32.52, -80.8324}} *)

Augmenting your GeoGraphics:

GeoGraphics[
  {Entity["Country", "UnitedStates"], 
   GeoMarker[atlanta, "Alignment" -> Bottom], 
   GeoMarker[GeoPosition[nearestCoastalPoint], "Alignment" -> Bottom]},
   GeoCenter -> atlanta, 
   GeoRange -> Quantity[600, "Kilometers"], 
   GeoBackground -> "Coastlines"]

The point doesn't look like it's quite on the coast, but maybe the plot just doesn't show sufficient detail at this scale.

EDIT

The option GeoBackground -> "Coastlines" reduces the precision of the plot. If I try this,

GeoGraphics[
  {Entity["Country", "UnitedStates"], 
   GeoMarker[GeoPosition[nearestCoastalPoint], "Alignment" -> Bottom]},
   GeoCenter -> nearestCoastalPoint, 
   GeoRange -> Quantity[50, "Kilometers"]]

It does indeed seem like this point could be consdidered to be on the coast.

$\endgroup$
2
  • $\begingroup$ GeoGraphics[{ Entity["Country", "UnitedStates"] , GeoMarker[atlanta, "Alignment" -> Bottom] , GeoMarker[GeoPosition[nearestCoastalPoint] , "Alignment" -> Bottom], GeoDisk[atlanta, Quantity[350, "Kilometers"]] } , GeoCenter -> atlanta , GeoRange -> Quantity[400, "Kilometers"] , GeoBackground -> "Coastlines" ] suggests otherwise, but this could be a projection issue. $\endgroup$
    – Syed
    Oct 5, 2022 at 17:07
  • $\begingroup$ Thanks @lericr, I will have to study this solution, especially the polygon part further. $\endgroup$
    – Syed
    Oct 5, 2022 at 19:32
2
$\begingroup$

Another possibility: Take a position for your city:

a = GeoPosition@Entity["City", {"Atlanta", "Georgia", "UnitedStates"}]
(* GeoPosition[{33.7629, -84.4227}] *)

Then take the points of the US boundary (I'm skipping the nearestOcean computation performed in the accepted solution):

us = First[Entity["Country", "UnitedStates"]["Polygon"]]

Compute the closest of those points:

q = First[Nearest[us, p]]
(* GeoPosition[{31.8109, -81.3837}] *)

Check that the distance is approximately what you obtained initially:

GeoDistance[p, q, UnitSystem -> "Metric"]
(* Quantity[357.609, "Kilometers"] *)

The difference is due to the fact that the original computation was performed with the polygon of Atlanta, while we used a central point.

$\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.