• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Python at 10.1
 

Python at 10.1

on

  • 1,836 views

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

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

Statistics

Views

Total Views
1,836
Views on SlideShare
1,836
Embed Views
0

Actions

Likes
0
Downloads
18
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • ** da module - to numpy array- what's numpy?- can convert values from a feature class to a numpy array- this allows lots of things straight-up like very fast column-based summary statistics (can take the mean of a column) or manipulation of all fields/rows at once (ever needed to multiply all values in all fields by 10?)- numpy arrays are the native datatype of many scipy & related libraries. allows for good extension of functionality- even better, easy(er) transfer to-from R
  • ** da module - fast cursors- cursors have been vastly improved; 30x faster for SearchCursor, >10x faster for insert- support "with" keyword for setup/teardown; prevents locks- have some funky shape properties accessors (centroid, x, y etc)- different syntax - requires a rewrite, not find-replace (fields req'd)
  • ** improved mapping module- can specify basic layer symbology e.g. graduated colours, symbols, unique vals, raster classifications- can apply legend styles- automatically create server connections (deployable)
  • ** Difference between add-ins & script tools- addins involve a toolbar- user interaction e.g. click on feature, drag envelope, type in address- anything that requires dynamic interaction is better as an addin** How to make/distribute them- have a "template wizard" which sets up the folder structure & basic classes- fills in the config.xml which could be edited directly- ultimately just a .zip file with a different extension** List of functions/events you can use- Can capture following events: - dbl-click - circle, rectangle, line - info about mouse click: - which button - map OR screen coordinates on mouse-down or mouse-up - whether a modifier (shift, ctrl, alt) was present - keypress captures (incl. modifiers)- All these can be fed into your tool logic. Could generate custom editing, extraction, interactive geoprocessing, etc.
  • ** What they are- .pyt file- Just a Python script with specific classes- ArcGIS understands them as a Toolbox- Incorporates everything: parameter info, descriptions, validation, program logic** Advantages over "normal" toolboxes- Easier to deploy- Easier to maintain - can actually have >1 person editing at once, with proper version control!- Could theoretically generate them automatically... with different tools according to some parameters. We used to have to make >1 toolbox with subsets of tools, this would have helped- No worrying about relative paths/python files going missing/models losing their sub-models

Python at 10.1 Python at 10.1 Presentation Transcript

  • Python in 10.1Thom Mackey
  • Contents• arcpy Enhancements• Add-ins• Python Toolboxes
  • FeatureClassToNumPyArrayimport arcpyimport numpyinput = "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())
  • FeatureClassToNumPyArrayimport arcpyimport numpyinput = "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 Cursorsimport arcpyarcpy.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 arcpymxd = arcpy.mapping.MapDocument(r"C:ProjectProject.mxd")df = arcpy.mapping.ListDataFrames(mxd, "Census")[0]lyr = arcpy.mapping.ListLayers(mxd, "StatePopulation", df)[0]lyrFile = arcpy.mapping.Layer(r"C:ProjectLYRsPopulation.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:ProjectOutputStatePopulation.pdf")del mxd, lyrFile
  • Add-Ins
  • Python Toolboxes