Arcade Centroid function sometimes places point outside of polygon

865
8
Jump to solution
03-19-2021 12:23 PM
Labels (2)
TomMiller
New Contributor II

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?

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Notable Contributor

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 Carlson
Kendall County GIS

View solution in original post

8 Replies
DanPatterson
MVP Esteemed Contributor

centroids can be located outside of polygons, does Arcade have a "label point" ?


... sort of retired...
0 Kudos
TomMiller
New Contributor II

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. 

DanPatterson
MVP Esteemed Contributor

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


... sort of retired...
0 Kudos
jcarlson
MVP Notable Contributor

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.

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

Thank you very much for the reply. Not a very easy thing to understand through a forum.

What is happening in the map is:

  • I have two polygon layers (City limits and Parcels).
  • In the popup for parcels, I have an expression that tells you if this parcel intersects with the city limits poly, and if it does, returns the city name.

My issue is:

  • The parcels and city limits don't always align exactly, in fact they almost never do. So I was attempting to use the centroid of the parcel for my intersection with the city limits.
  • For a few larger,irregular shaped parcels, it is placing the centroid point outside of the poly, causing the popup to think the parcel falls outside of city limits, when in fact it does.

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.

0 Kudos
jcarlson
MVP Notable Contributor

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 Carlson
Kendall County GIS
TomMiller
New Contributor II

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.

0 Kudos
jcarlson
MVP Notable Contributor

Ha, thanks! Now if I could just get the local surveyors and attorneys as excited about the changes we're making...

Happy to help!

- Josh Carlson
Kendall County GIS
0 Kudos