|
BLOG
|
This is a very good point. I don't really know how Arcade interacts with servers (and I think that's shared by most users). All we have to lead us are common tips like "don't load geometries if not absolutely necessary", but I often feel like excluding geometries and fields doesn't really have much impact on performance. But I 100% used Filter() in loops, thinking that it would only communicate with the server once. Same goes for other functions like Intersects(), which probably has the same outcome of hammering the server. It would be good to have a native function to load Featuresets into RAM. Maybe even an optional argument in the FeaturesetBy*() functions. var fs = FeatureSetByPortalItem(portalObject, itemId, layerId?, fields?, includeGeometry?, memorize?) If you turn this blog into an Idea, I'd be sure to upvote.
... View more
05-13-2023
02:00 AM
|
1
|
0
|
6291
|
|
POST
|
Hmm, works for me. Did you refresh your Experience? The map widget will not change dynamically, you need to reload it.
... View more
05-12-2023
02:07 AM
|
0
|
0
|
1587
|
|
POST
|
To post code: (Probably) for performance reasons, fields that are not called explicitly ($feature.FieldName / $feature["FieldName"]) are not loaded. If you want to address fields dynamically, you need the Expects() function to load them first. Luckily, you don't need to type in all the fields you want to load, you can just supply a wildcard. This is without Expects(): var fields = Schema($feature).fields
var output = []
for (var field in $feature) {
Push(output, field + ": " + $feature[field])
}
return Concatenate(output, TextFormatting.NewLine) And with Expects(), it actually loads all the fields first, so it can show the values: var fields = Schema($feature).fields
Expects($feature, "*")
var output = []
for (var field in $feature) {
Push(output, field + ": " + $feature[field])
}
return Concatenate(output, TextFormatting.NewLine) Also, you don't need to get the Featureset, you can just call Schema() on $feature. var fields = Schema($feature).fields
Expects($feature, "*")
var output = []
for (var field in $feature) {
if ($feature[field] == 'Yes') {
for (var i in fields) {
if(fields[i].name == field) {
Push(output, Replace(fields[i].alias, "_", " "))
}
}
}
}
return Concatenate(output, TextFormatting.NewLine)
... View more
05-12-2023
01:57 AM
|
4
|
1
|
2149
|
|
POST
|
Web AppBuilder: Splash Widget Experience Builder: Add a window and set it as Splash Both of these show a splash screen when you start the app. The user has to acknowledge that screen. Optionally, you can add a checkbox to not show this screen again.
... View more
05-12-2023
01:21 AM
|
0
|
0
|
1372
|
|
POST
|
Maybe if you set the return value to the default and only edit it if all the conditions are met? var recOrder = OrderBy(FeatureSetByRelationshipName($feature, "T4C_Records"),"CollectDate DES" );
var countRec = count(recOrder);
var relatedInfo = "None to date";
if (countRec > 0) {
var lastDate = First(recOrder).CollectDate;
if(lastDate != null) {
relatedInfo = Text(ToLocal(lastDate), "MM/DD/Y");
}
}
return relatedInfo You could also filter out null dates: var rec = FeatureSetByRelationshipName($feature, "T4C_Records")
var recFilter = Filter(rec, "CollectDate IS NOT NULL")
var recOrder = OrderBy(recFilter, "CollectDate DES");
var countRec = count(recOrder);
var relatedInfo = "None to date";
if (countRec>0) {
var info = First(recOrder);
relatedInfo = Text(ToLocal(info.CollectDate), "MM/DD/Y");
}
return relatedInfo
... View more
05-10-2023
10:41 AM
|
0
|
1
|
1798
|
|
POST
|
That isn't expected behavior, no. SQL should be case sensitive. I couldn't reproduce that behavior (FGDB, 3.1.1), regardless of whether the field has a domain or not. To solve your immediate problem, you could just use the Calculate Field tool with an expression (Python) like this: !WA_FLAG!.title()
... View more
05-10-2023
09:17 AM
|
1
|
0
|
4904
|
|
POST
|
Multiple problems here: line 2: Buffer() takes a Feature or a Geometry, you're giving it a field value. Buffer($feature, 50, 'feet'); line 6&7: If you loop through a Featureset, the loop variable is actually the Feature: for(var f in fs) {
Console(f.Field)
} line 8: Distance() takes tow Features or Geometries. You're supplying a non-existing field. var d = Distance($feature, other_feature, "feet") line 14: this looks like you're used to the truthy values of Python. This doesn't work with Arcade, you have to check actual booleans. if (closestHydrant != null) { throughout the expression: You're using function names as variable names (Buffer, Feature, Distance). This is a very bad practice, because you're overwriting these functions. After line 2, you can't call Buffer() anymore, because that name is now bound to a polygon. This isn't a problem in your expression, but you have the same thing going on with Distance(), and you try to call that in a loop, which will fail. var hydrantLayer = FeatureSetByName($datastore, 'SDEP.SDEADMIN.w_watr_hydrant');
var b = Buffer($feature, 50, 'feet');
var closestHydrant;
var closestDistance = 9999999;
var intersectedFeatures = Intersects(hydrantLayer, b);
for (var f in intersectedFeatures) {
var d = Distance($feature, f, 'feet');
if (d < closestDistance) {
closestDistance = d;
closestHydrant = f;
}
}
if (closestHydrant != null) {
return closestHydrant['UID'];
}
return null;
... View more
05-10-2023
08:36 AM
|
2
|
0
|
2886
|
|
POST
|
To post code: Can't see anything obviously wrong at first glance. Maybe you see features that do have related records, but those records have null values in the date field? In that case, the expression returns an empty string. Try to incorporate that condition: var relRec = OrderBy(FeatureSetByRelationshipName($feature , "T4C_Records"), "CollectDate DES")
var info = First(relRec)
return IIf(info == null || info.CollectDate == null,
"None To Date",
Text(ToLocal(info.CollectDate), "MM/DD/Y")
)
... View more
05-10-2023
08:11 AM
|
0
|
3
|
1817
|
|
POST
|
If that solved your question, please mark the answer as solution, so this question is shown as solved.
... View more
05-06-2023
01:11 AM
|
0
|
0
|
1759
|
|
POST
|
You can access field values by using the field name in brackets or in dot notation: return $feature["Field"]
return $feature.Field So you could do something like this: return When(
$feature.Option1 == 1, $feature.Question3,
$feature.Option2 == 1, $feature.Question4,
"something went wrong: both options were deselected"
)
... View more
05-04-2023
04:41 PM
|
0
|
0
|
1769
|
|
POST
|
AFAIK, each field in a GroupBy (be it in Arcade or SQL) is either part of the group or part of the statistics. If I add them to the GroupBy clause, I get every unique combination of all three fields, which I don't want Well, that seems logical to me. Say we have the sample types ["S1", "S2", "S3"] and the sites ["A", "B", "C", "D"] (we'll skip the dates) You can get statistics on the sample types ("There were 123 samples of type S1, 2 samples of type S2, 34 samples of type S3"). You can get statistics on the type and site: "There were 25 S1 samples at A, 50 at B, 25 at C, 23 at D. etc." If you don't put the sites into the group too, the sample type loses its relationship to the site. So how do you want to relate them? Or do you just want to return distinct values for sites and dates?
... View more
05-04-2023
04:34 PM
|
0
|
2
|
1865
|
|
POST
|
You don't need all those fields. Loading many fields slows the expression down. You actually don't need any fields for your calculation, so you should be a able to get away with only loading GlobalID. Reverse your intersect. Right now, you're iterating over each feature of each priority fs, buffer it and check for intersections with the ramp fs. Instead, iterate over the ramp fs, create a buffer for each ramp and check for intersections with each priority fs. This means you call Buffer() and Intersects() far less. If you do it that way, you also don't need to get the priority fs geometries (which also slows the expression down) because you don't actually need to work with the geometries. The Intersects() is done by AGOL/Portal var portals = portal('Some org url');
var mRamp = FeatureSetByPortalItem(portals, 'some item id',8,['PassFail', 'GlobalID'], true);
var sql = `PassFail = 'Fail'`;
Var FailRamps = Filter(mRamp,sql);
//set feature sets of prox priorities
var PriorityFeaturesets = [
FeatureSetByPortalItem(portals, 'some item id',4,['GlobalID'], false),
FeatureSetByPortalItem(portals, 'some item id',8,['GlobalID'], false),
FeatureSetByPortalItem(portals, 'some item id',7,['GlobalID'], false),
FeatureSetByPortalItem(portals, 'some item id',9,['GlobalID'], false),
FeatureSetByPortalItem(portals, 'some item id',8,['GlobalID'], false),
FeatureSetByPortalItem(portals, 'some item id',20,['GlobalID'], false),
]
var capturedRamps = 0
for(var fr in FailRamps) {
var frBuffer = Buffer(fr, 0.125, "miles")
for(var i in PriorityFeaturesets) {
capturedRamps += Count(Intersects(PriorityFeaturesets[i]))
}
}
return capturedRamps It could very well be that this doesn't make the expression much faster. It turns out that accessing a featureset for the first time just takes a lot of time, while subsequent accesses are basically instantaneous. Consider lending your support to this idea to maybe get that changed in the future.
... View more
05-04-2023
04:19 PM
|
0
|
0
|
4134
|
|
BLOG
|
Time to bookmark this post for all the future questions, I guess... But yeah, better fix it than leave it broken. Thanks for the heads-up! PS: Your examples won't work in 3.1 either (I hope), because you try to get the attribute from the fs, not firstRow. Also maybe remove the comment from the fixed example, because now it actually should not fail anymore.
... View more
05-04-2023
03:37 PM
|
2
|
0
|
1293
|
|
POST
|
To post code: Wow, I searched and searched for an error, because your expression returned the correct result (except for that "0" at the start). But you actually have multiple codes for the same land use... So you need to summarize by the actual land use, not the code. Do the decoding in the loop where you fill int_dict.
... View more
05-04-2023
03:30 PM
|
1
|
4
|
3726
|
|
POST
|
Calculate Field expects you to return a single value, but you return an Array (the square brackets), which is a collection of multiple values. (Popup expressions also expect a single return value, I get that by using the Concatenate function) You just have to return the count: var filtered_defects = Filter(defects, query)
return Count(filtered_defects)
... View more
05-04-2023
02:34 PM
|
0
|
0
|
2496
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 01-30-2023 09:57 AM | |
| 1 | 05-18-2023 12:51 AM | |
| 1 | 03-05-2023 12:46 PM | |
| 1 | 12-07-2022 07:01 AM | |
| 1 | 06-21-2022 08:27 AM |
| Online Status |
Offline
|
| Date Last Visited |
02-03-2024
06:14 PM
|