I am using the arcade expression builder in enterprise 10.8.1 web map. I am trying to select the intersection of two polygons, using the centroid of one. However, the arcade function "Centroid" does not give me a parameter to specify that I only want the point placed inside the poly, so it is giving me false results. Here is my code so far:
var citylimits = FeatureSetByName($map,"City Limits")
var inter = intersects(centroid($feature) ,citylimits)
var cityname = ''
for (var i in inter){
cityname = i.CITY + ' City Limits'
}
if(cityname == ''){
cityname = ' '}
return cityname
Since the point is sometimes placed outside of the polygon, my result gives me false returns. Any tips here on using centroid in arcade?
Solved! Go to Solution.
Sounds similar to a map we use for parcels and voting districts. Even tiny misalignments can cause the "intersects" function to return false positives.
For most parcels, the centroid is fine. For those complex ones, we use Buffer($feature, -10) and feed that into the intersection. Our layers are aligned enough that shrinking the parcel feature in by ten feet eliminates those false positives.
Maybe that would work for your situation?
centroids can be located outside of polygons, does Arcade have a "label point" ?
I understand they can be placed outside, but I don't want them to be. In Pro, or using the "find Centroid" tool in a web map analysis, you can force the centroid to be placed inside the poly.
Arcade Function Reference | ArcGIS for Developers versus
Polygon—ArcGIS Pro | Documentation
for centroid shows that the arcade functionality is not as complete as for arcpy etc which implement a label point if necessary/desired
Unfortunately, Arcade doesn't have a label point / point on surface equivalent.
One way you might work around this is to first check if the centroid of a feature intersects the feature itself. For those features where the centroid lands outside of the shape, you can have an alternate method of attempting to find the intersection of the features.
var pt = Centroid($feature)
var cityname
if(Within(pt, $feature)){
// the 'normal' procedure
} else {
// alternate procedure
}
return cityname
Now, as to what that alternate procedure might be probably depends on the features being intersected. Could you give an example of where this is occurring in your map?
Also, are the layers changing often? For more complex Arcade expressions like this, sometimes it's honestly easier to add a new field and calculate its values by other means, but I understand there may be situations where that's not an option.
Thank you very much for the reply. Not a very easy thing to understand through a forum.
What is happening in the map is:
My issue is:
We don't own the parcel layer, and creating a separate copy just for this one purpose most likely wouldn't fly.
So I am left with your suggestion of an alternate procedure...
Thanks again.
Sounds similar to a map we use for parcels and voting districts. Even tiny misalignments can cause the "intersects" function to return false positives.
For most parcels, the centroid is fine. For those complex ones, we use Buffer($feature, -10) and feed that into the intersection. Our layers are aligned enough that shrinking the parcel feature in by ten feet eliminates those false positives.
Maybe that would work for your situation?
Josh,
That did the trick for the parcels I was having issues with. I will do some more testing but I think this will solve my issue. Thanks for taking the time to dig into this.
-Tom
P.S love what you have going on with your Portal site and content.
Cheers.
Ha, thanks! Now if I could just get the local surveyors and attorneys as excited about the changes we're making...
Happy to help!
I want a Label in a print layout to update based on the centroid of the maps intersection with a particular layer. Is that doable?