Calculate Area Add In - problem with multiple dataset types

479
2
05-02-2014 10:02 AM
SarahFranklin
New Contributor
I am working on what I thought was a simple button to calculate the area of a selected polygon.. however the script fails if there is a raster dataset loaded in the .mxd - even if it is not selected, due to the FIDSet command.. any ideas on how to get around this (other than removing the raster)?


Code in reply below...
Tags (2)
0 Kudos
2 Replies
SarahFranklin
New Contributor
Sorry.. here's the formatted version of the code
        if testCount==0:
            msg = "You must first add a polygon layer or feature class and select some features to report their acreage."
            pythonaddins.MessageBox(msg, 'Area Report', 0)
        else:
            for lyr in arcpy.mapping.ListLayers(mxd):
                if lyr.isGroupLayer:
                    for sublyr in lyr:
                        tlyr = lyr
                else:
                    tlyr = lyr
                    dsc = arcpy.Describe(tlyr)
                    sel_set = dsc.FIDSet
                    if dsc.shapeType == "Polygon":
                        if len(sel_set) > 0:
                            with arcpy.da.SearchCursor(tlyr, ("OID@", "SHAPE@AREA")) as cursor:
                                for row in cursor:
                                    parea = row[1] + parea
                                    resSQFT = parea
                                    resAC = parea / 43560
                                    resHA = parea / 107639.104
0 Kudos
SarahFranklin
New Contributor
Sorry.. here's the formatted version of the code
        if testCount==0:
            msg = "You must first add a polygon layer or feature class and select some features to report their acreage."
            pythonaddins.MessageBox(msg, 'Area Report', 0)
        else:
            for lyr in arcpy.mapping.ListLayers(mxd):
                if lyr.isGroupLayer:
                    for sublyr in lyr:
                        tlyr = lyr
                else:
                    tlyr = lyr
                    dsc = arcpy.Describe(tlyr)
                    sel_set = dsc.FIDSet
                    if dsc.shapeType == "Polygon":
                        if len(sel_set) > 0:
                            with arcpy.da.SearchCursor(tlyr, ("OID@", "SHAPE@AREA")) as cursor:
                                for row in cursor:
                                    parea = row[1] + parea
                                    resSQFT = parea
                                    resAC = parea / 43560
                                    resHA = parea / 107639.104
0 Kudos