Help completing Arcade Script in AGOL to extract data from one layer's field to insert into another layer's field based on intersecting features

360
5
Jump to solution
02-15-2024 08:20 AM
Labels (3)
Mowgli_GIS
New Contributor III

Hello, I'm trying to write a script in Field Maps that will extract a value from a field in one layer and then insert that value into a field in another layer based on snapped/intersecting features.  However, I only have a basic understanding of Arcade and am having difficulty formulating a working script (if it's possible?).  I found some example of code that I think is what I need, or at least close to what I need but I can't figure out how to tailor it to my needs.

My task is to design where Risers should be placed on Utility Poles, which there is a field in the Riser layer for "Pole ID".  So as I'm placing new Risers in the Web map I would like the Riser's "Pole ID" field to auto populate with the corresponding Pole feature ID on which the Riser is snapped.  The Riser and Pole are both point features and part of the same Geodatabase which was published as Hosted Feature layer.  Below is what I have so far, code is being created within the Riser's "Pole ID" field:

Mowgli_GIS_0-1708013525229.png

I can't figure out what my return script should be? Or if I should be utilizing completely different approach?

Appreciate any help or insight anyone could offer!

 

0 Kudos
1 Solution

Accepted Solutions
EmilyGeo
Esri Contributor

Hi @Mowgli_GIS

You're on the right track.

Check out this blog post on using Feature Set/ Intersect for more info and a sample expression. 

Here is the sample expression from the post: 

// Define a Featureset (zones) from the layer "Zoning Codes" in the $map
// that contains the attribute ['zone_class']

var zones = FeatureSetByName($map, "Zoning Codes", ['zone_class'])

// Define a variable (code) to store the value we want
// Get the value by Intersecting the point location
// with the FeatureSet "Zoning Codes", or zones

var code = First(Intersects($feature, zones))

// If the current location intersects Zoning Codes,
// return the value in the field ['zone_class'].
// Otherwise, return a null value for areas where there is no intersecting polygon

if (!IsEmpty(code)) {
return code['zone_class']
} else {
return null
}

Hope that helps! 

Emily

View solution in original post

5 Replies
EmilyGeo
Esri Contributor

Hi @Mowgli_GIS

You're on the right track.

Check out this blog post on using Feature Set/ Intersect for more info and a sample expression. 

Here is the sample expression from the post: 

// Define a Featureset (zones) from the layer "Zoning Codes" in the $map
// that contains the attribute ['zone_class']

var zones = FeatureSetByName($map, "Zoning Codes", ['zone_class'])

// Define a variable (code) to store the value we want
// Get the value by Intersecting the point location
// with the FeatureSet "Zoning Codes", or zones

var code = First(Intersects($feature, zones))

// If the current location intersects Zoning Codes,
// return the value in the field ['zone_class'].
// Otherwise, return a null value for areas where there is no intersecting polygon

if (!IsEmpty(code)) {
return code['zone_class']
} else {
return null
}

Hope that helps! 

Emily

Mowgli_GIS
New Contributor III

Hi @EmilyGeo , thank you so much for the help!!  This is exactly what I needed.  I also realized that for scenarios where a point is being snapped to a point, the 'EnvelopeIntersects' function is needed rather than 'Intersects'.

Thank you for the help, really appreciate it!!

0 Kudos
Mowgli_GIS
New Contributor III

Hi @EmilyGeo , sorry to bother you again, but I've hit another wall and cannot wrap my head around the code that is required.

Similar scenario as before, but now I would like the line features created in a Cable layer to pull the Pole ID for the Start and End points of the lines (i.e., Cable A feature starts at Pole 1 feature and ends at Pole 2 feature, and thus the Start ID and End ID fields in the Cable layer would be auto populated with "Pole 1" and "Pole 2").  I found some references to "looping" thru the line to acquire this along with the start/end point functions for lines, but I'm struggling to understand.  

I did use the below, which worked but only for extracting the Pole ID if the Pole point was snapped to a midpoint of the line, it wouldn't extract the ID of the pole where the line started/ended:

// Define a Featureset (poles) from the layer "Pole" in the $map
// that contains the attribute ['ID']

var poles = FeatureSetByName($map, "Pole", ['ID'])

// Define a variable (PoleID) to store the value we want
// Get the value by Intersecting the point location
// with the FeatureSet "Pole", or poles

var PoleID = First(EnvelopeIntersects($feature, poles))

// If the current location intersects Pole,
// return the value in the field ['ID'].
// Otherwise, return a null value for areas where there is no intersecting point

if (!IsEmpty(PoleID)) {
return PoleID['ID']
} else {
return "test"
}

 

I appreciate any help you could offer.  Thank you!  

0 Kudos
EmilyGeo
Esri Contributor

Hi @Mowgli_GIS

I recommend checking out this article by Alix where she provides some sample code for functions like fetching an attribute from a nearby feature. https://www.esri.com/arcgis-blog/products/arcgis-online/mapping/from-the-smart-editor-to-smart-forms...

I hope it helps! 

 

0 Kudos
Mowgli_GIS
New Contributor III

Thank you @EmilyGeo !  This looks like it has a lot of very useful info and application to my work flows!

0 Kudos