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 ?
1 Answer
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:
-
-
$\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$– sraJan 19, 2021 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$– joseJan 19, 2021 at 22:42
-
$\begingroup$ For bunch of US Cities, I am getting
Missing["NotAvailable"]
for exampleWeatherData[WeatherData["Miami"], "Temperature", "NonMetricValue"]
..why is that so? Is there a way to fix it? $\endgroup$– sraJan 20, 2021 at 7:01 -
$\begingroup$ Actually this
WeatherData["Miami", "Temperature", "NonMetricValue"]
works instead ofWeatherData[WeatherData["Miami"], "Temperature", "NonMetricValue"]
$\endgroup$– sraJan 20, 2021 at 17:21