|
POST
|
A few notes: Line 2: % is a wildcard for multiple characters, you need only one. You forgot to exclude "8%". You have leading zeros, so you can just do a string comparison: "ESTABLISHMENTID < '500'". Line 8: next is already a number! you're needlessly converting to text and then back to number. Your conversion is wrong. You always put two zeros before the number, resulting in "004", "0040", "00400". I overlooked the Right(). Still, it's very cumbersome. You want Text(next, "000"). Instead of checking if next is 500, check if next is smaller than 500 and return it straightaway. That save you from writing and reading the big if block. Line 10-21: instead of building the array, completely editing it, and then returning the first element, just return the first number not found in the featureset. Here's a simpler way to do this: // filter only business establishments
var fs = Filter($featureset, "ESTABLISHMENTID < '500'")
// get the next available id
var next = Number(Max(fs, "ESTABLISHMENTID")) + 1
// if that id is under 500, return it
if(next < 500) { return Text(next, "000") }
// else loop over the ordered featureset
fs = OrderBy(fs, "ESTABLISHMENTID")
var last = 0
for(var f in fs) {
// if there is a gap between the last checked and the current id, return the last id + 1
var current = Number(f.ESTABLISHMENTID)
if(current - last > 1) { return Text(last + 1, "000") }
last = current
}
// if we land here, there are no gaps. return a default value
return "999"
... View more
03-14-2023
03:37 AM
|
1
|
0
|
1537
|
|
POST
|
Use Summary Statistics to get counts of each combination of author/country. use anything for the Statistics Fields parameter, we don't care about that In the Case Fields parameter, input your two fields (author_name & country_en) The tool will generate a table. We're interested in the fields author_name, country_en (from your input table) and FREQUENCY, which counts how often the combination appeared in your input table. Use Calculate Field to create a new text field in the statistics table. Switch the language to Arcade and use this expression: // get all rows of the current user
var user = $feature.TextField1
var fs_user = Filter($featureset, "author_name = @user")
// get the total post count
var total = Sum(fs_user, "FREQUENCY")
// order by frequency and country name
var fs_user_ordered = OrderBy(fs_user, "FREQUENCY DESC, country_en")
// if you're only interested in the most likely country, uncomment this line and delete everything after
//return First(fs_user_ordered).country_en
// get the percentages of posts from each country
var percentages = []
for(var f in fs_user_ordered) {
var p = Round(f.FREQUENCY / total * 100)
Push(percentages, `${f.country_en} (${p}%)`)
}
return Concatenate(percentages, " / ") Run Summary Statistics on the statistics table to get one row for each user (use author_name & the new field as case fields)
... View more
03-14-2023
02:37 AM
|
2
|
1
|
1670
|
|
POST
|
You could use IsEmpty(Stage3), which will return true for null and "" (and some other values). But if if Stage3 is dependent on both previous stages passing, you can just leave it out of those conditions: var Stage1= $feature.inspectionresult
var Stage2= $feature.installationresults
var Stage3= $feature["ns_serviceentrance"]
return When(
Stage1=="Pass" && Stage2=="Fail", "Stage 1 Pass Stage 2 Fail",
Stage1=="Fail" && Stage2=="Pass", "Stage 1 Fail Stage 2 Pass",
Stage1=="Fail" && Stage2=="Fail", "Stage 1-2 Fail",
Stage1=="Pass" && Stage2=="Pass" && Stage3=="Pass", "Stage 1-2-3 Pass",
Stage1=="Pass" && Stage2=="Pass" && Stage3=="Fail", "Stage 1-2 Pass Stage 3 Fail",
"You missed a condition!"
)
... View more
03-14-2023
01:44 AM
|
1
|
0
|
3575
|
|
POST
|
consider using 'else if' to make the code more efficient If I'm not mistaken, that won't do anything here. If the condition is evaluated to be false, the following block is skipped, and the next condition is evaluated, regardless of if you use "if " or "else if". And if the condition evaluates to true, then the following block will be entered, and then the expression returns, skipping everything after that (as you said). In terms of writing efficiency, you could do this a little easier with When(): return When(
Stage1=="Pass" && Stage2=="Fail" && Stage3=="Fail", "Stage 1 Pass Stage 2-3 Fail",
Stage1=="Pass" && Stage2=="Pass" && Stage3=="Fail", "Stage 1-2 Pass Stage 3 Fail",
Stage1=="Pass" && Stage2=="Fail" && Stage3=="Pass", "Stage 1-3 Pass Stage 2 Fail",
Stage1=="Pass" && Stage2=="Pass" && Stage3=="Pass", "Stage 1-2-3 Pass",
Stage1=="Fail" && Stage2=="Pass" && Stage3=="Pass", "Stage 1 Fail Stage 2-3 pass",
Stage1=="Fail" && Stage2=="Fail" && Stage3=="Pass", "Stage 1-2 Fail Stage 3 pass",
Stage1=="Fail" && Stage2=="Pass" && Stage3=="Fail", "Stage 1-3 Fail Stage 2 pass",
Stage1=="Fail" && Stage2=="Fail" && Stage3=="Fail", "Stage 1-2-3 Fail",
"SomeDefaultValue"
) And if we go down the path of writing efficiency, this is still quite bad. For the 8 permutations in this case, writing out all of them is still feasible. But imagine you'd need to add a fourth stage or another possible evaluation result (eg "undetermined"). Then we have 16 (4^2) or 27 (3^3) possible permutations. It quickly becomes unfeasible to write them all out. In these cases, it's much more effcient (at least in terms of writing the expression, no idea about execution), to work with arrays/dictionaries: var stages = [
$feature.inspectionresult,
$feature.installationresults,
$feature.ns_serviceentrance,
]
var possible = ["Pass", "Fail"]
var values = Dictionary()
for(var i in stages) {
var v = stages[i]
Console(v)
if(HasKey(values, v)) { Push(values[v], i + 1) }
else { values[v] = [i + 1] }
}
var parts = []
for(var i in possible) {
var v = possible[i]
if(!HasKey(values, v)) { continue }
Push(parts, "Stage " + Concatenate(values[v], "-") + " " + v)
}
return Concatenate(parts, " & ") Now, if we want to add another stage and/or another possible result, we just have to edit the two variables:
... View more
03-11-2023
04:34 AM
|
1
|
3
|
3654
|
|
POST
|
Ah. You can use this expression in a dashboard list/table: // load all project layers (change to you layer ids)
var project_layers = [
FeaturesetByPortalItem(Portal("https://arcgis.com"), "b0d335151aad48a5883326b9aed69cdd", 0),
FeaturesetByPortalItem(Portal("https://arcgis.com"), "b0d335151aad48a5883326b9aed69cdd", 1),
FeaturesetByPortalItem(Portal("https://arcgis.com"), "b0d335151aad48a5883326b9aed69cdd", 2),
]
// read the project data (change to yoour fields)
var projects = []
for(var i in project_layers) {
for(var p in project_layers[i]) {
var project = {
name: p.TextField1,
contact: p.TextField2,
start: p.DateField1,
end: p.DateField2,
geo: Geometry(p),
b_geo: Buffer(p, 250, "feet"),
}
Push(projects, project)
}
}
// create the output dictionary
var out_dict = {
fields: [
{name: "Project1", type: "esriFieldTypeString"},
{name: "Contact1", type: "esriFieldTypeString"},
{name: "Runtime1", type: "esriFieldTypeString"},
{name: "Project2", type: "esriFieldTypeString"},
{name: "Contact2", type: "esriFieldTypeString"},
{name: "Runtime2", type: "esriFieldTypeString"},
{name: "Distance", type: "esriFieldTypeDouble"},
{name: "Overlap", type: "esriFieldTypeInteger"},
],
geometryType: "",
features: []
}
// find overlapping projects
for(var p in projects) {
for(var q = p + 1; q < Count(projects); q++) {
var p1 = projects[p]
var p2 = projects[q]
// skip if no spatial overlap
if(!Intersects(p1.b_geo, p2.geo)) { continue }
// skip if no temporal overlap
if(p1.start > p2.end || p2.start > p1.end) { continue }
// calculate temporal overlap
var overlap_start = Date(Max([Number(p1.start), Number(p2.start)]))
var overlap_end = Date(Min([Number(p1.end), Number(p2.end)]))
var overlap = DateDiff(overlap_end, overlap_start, "days") + 1
// append the project pair to output
var pair = {
Project1: p1.name,
Contact1: p1.contact,
Runtime1: Text(p1.start, "MM/DD/Y") + " - " + Text(p1.end, "MM/DD/Y"),
Project2: p2.name,
Contact2: p2.contact,
Runtime2: Text(p2.start, "MM/DD/Y") + " - " + Text(p2.end, "MM/DD/Y"),
Distance: Distance(p1.geo, p2.geo),
Overlap: overlap,
}
Push(out_dict.features, {attributes: pair})
}
}
// convert to Featrueset and return
return Featureset(Text(out_dict)) With the expression set up like this, it will return one entry for each pair of overlapping projects: You can replace line 41 with this: for(var q in projects) {
if(p == q) { continue } Then you will get two entries for each pair of overlapping projects:
... View more
03-09-2023
04:56 AM
|
1
|
0
|
3970
|
|
POST
|
To post code: You didn't adapt the filter query to your data. This should work: // Filter related features by using a common attribute
var globalid = $feature.globalid
var filterStatement = 'GUID = @globalid' // GUID instead of parentglobalid
... View more
03-07-2023
09:32 AM
|
0
|
2
|
1608
|
|
POST
|
FeatureclassByName- is not available Oops, got confused with the terminology. Good catch, I edited my answer.
... View more
03-07-2023
09:26 AM
|
1
|
0
|
1955
|
|
POST
|
We gave you solutions for parcel ids with exactly 16 characters. Is this always the case? You also should implement a null check: if(IsEmpty($feature.PARCELID)) { return null }
// any of our expressions after this.
... View more
03-07-2023
09:23 AM
|
0
|
1
|
5288
|
|
POST
|
// Calculation Attribute Rule on Featureclass B
// Field1
// Triggers: Insert, Update
var field_2 = $feature.Field2
// if we're inserting a fetaure with an empty Field2
// or we're updating a feature without changing Field2,
// return the value that is already in Field1
if(($editcontext.editType == "INSERT" && field_2 == null) ||
($editcontext.editType == "UPDATE" && $originalfeature.Field2 == field_2)) {
return $feature.Field1
}
// load Featureclass A
var fc_a = FeaturesetByName($datastore, "FeatureclassA")
// get the related feature
var related_a = First(Filter(fc_a, "Field2 = @field_2"))
// return that feature's Field1 value or null if no feature was found
return IIf(related_a == null, null, related_a.Field1)
... View more
03-07-2023
04:59 AM
|
1
|
0
|
1976
|
|
POST
|
A configurable way: var parcel_id = Split(Text($feature.PARCELID), "")
//var parcel_id = Split("1701010000001000", "")
var counts = [2, 2, 2, 1, 3, 3, 3]
var separators = ["-", "-", "-", "-", "-", ".", null]
var formatted_id = ""
var index = 0
for(var c in counts) {
var part = Concatenate(Slice(parcel_id, index, index + counts[c]))
formatted_id += part + separators[c]
index += counts[c]
}
return formatted_id
... View more
03-07-2023
04:47 AM
|
2
|
1
|
5294
|
|
POST
|
How would I generate the overlap feature and table that met the spatial and date conditions? Not sure what you're asking. Can you clarify? if a field like contact existed with an email, would it be possible to generate a notification to both project contacts if the conditions of location and dates is met? Probably, but not with Arcade. You can whip up a Python script that sends the mails. I think you could execute the script via a webhook when a new project is inserted, but I don't know anything about that.
... View more
03-06-2023
11:28 AM
|
0
|
2
|
3991
|
|
POST
|
I think table b has to be included for the $datastore to work. You don't need to consume the published table b in your map/application, but it should be in the service.
... View more
03-06-2023
11:20 AM
|
0
|
0
|
2740
|
|
POST
|
Hmm, according to the version matrix, ArcGIS Server 10.8.1 should include Arcade 1.10 at least. Filter() was released in 1.5. What error do you get? Anyway, you could try FeaturesetByRelationshipName(), but that was released in Arcade 1.8, so it will probably be the same. You could also do it with a for loop. It will be slower than Filter(), especially if table B has many entries, but it should get the job done: var table_b = FeaturesetByName($datastore, "TableB")
var gid = $feature.GLobalID
var v = null
for(var b in table_b) {
if(b.gid_fk == gid) {
v = b.v
break
}
}
return {
"edit": [{
"className": "table C",
"adds": [{
'attributes':
{
"gid_fk":$feature.globalid,
"v": v
}
}]
}]
}
... View more
03-06-2023
04:39 AM
|
0
|
2
|
2763
|
|
POST
|
You could use the Filter() function. var table_b = FeaturesetByName($datastore, "TableB")
var gid = $feature.GLobalID
var related_b_row = First(Filter("gid_fk = @gid")) // use the actual field name!
var v = IIf(related_b_row == null, null, related_b_row.V)
return {
"edit": [{
"className": "table C",
"adds": [{
'attributes':
{
"gid_fk":$feature.globalid,
"v": v
}
}]
}]
}
... View more
03-05-2023
10:49 PM
|
0
|
4
|
2782
|
|
POST
|
There should be an option in the Map Widget to allow popups. https://doc.arcgis.com/en/experience-builder/latest/configure-widgets/map-widget.htm
... View more
03-05-2023
12:46 PM
|
1
|
0
|
5269
|
| 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
|