Select to view content in your preferred language

Populate a field using intersect/arcade

111
2
Thursday
MicBry
by
Emerging Contributor

Hi!

I have a point layer with the attirbute "location". Alongside this i have a polygon layer with the same field. When editing the point layer (e.g. making a new point) i would like the field location to be populated with the intersecting value from the polygon. From what i reckon this is doable in both pro and enterprise (ExB), which is what I would like. I have tried to follow instructions on how to use the attribute rules, but I get an arcade error every time. It does not seem like it's able to retrieve the information from the polygon. I tried using the instructions from this page: https://support.esri.com/en-us/knowledge-base/how-to-auto-populate-the-attribute-field-with-values-o...

Information about data:

Point layer

Name: Träd

Field name: Location

Polygon layer

Name: Fastighetsnummer

Field name: Locationname

 

Example of arcade code: 

var intersectline = FeatureSetByName($datastore, "Fastighetsnummer")
for( var f in intersectline){
if(Intersects($feature, f)){
return f.Locationname}
}

 

--

Does anyone know what I am doing wrong? I am currently working in arcgis pro, but I will upload it to enterprise if I manage to find a working solution. 

 

Best, Michaela

Tags (2)
0 Kudos
2 Replies
CodyPatterson
MVP Regular Contributor

Hey @MicBry 

I'm a big fan of testing through small adjustments and additions, in the Arcade, you'll want to use the Console() function to print out the outputs to verify they are what you expect, I would do something like this, please let me know if any do not happen to work, I'm working off documentation!

var polyg = FeatureSetByName($datastore, "Fastighetsnummer");
Console(polyg)

var inter = Intersects(polyg, $feature);
Console(inter)

Console(inter.Locationname)
return First(inter).Locationname;

 

Try this out and let me know if you see the expected results, I just separated the polygon and intersection calls! First just because there should only be one polygon per point, but if they're overlapped then I would add some logic to ensure it's the expected value!

Cody

KenBuja
MVP Esteemed Contributor

Just a warning that line 7 will crash the code. You'd have to return something like the count of the FeatureSet or get the first feature to get the Locationname attribute like you have in line 8.