This is current method to find the maximal EuclideanDistance
in American
NMaximize[
EuclideanDistance[x, y],
{x ∈ BoundaryDiscretizeGraphics[CountryData["UnitedStates", "Polygon"]],
y ∈ BoundaryDiscretizeGraphics[CountryData["UnitedStates", "Polygon"]]}
]
{57.8918, {x -> {-124.732, 48.381}, y -> {-66.9498, 44.8179}}}
But as we know, EuclideanDistance
is not suitable to calculate the geodesic distance. So I change it.
Failure one
NMinimize[
QuantityMagnitude[GeoDistance[x, y]], {x ∈ CountryData["UnitedStates", "Polygon"],
y ∈ CountryData["UnitedStates", "Polygon"]}]
It will give a promp that we cannot set a constraint for x
and y
by ∈
here.
Failure two
region = TransformedRegion[
BoundaryDiscretizeGraphics[
CountryData["UnitedStates", "Polygon"]], {#2, #1} &];
geoDist =
NMaximize[QuantityMagnitude[GeoDistance[x, y]], {x ∈ region, y ∈ region}]
It will give some error informations and a result:
{3892.01, {x -> {46.3815, -122.129}, y -> {42.9557, -72.4605}}}
But after I visualize the results, I don't think it is right:
GeoGraphics[{Entity["Country", "UnitedStates"],
Arrow@GeoPath[GeoPosition /@ Values[Last[geoDist]]], Red,
PointSize[Large], Point[GeoPosition /@ Values[Last[geoDist]]]}]
Those places point by red arrow should have larger distance obviously. And we will also fail to calculate the TravelDistance
by this method.
travelDist =
NMaximize[
QuantityMagnitude[TravelDistance[{GeoPosition[x], GeoPosition[y]}]],
{x ∈ region, y ∈ region}]
Actually this error information same to the above expression
...QuantityMagnitude[GeoDistance[x, y]]...
.So any workarounds can calculate GeoDistance
and TravelDistance
?
TravelDistance
fail, even before passing a result toQuantityMagnitude
. That's a good starting point to debug your code: you want to make sure that you can get the calls toTravelDistance
to work consistently first. Besides, if travel distance requires an external connection, wouldn't the minimization be horribly slow? $\endgroup$