Programming and Automation

Slides:



Advertisements
Similar presentations
WITHOUT LANGUAGE [ DEVELOPING GEO-PROCESSING MODELS USING ARCGIS MODELBUILDER 10 ] PROGRAMMING R. RYAN STEVENS / GIS RESEARCH ANALYST / THE POLIS CENTER.
Advertisements

Using VB with MS Applications R. Juhl, Delta College.
Intro to Python Welcome to the Wonderful world of GIS programing!
Customisation The GUI in most GIS applications is sufficient for most needs. However, situations arise where you want either to: –Modify the interface,
Environmental GIS Nicholas A. Procopio, Ph.D, GISP Some slides from Lyna Wiggins (Rutgers University)
Why python? Automate processes Batch programming Faster Open source Easy recognition of errors Good for data management What is python? Scripting programming.
Introduction to Python. Python is a high-level programming language Open source and community driven “Batteries Included” – a standard distribution includes.
Scripts and Flow Control. Scripts So far we have been entering commands directly into the command line But there is a better way Script files (and functions)
GIS Topics and Applications
ArcView / Avenue / ArcGIS Customization. Basic Customization in ArcView 3.x Sources for scripts and extensions Installing an extension Adding and running.
Python & ModelBuilder. Overview Python/ModelBuilder Concepts – The Geoprocessor – Checking some environment variables – Providing feedback from your model/script.
ModelBuilder In ArcGIS 9.x By Tim Weigel GEOG 407/607 April 3 rd, 2006.
Spatial Analysis, Geoprocessing,
Geography 465 Overview Geoprocessing in ArcGIS. MODELING Geoprocessing as modeling.
What Geoprocessing? Geoprocessing is the processing of geographic information. Commonly used to describe a process when geographic objects are manipulated.
ModelBuilder at ArcGIS 9.2 Lyna Wiggins Rutgers University May 2008.
GISC 6382 Applied GIS UT-Dallas Briggs 1 Customizing ArcGIS Spring 2008.
Introduction to ArcGIS for Environmental Scientists Module 3 – GIS Analysis ArcGIS Toolbox.
Advance Model Builder Features. Advance Features Using Lists (also Batching) Iteration Feedback Model Only Tools Inline Variable Substitution Preconditions.
Arc: Programming Options Dr Andy Evans. Programming ArcGIS ArcGIS: Most popular commercial GIS. Out of the box functionality good, but occasionally: You.
Python & ModelBuilder. Continuing Education Python and ModelBuilder Overview Python/ModelBuilder Concepts –The Geoprocessor –Checking some environment.
Esri International User Conference | San Diego, CA Technical Workshops | Python – Getting Started Drew Flater, Ghislain Prince July 12 - July 14, 2011.
Working with cursors in Python GISDE Python Workshop Qiao Li.
2006 GIS Jam: ArcGIS Python Scripting
Introduction to InVEST ArcGIS Tool Nasser Olwero GMP, Bangkok April
Introduction to Spatial Analysis and Spatial Modeling
Introduction to Python John Reiser May 5 th, 2010.
Introduction to ArcPy. Topics What is ArcPy? Accessing geoprocessing tools using ArcPy Writing scripts using ArcPy.
Python: An Introduction
ArcGIS Network Analyst: Automating Workflows with Geoprocessing
Programming for Geographical Information Analysis: Advanced Skills Lecture 1: Introduction Programming Arc Dr Andy Evans.
Introduction of Geoprocessing Topic 7a 4/10/2007.
WyGEO Conference September 17 & 18, About Me Shawn Lanning – GIS Research WyGISC – ModelBuilder Experience About You?
Copyright © 2006 by Maribeth H. Price 8-1 Chapter 8 Geoprocessing.
An Introduction to Designing and Executing Workflows with Taverna Aleksandra Pawlik materials by: Katy Wolstencroft University of Manchester.
Module 6: Geoprocessing Scripts. Processing loops and decisions.
Introduction to ArcGIS for Environmental Scientists Module 3 – GIS Analysis Model Builder.
Esri UC2013. Technical Workshop. Technical Workshop 2013 Esri International User Conference July 8–12, 2013 | San Diego, California Automating Geodatabase.
Introduction of Geoprocessing Lecture 9. Geoprocessing  Geoprocessing is any GIS operation used to manipulate data. A typical geoprocessing operation.
Introduction of Geoprocessing Lecture 9 3/24/2008.
Python: Building Geoprocessing Tools David Wynne, Ghislain Prince.
CSE 303 Concepts and Tools for Software Development Richard C. Davis UW CSE – 10/9/2006 Lecture 6 – String Processing.
Lecture 9: Geoprocessing with Python
Development Environment
Introduction to InVEST ArcGIS Tool
Introduction to GIS PythonScript CGIS-NURIntroduction to ArcGIS II.
Topics Introduction to Repetition Structures
PYTHON: AN INTRODUCTION
How to automatise the grid production - using model builder in ArcGIS
Environmental GIS Nicholas A. Procopio, Ph.D, GISP
String several geoprocessing processes
Using Model Builder in ArcGIS
Lecture 9 Using Python for Geoprocessing
Programming for Geographical Information Analysis: Advanced Skills
ModelBuilder for Beginners
URBDP 422 Urban and Regional Geo-Spatial Analysis
Arcpy Dr Andy Evans Welcome to the course. You’ll find extra information in these note sections below each slide.
Programming for Geographical Information Analysis: Advanced Skills
This lecture Introduction to arcpy Debugging Using arcpy.
GIS Lecture: Geoprocessing
Python programming exercise
Geography 465 GIS Database Programming
Flowcharts and Pseudo Code
Module 4 - Analysis Module 4: Basic Analysis Tools
PYTHON: BUILDING GEOPROCESSING TOOLS
Building Map Books in ArcGIS
Network Analyst – Automating Workflows with Geoprocessing
Extending ArcGIS using programming
Programming Arc.
Presentation transcript:

