Using Arcade to calculate percent coverage

1691
4
Jump to solution
12-29-2020 10:02 AM
James_Armstrong
Occasional Contributor

I have two layers:  1-Parcels, 2-Soils.  I am trying to create an Arcade expression that would return the percentage of soil types within the selected property.  I have been successful to some degree, but it appears that the percentages return are not clearing.  The expression is below.  I have published a web map application which uses the expression for purpose of illustration. Any suggestion, advice, or idea is most appreciated.  - James Armstrong

Soils Calculator 

---------------------------------------------------------------------------------------------------------------------------------------------

var gensoils = FeatureSetById($datastore, /* GeneralSoils */ "1")

var soils_int = Intersects($feature, gensoils)

var numsoil = Count(soils_int)

var sum_area = SUM(soils_int, 'Acreage')

var results = 'There are '+ numsoil +' type(s) of General Soils.'+TextFormatting.NewLine


for (var s in soils_int){
     var soilarea = s.Acreage
     var percent = (s.Acreage / sum_area)
     var soilname = s.SOIL_NAME2
     var soilpercent = Round(percent,2 ) * 100 +'%'
     results += TextFormatting.NewLine + soilname + '---- ' + soilpercent
}

return results

1 Solution

Accepted Solutions
James_Armstrong
Occasional Contributor

Angela,  Thanks for your help.  I was able to wrap my head around what you were saying regarding the featureset vs  feature.  The following code works and is relatively quick to respond.

James Armstrong

 

 

 

2020-12-29 18_54_31-ArcGIS Enterprise - RichmondPArcelAssessment.png

 

View solution in original post

4 Replies
AngelaDeegan
Occasional Contributor

I think you may need to use the https://developers.arcgis.com/arcade/function-reference/geometry_functions/#intersection function in addition to the https://developers.arcgis.com/arcade/function-reference/geometry_functions/#intersects function. I can't see the layers you're working with, but unless they have coincident boundaries, seems like you'd need to "cut" the soils layer using the parcels layer and looks like the intersection function would do that for you.

Also, you might want to use the https://developers.arcgis.com/arcade/function-reference/geometry_functions/#area function on the $feature to set the sum_area. Seems like that would be more straightforward.

James_Armstrong
Occasional Contributor

Thanks Angela;  I see what you mean about using the other Functions.  Below is the espression using the Intersection function and the result (Illegal Argumemt).  do you see where the illegal argument might be?  Any help would be great?  

James

 

2020-12-29 18_54_31-ArcGIS Enterprise - RichmondPArcelAssessment.png

0 Kudos
AngelaDeegan
Occasional Contributor

I'm not clear why you're buffering the parcel. And by using a negative number I think you may be "shrinking" the parcel by that footage. That could cause a problem if a parcel is less than 25 feet wide in places.

Also, looking at the documentation, it appears that the arguments for Intersection must be either a geometry or feature. It doesn't appear to allow a featureset as an argument. You are passing in 'gensoils' (a featureset) as an argument.

I'm guessing you'd need to run Intersection on any geometry in gensoils recursively.

0 Kudos
James_Armstrong
Occasional Contributor

Angela,  Thanks for your help.  I was able to wrap my head around what you were saying regarding the featureset vs  feature.  The following code works and is relatively quick to respond.

James Armstrong

 

 

 

2020-12-29 18_54_31-ArcGIS Enterprise - RichmondPArcelAssessment.png