Select to view content in your preferred language

Arcade Attribute Rules to Create Sequential Number within Quads

315
6
10-30-2024 10:58 AM
GIS_geek
Regular Contributor

Hello,

I am using Attribute Rules and want to automate assigning numbers to newly created layers within a polygon. Eg. If I create a point in quad 267N, I want to look for the last number used for that point feature within that quad, and assign it the next sequential number.  The script that I am working on returned an error when verifying, "Invalid expression. Error on line 9. String type expected"

 

 

// Layers
var valves = FeatureSetByName($datastore, "dwSystemValve");
var quad = FeatureSetByName($datastore, "AtlasGrid_AtlasBook");

// Get the geometry of the current valve
var valveGeometry = Geometry($feature);

// Find the quad that contains the current valve
var containingQuad = First(Intersects(quad, $feature));

// If no quad is found, return an error or default value
if (IsEmpty(containingQuad)) {
return "No quad found";
}

// Get the quad sheet number of the current quad
var sheetID = containingQuad.SHEET;

// Query valves within the same quad
var valvesInQuad = Filter(valves, "SHEET = @sheetID");

// If no valves exist in the quad, start from 1
if (IsEmpty(valvesInQuad)) {
return 1;
}

// Find the highest valve number in the quad
var maxValve = Max(valvesInQuad, "NUM");

// Return the next available number
return maxValve +1;

 

 

 

0 Kudos
6 Replies
KenBuja
MVP Esteemed Contributor

You don't need the Filter function in line 9.

var containingQuad = First(Intersects(valveGeometry, Geometry($feature)));

In lines 12 and 17, you use the variable currentQuad. Shouldn't that be containingQuad?

Consider moving the if statement in line 26 to line 21, since you can evaluate whether there are any values found before trying to get the max value.

0 Kudos
GIS_geek
Regular Contributor

@KenBuja,

I removed the Filter function in line 9 and get a "Invalid expression. Error on line 9. Expected array or feature set"

Thank you for catching typos in line 12 and 17.

0 Kudos
KenBuja
MVP Esteemed Contributor

Sorry, I used the incorrect variable. This should work

var containingQuad = First(Intersects(quad, $feature));

You don't need to get the Geometry of the feature, in addition.

0 Kudos
GIS_geek
Regular Contributor

Encountered and error in line 28, "Field not found SHEET".

Is expression in line 28 looking for SHEET in the valve layer? That field does not exist in the valve layer. It is in the quad layer.

0 Kudos
KenBuja
MVP Esteemed Contributor

The way you have the Filter written in this line, it's expecting the valve layer to have a SHEET field.

var valvesInQuad = Filter(valves, "SHEET = @sheetID");

Do you have a field in the valve layer that contains that related sheetID values from the quad layer? Or do you need to use the Contains function to select the valves within the quad?

0 Kudos
GIS_geek
Regular Contributor

Valve layer does not contain sheetID.  I believe using the Contains function is what I am looking for.  I need this process to only look at valves within the quad the new valve is created.

0 Kudos