writing geoprocessing scripts with arcgis
TRANSCRIPT
![Page 1: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/1.jpg)
Writing Geoprocessing Scripts
With ArcGIS
Lecture 10
![Page 2: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/2.jpg)
GIS System
![Page 3: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/3.jpg)
ArcObjects ArcObjects are the building blocks of ArcGIS. With
ArcObjects, you can create your own menus, tools, workflows, applications, and custom feature classes for use with ArcGIS.
ESRI ArcObjects is the development platform for the ArcGIS family of applications, such as ArcMap, ArcCatalog, ArcScene, ArcGIS Engine, and ArcGIS Server. The ArcObjects software components expose the full range of functionality available in ArcInfo, ArcEditor, and ArcView to software developers
Can use VBA, Python, C++, Java to program
![Page 4: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/4.jpg)
![Page 5: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/5.jpg)
![Page 6: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/6.jpg)
![Page 7: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/7.jpg)
![Page 8: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/8.jpg)
For ArcGIS 10 and Python 2.6.5:
import arcpy
Tells Python to import basic ArcGIS geoprocessing functionality
*****
from arcpy import env
Tells Python to import ability to control the ArcGIS Environment
*****
from arcpy.sa import *
arcpy.CheckOutExtension("Spatial")
Example: Tells Python to import functionality from ArcGIS Spatial Analyst
and a second command to get/check the Spatial Analyst license
![Page 9: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/9.jpg)
env.workspace = "C:/Temp"
env.workspace
arcpy.Buffer_analysis ("C:/input/roads.tif", "C:/output/Output.gdb/buffer_output", 100)
![Page 10: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/10.jpg)
arcpy.Clip_arc() arcpy.Clip_analysis()
Always assign names
to custom toolboxes
![Page 11: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/11.jpg)
env.workspace = "c:/basedata/roads.gdb"
arcpy.Select_analysis("nfroads", "paved", '[ROAD_CLASS] = "PAVED"')
Python uses forward slashes, different than Windows using back slashes
Double quotes pass text strings
Single quotes contain text strings intended to pass variable names
![Page 12: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/12.jpg)
![Page 13: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/13.jpg)
Python Basics
![Page 14: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/14.jpg)
![Page 15: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/15.jpg)
gdbPath = "C:/SouthAfrica.mdb"
fc = "Roads"
fullPath = gdbPath + "/" + fc
![Page 16: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/16.jpg)
![Page 17: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/17.jpg)
Variable index
Word =
Word[0]=‘H’
Word[2:4]=‘lp’
Word[:3]=‘Hel’
Word[-2:-4]=‘el’
Word[-3:]=‘lpA’
![Page 18: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/18.jpg)
"C:/Stockholm.mdb"
![Page 19: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/19.jpg)
arcpy.Buffer_analysis
![Page 20: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/20.jpg)
"C:/XY.txt"
![Page 21: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/21.jpg)
Accessing Python modules
( "C:/student" )
( "C:/student/Streets.shp" ) returns "Streets.shp"
( "C:/student/Streets.shp" ) returns "C:/Student"
![Page 22: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/22.jpg)
![Page 23: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/23.jpg)
![Page 24: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/24.jpg)
![Page 25: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/25.jpg)
"C:/STUDENT" = "c:/StUdEnT"
arcpy.BUFFER = arcpy.buffer
![Page 26: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/26.jpg)
Introduction to
Python and ArcGIS for
Geoprocessing Scripts
Lecture 10
![Page 27: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/27.jpg)
Python: An open-source programming language
![Page 28: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/28.jpg)
Many places for help, not just Python.org
![Page 29: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/29.jpg)
Support comes in many languages
![Page 30: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/30.jpg)
Search, and you will find many guides
![Page 31: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/31.jpg)
Python as a first language
![Page 32: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/32.jpg)
Python for Programmers
![Page 33: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/33.jpg)
As with any language: “Read the freaking manual”
![Page 34: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/34.jpg)
ArcGIS 10 installs Python 2.6.5
![Page 35: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/35.jpg)
Only use ArcGIS 10 help / tutorials / examples
Version 9.3 is significantly different
![Page 36: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/36.jpg)
Only use Python 2.6.5 help / tutorials / examples
Upgrading might break link with ArcGIS
![Page 37: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/37.jpg)
ESRI created Python routines to automate GIS
![Page 38: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/38.jpg)
Pick any ArcGIS tool - help is not helpful
![Page 39: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/39.jpg)
Tool Help is much better
![Page 40: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/40.jpg)
Scroll to bottom for sample Python script
![Page 41: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/41.jpg)
Python scripts are text files with “.py” extension
![Page 42: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/42.jpg)
Create new document, copy / paste text
![Page 43: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/43.jpg)
For existing scripts, right click and edit with IDLE
![Page 44: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/44.jpg)
IDLE displays color-coded script
(Don't need the Python Shell, close it)
![Page 45: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/45.jpg)
Example
Get GIS data
![Page 46: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/46.jpg)
Example
Downloaded, processed, and symbolized layers
![Page 47: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/47.jpg)
Gulf Of Mexico outline, plus monthly Chlorophyll
concentration from Terra, SeaWiFS, and Aqua
![Page 48: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/48.jpg)
Edit script to match data location and names
![Page 49: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/49.jpg)
Setup
Run Python from Windows Command Prompt
![Page 50: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/50.jpg)
Setup
Easier to create a customized shortcut
![Page 51: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/51.jpg)
Setup
Start Command Prompt in same folder as script
![Page 52: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/52.jpg)
Desktop and Command Prompt ready
![Page 53: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/53.jpg)
Run... no feedback (maybe you like that)
![Page 54: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/54.jpg)
Script created “Mean” datafiles
![Page 55: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/55.jpg)
Open in ArcMap... unsymbolized
![Page 56: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/56.jpg)
ArcPython does not like to overwrite files
![Page 57: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/57.jpg)
Add status messages, create symbolize layer
![Page 58: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/58.jpg)
Run again... feedback shows
![Page 59: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/59.jpg)
Script created “Mean” datafiles and layer
![Page 60: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/60.jpg)
Open in ArcMap... symbolized
![Page 61: Writing Geoprocessing Scripts With ArcGIS](https://reader033.vdocument.in/reader033/viewer/2022052406/586f9e591a28ab912c8ba441/html5/thumbnails/61.jpg)
Do not be fooled by simple problems described
and solved by scripts in beginner textbooks
Try manually processing multiple GB of data with
dozens of processing steps, EVERY DAILY
Python and ArcGIS are powerful tools