Module 6: Geoprocessing Scripts. Processing loops and decisions.

Slides:



Advertisements
Similar presentations
Introducing JavaScript
Advertisements

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,
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.
GIS 4107 – Week 5. David Francey … working in Toronto train yards, the Yukon bush, and as a carpenter in the Eastern Townships … releases his first CD.
Introduction to GIS and ArcGIS How a GIS works Introduction to ArcGIS The ArcGIS Interface.
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
Python & ModelBuilder. Overview Python/ModelBuilder Concepts – The Geoprocessor – Checking some environment variables – Providing feedback from your model/script.
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
Introduction to ESRI Add-Ins
Geography 465 Analytic Cartography: Getting Started with Python Scripting.
Geography 465 GIS Database Programming Getting Started with GIS Database Programming.
GISC 6382 Applied GIS UT-Dallas Briggs 1 Customizing ArcGIS Spring 2008.
An ide for teaching and learning prolog
CSC 9010: Natural Language Processing
Arc: Programming Options Dr Andy Evans. Programming ArcGIS ArcGIS: Most popular commercial GIS. Out of the box functionality good, but occasionally: You.
Programming 101 with Python: an open-source, cross-platform, and fun language By J. Burton Browning, Ed.D. Copyright © J. Burton Browning All rights reserved.
Python Programming Fundamentals
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.
2006 GIS Jam: ArcGIS Python Scripting
Introduction to InVEST ArcGIS Tool Nasser Olwero GMP, Bangkok April
Writing Geoprocessing Scripts With ArcGIS Lecture 9.
Introduction to Spatial Analysis and Spatial Modeling
Copyright © 2002, 2003, 2004 ESRI. All rights reserved. What's New in ArcGIS 9 Introduction to Geoprocessing in ArcGIS 9 Jason Grootens ESRI-Minneapolis.
Introduction to Python John Reiser May 5 th, 2010.
An Introduction to Visual Basic
Network Analysis with Python
Introduction to ArcPy. Topics What is ArcPy? Accessing geoprocessing tools using ArcPy Writing scripts using ArcPy.
Python: An Introduction
9. Introduction to ArcObjects Most GIS analysis carried out within a GIS consists of a labor- intensive sequence of steps. Automating a GIS makes it possible.
Internet and Distributed Representation of Agent Based Model by- Manish Sharma.
Programming for Geographical Information Analysis: Advanced Skills Lecture 1: Introduction Programming Arc Dr Andy Evans.
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
ArcGIS Pro: A Quick Tour of Python David Wynne.
Esri UC2013. Technical Workshop. Technical Workshop 2013 Esri International User Conference July 8–12, 2013 | San Diego, California Developing.NET Applications.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
CS4710 Why Progam?. Why learn to program? Utility of programming skills: understand tools modify tools create your own automate repetitive tasks automate.
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
ArcGIS Geoprocessing Advanced Scripting With Python Corey Tucker Nathan Warmerdam.
CE 697V, Project 41 Project 4: Geoprocessing Script November 10, 2006 Kwangbae Kim.
CS105 Computer Programming PYTHON (based on CS 11 Python track: lecture 1, CALTECH)
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
Jim Havrilla. Invoking Python Just type “python –m script.py [arg]” or “python –c command [arg]” To exit, quit() or Control-D is used To just use the.
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
PROGRAMMING USING PYTHON LANGUAGE ASSIGNMENT 1. INSTALLATION OF RASPBERRY NOOB First prepare the SD card provided in the kit by loading an Operating System.
Technical Workshops | Esri International User Conference San Diego, California Branching and Iteration in ModelBuilder Shitij Mehta July 24, :15.
Tips. Iteration On a list: o group = ["Paul","Duncan","Jessica"] for person in group: print(group) On a dictionary: o stock = {'eggs':15, 'milk':3, 'sugar':28}
Outline of Script Import Modules Setup Workspace Environment and Assign Data Path Variables Summary of Script Title and Author Info.
Intro to Programming STARS College of Communication and Information Florida State University Written by: Hannah Brock Alissa Ovalle Nicolaus Lopez Martin.
Introduction to GIS Programming Final Project Submitted by Todd Lenkin Geography 375 Spring of 2011 American River College.
Lecture III Syntax ● Statements ● Output ● Variables ● Conditions ● Loops ● List Comprehension ● Function Calls ● Modules.
Introduction to InVEST ArcGIS Tool
Introduction to GIS PythonScript CGIS-NURIntroduction to ArcGIS II.
PowerShell Introduction Copyright © 2016 – Curt Hill.
PYTHON: AN INTRODUCTION
Lecture 1 Introduction to Python Programming
PHP Introduction.
Programming and Automation
Lecture 9 Using Python for Geoprocessing
Writing Geoprocessing Scripts With ArcGIS
Programming for Geographical Information Analysis: Advanced Skills
Lecture 10 Accessing tools and environment setting in Scripts
Writing Geoprocessing Scripts With ArcGIS
Programming for Geographical Information Analysis: Advanced Skills
Geography 465 GIS Database Programming
Programming Arc.
Clip & Convert to ASCII Program Kelly Knapp Spring 2010
Presentation transcript:

