Slide 1

Slide 1 text

arcPy Jason Tipton @jTiptonGIS [email protected]

Slide 2

Slide 2 text

Add To Path Env Variable • Open cmd • setx path "%path%; C:\Python27\ArcGISx6410.1“ • open new cmd. "echo %path%" to confirm OR • Right Click Computer > Properties > Advanced System Settings > Environment Variables • Open Path and add path to Python

Slide 3

Slide 3 text

Why Arcpy over Model Builder • Greater control over processes • More reliable results • Faster • Can be run outside of ArcMap – import arcpy

Slide 4

Slide 4 text

Today’s Topics • MXD tweaks (Fix Broken Sources) • ArcPy prevails when Model Builder Fails • Cursors, Messages, inputs, Selections • Use Case (Auto-clipper) • GUI’s (Tkinter)

Slide 5

Slide 5 text

MXD - Update Source • What happens when drives/directories change locations? • mxd = arcpy.mapping.MapDocument(fullpath) • mxd.findAndReplaceWorkspacePaths(dirIn,dir Out,False)

Slide 6

Slide 6 text

MXD – List Broken Sources • mxd = arcpy.mapping.MapDocument(‘mxdPath') • arcpy.mapping.ListBrokenDataSources(mxd)

Slide 7

Slide 7 text

MXD • View Example

Slide 8

Slide 8 text

Input Paramaters 0 1 2 3 arcpy.GetParameterAsText(0) arcpy.GetParameterAsText(1) arcpy.GetParameterAsText(2) arcpy.GetParameterAsText(3)

Slide 9

Slide 9 text

Messaging • Arcpy.AddMessage(“message”) • Arcpy.AddWarning(“message”) • Arcpy.AddError(“message”) Message Warning

Slide 10

Slide 10 text

Cursors • Arcpy.SearchCursor(“layer”,{where}) – Used to read through each row in feature class • Arcpy.UpdateCursor(“layer”, {where}) – Same, but with the ability to edit/delete – Call cursorObject.updateRow(rowObject) to commit • Arcpy.InsertCursor(“layer”) • Insert data

Slide 11

Slide 11 text

Cursor Structure cursor = arcpy.UpdateCursor(“layer”, {where}) for row in cursor: # loop through each row x = row.FieldName x = row.getValue(“FieldName”) row.FieldName2 = y row.setValue(“FieldName2”, y) cursor.updateRow(row)

Slide 12

Slide 12 text

Water Well Example • Cursors • Messages • Inputs • Selections – Select by Attribute – Select by Location • Where to get help on syntax

Slide 13

Slide 13 text

ArcPy When MB Fails • Address Locator Example • Not that complicated, but MB fails • Must run model halfway once, then run again for it to work. • Python works 1st time every time. . . • View Example

Slide 14

Slide 14 text

Use Case – Raster Clipper • Automatically detects new tiffs • Determines if they have been georeferenced • Clip them to the best Quad boundary • View Example

Slide 15

Slide 15 text

Useful Tools/Links • Pywin IDE • Python for Visual Studio • Notepad ++

Slide 16

Slide 16 text

Python 64 Bit • Be cautious. Things will break! • External libraries may not be compiled • Use Python for VS to run in 32 bit

Slide 17

Slide 17 text

Questions?