Hi all,
I am trying to make a dynamic symbology for a time dependent hosted feature layer. Where I have some point data and its last 15 minutes record (changes in every minute) coming from the geoevent server. This is a weather station data, I would like to turn my map symbol red if there is a rain over 50 mm for the last 15 minutes. I was planning to use arcade, tried the following code:
var rainfallField = $feature.rainfall;
// Check if the rainfall is greater than 50 mm for all records
var allRecordsAboveThreshold = true;
for (var i = 0; i < Count(rainfallField); i++) {
if (rainfallField[i] <= 50) {
allRecordsAboveThreshold = false;
break;
}
}
// Return a color based on the condition
if (allRecordsAboveThreshold) {
return "red"; // All records have rainfall > 50 mm
} else {
return "blue"; // Not all records have rainfall > 50 mm
}
But it do not give any output. Is it possible to manage it using arcade expressions?
Solved! Go to Solution.
thanks @DominicReed for answering my questions
here is what I'd do:
this blog might give you a bit more details information about the later half of instructions from above.
please let me know if you have any questions
I mean, that's how it should be, right? You shouldn't need to change the schema so much before it's a data product you're hosting, but then again I don't know you're setup and system capabilities. If you're not seeing data (row level) edits in joined views, you're either filtering the changes, or something is wrong. I use these with dynamic, constantly changing datasets, and all is good https://speedtest.vet/ .
Arcade has this concept called profiles. https://developers.arcgis.com/arcade/profiles/
The short version is that Arcade capabilities are dependent upon the context in which it's used. For symbology, for instance, your expression will only have access to the individual record it's being evaluated for. The expression can't "see" anything outside of a single feature. But the expression will run on every single feature separately. To think of it another way, the expression you write in a symbology expression is already in a for loop.
That in mind, trying to do something "for all records" just won't work. When you do your loop, it's only going to evaluate once, because your rainfallField variable only has a single number in it.
If you just want to color-code based on the value, try:
return Iif(
$feature.rainfall <= 50,
'blue',
'red'
)
And keep in mind that this won't automatically make your symbols red and blue. Nor will it actually give you all possible categories of your expression. If you don't have any features that evaluate to "red", that category won't show up, and you'll have to manually define it.
And you'll still need to go into each category and actually set the color.
Hi @jcarlson,
Thanks for your explanations. I am using this logic for considering other factors for the symbology, as this expression automatically detects the latest value for each stations. Only for rain rate I need to consider this 15 minute issue. That's where I am stuggling actually!
This looks like an interesting problem. I hope you won't mind if I ask you a few questions:
Thanks.
Tanu
Hi @TanuHoque ,
Thanks for asking. Yes, I did not use a stream service due to some other analytics and integration with experience builder, and yes, a geoevent process feeds data into my hosted feature service. And spatial data and time-series data can be stored in separate layer and table respectively, however, this layer is specially for creating a symbology, there are other logics, which I have already managed, but struggling with this one.
thanks @DominicReed for answering my questions
here is what I'd do:
this blog might give you a bit more details information about the later half of instructions from above.
please let me know if you have any questions
Hi @TanuHoque,
Thanks for your solution, although when thinking about your questions, I have discovered a similar way around, but your idea will help me to bypass lots of steps! Thanks a lot again!
Hello @DominicReed,
In addition to suggestions of @jcarlson , I would suggest you to try to use "FeatureSetByPortalItem"(for reference) to achieve the filtering functionality you desire, you might need to structure your Arcade expression a bit differently to create a dictionary that links the data to Hosted Feature service directly. Here's a suggested method, how you can approach it:
Here's a probable way to approach using Arcade to achieve this (I have made some assumption in regards to dictionary components, you would need to adjust that accordingly):
// Access the portal and feature set
var portal = Portal('https://www.iede.rs.gov.br/portal');
var fs = FeatureSetByPortalItem(portal, "<Item_ID>", <Layer_ID>);
// Initialize a dictionary to store specialties and their corresponding health unit codes
var specialtyDict = {};
// Iterate over the features in the feature set
for (var feature in fs) {
var specialty = feature['DS_ESPECIALIDADE'];
var healthUnitCode = feature['CNES_ref'];
// Check if the specialty already exists in the dictionary
if (!HasKey(specialtyDict, specialty)) {
// If not, initialize an empty array for this specialty
specialtyDict[specialty] = [];
}
// Add the health unit code to the array for this specialty
Push(specialtyDict[specialty], healthUnitCode);
}
// Return the dictionary as a JSON object
return Text(specialtyDict);
Description:
Hope it helps!
Hi there, I tried this FeatureSetByPortalItem but the problem is, it is not supported for symbology, it only supports popup and dashboard, as far as I learned from my endeavor! Thanks for your tips!