4
$\begingroup$

Why does NearestNeighborGraph[ CityData[{Large, "Colorado", "UnitedStates"}], 3, DistanceFunction -> GeoDistance, DirectedEdges -> False, VertexLabels -> "Name"] create a self loop on the graph? Is there a way to get rid of it ?

enter image description here

$\endgroup$
0
4
$\begingroup$

GeoDistance is computing minimal distances between the polygons of the cities, and some cities are contiguous, i.e. their polygons are touching, so the result is zero. See the non-diagonal zeros in

TableForm[GeoDistance[cities, cities], TableHeadings -> {cities, cities}]

You can compute distances among centered points instead of polygons using this alternative distance function:

DistanceFunction -> Function[GeoDistance[GeoPosition[#1], GeoPosition[#2]]]

Then this is the result:

enter image description here

$\endgroup$
6
  • $\begingroup$ Thanks a lot @jose! $\endgroup$
    – psimeson
    Jan 19 at 16:37
  • $\begingroup$ Why does WeatherData[{"Buckeye", "Arizona", "UnitedStates"}, "Temperature", "NonMetricValue"] this fail? @jose I am trying to create a city graph with weather data as feature. $\endgroup$
    – psimeson
    Jan 19 at 20:50
  • 3
    $\begingroup$ WeatherData is based on weather stations. In a case like this you can first find the nearest station and then check its temperature. Something like: WeatherData[ WeatherData[{"Buckeye", "Arizona", "UnitedStates"}], "Temperature", "NonMetricValue"]. This should have worked automatically. $\endgroup$
    – jose
    Jan 19 at 22:42
  • $\begingroup$ For bunch of US Cities, I am getting Missing["NotAvailable"] for example WeatherData[WeatherData["Miami"], "Temperature", "NonMetricValue"]..why is that so? Is there a way to fix it? $\endgroup$
    – psimeson
    Jan 20 at 7:01
  • $\begingroup$ Actually this WeatherData["Miami", "Temperature", "NonMetricValue"] works instead of WeatherData[WeatherData["Miami"], "Temperature", "NonMetricValue"] $\endgroup$
    – psimeson
    Jan 20 at 17:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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