15.02.2017 Views

Learning ArcGIS Pro

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Python script<br />

A Python script is also a custom tool that can run multiple geoprocessing tools along with<br />

their various parameters as part of an integrated process. However, unlike a model that<br />

does not require you to write programming code, Python scripts do. You must know the<br />

Python scripting language in order to create Python scripts. The following is a small<br />

snippet of a Python script created for <strong>ArcGIS</strong>:<br />

#--------------------------------------------------------------<br />

# Name: Union Tool Sample Script<br />

# Purpose: Runs the Union Geoprocessing tool from <strong>ArcGIS</strong><br />

# Author: Esri & Tripp Corbin<br />

#<br />

# Created: 09/15/2015<br />

# Updated: 09/15/2015<br />

#<br />

# Usage: Union two feature classes<br />

#---------------------------------------------------------------<br />

# Import the system modules<br />

import arcpy<br />

from arcpy import env<br />

# Sets the current workspace to avoid having to specify the full path<br />

# to the feature classes each time<br />

env.workspace = "C:\\student\\IntroArc<strong>Pro</strong>\\Databases\\Trippville_GIS.gdb"<br />

#Runs Union Geoprocessing tool on 2 Feature classes<br />

arcpy.Union_analysis (["Parcels", "Floodplains"],<br />

"Parcels_Floodplain_Union", "NO_FID", 0.0003)<br />

Python scripts have several advantages over a geoprocessing model. First, Python is not<br />

limited to <strong>ArcGIS</strong>. Python can actually be used to create scripts for many other<br />

applications such as Excel, SharePoint, AutoCAD, Photoshop, SQL Server, and more.<br />

This means you can use a Python script to run tools across multiple platforms to create a<br />

truly integrated process.<br />

Second, Python scripts can be run from outside of <strong>ArcGIS</strong>. This means you can schedule<br />

them to run at specific times and days using your operating system’s scheduler<br />

application. If your script does include <strong>ArcGIS</strong> geoprocessing tools, the script will require<br />

access to an <strong>ArcGIS</strong> license to run successfully but <strong>ArcGIS</strong> does not need to be open and<br />

active at the time the script is scheduled to run.<br />

Third, Python can be used to create completely customized geoprocessing tools. It is not<br />

limited to just the geoprocessing tools you will find in the <strong>ArcGIS</strong> <strong>Pro</strong> toolboxes.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!