I am trying to construct a NearestNeighborGraph
of the 3143 US counties, using their latitude and longitude positions.
counties =
EntityList[
EntityClass["AdministrativeDivision", "USCountiesAllCounties"]];
countyPositions = EntityValue[counties, {"Latitude", "Longitude"}];
So far so good. However, computing NearestNeighborGraph[countyPositions, DistanceFunction -> GeoDistance]
takes forever, or at least long enough that I aborted the computation because I got bored. It works as expected with a shorter list of counties, but is still pretty slow:
NearestNeighborGraph[Take[countyPositions, 10],
DistanceFunction -> GeoDistance] // AbsoluteTiming
(* {0.266751, graph omitted} *)
Also, if I just use latitude and longitude as Cartesian coordinates with the default EuclideanDistance
it works just fine, and is considerably faster for the whole list of counties than using GeoDistance
for just 10 of them!
NearestNeighborGraph[
QuantityMagnitude /@ countyPositions] // AbsoluteTiming
(* {0.13108, graph omitted} *)
It makes sens that GeoDistance
is slower than EuclideanDistance
, but it's annoying that it's so much slower, and I would very much like to speed it up.