arcgissamples\scenario\extension\AreaCalculator.java
/* Copyright 2010 ESRI * * All rights reserved under the copyright laws of the United States * and applicable international laws, treaties, and conventions. * * You may freely redistribute and use this sample code, with or * without modification, provided you include the original copyright * notice and use restrictions. * * See the use restrictions. * */ package arcgissamples.scenario.extension; import com.esri.arcgis.geodatabase.IFeature; import com.esri.arcgis.geodatabase.IFeatureClass; import com.esri.arcgis.geometry.Polygon; import com.esri.arcgis.interop.extn.ArcGISExtension; @ArcGISExtension public class AreaCalculator implements ICalculateArea { public AreaCalculator(){} public double calculateArea(IFeatureClass fClass) { double totalArea = 0; try{ // Get the counties layer int numFeatures = fClass.featureCount(null); IFeature feature = null; Polygon polygon = null; for(int i=0; i<numFeatures; i++) { feature = fClass.getFeature(i); polygon = (Polygon)feature.getShape(); totalArea += polygon.getArea(); } } catch(Exception e){ e.printStackTrace(); } return totalArea; } }