var searchDistance = 50; // Search distance in kilometers
'38406bada3104e258fc8b42a2a96581a',
0,
['Temperature_C'],
True
);
var proximityWeatherStations = Intersects(weatherStations, Buffer($feature, searchDistance, "kilometers"));
var minDistance = Infinity;
var closestWeatherStationTemp;
for (var f in proximityWeatherStations){
var weatherDist = Round(Distance(f, $feature, "kilometers"),2);
if (weatherDist < minDistance) {
closestWeatherStationTemp = f["Temperature_C"];
minDistance = weatherDist;
}
}
// Check if a closest individual weather station was found before accessing its property
if (closestWeatherStationTemp != null) {
return "Closest Weather Station Temperature is: " + closestWeatherStationTemp + " degrees C and is located approximately " + Round(minDistance,0) + " km away.";
} else {
return "No closest weather station was found within the search distance.";
}