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
}
return{
"errorMessage": Text('Something Went Wrong')
}
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 thanks for the advice. I tried that in the past. Here is the new error....
JS_Esri_0-1659121057582.png
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
}
The same error occurs just in the else statement. So it sees the intersection,
JS_Esri_0-1659126005126.png
Some reason just having an issue with getting the centroid geometry still. Not sure this is even possible.
Thanks for your help though!!!
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