Attribute Rule for Intersecting Layer

4902
8
Jump to solution
09-01-2020 03:47 PM
JoeBorgione
MVP Emeritus

ArcGIS Pro 2.5.1

In March, 2020, I posted Chasing my tail with Arcade/Attribute Rules and Jake Skinner‌ provided an attribute rule that worked just fine for me.  Until today.  The rule  updates a field in a point feature class when a new point is created with the name of the municipality the point is located within:

var township = FeatureSetByName($datastore,"MunicipalitiesMSD",["NAME"],true)
var intersectLayer = Intersects(township, Geometry($feature))
var layer = First (intersectLayer)
return layer.NAME

When I verify the expression, I get an error:

Invalid expression

Error line 4.

Dictionary type expected

I've also deployed the same basic expression to get the Zipcode from an intersecting zip polygon and it now tosses the same error. I don't see the problem.

Jake Skinner

Xander Bakker

That should just about do it....
Tags (1)
0 Kudos
1 Solution

Accepted Solutions
XanderBakker
Esri Esteemed Contributor

Hi jborgion ,

The fact that something stopped working could be due to change in Arcade (which I highly doubt) or change in the data. Can you test the expression in a pop-up to see what is returned?

I would change a couple of things: 

  • You don't need to retrieve the geometry, even if you are going to use the featureset in an intersect afterwards (line one "true" changed to "false")
  • I included two Console statements on line 2 and 5 (but I'm not sure if you can see the result in Pro)
  • When you are going to access the first of something, always be sure there is something. I use a count on line 5 and 6 to validate that
  • Also define what to do when you don't find an intersecting feature
var township = FeatureSetByName($datastore, "MunicipalitiesMSD", ["NAME"], false);
Console("cnt township: " + Count(township));
var intersectLayer = Intersects(township, $feature);
var cnt = Count(intersectLayer);
Console("cnt intersectLayer: " + cnt);
if (cnt > 0) {
    var feat = First(intersectLayer);
    return feat.NAME;    
} else {
    // what do you want to do if no intersecting feature was found?
}

However, none of these recommendations explains why a something that worked before suddenly does not work. It might be good to call support for this one.

View solution in original post

8 Replies
XanderBakker
Esri Esteemed Contributor

Hi jborgion ,

The fact that something stopped working could be due to change in Arcade (which I highly doubt) or change in the data. Can you test the expression in a pop-up to see what is returned?

I would change a couple of things: 

  • You don't need to retrieve the geometry, even if you are going to use the featureset in an intersect afterwards (line one "true" changed to "false")
  • I included two Console statements on line 2 and 5 (but I'm not sure if you can see the result in Pro)
  • When you are going to access the first of something, always be sure there is something. I use a count on line 5 and 6 to validate that
  • Also define what to do when you don't find an intersecting feature
var township = FeatureSetByName($datastore, "MunicipalitiesMSD", ["NAME"], false);
Console("cnt township: " + Count(township));
var intersectLayer = Intersects(township, $feature);
var cnt = Count(intersectLayer);
Console("cnt intersectLayer: " + cnt);
if (cnt > 0) {
    var feat = First(intersectLayer);
    return feat.NAME;    
} else {
    // what do you want to do if no intersecting feature was found?
}

However, none of these recommendations explains why a something that worked before suddenly does not work. It might be good to call support for this one.

JoeBorgione
MVP Emeritus

Xander Bakker‌; I think the problem was on my end: this particular rule is based on a relationship class, and I had neglected to have that relationship class created when I tested yesterday.  (It came to me as s one of those 'eyes slamming open moments at 2 am.) So I created the relationship class and things seem to be just fine.

That should just about do it....
0 Kudos
JoeBorgione
MVP Emeritus

I spoke to soon:  I have two attribute rules that do the basically the same thing; after creating the relationship class, one works and the other tosses the dictionary error as noted originally.

This flavor works: it grabs the underlying city and adds it to a new point:

var township = FeatureSetByName($datastore,"MunicipalitiesMSD",["NAME"],true)
var intersectLayer = Intersects(township, Geometry($feature))
var layer = First (intersectLayer)
return layer.NAME

This flavor should add the underlying Zip code to the same point:

var zip = FeatureSetByName($datastore,"Zipcodes",["ZIP_MOD_ID"], true)
var intersectLayer = Intersects(zip, Geometry($feature))
var layer = First(intersectLayer)
return layer.ZIP_MOD_ID‍‍‍‍

The 'ZIP_MOD_ID' field in the Zipcodes feature class is of long numeric type, as is the field I'm applying this rule to in my point feature class.

Xander Bakker- the console() function does not work in Pro, but when I mimic the rest of your suggested code, it tosses the same Dictionary type error:

Sigh....

That should just about do it....
0 Kudos
JoeBorgione
MVP Emeritus

I just migrated the the one expression that 'works' in the FGDB environment to out EGDB environment.  The good news is it doesn't toss the Dictionary error.  The bad news is it tosses a different error...

That should just about do it....
0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Joe Borgione ,

See my initial comment and always include a check to see if you have something before you try to access the properties of nothing.

Also, I have noticed in the past that Arcade does not always like you at access attributes using $feature.field_name, when the field name has un underscore in the name. Please use $feature["field_name"] instead.

0 Kudos
JoeBorgione
MVP Emeritus

always include a check to see if you have something before you try to access the properties of nothing.

Xander Bakker-  words of wisdom to be sure.  In a separate email to and from Chris Fox‌, he explained that when one uses Verify in the expression window, it not only checks for syntax issues but executes the expression as well.  I did not realize that.  None the less, now that I have deployed your check, all is well.  I don't have any idea why it worked in the past, but I'm moving forward, not looking back!

That should just about do it....
by Anonymous User
Not applicable

I had the same issue and your Arcade code works for me. Thanks! Now I ran into something else and can't seem to figure out a good way to get it to work.

I have a couple polygons that features intersect with that are overlapping. Do you have any suggesstions with dealing with overlapping polygons? One easy solution would be to clip the polygons so they don't overlap but that is not an option for now. In my case there is a field in the features being intersected with the polgyons that could be used. For example when feature A intersects with overlapping polgyons 1 and 2 and feature A has an attribute value of Blue I want it to take the value coming from polygon 2 because polygon 2 is also blue. Hope that made sense. I would apprieiate any help.

0 Kudos
SU00861536
New Contributor III

Hi @XanderBakker / @JoeBorgione 

I am facing some technical challenge in calculating the immediate attribute rule to generate the unique parcel id. In my requirement at the time of insert new feature unique id generated and no problem.

if ($editContext.editType == "INSERT") {
                 //var seq = NextSequenceValue("uniqueparcel")
                 //return "ID-"+seq
                 var seq = Text(NextSequenceValue("uniqueparcel"), "000000")
                 var parcelid = planning_area_code+"_"+ "I" +"_"+parentcode +"_"+seq
                 return parcelid

Now I want to update means split this polygon into 2 polygons, so this time i want to update the parcel id with old parcel id and suffix _1 & _2.  eg OLD ID = PA00050 and after split update the parcel id = PA00050_01 & PA00050_02. 

else if ($editContext.editType == "UPDATE") {
    // get intersecting polygon
       for(var poly in Intersects($originalfeature, fsMAP)) 
0 Kudos