Three step process to integrate python into your GIS projects

advertisement
What is python?
Scripting programming language
Similar to models but text based
Design emphasized code readability
Why python?
Automate processes
Batch programming
Faster
Open source
Easy recognition of errors
Good for data management
Three step process to integrate python into your GIS projects. . .
1. Create model outline in ModelBuilder
2. Customize model in an Python editor, such as
PythonWin or IDLE
3. Import script into a ToolBox in ArcCatalog
Create a file management model using ModelBuilder
Script for easy data management includes:
Main folder: Name of folder determined by user
Subfolders: Data, MXD, Images, Other
Sub-Subfolder: Working Data
Geodatabase: Output Geodatabase and Feature Dataset
Export as a python script
Edit script in an editor (I used IDLE)
Add descriptions
Import necessary modules
Change variables to get
parameters.
Make necessary changes to
actual script to match
changes
Added descriptions
Imported Modules
Set Parameters and
local variables
Run and correct necessary
errors
Swiss Hillshade Process
for Multiple Rasters
Create a swiss hillshade model using model builder
Export to script
Open script in an editing program (IDLE or Pythonwin)
Import necessary modules
And check out extensions
Designate the workspace containing rasters for processing
Get Parameter As Text
allows the input to be
entered as a parameter
of the tool
Enable overwriting of output
Make a list of all the rasters in the workspace
The list is created and
stored as rasterList but
not displayed
“GRID” specifies the raster type
Create a “for” loop to run the model for each raster
Everything indented
under this command is
performed for every
raster in the folder
Create a new folder name for each iteration
The folder name that stores
the output rasters will be
“swiss_hs” followed by the
name of the input raster
Create the folder under a variable
Determine which variables are to be dynamic
Inputs
Outputs
Azimuth
Z Factor
Assign the dynamic inputs to the variables
“raster” = the raster in
the folder
Output folder (created
above) and the new
raster name
Change the process parameters to match the variables
*Note: The following code is used for
the raster calculation rather than the
one that is exported from modelbuilder
Copy and paste the processing code and change parameter variables
Updating the
variables as
needed
Repeat if desired
Enter a print statement to say what folder the new rasters are in
Load the script into an ArcGIS toolbox
Name the script
Select the script
Enter the inputs from the script and their type
The script can now be run from an ArcGIS Toolbox
Download