Programming and Automation

Agenda Reason for Data automation ModelBuilder Python Windows Scheduler

Strength of GIS is analysis Automation builds on that strength Allows the user to control the process but the system runs the process. Scripts, models and programs

Reasons for automation Easier Faster More Accurate Repeatable

In the past ... ESRI AML – Arc Macro Language SML – Simple Macro Language Avenue – ArcView 3.2 – C, C++ - Slowly fading Visual Basic – Microsoft says bye bye Perl Awk

Currently ESRI Modelbuilder Python (Arcpy) ArcObjects Java Silverlight FME

ESRI Simplified process means you don't need a developer to automate tasks ESRI has 3 way of automating tasks Model Builder (Any level) Python Script (Any Level) ArcObjects (ArcServer required)

ArcToolbox

ArcToolbox Tools that automate a single task Buffer Union Projections Easy to use and can be accessed in multiple locations (ArcMap, ArcCatalog, ArcToolbox) Restricted by license

ArcToolbox Contains ESRI tools/scripts 3rd party tools/scripts Personal tools/scripts

Model Builder

Modelbuilder Integrated with ArcToolbox Chaining tools together No programming needed Can run a single iterator Workflows can be very simple to very complex

Models are created and saved within a custom toolbox. The toolbox can contain your favourite tools or a set of tools that are used within you model, or just your model

Models are created by dragging and dropping tools into the Model Builder Can contain Multiple processes. Parameters can be added that require user input Output workspaces can be controlled

Uses Geoprocessing Data Management Cartography/Mapping Buffer Clip Unions Data Management Add xy Calculate fields topology Cartography/Mapping Representations Data driven pages

Geoprocessing simple Probably wouldn’t build a model for this

Geoprocessing

Geoprocessing using a simple iterator (loop)

3 processes in 1 model

Administrative

Models are not quite fully automated Require user input/Parameters Someone has to press the button to run them Remember to add meta data Models can be exported to Python

Python

Python The preferred ArcGIS scripting language Others can be used Executes a sequence of steps Can use conditional logic Can include numerous iteration (loops) Can be generated from Model builder or built independently.

What is Python High level language used to automate tasks through programs called scripts A good beginning language Logic is fairly simple to follow Works on a variety of systems (Windows, Linux, Unix) A version of python is installed when ArcGIS is installed

Basic Python X = 5 Y = 3 Print X + Y 8 First = “John” Last = “Masich” Print “First Last” JohnMasich

Lists >>>suits = ['Spades', 'Clubs', 'Diamonds', 'Hearts'] >>>values = ['Ace', 2, 3, 4, 5, 6, 7, 8, 9, 10, 'Jack', 'Queen', 'King'] >>>print suits[0] Spades >>>print values[12] King

Loops >>> x = 2 >>> multipliers = [1,2,3,4] >>> for num in multipliers: print x * num 2 4 6 8

Decision structures >>> x = 3 >>> if x > 2: ... print "Greater than two" ... Greater than two

The Python Window Accessed through ArcGIS Commands are typed into the window >>> import arcpy >>> arcpy.Buffer_analysis(“Nests”, “Buffered_Nests”, “100 meters”, “”,””,”ALL”) Script can be loaded from an external source

