[GIS] How to calculate the center point inside a polygon in ArcGIS 9.3

arcgis-9.3arcgis-javascript-apicentroidspolygon

I'm using the JavaScript API 1.6 on ArcGIS 9.3. I have a polygon geometry in an ArcGIS map, and I'm trying to find a way to get the point that lies in the exact center of the geometry. What is the best way to do this?

Thanks!

Best Answer

Each instance of geometry (esri.geometry.Geometry) has a method called getExtent() which returns the extent of the geometry (polygon in your example). esri.geometry.Extent has a method called getCenter() that returns a point.

So you could do something like:

var myPolygonCenterLatLon = myPolygon.getExtent().getCenter();

You could alternatively calculate the centroids to polygons beforehand in ArcMap. Then host the layer which has a one-to-one relationship with the polygons.