Module 6: Geoprocessing Scripts

Processing loops and decisions

AML (Arc Macro Language) VB script Jscript PERL Python (comes with ArcGIS) Most COM compliant scripting languages

Python Platform independent (linux, unix, windows) Object-oriented, developer language Good website ( Comes with ArcGIS, free from web

Installing Python ArcGIS Desktop CD Explore rather than open to avoid autoinstallation of ArcGIS

In Python folder.. Run both exe files

GeoProcessor Object

Export Model to Script

# polygon_to_poly_line.py # Created on: Fri Dec :34:54 PM # (generated by ArcGIS/ModelBuilder) # Import system modules import sys, string, os, win32com.client # Create the Geoprocessor object gp =win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1") # Set the ArcGIS product code (Arcview, ArcEditor, or ArcInfo) gp.SetProduct("ArcInfo") Python system String module Operating System COM Dispatch

# Load required toolboxes... gp.AddToolbox("C:/workshop_geoprocessing/ExampleToolbox.tbx") # Local variables... poly_lines_shp = "C:/temp/poly_lines.shp" selected_polygons_shp = "C:/temp/selected_polygons.shp" # Process: Polygon To Line... gp.toolbox = "C:/workshop_geoprocessing/ExampleToolbox.tbx" gp.PolygonToLine(selected_polygons_shp, poly_lines_shp)

# Script arguments or variables... Input_Features = sys.argv[1] Output_Feature_Class = sys.argv[2] # Process: Polygon To Line... gp.toolbox = "C:/temp/My Toolbox.tbx" gp.PolygonToLine(Input_Features, Output_Feature_Class)

# use + to concatenate strings: # single or double-quotes enclose string chars name = ‘moose_locations’ type = “.shp” shapefile = name + type print shapefile moose_locations.shp

# decisions or branching: # indentation used to indicate structure if type == 'point' : print 'Theme is point type' print 'Must be polygon type to use erase tool' elif type == 'polyline' : print 'Theme is polyline type' print 'Convert to polygon type, then rerun script' elif type == 'polygon' : print 'Theme is polygon type' print 'Correct feature type for using erase tool' else : print "Theme type is not point, line, or polygon" print “End of Script” #out of if block

Listing Data

List first 2 pond polygon feature classes # Import system modules import sys, string, os, win32com.client # Create the Geoprocessor object gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1") #set workspace gp.workspace = "C:/ponds "; print "workspace set to: ", str(gp.workspace) #get list of feature classes fcs = gp.ListFeatureClasses("pond*","polygon") fcs.reset() #get first two objects in list and assign to variables theme1, theme2: theme1 = fcs.next() theme2 = fcs.next() print "First two polygon themes in workspace: ", str(theme1), str(theme2)

List all pond polygon feature classes # Import system modules import sys, string, os, win32com.client # Create the Geoprocessor object gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1") #set workspace gp.workspace = "C:/ponds“; print "workspace set to: ", str(gp.workspace) #get list of feature classes fcs = gp.ListFeatureClasses("pond*","polygon") fcs.reset() # Get the first theme and start the loop Current_Theme = fcs.next() while Current_Theme: # While the Current_Theme is not empty Print “Current theme in list is:”, str(Current_Theme) Current_Theme = fcs.next() Print “End of Script”

Convert all pond polygon to line themes # Import system modules import sys, string, os, win32com.client # Create the Geoprocessor object gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1") #set workspace gp.workspace = "C:/ponds"; print "workspace set to: ", str(gp.workspace) #get list of feature classes fcs = gp.ListFeatureClasses("pond*","polygon") fcs.reset() print "All pond polygon themes will be converted to pond shoreline themes..." # Get the first theme and start the loop Current_Theme = fcs.next() while Current_Theme: # While the Current_Theme is not empty print "Converting Theme:", str(Current_Theme) gp.PolygonToLine(Current_Theme, "c:/shorelines/" + Current_Theme) Current_Theme = fcs.next() print "End of Script"

1) Check for syntax errors 2) Step Through Script Using Debugger

Test Batch Process….

Scheduling Scripts

Sources of Confusion Python commands and variables are case sensitive ( print theme <> Print theme <> print Theme ) Geoprocessor properties not case sensitive ( gp.workspace = gp.WorkSpace ) \ is a reserved character meaning line continuation (use / or \\ for paths instead of \) Indentation is a source of loop structure

Sources of Confusion Model does not use UML like ArcObjects Arrows indicate instantiation Only non character properties are indicated in diagram