# Get and compare area of arcpy geometry from extent object

I'm trying to get a numerical value for the area of a polygon that I am generating from an extent object. In this case, I am using the "onRectangle" function in the python addins for arcpy. The problem starts when using the getArea method on the polygon geometry. I have no intention of writing this polygon to disk. Ultimately, I want to be able to compare the extent of a user drawn rectangle to the dataframe extent. Here's what I've got so far.

``````def onRectangle(self, rectangle_geometry):
frameExtent = rectangle_geometry
XMAX = frameExtent.XMax
XMIN = frameExtent.XMin
YMAX = frameExtent.YMax
YMIN = frameExtent.YMin
pnt1 = arcpy.Point(XMIN, YMIN)
pnt2 = arcpy.Point(XMIN, YMAX)
pnt3 = arcpy.Point(XMAX, YMAX)
pnt4 = arcpy.Point(XMAX, YMIN)
print XMAX, XMIN, YMAX, YMIN
array = arcpy.Array()
rectPoly = arcpy.Polygon(array)
global rectArea
rectArea = rectPoly.getArea()
print str(rectArea)
return rectArea
``````

The python window in ArcMap returns this error: `TypeError: Invalid geometry type for method.` Any pointers would be appreciated for both getting the area of the polygon and comparing it (percentage wise) to the full data extent would be appreciated.

• The area of a rectangle is (maxX-minX)*(maxY-minY). Why go though the effort of generating a polygon? – Vince Nov 7 '13 at 21:20
• Thanks, I decided this was the best way to do this as you said, I was simply over complicating the matter. – amasephy Nov 14 '13 at 18:55

The area of a rectangle is just height * width, so you can cut to the chase with

``````def onRectangle(self, rectangle_geometry):
frameExtent = rectangle_geometry
XMAX = frameExtent.XMax
XMIN = frameExtent.XMin
YMAX = frameExtent.YMax
YMIN = frameExtent.YMin
return (XMAX-XMIN)*(YMAX-YMIN)
``````

If you look at the help file the method getArea() takes a string parameter for `type` i.e. it "Returns the area of the feature using a measurement type."

PLANAR measurements reflect the projection of geographic data onto the 2D surface (in other words, they will not take into account the curvature of the earth). GEODESIC, GREAT_ELLIPTIC, LOXODROME, and PRESERVE_SHAPE measurement types may be chosen as an alternative, if desired.

• I used those but they always failed to yeild the area as I expected. However, I realized I was simply over complicating the matter and took Vince's advice and just did the math in code instead. I'm not sure how to use his response as the answer. – amasephy Nov 14 '13 at 18:54