Update point geometry based on polygons centroid

07-29-2022 10:56 AM
Occasional Contributor

I've got a strange one for you folks. Working with some address points and parcel polygons, is it possible to get the x and y geometry from a centroid of an intersecting polygon?

I followed this documentation and the way the author's script works great when replicating the author's scenario. Yet when I try to get the centroid of a polygon I get an error 'Expected convertable to geometry'.

Basically, I'm trying to update the geometry of a point on intersect based on the centroid geometry of the intersecting polygon


//This calculation attribute rule is added to the shape field of a point feature $feature
var parcels = Intersects(FeatureSetByName($datastore, "Parcel", ["*"], true), $feature)
var parcelCentriod = Centroid(parcels)
if (!IsEmpty(parcelCentriod)) {
    var x0 = Geometry(parcelCentriod).x
    var y0 = Geometry(parcelCentriod).y
    var addressPoint = Point({
        "x": x0,
        "y": y0,
        "z": 0,
        "spatialReference": Geometry(parcelCentriod).spatialReference
    return addressPoint
    "errorMessage": Text('Something Went Wrong')


0 Kudos
5 Replies
MVP Esteemed Contributor

Intersects returns a FeatureSet. Centroid requires a Feature.

Add something like

var parcel = First(parcels)

between lines 2 and 3, then have your Centroid function use parcel as its input.

Does that help?

- Josh Carlson
Kendall County GIS
Occasional Contributor

Josh thanks for the advice. I tried that in the past. Here is the new error....



0 Kudos
MVP Esteemed Contributor

So, that means that there's nothing in the intersection.

Instead of checking IsEmpty on the centroid, check first on the parcels FeatureSet.

if(Count(parcels) < 1){
Console('No intersecting parcels')
// return some default message
} else {
parcel = First(parcels)
var parcelCentroid = Centroid(parcel)
... etc


- Josh Carlson
Kendall County GIS
Occasional Contributor

The same error occurs just in the else statement. So it sees the intersection, 


Some reason just having an issue with getting the centroid geometry still. Not sure this is even possible. 

Thanks for your help though!!!

0 Kudos
Esri Frequent Contributor

Can you post a sample dataset with the rule?

Couple things: 

  - In this case, I would not call Count.  Count can be expensive, as it makes a query to the FS.  Best to just call First or loop over the FS and exit on the first record

  - I do not like reusing the variable parcel to be the FeatureSet and the Feature.  Change the first item to var parcelFS

  - If you right click in the expression, you can turn on line numbers.  Will help identify which line has the error