Introduction to GIS PythonScript CGIS-NURIntroduction to ArcGIS II.

Slides:



Advertisements
Similar presentations
Introducing JavaScript
Advertisements

Intro to Python Welcome to the Wonderful world of GIS programing!
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
Tutorial 12: Enhancing Excel with Visual Basic for Applications
Why python? Automate processes Batch programming Faster Open source Easy recognition of errors Good for data management What is python? Scripting programming.
 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
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.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Geography 465 Analytic Cartography: Getting Started with Python Scripting.
Geography 465 Assignments, Conditionals, and Loops.
Geography 465 GIS Database Programming Getting Started with GIS Database Programming.
Creating a Console Application with Visual Studio
Chapter 9 Introduction to ActionScript 3.0. Chapter 9 Lessons 1.Understand ActionScript Work with instances of movie clip symbols 3.Use code snippets.
Python Programming Fundamentals
Esri International User Conference | San Diego, CA Technical Workshops | Python – Getting Started Drew Flater, Ghislain Prince July 12 - July 14, 2011.
Lecture Note 3: ASP Syntax.  ASP Syntax  ASP Syntax ASP Code is Browser-Independent. You cannot view the ASP source code by selecting "View source"
2006 GIS Jam: ArcGIS Python Scripting
Writing Geoprocessing Scripts With ArcGIS Lecture 9.
Introduction to Python John Reiser May 5 th, 2010.
Python: An Introduction
Python Basic Syntax. Basic Syntax - First Program 1 All python files will have extension.py put the following source code in a test.py file. print "Hello,
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
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.
Intro and Review Welcome to Java. Introduction Java application programming Use tools from the JDK to compile and run programs. Videos at
Introduction to VB.NET 2005 Dr. McDaniel IDS4704 Spring 2005.
Lesson 6. Python 3.3 Objectives. In this lesson students will learn how to output data to the screen and request input from the user. Students will also.
7 1 User-Defined Functions CGI/Perl Programming By Diane Zak.
Chapter 1 – Matlab Overview EGR1302. Desktop Command window Current Directory window Command History window Tabs to toggle between Current Directory &
Chapter 9 Macros And Visual Basic For Applications.
Variables, Expressions and Statements
You Need an Interpreter!. Closing the GAP Thus far, we’ve been struggling to speak to computers in “their” language, maybe its time we spoke to them in.
ECET – Dynamic Programming with Python Spring 2013 Lecture L1 – Introduction to Python Page 1 Welcome! This is Professor Jai P. Agrawal. I will walk.
CSC 1010 Programming for All Lecture 2 Introduction to Python Some material based on material from Marty Stepp, Instructor, University of Washington.
Python 1 SIGCS 1 Intro to Python March 7, 2012 Presented by Pamela A Moore & Zenia C Bahorski 1.
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
CHAPTER 3 COMPLETING THE PROBLEM- SOLVING PROCESS AND GETTING STARTED WITH C++ An Introduction to Programming with C++ Fifth Edition.
Getting Started With Python Brendan Routledge
PHP Basics and Syntax Lesson 3 ITBS2203 E-Commerce for IT.
Development Environment
CST 1101 Problem Solving Using Computers
Whatcha doin'? Aims: To start using Python. To understand loops.
Chapter 6 JavaScript: Introduction to Scripting
Introduction to Python
Introduction Python is an interpreted, object-oriented and high-level programming language, which is different from a compiled one like C/C++/Java. Its.
Pamela Moore & Zenia Bahorski
PYTHON: AN INTRODUCTION
Introduction to C# Applications
Lecture 1 Introduction to Python Programming
Variables, Expressions, and IO
Java programming lecture one
Microsoft Access Illustrated
Microsoft Office Illustrated
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 2 Applications and Data.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Programming Vocabulary.
Writing Geoprocessing Scripts With ArcGIS
Introduction to Python
An Introduction to Python
CSCI N317 Computation for Scientific Applications Unit 1 – 1 MATLAB
Geography 465 GIS Database Programming
Tutorial 6 PHP & MySQL Li Xu
Experiment No. (1) - an introduction to MATLAB
12th Computer Science – Unit 5
Chapter 1: Programming Basics, Python History and Program Components
L L Line CSE 420 Computer Games Lecture #3 Introduction to Python.
CS313T Advanced Programming language
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

Introduction to GIS PythonScript CGIS-NURIntroduction to ArcGIS II

Lesson 6 overview How do I create a new script? Introduction to GIS Lesson 6 overview How do I create a new script? How do I write/change a script? How do I run a tool from a script? How do I set an environment setting in a script? What syntax do I use? What functionality is available? How do I run a script from an ArcGIS application? How do I fix my errors? CGIS-NURIntroduction to ArcGIS II

Why write scripts? Automate workflow Introduction to GIS Why write scripts? Automate workflow Copy all incoming data into a geodatabase Perform project, clip, buffer operations on multiple data sets Run code at specific dates and times Windows AT command Windows scheduler Easily distribute code A script is a self-contained, single file CGIS-NURIntroduction to ArcGIS II