Python in ArcMap arcpy – lets python know you are working with ArcGIS tools and features. Without it the commands won’t work Buffer_analysis – refers to the tool that you are running. Data after that reflects the information that needs to be entered to run the tool Toolbox – Analysis Tools - Buffer

# This script runs the Buffer tool # This script runs the Buffer tool. The user supplies the input # and output paths, and the buffer distance. import arcpy arcpy.env.overwriteOutput = True try: # Get the input parameters for the Buffer tool inPath = arcpy.GetParameterAsText(0) outPath = arcpy.GetParameterAsText(1) bufferDistance = arcpy.GetParameterAsText(2) # Run the Buffer tool arcpy.Buffer_analysis(inPath, outPath, bufferDistance) # Report a success message arcpy.AddMessage("All done!") except: # Report an error messages arcpy.AddError("Could not complete the buffer") # Report any error messages that the Buffer tool might have generated arcpy.AddMessage(arcpy.GetMessages())

Block merge # --------------------------------------------------------------------------- # Block merge.py # Created on: 2013-02-19 16:37:05.00000 # (generated by ArcGIS/ModelBuilder) # Description: # Import arcpy module import arcpy # Set Geoprocessing environments arcpy.env.scratchWorkspace = "C:\\Users\\KFM\\Documents\\ArcGIS\\Default.gdb" arcpy.env.workspace = "F:\\GIS\\Projects\\2013\\2012_50_ThreeFeathers\\ThreeFeathersRecce.gdb" # Local variables: CFP = "F:\\GIS\\Projects\\2013\\2012_50_ThreeFeathers\\LicenseeData\\Canfor\\a15384_cfp_blocks.shp" CFP_Reserves = "F:\\GIS\\Projects\\2013\\2012_50_ThreeFeathers\\LicenseeData\\Canfor\\ExternalReserves_A15384.shp" TKD = "F:\\GIS\\Projects\\2013\\2012_50_ThreeFeathers\\LicenseeData\\tkd_consultation_12-18-2012\\tkd_consultation_blobs_12_18_2012.shp" Mac_Fibre = "F:\\GIS\\Projects\\2013\\2012_50_ThreeFeathers\\LicenseeData\\macfibre\\A87345_Development.shp" Conifex = "F:\\GIS\\Projects\\2013\\2012_50_ThreeFeathers\\LicenseeData\\Conifex\\Conifex_Mackenzie_Blocks_for_KFM_130124.shp" FTA = "F:\\GIS\\Projects\\2013\\2012_50_ThreeFeathers\\LicenseeData\\FTA\\FTN_C_B_PL_polygon.shp" mac_tsa = "F:\\GIS\\Projects\\2013\\2012_50_ThreeFeathers\\ThreeFeathersRecce.gdb\\Base\\mac_tsa" licencee_blocks = "F:\\GIS\\Projects\\2013\\2012_50_ThreeFeathers\\ThreeFeathersRecce.gdb\\Licensee\\licencee_blocks" RESULTS = "F:\\GIS\\Projects\\2013\\2012_50_ThreeFeathers\\ThreeFeathersRecce.gdb\\Licensee\\results_blocks" Original_FDU_clip = "F:\\GIS\\Projects\\2013\\2012_50_ThreeFeathers\\ThreeFeathersRecce.gdb\\FSP\\Original_FDU_clip" CFP_2 = "F:\\GIS\\Projects\\2013\\2012_50_ThreeFeathers\\LicenseeData\\Canfor\\a15384_cfp_blocks.shp" Output_Feature_Class = "F:\\GIS\\Projects\\2013\\2012_50_ThreeFeathers\\LicenseeData\\Canfor\\a15384_cfp_blocks.shp" a15384_cfp_blocks_shp = "F:\\GIS\\Projects\\2013\\2012_50_ThreeFeathers\\LicenseeData\\Canfor\\a15384_cfp_blocks.shp" CFP_BLOCKS = "C:\\Users\\KFM\\Documents\\ArcGIS\\Default.gdb\\CFP_BLOCKS" Output_Feature_Class__3_ = "F:\\GIS\\Projects\\2013\\2012_50_ThreeFeathers\\LicenseeData\\tkd_consultation_12-18-2012\\tkd_consultation_blobs_12_18_2012.shp" Output_Feature_Class__2_ = "F:\\GIS\\Projects\\2013\\2012_50_ThreeFeathers\\LicenseeData\\macfibre\\A87345_Development.shp" FTA_Blocks_shp = "F:\\GIS\\Projects\\2013\\2012_50_ThreeFeathers\\LicenseeData\\FTA\\FTA_Blocks.shp" FTA_Blocks_shp__2_ = "F:\\GIS\\Projects\\2013\\2012_50_ThreeFeathers\\LicenseeData\\FTA\\FTA_Blocks.shp" Output_Feature_Class__7_ = "F:\\GIS\\Projects\\2013\\2012_50_ThreeFeathers\\ThreeFeathersRecce.gdb\\Licensee\\licencee_blocks" Output_Feature_Class__4_ = "F:\\GIS\\Projects\\2013\\2012_50_ThreeFeathers\\LicenseeData\\Conifex\\Conifex_Mackenzie_Blocks_for_KFM_130124.shp" results_blocks__2_ = "F:\\GIS\\Projects\\2013\\2012_50_ThreeFeathers\\ThreeFeathersRecce.gdb\\Licensee\\results_blocks" Licensee_Blocks_Copy = "F:\\GIS\\Projects\\2013\\2012_50_ThreeFeathers\\ThreeFeathersRecce.gdb\\Licensee\\Licensee_Blocks_Copy" licencee_blocks__2_ = "F:\\GIS\\Projects\\2013\\2012_50_ThreeFeathers\\ThreeFeathersRecce.gdb\\Licensee\\licencee_blocks" licencee_blocks_clip = "F:\\GIS\\Projects\\2013\\2012_50_ThreeFeathers\\ThreeFeathersRecce.gdb\\Licensee\\licencee_blocks_clip" # Process: Copy arcpy.Copy_management(licencee_blocks, Licensee_Blocks_Copy, "FeatureClass") # Process: Clip arcpy.Clip_analysis(FTA, mac_tsa, FTA_Blocks_shp, "") # Process: Add Field (4) arcpy.AddField_management(FTA_Blocks_shp, "COMPANY", "TEXT", "", "", "15", "", "NON_NULLABLE", "NON_REQUIRED", "") # Process: Calculate Field (4) arcpy.CalculateField_management(FTA_Blocks_shp__2_, "COMPANY", "\"FTA\"", "VB", "") # Process: Add Field (2) arcpy.AddField_management(Mac_Fibre, "COMPANY", "TEXT", "", "", "15", "", "NON_NULLABLE", "NON_REQUIRED", "") # Process: Calculate Field (3) arcpy.CalculateField_management(Output_Feature_Class__2_, "COMPANY", "\"MFL\"", "VB", "") # Process: Add Field (3) arcpy.AddField_management(TKD, "COMPANY", "TEXT", "", "", "15", "", "NON_NULLABLE", "NON_REQUIRED", "") # Process: Calculate Field (2) arcpy.CalculateField_management(Output_Feature_Class__3_, "COMPANY", "\"TKD\"", "VB", "") # Process: Append arcpy.Append_management("F:\\GIS\\Projects\\2013\\2012_50_ThreeFeathers\\LicenseeData\\Canfor\\ExternalReserves_A15384.shp", CFP, "NO_TEST", "BLOCK_ID \"BLOCK_ID\" true false false 20 Text 0 0 ,First,#,F:\\GIS\\Projects\\2013\\2012_50_ThreeFeathers\\LicenseeData\\Canfor\\ExternalReserves_A15384.shp,BLOCK_ID,-1,-1;LICENCE \"LICENCE\" true false false 15 Text 0 0 ,First,#;DIVISION_N \"DIVISION_N\" true false false 254 Text 0 0 ,First,#;AREA_HA \"AREA_HA\" true false false 19 Double 8 18 ,First,#", "") # Process: Add Field arcpy.AddField_management(CFP_2, "COMPANY", "TEXT", "", "", "15", "", "NON_NULLABLE", "NON_REQUIRED", "") # Process: Calculate Field arcpy.CalculateField_management(Output_Feature_Class, "COMPANY", "\"CFP\"", "VB", "") # Process: Dissolve arcpy.Dissolve_management(a15384_cfp_blocks_shp, CFP_BLOCKS, "COMPANY", "", "MULTI_PART", "DISSOLVE_LINES") # Process: Add Field (6) arcpy.AddField_management(RESULTS, "COMPANY", "TEXT", "", "", "15", "", "NULLABLE", "NON_REQUIRED", "") # Process: Calculate Field (6) arcpy.CalculateField_management(results_blocks__2_, "COMPANY", "\"RSLT\"", "VB", "") # Process: Add Field (5) arcpy.AddField_management(Conifex, "COMPANY", "TEXT", "", "", "15", "", "NON_NULLABLE", "NON_REQUIRED", "") # Process: Calculate Field (5) arcpy.CalculateField_management(Output_Feature_Class__4_, "COMPANY", "\"CFF\"", "VB", "") # Process: Delete Features arcpy.DeleteFeatures_management(licencee_blocks) # Process: Append (2) arcpy.Append_management("F:\\GIS\\Projects\\2013\\2012_50_ThreeFeathers\\LicenseeData\\FTA\\FTA_Blocks.shp;F:\\GIS\\Projects\\2013\\2012_50_ThreeFeathers\\LicenseeData\\macfibre\\A87345_Development.shp;F:\\GIS\\Projects\\2013\\2012_50_ThreeFeathers\\LicenseeData\\tkd_consultation_12-18-2012\\tkd_consultation_blobs_12_18_2012.shp;C:\\Users\\KFM\\Documents\\ArcGIS\\Default.gdb\\CFP_BLOCKS;F:\\GIS\\Projects\\2013\\2012_50_ThreeFeathers\\ThreeFeathersRecce.gdb\\Licensee\\results_blocks;F:\\GIS\\Projects\\2013\\2012_50_ThreeFeathers\\LicenseeData\\Conifex\\Conifex_Mackenzie_Blocks_for_KFM_130124.shp", Output_Feature_Class__7_, "NO_TEST", "SHAPE_Length \"SHAPE_Length\" false true true 8 Double 0 0 ,First,#,C:\\Users\\KFM\\Documents\\ArcGIS\\Default.gdb\\CFP_BLOCKS,Shape_Length,-1,-1,F:\\GIS\\Projects\\2013\\2012_50_ThreeFeathers\\ThreeFeathersRecce.gdb\\Licensee\\results_blocks,SHAPE_Length,-1,-1;SHAPE_Area \"SHAPE_Area\" false true true 8 Double 0 0 ,First,#,F:\\GIS\\Projects\\2013\\2012_50_ThreeFeathers\\LicenseeData\\tkd_consultation_12-18-2012\\tkd_consultation_blobs_12_18_2012.shp,Shape_Area,-1,-1,C:\\Users\\KFM\\Documents\\ArcGIS\\Default.gdb\\CFP_BLOCKS,Shape_Area,-1,-1,F:\\GIS\\Projects\\2013\\2012_50_ThreeFeathers\\ThreeFeathersRecce.gdb\\Licensee\\results_blocks,SHAPE_Area,-1,-1;COMPANY \"COMPANY\" true true false 10 Text 0 0 ,First,#,F:\\GIS\\Projects\\2013\\2012_50_ThreeFeathers\\LicenseeData\\macfibre\\A87345_Development.shp,COMPANY,-1,-1,F:\\GIS\\Projects\\2013\\2012_50_ThreeFeathers\\LicenseeData\\tkd_consultation_12-18-2012\\tkd_consultation_blobs_12_18_2012.shp,COMPANY,-1,-1,C:\\Users\\KFM\\Documents\\ArcGIS\\Default.gdb\\CFP_BLOCKS,COMPANY,-1,-1,F:\\GIS\\Projects\\2013\\2012_50_ThreeFeathers\\ThreeFeathersRecce.gdb\\Licensee\\results_blocks,COMPANY,-1,-1,F:\\GIS\\Projects\\2013\\2012_50_ThreeFeathers\\LicenseeData\\Conifex\\Conifex_Mackenzie_Blocks_for_KFM_130124.shp,COMPANY,-1,-1,F:\\GIS\\Projects\\2013\\2012_50_ThreeFeathers\\LicenseeData\\FTA\\FTA_Blocks.shp,COMPANY,-1,-1;AREA_HA \"AREA_HA\" true true false 8 Double 0 0 ,First,#", "") # Process: Clip (2) arcpy.Clip_analysis(licencee_blocks__2_, Original_FDU_clip, licencee_blocks_clip, "")

PyWin or IDLE Outside of the ArcMap environment you can work with python in the IDLE program or use an open source such as PYWIN. Friendlier programming environment. Create, edit and execute tools

Running Scripts through Python scripts can be run through a basic program such as Windows task scheduler. Models Can’t be run this way This allows the user to run memory intensive or longer scripts out side of normal work hours

Management Perspective Cost effective Controlled output Less errors Data is where it should be. Create more confidence in the results Doesn’t necessarily mean the are correct! Process is easily transferred between users