Intersection within Intersect, or Intersect on filtered layer using Arcade

448
6
Jump to solution
07-09-2021 10:12 AM
Labels (1)
tahunt01
New Contributor II

Hello,

I am working in Portal and I have three layers that I want to function together to provide more information in a popup. The layers include:
Project Boundary (polygon)
Parcel Boundary (polygon)
Wind Turbines (points)

First I want to filter the parcel boundary layer down to only those that are signed leases ("PRCL_STAT_CD = 'LSE'"). Then, when I click on a project boundary, I want the popup to display how many wind turbines fall on signed lease parcels within that project.

Theoretically, I envision this working with the expression:

 

 

Count(Intersects(Turbines, Intersection(Parcel Boundary, $feature)))

 

 


with some additional variables defined, but depending on how I write it I receive the error either "Illegal Argument" or "Spatial Relation cannot accept this parameter type"

There is also a common project name field between the Parcel Boundary and the Project Boundary which I thought maybe I could use to filter the parcels rather than perform an intersection but I can't figure that out either.

 

Here is my expression currently. If someone could please tell me where I am going wrong I would appreciate it!

 

var turbines = FeatureSetByName($map, "Preferred Array")
var parcels = FeatureSetById($datastore, /* Prospecting - Status */ "53")
var projname = $feature["PROJECT_NAME"]
var projparcels = Filter(parcels,"PROJ_NM = @projname")
var LSEparcels = Filter(projparcels,"PRCL_STAT_CD = 'LSE'")
Count(Intersects(turbines,LSEparcels))

 

0 Kudos
1 Solution

Accepted Solutions
tahunt01
New Contributor II

I figured out the solution!

By referencing your solution to a similar problem on a different thread, I added a couple of lines to what you provided above and was able to make this work.

var final_count = 0

// Iterate over LSEparcels FeatureSet and get intersected turbines for each

for(var p in LSEparcels){
    var t_count = Count(Intersects(turbines, p))
    final_count += t_count
}

return "There are " + final_count + " turbines on signed lease parcels for this project"

 

Thank you so much for helping me work through this. I appreciate it very much! 

View solution in original post

6 Replies
jcarlson
MVP Notable Contributor

The problem with that first expression is that Intersection takes two individual geometries, not FeatureSets. The problem with the second expression is that Intersects can take a single FeatureSet, but not two.

What you need is some way of intersecting the turbines with a single feature. A simple for-loop can accomplish this.

var out_count = 0

for(var t in turbines){
    if(Intersects(LSEparcels, t)){
        out_count += 1
    }
}

return out_count

 

- Josh Carlson
Kendall County GIS
0 Kudos
tahunt01
New Contributor II

Thank you for your input Josh! I replaced the last line of my expression with what you provided above but it is returning a value of '0' for everything. I wonder if this is because even after the filters, LSEparcels contains multiple features (there are many LSE parcels within each project). Do I need some sort of for-loop for both the turbines AND the LSEparcels? Is that possible?

Thank you again for your help!

0 Kudos
jcarlson
MVP Notable Contributor

It is possible, but I don't believe it's necessary. Since the LSEparcels is itself a FeatureSet, Intersects will return true if the given turbine intersects with anything in the set.

In order to check on your code, it can be helpful to include Console statements. Try the following code, then click over to the Messages tab after it runs. This will help you identify where problems may be occurring, whether it's an issue with the intersection, filter, etc.

jcarlson_0-1626096232805.png

 

 

var turbines = FeatureSetByName($map, "Preferred Array")
Console(`Turbines: ${Count(turbines)}`)

var parcels = FeatureSetById($datastore, /* Prospecting - Status */ "53")
Console(`Parcels: ${Count(parcels)}`)

var projname = $feature["PROJECT_NAME"]

var projparcels = Filter(parcels,"PROJ_NM = @projname")
Console(`Project Parcels: ${Count(projparcels)}`)

var LSEparcels = Filter(parcels, "PRCL_STAT_CD = 'LSE')
Console(`LSE Parcels: ${Count(LSEparcels)}`)

var out_count = 0

for(var t in turbines){
    if(Intersects(LSEparcels, t)){
        out_count += 1
    }
}

return out_count

 

 

- Josh Carlson
Kendall County GIS
0 Kudos
tahunt01
New Contributor II

Using the Console messages, I can see that all of my variables are functioning properly, but again the Count(Intersects(turbines,LSEparcels) expression returns an error that the "Spatial Relationship cannot accept this parameter type"

Ultimately it returns many turbines (all of them), and many LSE parcels within the selected project boundary.

For the sample project boundary that's being referenced within the "playground", there are 83 LSE parcels.

To reiterate what I'm after - when I click on the project boundary, I want to know how many turbines fall on those 83 LSE parcels. 

I'm not sure if this helps clarify my task or muddy the waters. Let me know if there's any additional info I can provide.

Thank you!

0 Kudos
jcarlson
MVP Notable Contributor

What you're looking for makes sense, but remember that Intersects can only accept a single FeatureSet parameter. The expression Intersects(turbines,LSEparcels) contains two. That why I suggested the for-loop, but I realize I re-pasted the earlier expression in my response about console messages. I'll edit the code snippet in that response.

- Josh Carlson
Kendall County GIS
0 Kudos
tahunt01
New Contributor II

I figured out the solution!

By referencing your solution to a similar problem on a different thread, I added a couple of lines to what you provided above and was able to make this work.

var final_count = 0

// Iterate over LSEparcels FeatureSet and get intersected turbines for each

for(var p in LSEparcels){
    var t_count = Count(Intersects(turbines, p))
    final_count += t_count
}

return "There are " + final_count + " turbines on signed lease parcels for this project"

 

Thank you so much for helping me work through this. I appreciate it very much!