python at 10.1
DESCRIPTION
Python presentation by Thomas Mackey at the Melbourne Esri Australia Developer MeetupTRANSCRIPT
Python in 10.1Thom Mackey
Contents
• arcpy Enhancements
• Add-ins
• Python Toolboxes
FeatureClassToNumPyArray
import arcpy import numpy input = "C:/Data/ABSData.gdb/VIC_CCDs" arr = arcpy.da.FeatureClassToNumPyArray(input,('CCD', 'pop_m', 'pop_f')) # Sum the total population for males & females # print(arr['pop_m'].sum()) print(arr['pop_f'].sum()) # Sum the female population for a particular CCD # print(arr[arr['CCD'] == "2010101"]['pop_f'].sum())
FeatureClassToNumPyArray
import arcpy import numpy input = "C:/Data/ABSData.gdb/VIC_CCDs"field1 = "INCOME"field2 = "EDUCATION"arr = arcpy.da.FeatureClassToNumPyArray(input, (field1, field2)) # Print correlation coefficients for the two fieldsprint(numpy.corrcoef((arr[field1],arr[field2])))
Improved Cursors
# Turn the contents of a GDB table into a Python list of lists# Simple syntax & little codewith arcpy.da.SearchCursor(zonalstats_results_table,
["MINORITY","MAJORITY","MEAN"]) as tblcur:
results = [r for r in tblcur]
Improved Cursors
import arcpy arcpy.env.workspace = "c:/data/output.gdb" fc = "c:/data/base.gdb/roads" fields = ("ROAD_TYPE", "BUFFER_DISTANCE") with arcpy.da.UpdateCursor(fc, fields) as cursor: # Update the field used in Buffer so the distance is based on road # type. Road type is either 1, 2, 3 or 4. Distance is in meters.
for row in cursor:row[1] = row[0] * 100 cursor.updateRow(row)
arcpy.mapping: update/apply symbologyimport arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "Census")[0]
lyr = arcpy.mapping.ListLayers(mxd, "StatePopulation", df)[0]
lyrFile = arcpy.mapping.Layer(r"C:\Project\LYRs\Population.lyr")
arcpy.mapping.UpdateLayer(df, lyr, lyrFile, True)
if lyr.symbologyType == "GRADUATED_COLORS":
lyr.symbology.valueField = "POP2000"
lyr.symbology.classBreakValues = [250000, 999999, 4999999, 9999999, 35000000]
lyr.symbology.classBreakLabels = ["250,000 to 999,999", "1,000,000 to 4,999,999",
"5,000,000 to 9,999,999",
"10,000,000 to 35,000,000"]
arcpy.mapping.ExportToPDF(mxd, r"C:\Project\Output\StatePopulation.pdf")
del mxd, lyrFile
Add-Ins
Python Toolboxes