Solved! Go to Solution.
import arcpy fc = "c:/data/base.gdb/well" areaTotal = 0.0 # For each row print the Object ID field, and use the SHAPE@AREA # token to access geometry properties # with arcpy.da.SearchCursor(fc, ("OID@", "SHAPE@AREA")) as cursor: for row in cursor: print("Feature {0} has an area of {1}".format(row[0], row[1])) areaTotal += row[1] print("Features have a total area of {0}".format(areaTotal))
import arcpy fc = "c:/data/base.gdb/well" areaTotal = 0.0 # For each row print the Object ID field, and use the SHAPE@AREA # token to access geometry properties # with arcpy.da.SearchCursor(fc, ("OID@", "SHAPE@AREA")) as cursor: for row in cursor: print("Feature {0} has an area of {1}".format(row[0], row[1])) areaTotal += row[1] print("Features have a total area of {0}".format(areaTotal))
#set the pandas dataframe to the array dbhydDF = DataFrame(datArray, columns=['site', 'value', 'dateread']) #get min/max date values dmax = dbhydDF.dateread.max() dmin = dbhydDF.dateread.min() #not tested, but I think you just issue .sum to get a sum value from the appropriate field dsum = dbhydDF.value.sum()
Thanks folks. I couldn't find a way to do what I needed, so I just ended up creating a table (in a GDB) using the arcpy.Statistics_analysis tool, extracting the value from the table using a searchcursor, and then overwriting the table each time. A bit of a go-around, but it works.
If anyone can think of a better way then I'd be keen to hear. Thanks
I just want to return the results within python, eg:
- create selection
- return sum area for a field within that selection
- do something with the returned result
warea = 0 with arcpy.da.SearchCursor(lyr1, "SHAPE@AREA") as cursor: for row in cursor: warea += row[0] del cursor
>>> import arcpy >>> arcpy.env.workspace = r'C:\YOUR GDB.gdb' >>> fc = 'YOUR FC' >>> rows = arcpy.SearchCursor(fc) >>> area = 0.0 >>> for row in rows: area += row.Shape.area >>> print area 471790363.853 >>>
if arcpy.SearchCursor(activelayer).next() == None:
>>> where_clause = arcpy.AddFieldDelimiters(fc, 'UNIT') + ' IS NOT NULL' >>> print where_clause "UNIT" IS NOT NULL >>> rows = arcpy.SearchCursor(fc, where_clause, '', 'Shape; UNIT') >>> area = 0.0 >>> for row in rows: area += row.Shape.area >>> print area 17385325.4074 >>>