python at 10.1

9
Python in 10.1 Thom Mackey

Upload: simon-jackson

Post on 06-May-2015

1.641 views

Category:

Technology


0 download

DESCRIPTION

Python presentation by Thomas Mackey at the Melbourne Esri Australia Developer Meetup

TRANSCRIPT

Page 1: Python at 10.1

Python in 10.1Thom Mackey

Page 2: Python at 10.1

Contents

• arcpy Enhancements

• Add-ins

• Python Toolboxes

Page 3: Python at 10.1

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())

Page 4: Python at 10.1

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])))

Page 5: Python at 10.1

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]

Page 6: Python at 10.1

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)

Page 7: Python at 10.1

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

Page 8: Python at 10.1

Add-Ins

Page 9: Python at 10.1

Python Toolboxes