Hello again!
So I have been wanting to use Arcade to create labels that show temperature changes at weather stations. The station data is a REST link from nowcast's site and is time enabled, having a couple hours of past observations as well as the current at any one time. At each station location, I wanted to filter out each current and -2hour temperature observation, then find the difference for a simple trend analysis and display that difference. The code at the bottom is working up until finding a temperature for "current time - 2 hours" (i think). I don't think I am writing this part correctly due to the data being time enabled.. Or I could be missing something else. However when I run this, it gives me just the current station temperature, so I am thinking it isn't grabbing the data before 2 hours. I tested this with just a 1 hour time step, and the values were still the same as current time.
If you have any insight on working with time enabled layers via arcade in the label profile, it would be much appreciated. Thanks!
// define variables used
$feature.obstime;
$feature["tmdb_f"];
// set the times used for the trend analysis
var current = DateAdd($feature.obstime, 0, "hours")
var not_current = DateAdd($feature.obstime, -2, "hours")
// pull out temp values for each time above
var current_temp = 0
var previous_temp = 0
if ($feature.obstime == current) {
current_temp = $feature["tmdb_f"]
}
else if ($feature.obstime == not_current){
previous_temp = $feature["tmdb_f"]
}
// subtract the current from previous
var temp_trend = current_temp - previous_temp
return text(temp_trend)
Solved! Go to Solution.
Just noticed that you are looking to do this in the label profile. This will not be possible since the FeatureSetBy functions that you will need are not available in the label profile.
You are going to face a couple of challanges, although it is possible to access the multitemporal data and try to analyze the trend.
Just did a little test, but the data does not allow you to use the FeatureSetBy* functions, so there will be no way for Arcade to access the different observations at a single location.
Edit: When the layer is added separately, you do have access, so it is possible. Will post back a solution later.
Below an example of what you can do. However, when I tested this, for some strange reason the data retrieved does not correspond to the data I retrieve manually. I will look into it later and see if I can correct the error.
var locid = $feature.locid; // "KELP";
var sql = "locid = '" + locid + "'";
Console(sql);
var fldlist = ["locid", "obstime", "tmdb_f", "validtime"];
var observations = OrderBy(Filter(FeatureSetByName($map,"Station scale5", fldlist, False), sql), "validtime ASC");
var cnt = Count(observations);
Console(cnt);
var result = "";
if (cnt >= 3) {
Console("start");
var i = 0;
for (var obs in observations) {
i += 1;
Console(obs);
Console(" - " + i + ": " + obs.validtime + " - " + obs.tmdb_f + " - " + obs.obstime);
if (i == cnt) {
var temp_curr = obs.tmdb_f;
Console("found current...");
}
if (i == cnt-2) {
var temp_min2 = obs.tmdb_f;
Console("Found minus 2...");
}
}
var dif_temp = temp_curr - temp_min2;
result = "Current temperature: " + temp_curr + "°F";
result += TextFormatting.NewLine + "Temperature 2 hours before: " + temp_min2 + "°F";
if (dif_temp > 0) {
result += TextFormatting.NewLine + "Temperature has increased by " + dif_temp + "°F";
} else if (dif_temp < 0) {
result += TextFormatting.NewLine + "Temperature has decreased by " + Abs(dif_temp) + "°F";
} else {
result += TextFormatting.NewLine + "No change in temperature";
}
} else {
// number of observations less than 3}
result = "There are only " + cnt + " observations..."
}
return result;
Just noticed that you are looking to do this in the label profile. This will not be possible since the FeatureSetBy functions that you will need are not available in the label profile.
Thank you very much for the effort with these responses, I have learned a lot with dissecting your workflow for future problems.
Is there anyway to do the first half that uses FeatureSet in ArcPro's attribute editor, then the rest in AGOL's label editor? What would need to happen for the attribute editor in arcpro to run whenever new data come in, updating the layer in AGOL and allowing the label scripts in AGOL (the last part) to run with the new and sorted data? Could I construct a model in model builder for the first part?
I understand that you work for NOAA and might have access to the source data. It would be best to include in the update procedure of the data an additional field that you can use to label on, one that simply describes the change temperature. If this is stored in an actual field, you can also define you symbology on this type of data. I don't see how you would be able to do part in ArcGIS Pro and part of the expression in the label profile of Arcade (although you could have a simple expression that adds the °F to the data for display).
Sounds good, thank you for your help!