Select to view content in your preferred language

Arcade expression cut function in popup - how to use?

679
3
07-18-2023 07:39 PM
CharlescobBailey
Regular Contributor

Hello, I am trying to do something very simple (I thought), just to run a cut tool in a popup to show a reduced acreage value based on stream buffers with an arcade expression. I just don't understand how to reference the cutting layer in the expression. I've tried many things and went down the featureclassasID rabbit hole, but I just can't get to it. It's in the same map as the layer I'm trying to cut. 

0 Kudos
3 Replies
jcarlson
MVP Esteemed Contributor

Cut is meant to use a single line feature to cut a polygon or line, and to then return all the resulting pieces.

Your description sounds more like Intersection, where you want the overlap between two geometries, and you don't really care about retaining the non-intersecting area. Is that right?

Even if you're using Intersection, though, you'll have to somehow identify which feature to use for the clip. You can't simply call up the whole stream layer. Typically, you'd use Intersects to first find the intersecting feature, then the result of that would be used in the overlay tool.

Since you want to incorporate a buffer, too, things get slightly more complicated. Buffer also works against a single feature, not a FeatureSet, so you'd need to know which stream features to buffer. But we can run our intersection using a buffer of the input feature to identify streams that, when buffered, will clip the original feature.

// stream layer
var streams = FeatureSetByName($map, 'streams_layer')

// buffer distance, units; not really necessary to establish as own var, but since we're going to reference it more than once, we might as well, just in case you need to change it later
var buff = {
  'dist': 15,
  'unit': 'miles'
}

// get streams w/in your buffer
var xs_fs = Intersects(
  Buffer($feature, buff['dist'], buff['unit']),
  streams
)

 

Now, this will give us a FeatureSet xs_fs, consisting of the streams that will clip our feature. Another problem you may run into is that your feature may intersect with multiple features. Or it may intersect with none. So we want to make sure that what we're doing can accommodate any number of features.

// create acreage var for output; start at 0
var xs_acreage = 0.0

// iterate over intersecting stream features; within the loop, we'll have access to individual features for overlay operations
for (var x in xs_fs) {
  // buffer stream
  var stream_buff = Buffer(x, buff['dist'], buff['unit'])

  // clip original feature
  var feat_clip = Intersection($feature, stream_buff)

  // calculate acreage of intersection
  var clip_ac = Area(feat_clip, 'acres')

  // add calculated acreage to total
  var xs_acreage += clip_ac
}

return xs_acreage

This way, if there are no intersecting features, you get a 0, and if there were 20, you'd get the total acreage of all of them.

- Josh Carlson
Kendall County GIS
0 Kudos
CharlescobBailey
Regular Contributor

Thanks so much for your response. I'm fair with Arcade but this is at the very edge of my understanding. 😄 One more question - in line 2 when you define the feature set, where is that name coming from? Is it the actual name of the FC or the name of the layer in the map? I couldn't get anything to work with this to get the cutting layer. 

0 Kudos
jcarlson
MVP Esteemed Contributor

Oh, that's just a placeholder. You'd use the name of your actual layer from the map. In the expression builder, you should be able to see a list of available variables, and your other map layers should be there.

- Josh Carlson
Kendall County GIS
0 Kudos