<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Using Intersect Attribute Rule on Overlapping Polygons? in Attribute Rules Questions</title>
    <link>https://community.esri.com/t5/attribute-rules-questions/using-intersect-attribute-rule-on-overlapping/m-p/1187189#M451</link>
    <description>&lt;P&gt;Your syntax is OK.&lt;/P&gt;&lt;P&gt;You don't need the elses here, because when you return, the rest of the code gets skipped and isn't executed. But that's a small, optional thing.&lt;/P&gt;&lt;P&gt;Back() only works on arrays, not on feature sets, I just added an &lt;A href="https://community.esri.com/t5/arcgis-online-ideas/arcade-enhance-back-to-be-the-equivalent-of-first/idi-p/1187185/" target="_blank" rel="noopener"&gt;idea&lt;/A&gt; to change that.&lt;/P&gt;&lt;P&gt;So to return the last feature, you need to sort the featureset. Assuming you have some key field (I use OBJECTID here), you could do it like that:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var fsParcel = FeatureSetByName($datastore, "Parcel", ["OBJECTID", "APN", "SitusUnitNumber", "SitusStreetNumber"])
var fsParcelIntersect = OrderBy(Intersects(fsParcel, $feature), "OBJECTID")

// loop through parcel features
for (var Parcel in fsParcelIntersect) {
    // unit number is not empty and matches -&amp;gt; return APN
    if (Parcel.SitusUnitNumber != null &amp;amp;&amp;amp; Parcel.SitusUnitNumber ==$feature.Unit){
        return Parcel.APN
    }
    // unit number is empty, but street number matches -&amp;gt; return APN
    if (Parcel.SitusUnitNumber == null &amp;amp;&amp;amp; Parcel.SitusStreetNumber == $feature.Add_Number){
       return Parcel.APN
    }
    // both unit number and street number are empty/0 -&amp;gt; return last parcel's APN
    if (Parcel.SitusUnitNumber == null &amp;amp;&amp;amp; Parcel.SitusStreetNumber == "0"){
        // to get the last feature, reverse the featureset and call First()
        var LastParcel = First(OrderBy(fsParcelIntersect, "OBJECTID DESC"))
        return Iif(IsEmpty(LastParcel), Null, LastParcel.APN)
    }
}
// if we land here, none of the intersected parcels has the address's Unit
// returns first intersect
var Parcel = First(fsParcelIntersect)
return Iif(IsEmpty(Parcel), Null, Parcel.APN)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't really understand your last check. If both SitusUnitNumber and SitusStreetNumber are empty (I guess that what "0" represents), why do you want to get the last parcel instead of just letting the loop get to the next parcel?&lt;/P&gt;</description>
    <pubDate>Tue, 28 Jun 2022 09:20:25 GMT</pubDate>
    <dc:creator>JohannesLindner</dc:creator>
    <dc:date>2022-06-28T09:20:25Z</dc:date>
    <item>
      <title>Using Intersect Attribute Rule on Overlapping Polygons?</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/using-intersect-attribute-rule-on-overlapping/m-p/1185836#M445</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;My Problem: I wanted to use an Attribute Rule on my Address layer (APN field) to intersect the Parcel layer and return the APN field with the proper feature.. The problem I am running into, is that the Parcel layer has overlapping polygons in some area and my logic can only figure out how to return the 1st intersect.&lt;/P&gt;&lt;P&gt;My Goal: To use a attribute rule that intersects the Parcel &amp;amp; does something similar to the logic below:&lt;/P&gt;&lt;P&gt;for Parcel.APN&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;if Parcel.Unit is not null&lt;/P&gt;&lt;P class="lia-indent-padding-left-60px"&gt;if Address.Unit == Parcel.Unit&amp;nbsp;&lt;/P&gt;&lt;P class="lia-indent-padding-left-60px"&gt;&amp;nbsp; &amp;nbsp; return Parcel.APN&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;else return First on Parcel.APN intersect.&lt;/P&gt;&lt;P&gt;I am not sure add this functionality into my script.&lt;/P&gt;&lt;P&gt;I am able to get the return first using:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;var fsParcel = FeatureSetByName($datastore, "Parcel", ["APN"])
var fsParcelIntersect = Intersects(fsParcel, $feature)
var Parcel = First(fsParcelIntersect)

