2006 GIS Jam: ArcGIS Python Scripting

Slides:



Advertisements
Similar presentations
Intro to Python Welcome to the Wonderful world of GIS programing!
Advertisements

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.
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
Ruby The Gem of new programming languages. An interpreted scripting language.
Python & ModelBuilder. Overview Python/ModelBuilder Concepts – The Geoprocessor – Checking some environment variables – Providing feedback from your model/script.
Spatial Analysis, Geoprocessing,
Introduction to Perl Software Tools. Slide 2 Introduction to Perl l Perl is a scripting language that makes manipulation of text, files, and processes.
Geography 465 Analytic Cartography: Getting Started with Python Scripting.
Geography 465 GIS Database Programming Getting Started with GIS Database Programming.
Principles of Procedural Programming
An ide for teaching and learning prolog
8/17/2015CS346 PHP1 Module 1 Introduction to PHP.
© Paradigm Publishing Inc Chapter 12 Programming Concepts and Languages.
Arc: Programming Options Dr Andy Evans. Programming ArcGIS ArcGIS: Most popular commercial GIS. Out of the box functionality good, but occasionally: You.
Python Mini-Course University of Oklahoma Department of Psychology Day 1 – Lesson 2 Fundamentals of Programming Languages 4/5/09 Python Mini-Course: Day.
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.
AIT 616 Fall 2002 PHP. AIT 616 Fall 2002 PHP  Special scripting language used to dynamically generate web documents  Open source – Free!!!  Performs.
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
Introduction to ArcPy. Topics What is ArcPy? Accessing geoprocessing tools using ArcPy Writing scripts using ArcPy.
Python: An Introduction
Lesson 6. GCSE Computing – programming languages Candidates should be able to:  describe common tools and facilities available in an integrated development.
Computer Programming for Biologists Oct 30 th – Dec 11 th, 2014 Karsten Hokamp  Fill out.
August 29, 2005ICP: Chapter 1: Introduction to Python Programming 1 Introduction to Computer Programming Chapter 1: Introduction to Python Programming.
GNU Compiler Collection (GCC) and GNU C compiler (gcc) tools used to compile programs in Linux.
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.
Python – Part 1 Python Programming Language 1. What is Python? High-level language Interpreted – easy to test and use interactively Object-oriented Open-source.
Java Programming, Second Edition Chapter One Creating Your First Java Program.
Computer Science 101 Introduction to Programming.
Guide to Programming with Python Chapter One Getting Started: The Game Over Program.
Automating Processes with ArcPy to do work so I don’t have to Joe Guzi GIS Systems Analyst Stark County GIS Department 2015 Ohio GIS Conference September.
Introduction.  The scripting language most often used for client-side web development.  Influenced by many programming languages, easier for nonprogrammers.
Module 6: Geoprocessing Scripts. Processing loops and decisions.
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.
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)
TCL TK. Tcl/Tk C functions can become Tcl commands that are invoked interactively Tk = scriptable, portable user interface –Windows, X (Unix), MacOS,
8 th Semester, Batch 2009 Department Of Computer Science SSUET.
Web Page Designing With Dreamweaver MX\Session 1\1 of 9 Session 1 Introduction to PHP Hypertext Preprocessor - PHP.
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
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}
Introducing Python 3 Introduction to Python. Introduction to Python L1 Introducing Python 3 Learning Objectives Know what Python is and some of the applications.
Introduction CMSC 202 Fall Instructors Mr. Ryan Bergeron – Lecture Section 01 Tues/Thu 1:00 – 2:15 am, Sondheim 111 – Lecture Section 04 Tues/Thu.
PHP using MySQL Database for Web Development (part II)
Introducing Python Introduction to Python.
CST 1101 Problem Solving Using Computers
Introduction to GIS PythonScript CGIS-NURIntroduction to ArcGIS II.
Whatcha doin'? Aims: To start using Python. To understand loops.
Programming Basics Web Programming.
PYTHON: AN INTRODUCTION
Programming and Automation
Lecture 9 Using Python for Geoprocessing
TRANSLATORS AND IDEs Key Revision Points.
Writing Geoprocessing Scripts With ArcGIS
Lecture 10 Accessing tools and environment setting in Scripts
Writing Geoprocessing Scripts With ArcGIS
Geography 465 GIS Database Programming
JavaScript: Introduction to Scripting
12th Computer Science – Unit 5
Introduction to Computer Science
Input and Output Python3 Beginner #3.
Clip & Convert to ASCII Program Kelly Knapp Spring 2010
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

2006 GIS Jam: ArcGIS Python Scripting

Getting Started With Python Geoprocessing Why use scripting with ArcGIS? Python Basics ArcGIS Geoprocessor Basics Simple Applications Sources of confusion

Why bother with scripting?

When NOT to bother with scripting?

VB script Jscript PERL Python (comes with ArcGIS) Scripting Languages for Geoprocessing

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

GeoProcessor Model

Export Model to Script

ArcGIS Geoprocessor Basics Import modules Create geoprocessor object Use geoprocessor

# 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") # 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) Python system String module Operating System COM Dispatch

OR

# 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) Script Arguments---input from user

Running python scripts Using PythonWin debugger Using Python command window As system process As scheduled process

PythonWin

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

Thousands of Toolbars Bog Down System To A Crawl!

“Easy Fix”— comment out self.SaveBarState(ToolbarDefault)

Python command window

Running script as system process

Scheduling Scripts

Messages From Executing Tools

Example Applications For every polygon theme in workspace Convert polygon theme to polyline theme Compute area and perimeter in all themes For every workspace in text file: Build raster pyramids for every raster in each workspace

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("*","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"

Problems With Python Scripting Interpreted language Case sensitive Indentation source of structure \ is a reserved character # is a commenting character Newline character at end of lines

Interpreted Line by Line = SLOW

Case Sensitive

Indentation Source of Structure

/ is a reserved character # is a comment character

Determine shape type of every theme listed in text file…..

More information Python ArcGIS Python Scripting