AnsweredAssumed Answered

What returns geometry.getCentroid()?

Question asked by htudosieesri-ca-esridist Employee on Apr 9, 2019
Latest reply on May 17, 2019 by bixb0012

I have this pice of code:

parcels.forEach(parcel => {
const centroid = parcel.geometry.getCentroid(); //getExtent().getCenter(); //getCentroid();
const feature = new Graphic(centroid, myUtils.NEW_ADDRESS_SYMBOL);;


and I'm getting this result:

The centroids are not in center of parcels, and some are outside their parcels.


There is no point in publishing all code (I can do that on request), but changing this line:

const centroid = parcel.geometry.getExtent().getCenter(); //getCentroid();

for ilustrating the center of the extent of the parcel instead of the centroid give better results:

Note that this is not a good solution:

I have added the extent for the last two parcels to show that the centre of the extent is not the desired solution, but this is a lot better solution that the getCentroid function the way I got it.