return Iif(IsEmpty(Parcel), Null, Parcel.APN);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;But am lacking the logic and understanding to include an if statement that works.&lt;/P&gt;&lt;P&gt;Any help would be appreciated.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2022 23:48:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/using-intersect-attribute-rule-on-overlapping/m-p/1185836#M445</guid>
      <dc:creator>Amarz</dc:creator>
      <dc:date>2022-06-23T23:48:09Z</dc:date>
    </item>
    <item>
      <title>Re: Using Intersect Attribute Rule on Overlapping Polygons?</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/using-intersect-attribute-rule-on-overlapping/m-p/1185883#M446</link>
      <description>&lt;P&gt;Something like this?&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var fsParcel = FeatureSetByName($datastore, "Parcel", ["APN", "Unit"])  // load Unit, too
var fsParcelIntersect = Intersects(fsParcel, $feature)

// this block returns the APN of the parcel whose unit is equal to the address's unit
for(var Parcel in fsParcelIntersect) {
    if(Parcel.Unit != null &amp;amp;&amp;amp; Parcel.Unit == $feature.Unit) {
        return Parcel.APN
    }
}
// if we land here, none of the intersected parcels have the address's unit
// just return the first one
var Parcel = First(fsParcelIntersect)
return IIF(Parcel == null, null, Parcel.APN)&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 24 Jun 2022 05:12:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/using-intersect-attribute-rule-on-overlapping/m-p/1185883#M446</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-06-24T05:12:13Z</dc:date>
    </item>
    <item>
      <title>Re: Using Intersect Attribute Rule on Overlapping Polygons?</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/using-intersect-attribute-rule-on-overlapping/m-p/1186734#M449</link>
      <description>&lt;P&gt;Thank you! I didn't know how to input the if statement! This works beautifully.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jun 2022 14:19:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/using-intersect-attribute-rule-on-overlapping/m-p/1186734#M449</guid>
      <dc:creator>Amarz</dc:creator>
      <dc:date>2022-06-27T14:19:02Z</dc:date>
    </item>
    <item>
      <title>Re: Using Intersect Attribute Rule on Overlapping Polygons?</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/using-intersect-attribute-rule-on-overlapping/m-p/1187089#M450</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/294341"&gt;@JohannesLindner&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to add additional if statements where I have found other errors in the the outcome. After it does its first inspection of:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;    if(Parcel.Unit != null &amp;amp;&amp;amp; Parcel.Unit == $feature.Unit) {
        return Parcel.APN&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was attempting to add&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;     // Checking to see if Parcel unit is pull, and there is a street number that matches the address, return that APN   
    } else if (Parcel.SitusUnitNumber == null &amp;amp;&amp;amp; Parcel.SitusStreetNumber == $feature.Add_Number){
       return Parcel.APN
    // else checking if Parcel Unit is null and Parcel Address = 0, return the last item in the intersect array.
    } else if (Parcel.SitusUnitNumber == null &amp;amp;&amp;amp; Parcel.SitusStreetNumber == "0"){
        var Parcel = Back(fsParcelIntersect)
        return Iif(IsEmpty(Parcel), Null, Parcel.APN)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The script validates, but does not return as expected. My guess is a syntax error. Do you have&amp;nbsp; sec to look at it?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;var fsParcel = FeatureSetByName($datastore, "Parcel", ["APN", "SitusUnitNumber", "SitusStreetNumber"])
var fsParcelIntersect = Intersects(fsParcel, $feature)

// this returns the APN of the Parcel whose unit is equal to the address's unit
for (var Parcel in fsParcelIntersect) {
    if (Parcel.SitusUnitNumber != null &amp;amp;&amp;amp; Parcel.SitusUnitNumber ==$feature.Unit){
        return Parcel.APN
     
    } else if (Parcel.SitusUnitNumber == null &amp;amp;&amp;amp; Parcel.SitusStreetNumber == $feature.Add_Number){
       return Parcel.APN
    
    } else if (Parcel.SitusUnitNumber == null &amp;amp;&amp;amp; Parcel.SitusStreetNumber == "0"){
        var Parcel = Back(fsParcelIntersect)
        return Iif(IsEmpty(Parcel), Null, Parcel.APN)
    }

}
// if we land here, none of the intersected parcels has the address's Unit
// returns first intersect
var Parcel = First(fsParcelIntersect)
return Iif(IsEmpty(Parcel), Null, Parcel.APN);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I appreciate your feedback. Thank you.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jun 2022 00:05:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/using-intersect-attribute-rule-on-overlapping/m-p/1187089#M450</guid>
      <dc:creator>Amarz</dc:creator>
      <dc:date>2022-06-28T00:05:09Z</dc:date>
    </item>
    <item>
      <title>Re: Using Intersect Attribute Rule on Overlapping Polygons?</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/using-intersect-attribute-rule-on-overlapping/m-p/1187189#M451</link>
      <description>&lt;P&gt;Your syntax is OK.&lt;/P&gt;&lt;P&gt;You don't need the elses here, because when you return, the rest of the code gets skipped and isn't executed. But that's a small, optional thing.&lt;/P&gt;&lt;P&gt;Back() only works on arrays, not on feature sets, I just added an &lt;A href="https://community.esri.com/t5/arcgis-online-ideas/arcade-enhance-back-to-be-the-equivalent-of-first/idi-p/1187185/" target="_blank" rel="noopener"&gt;idea&lt;/A&gt; to change that.&lt;/P&gt;&lt;P&gt;So to return the last feature, you need to sort the featureset. Assuming you have some key field (I use OBJECTID here), you could do it like that:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var fsParcel = FeatureSetByName($datastore, "Parcel", ["OBJECTID", "APN", "SitusUnitNumber", "SitusStreetNumber"])
var fsParcelIntersect = OrderBy(Intersects(fsParcel, $feature), "OBJECTID")

// loop through parcel features
for (var Parcel in fsParcelIntersect) {
    // unit number is not empty and matches -&amp;gt; return APN
    if (Parcel.SitusUnitNumber != null &amp;amp;&amp;amp; Parcel.SitusUnitNumber ==$feature.Unit){
        return Parcel.APN
    }
    // unit number is empty, but street number matches -&amp;gt; return APN
    if (Parcel.SitusUnitNumber == null &amp;amp;&amp;amp; Parcel.SitusStreetNumber == $feature.Add_Number){
       return Parcel.APN
    }
    // both unit number and street number are empty/0 -&amp;gt; return last parcel's APN
    if (Parcel.SitusUnitNumber == null &amp;amp;&amp;amp; Parcel.SitusStreetNumber == "0"){
        // to get the last feature, reverse the featureset and call First()
        var LastParcel = First(OrderBy(fsParcelIntersect, "OBJECTID DESC"))
        return Iif(IsEmpty(LastParcel), Null, LastParcel.APN)
    }
}
// if we land here, none of the intersected parcels has the address's Unit
// returns first intersect
var Parcel = First(fsParcelIntersect)
return Iif(IsEmpty(Parcel), Null, Parcel.APN)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't really understand your last check. If both SitusUnitNumber and SitusStreetNumber are empty (I guess that what "0" represents), why do you want to get the last parcel instead of just letting the loop get to the next parcel?&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jun 2022 09:20:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/using-intersect-attribute-rule-on-overlapping/m-p/1187189#M451</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-06-28T09:20:25Z</dc:date>
    </item>
    <item>
      <title>Re: Using Intersect Attribute Rule on Overlapping Polygons?</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/using-intersect-attribute-rule-on-overlapping/m-p/1187353#M452</link>
      <description>&lt;P&gt;EDIT: removing, due to user error!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I didn't realize the 'OBJECTID DESC' was not asking for Description, but in fact descending... and was removing it from my test script..&lt;/P&gt;&lt;PRE&gt; var LastParcel = First(OrderBy(fsParcelIntersect, "OBJECTID DESC"))&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;The accepted solution above does exactly what is needed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;EDIT2: After additional testing, I removed the 3rd if statement, and used the syntax of&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var LastParcel = First(OrderBy(fsParcelIntersect, "OBJECTID DESC"))
return Iif(IsEmpty(LastParcel), Null, LastParcel.APN)&lt;/LI-CODE&gt;&lt;P&gt;outside of the FOR loop to return the APN.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jun 2022 18:35:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/using-intersect-attribute-rule-on-overlapping/m-p/1187353#M452</guid>
      <dc:creator>Amarz</dc:creator>
      <dc:date>2022-06-28T18:35:42Z</dc:date>
    </item>
  </channel>
</rss>