Introduction to GIS Points of interest Scripting ArcObjects do not replace standard ArcObjects Customize or interact with the interface Developers (Desktop, Engine, Server) Can use many scripting/programming languages VBScript, JScript, Perl, Python, VBA, VB, C++, etc. Anything that supports COM Users do not have to learn a proprietary language ESRI primarily supports Python Installed with ArcGIS 9 Samples, documentation, help CGIS-NURIntroduction to ArcGIS II

The Python scripting language Introduction to GIS The Python scripting language What is Python? An open-source, object-oriented, scripting language Can view and modify source code Support for large projects Easy to use Why use Python? Offers IDEs with debugging tools Modular – can be broken apart Cross platform Ability to compile scripts Installed with ArcGIS 9, ESRI samples provided PythonWin CGIS-NURIntroduction to ArcGIS II

The Basics of Python Introduction to GIS CGIS-NURIntroduction to ArcGIS II

Lesson overview Where to write code Commenting code Introduction to GIS Lesson overview Where to write code Commenting code Strings, numbers, and lists Line continuation Functions, modules, and statements Decision making and looping Case sensitive rules CGIS-NURIntroduction to ArcGIS II

Where to write code There are many places to write Python code Introduction to GIS Where to write code There are many places to write Python code Text editor: Notepad, Wordpad, etc. Python command prompt IDE: PythonWin, IDLE, and so on IDEs allow you to perform all jobs from one location Write, save, run, and debug code from one location Command prompt and both IDEs installed with ArcGIS Lectures and exercises use PythonWin CGIS-NURIntroduction to ArcGIS II

PythonWin interface Menus, toolbars, and context menus Script window Introduction to GIS PythonWin interface Menus, toolbars, and context menus Script window Write and save code Interactive window Test lines of code Report messages Benefits Windows look and feel All in one application CGIS-NURIntroduction to ArcGIS II

Comments Comment: A non-executable line of code Introduction to GIS Comments Comment: A non-executable line of code One number sign (#) for green and italicized Two number signs (##) for grey Can comment and uncomment blocks of code Highlight code and use script window's context menu CGIS-NURIntroduction to ArcGIS II

Variables in Python Variables are dynamically typed Introduction to GIS Variables in Python Variables are dynamically typed No declaration keyword No type assignment fc = "C:/Student/PYTH/Database/rwanda.shp" Variables are case sensitive scale = 10000 Scale = 20000 Variables can hold different data types Strings, numbers, lists, tuples, dictionaries, files Two different variables! CGIS-NURIntroduction to ArcGIS II

Strings Variables can hold strings Introduction to GIS Strings Variables can hold strings folder = "C:/Student" whereClause = "[STREET_NAM] = 'CATALINA'" Strings surrounded in double (") or single (‘) quotes Can embed one string in another Pathnames use two back (\\) or one forward (/) slash Strings can be combined together gdbPath = "C:\\malaria.mdb" fc = “roads" fullPath = gdbPath + "\\" + fc Strings are indexed fc = “roads.shp" newFC = fc[:-4] CGIS-NURIntroduction to ArcGIS II

Numbers and lists Variables can hold numbers and expressions Introduction to GIS Numbers and lists Variables can hold numbers and expressions num1 = 1.2 num2 = 3 + 5 Variables can hold lists numList = [1, 2, 3] fcList = ["Roads", "Streets", "Parcels", "Zipcodes"] Lists are indexed fc1 = fcList[1] fc2 = fcList[0:2] fc3 = fcList[0:-1] fc4 = fcList[2:] CGIS-NURIntroduction to ArcGIS II

Variable naming conventions Introduction to GIS Variable naming conventions Uppercase versus lowercase First word lowercase, capitalize each successive word outputFieldName = "Rwanda" Acronym at the beginning, use lowercase letters gdbPath = "C:\\malaria.mdb" fc = "roads.shp" Acronym in the middle or at the end, use uppercase letters inputFC = "roads.shp" Avoid special characters (e.g. / \ & * !) Use descriptive variable names CGIS-NURIntroduction to ArcGIS II

Line continuation Line continuation characters Introduction to GIS Line continuation Line continuation characters Parentheses ( ), brackets [ ], and braces { } Backslash \ Indentation is automatic CGIS-NURIntroduction to ArcGIS II

Decision making syntax Introduction to GIS Decision making syntax Testing conditions Colons used at end of each condition Indentation defines what executes for each condition Python automatically indents when you press Enter Use tabs or spaces, must be consistent Two equal signs for conditions, one for assignment CGIS-NURIntroduction to ArcGIS II

Looping syntax While loops, counted loops, and list loops Introduction to GIS Looping syntax While loops, counted loops, and list loops Colons used at end of each statement Indentation defines what executes for the loop CGIS-NURIntroduction to ArcGIS II

Demo Used Syntax Examples Adapting scripts for own use Introduction to GIS Demo Used Syntax Examples Adapting scripts for own use CGIS-NURIntroduction to ArcGIS II