Clip Arcade

75
3
2 weeks ago
Highlighted
Regular Contributor

I am just starting to develop in Arcade in ArcGIS Online. I am testing the clip function and can't seem to get the syntax right. Using the example:

var envelope = Extent({ ... });
Area(Clip($feature, envelope), 'square-miles');

 

I created a simple web map and added 2 layers. 'Area of Interest' and 'Parcels'. I want to clip the parcels by the Area of Interest. So, I set my code like this:

var aoi = Extent(FeatureSetByName($map, "Area of Interest"))
var clp = Clip($feature, aoi)

return Round(Area(clp, 'hectare'), 2);

 

Yet, I keep getting an error:

Execution Error:JSON.parse: unexpected character at line 1 column 2 of the JSON data

 

I've googled around, and changed syntax in various ways, but I can't seem to get it to work. Can anyone suggest what is going wrong? What is the proper syntax to clip one layer by another?

Thanks

Reply
0 Kudos
3 Replies
Highlighted
Esri Esteemed Contributor

Hi @MikeMacRae ,

 

The error you are getting is caused by the fact that you are trying to get the extent of a featureset, when you can only do this using a json with the definition of the extent or a single feature.

To use the clip function you indeed need and extent, but you can't clip a layer with another and you can only clip a feature with an extent. It sounds a lot like you are looking for the intersects function, but this will create a featureset based on the overlap between a single feature and a featureset and will include all features that (partially) overlap with the input feature.

I mentioned that the result will be a featureset. What is your plan with that featureset? And where are you applying the expression, in the pop-up? 

 

Reply
0 Kudos
Highlighted
Regular Contributor

You ask some good questions @XanderBakker I guess I am trying to get used to these Arcade expressions and am using the Clip function as an example. Initially, I wanted to show area of overlap between the layers, but I did find a post you had answered to explain how this works. Thanks for that.

Yes, I am applying this to a popup.

I think I understand better, now that you clarified that the returned value is a featureset and that the extent is needed. I think that helps clarify things.

So, in so far as the Extent. Is it possible to construct an extent from a different layer, possibly using Geometry? I feel like that's what I was trying to do...

Reply
0 Kudos
Highlighted
Esri Esteemed Contributor

Hi @MikeMacRae ,

 

So, you can create an extent from a different layer, but this would take a loop through each of the geometries and use the union to create a single geometry and get the extent of that geometry. However, this will give you an extent and that does not tell much when you clip another geometry with this, since the extent is just a rectangle.

To get the amount of overlap between two layers you would have to use individual geometries of one layer and intersect those to get the selection of overlapping geometries from the other layer and user the Intersection function to create a new geometry of the overlap and read out the area.

This is all possible to do in the pop-up, but depending the number of features and complexity, this might have a large impact on performance.

Clip may not be the best function to start to learn Arcade since its functionality is different from a Clip you might do in ArcGIS Pro.

Tags (2)
Reply
0 Kudos