Upgrade to Pro — share decks privately, control downloads, hide ads and more …

arcpy - Rising Above ModelBuilder

arcpy - Rising Above ModelBuilder

ArcPy is one of the best features of ArcGIS. It is easy to script any process, and there’s no reason not to know it. Model builder is a nice way to make a quick script, but sometimes it fails you. Also, the more complicated a process becomes, the harder it is to build in model builder. This session will show you how to get started with ArcPy and how to find help on arcpy syntax. We will go over some sample scripts and show how powerful arcpy can be. Topics will include selections, cursors, MapDocument tweaks, all along with ArcGIS geoprocessing tools and python functions.

More Decks by Arkansas GIS Users Forum Conference

Other Decks in Programming

Transcript

  1. 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
  2. Why Arcpy over Model Builder • Greater control over processes

    • More reliable results • Faster • Can be run outside of ArcMap – import arcpy
  3. 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)
  4. MXD - Update Source • What happens when drives/directories change

    locations? • mxd = arcpy.mapping.MapDocument(fullpath) • mxd.findAndReplaceWorkspacePaths(dirIn,dir Out,False)
  5. 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
  6. 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)
  7. Water Well Example • Cursors • Messages • Inputs •

    Selections – Select by Attribute – Select by Location • Where to get help on syntax
  8. 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
  9. Use Case – Raster Clipper • Automatically detects new tiffs

    • Determines if they have been georeferenced • Clip them to the best Quad boundary • View Example
  10. Python 64 Bit • Be cautious. Things will break! •

    External libraries may not be compiled • Use Python for VS to run in 32 bit