Hello, I'm trying to extract data from a layer's field and insert into another layer's field based on attributes matching each other from both features, but I'm struggling to create the correct script.
My scenario is I have a Utility Pole layer and Cable layer, wherein I have a field in both layers for the combined lat/long coordinates, and as I create new features in the Cable Layer I need to provide both the Start Pole ID and End Pole ID on which the cable is attached (Start ID and End ID are fields in Cable Layer, and Pole Layer has an ID field). So my thought, if possible, is to create an Arcade script in the Cable Start/End ID fields that will look at the Pole layer's Lat/Long coordinate field for a feature with the matching coordinates to the Cable's feature, and if there is a match then extract that Pole Feature's ID and insert in either the corresponding Start or End ID field of the Cable feature. Below is what I have, code is being written within the Start ID and/or End ID fields of the Cable layer feature, however it does not work:
Solved! Go to Solution.
@JohnEvans6 , I guess I replied a bit too quick, I tried one more thing and it worked! Below is the code:
Adding to/Updating my original post - below is script I've come up with that seems to get me almost there, but not quite - this code block is being written in the "PoleID" field of the Cable layer:
1 | "Pole-1" |
And within the actual field it returns [object Object]
I need the Cable's PoleID field for the specific feature to return the "Pole-1" attribute value.
Sorry I don't have time to check if this actually works, but I think you want something that looks like this. If it doesn't work it hopefully gets you close to a solution.
// Build SQL to query against Pole Layer. LatLong is in the pole field. feature.LatLong is the cable's LatLong field
var sql = Concatenate("LatLong = ", $feature.LatLong)
// Filter your pole layer get to only return features where the LatLong fields are equal between Cable and Pole
var features = Filter(FeatureSetByName($map, "Pole", ['LatLong','PoleID']), sql)
// If return is not empty. get the first feature and build your return text
if (!IsEmpty(features)) {
var pole_data = First(features)
return {
type : 'text',
text : `This cables Start/End Pole is: ${pole_data.PoleID}`
}
}
Hi @JohnEvans6 , thank you for the feedback. I've been working thru what you provided, but am still having trouble/receiving errors, although I think it is likely due to me not replicating correctly.
If/when you have time, I have a few questions. Below is the code I have written based on the feedback/example you provided - **I realized instead of my fields in both layers called LatLong, they are titled "XYjoin":
Knowing me I overcomplicated it. What about something simpler like
var pole_features = FeatureSetByName($map, "Pole", ['XYjoin','PoleID'])
for (var f in pole_features) {
If (f.XYjoin == $feature.XYjoin) {
return {
type : 'text',
text : `Pole ID is : ${f.PoleID}`
}
}
}
Hi @JohnEvans6 , it’s me again, sorry…..
I keep getting errors and I have a tough time understanding the syntax fully. I’m not sure what I have wrong. I've tried a bunch of different iterations, but below is the current iteration that I have. The portions marked with yellow I’m not fully following what they represent and where those pieces are being pulled from.
What does f.XYjoin represent on line 8?
What do lines 10 & 11 represent/where is f.PoleID pulled from/represent?
I also provided the screen shots of the Profile variables
The string of code is being written within the pole_id field of the Riser Layer
Pole layer fields and info are being pulled from the $map feature service (see below)
The ID field marked below is the pole layer’s ID field from which I want to pull an attribute and insert into the pole_id field in the Riser layer based on the pole layer’s XYjoin field attribute matching the Riser layer’s XYjoin field attribute
Again, apologies for the repeated questions, and I appreciate if/when you’re able to provide any help & feedback.
THANK YOU!
Get rid of your first 3 variables and just use PoleFeatures.
f is just variable that holds the data from each feature within PoleFeatres
${f.PoleID} should just be ${f.ID}, sorry. Hard to work with data I can't see.
If you put a Console(f) above the if statement, it will print out each feature within PoleFeatures as it iterates. You're sure the XYjoin field will match between the two data sets, yeah?
Hi @JohnEvans6 , I think we're close? I adjusted based on your feedback and below is what came back:
I also confirmed that the XY values match in both layers for the specific features I used to test the code.
However, when I created the new Riser feature, below is what populated in the pole_id field for the Riser feature:
But what I want to populate is just the HSWG text, which is the pole feature's ID:
Sorry again for all the questions, and I appreciate all the feedback/help you've given!
@JohnEvans6 , I guess I replied a bit too quick, I tried one more thing and it worked! Below is the code: