Geography 465 GIS Database Programming Getting Started with GIS Database Programming.

Slides:



Advertisements
Similar presentations
Introducing JavaScript
Advertisements

Intro to Python Welcome to the Wonderful world of GIS programing!
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.
The Web Warrior Guide to Web Design Technologies
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.
GIS Topics and Applications
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.
 2003 Prentice Hall, Inc. All rights reserved. Customized by Sana Odeh for the use of this class. 1 Introduction to Computers and Programming in JAVA.
ModelBuilder In ArcGIS 9.x By Tim Weigel GEOG 407/607 April 3 rd, 2006.
Geography 465 Overview Geoprocessing in ArcGIS. MODELING Geoprocessing as modeling.
Guide To UNIX Using Linux Third Edition
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Chapter 2: The Visual Studio.NET Development Environment Visual Basic.NET Programming: From Problem Analysis to Program Design.
ModelBuilder at ArcGIS 9.2 Lyna Wiggins Rutgers University May 2008.
Geography 465 Analytic Cartography: Getting Started with Python Scripting.
Geography 465 Assignments, Conditionals, and Loops.
Chapter 9 Introduction to ActionScript 3.0. Chapter 9 Lessons 1.Understand ActionScript Work with instances of movie clip symbols 3.Use code snippets.
1 Chapter One A First Program Using C#. 2 Objectives Learn about programming tasks Learn object-oriented programming concepts Learn about the C# programming.
A First Program Using C#
Visual Basic Chapter 1 Mr. Wangler.
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.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
2006 GIS Jam: ArcGIS Python Scripting
Chapter 1: Creating Java Programs
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 2 - Welcome Application: Introduction to C++
The NetBeans IDE CSIS 3701: Advanced Object Oriented Programming.
Introduction to Spatial Analysis and Spatial Modeling
Using Visual Basic 6.0 to Create Web-Based Database Applications
Introduction to Python John Reiser May 5 th, 2010.
Chapter 1: A First Program Using C#. Programming Computer program – A set of instructions that tells a computer what to do – Also called software Software.
Python: An Introduction
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
1 JavaScript in Context. Server-Side Programming.
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.
TUTORIAL 10: PROGRAMMING WITH JAVASCRIPT Session 2: What is JavaScript?
Tutorial 10 Programming with JavaScript
Introduction of Geoprocessing Topic 7a 4/10/2007.
Intro and Review Welcome to Java. Introduction Java application programming Use tools from the JDK to compile and run programs. Videos at
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Module 6: Geoprocessing Scripts. Processing loops and decisions.
XP Tutorial 8 Adding Interactivity with ActionScript.
Trinity College Dublin, The University of Dublin GE3M25: Computer Programming for Biologists Python Karsten Hokamp, PhD Genetics TCD, 03/11/2015.
1 JavaScript in Context. Server-Side Programming.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
Copyright (c) 2003 by Prentice Hall Provided By: Qasim Al-ajmi Chapter 2 Introduction to Visual Basic Programming Visual Basic.NET.
Introduction of Geoprocessing Lecture 9 3/24/2008.
Python 1 SIGCS 1 Intro to Python March 7, 2012 Presented by Pamela A Moore & Zenia C Bahorski 1.
1 Project 7: Looping. Project 7 For this project you will produce two Java programs. The requirements for each program will be described separately on.
Visual Basic.Net. Software to Install Visual Studio 2005 Professional Edition (Requires Windows XP Pro) MSDN Library for Visual Studio 2005 Available.
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Java Programming Fifth Edition Chapter 1 Creating Your First Java Classes.
Linux Administration Working with the BASH Shell.
Introduction to GIS PythonScript CGIS-NURIntroduction to ArcGIS II.
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
Lecture 9 Using Python for Geoprocessing
Lecture 10 Accessing tools and environment setting in Scripts
Introduction to Python
T. Jumana Abu Shmais – AOU - Riyadh
Geography 465 GIS Database Programming
Automating Geodatabase Administration with Python
Tutorial 10: Programming with javascript
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

Geography 465 GIS Database Programming Getting Started with GIS Database Programming

See Geog 465 course web site forGeog 465 course web site Overview and Schedule

What is GIS Database Programming? Geoprocessing - application of GIS operations on a set of data inputs for generating information. Database (DB) programming – the part of geoprocessing focusing on DB manipulation; not quite spatial analysis but almost. Use scripting to automate DB programming

Why write scripts? Scripts supply the added benefit of decision making logic and looping functionality Automate a work flow, for example: –Copy all incoming data into a geodatabase –Perform a project, clip, buffer operation on multiple data sets (iterate) Easily distribute code –A script is a self-contained, single file

Why use Python for Scripting? An open-source, object-oriented, scripting language Offers IDE ( integrated development environment ) with debugging tools Modular, can be broken apart Ability to compile scripts Installed with ArcGIS 9 and ESRI samples provided

Writing code in Python Writing Python code –Python command line –IDE (integrated development environment) e.g., PythonWin, IDLE, Komodo –Michalis suggests using Komodo Edit e/komodo_edit.mhtml IDE allows you to perform all jobs from one location –Write, Save, Run, and Debug code

IDE Interface should have Script window –Write and save code Interactive window –Test lines of code –Report messages Menus and Toolbars –standard and debugging

Basics of Python Comment : A non-executable line of code –One number sign (#) for green and italicized –Two number signs (##) for gray # Name: Michalis Avraam # Date: January 5, 2009 # Purpose: To buffer a feature class import win32com.client gp = win32com.client.Dispatch(“esriGeoprocessing.GpDispatch.1”) ## gp.Workspace = “C:\\Python_Data\\SanDiego.mdb” Gp.Buffer_analysis (“Freeways”, “BuffFreeway”, 1000) Can comment and uncomment blocks of code

Creating Scripts in Python Use of ArcGIS help system to find: –Usage, command syntax, and scripting examples of standard ArcToolbox tools, –Usage and syntax of Geoprocessor properties and methods, which are only accessible through scripting

Running Python Scripts Three Modes 1) Running scripts in IDE 2) Running scripts as script tools in ArcGIS 3) Running scripts as embedded model components in ArcGIS

(non) Running Scripts in Python Problem with the schema lock –Cannot manipulate with the same file open in ArcGIS and in IDE at the same time

Running scripts in PythonWin Example of a simple script to buffer a feature class # Name: Tim Nyerges # Date: January 5, 2009 # Purpose: To buffer a feature class import win32com.client gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1“ gp.Workspace = "C:\\Python_Data\\SanDiego.mdb” gp.Buffer_analysis ("Freeways", "BufferedFreeways", 1000)

Debugging the Code Test code in IDE –A check for syntax errors Do not test a script from ArcToolbox Test code in IDE, then add it to ArcToolbox

Running scripts in IDE Run the script Check the messages that return: –While the script is running you will see the message “running script.py” -The indication of the successful run is the message “Script returned the exit code 0” Display the result in ArcCatalog

Running scripts in IDE Example of a simple script to clip a feature class # Name: Tim Nyerges # Date: January 3, 2007 # Purpose: To clip a feature class import win32com.client gp =win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1") gp.Workspace = "C:\\Python_Data\\SanDiego.mdb" gp.Clip_analysis ("MajorAttractions", "SDdowntown", "SDdowntownAttractions")

Running scripts in IDE Example of a simple script to buffer and clip a feature class # Name Tim Nyerges # Date: January 5, 2009 # Purpose: To buffer SD freeways first and then to clip the downtown section # of freeways import win32com.client gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1") gp.Workspace = "C:\\Python_Data\\SanDiego.mdb" if gp.Exists(gp.Workspace + "\\bufferedFreeways"): gp.Delete_management(gp.Workspace + "\\bufferedFreeways") gp.Buffer_analysis ("Freeways", "bufferedFreeways", "500") gp.Clip_analysis ("bufferedFreeways", "SDdowntown", "downtownFreeways")

Michalis will get you started in labb session… “hands-on” Python and Komodo edit

Variables in Python Variables are dynamically typed –No declaration required –No type assignment required fc = “C:\\ProjectData\\SanDiego.mdb\\Freeways.shp” Variables are case sensitive fc = “Freeways.shp” Fc = Variables can hold different data types –numbers, strings, lists, files Two different variables

Numbers Variables can hold numbers and expressions num1 = 1.2 num2 = 3 + 5

Strings Variables can hold strings folder = “c:/Student” Strings are surrounded in double (“) or single (‘) quotes Pathnames use two back (\\) or one forward (/) slash One backslash (\) is a reserved escape character and a line continuation character

Strings Strings can be combined together gdbPath = “c:\\SanDiego.mdb” fc = “Roads” fullPath = gdbPath + “\\” + fc Strings are indexed –strings are zero-based from the left and one-based from the right fc = “Streets.shp” fc[0] ---> “S”# S is in the 0 position fc[1:3] ---> “tr”# start at 1st, up to not including 3rd fc[:-4]---> “Streets” # get rid of the last 4 charaters C:\SanDiego.mdb\Roads”

Lists Variables can hold lists numList = [1, 2, 3] fcList = [“Roads”, “Streets”, “Parcels”, “Zipcodes”] Lists are indexed fc1 = fcList[1] fc2 = fcList[0:2] ---> “Roads”, “Streets” fc3 = fcList[0:-1] ---> “Roads”, “Streets”, “Parcels” fc4 = fcList[2:] ---> “Parcels”, “Zipcodes” ---> “Streets”

Variable naming conventions Upper case versus lower case –First word lower case, capitalize each successive word tableFieldName = “Street” - Acronym at the beginning, use lower case letters gdbPath = “C:\\SanDiego.mdb” -Acronym in the middle or at the end, use upper case letters inputFC = “Streets.shp” Avoid special characters (for example / \ & % # !) Use descriptive variable names

Line continuation Line continuation characters –Parentheses ( ), brackets [ ], and braces { } –Backslash \ Indentation is automatic fcList = [“Roads”, “Climate”, “Streams”, “Zipcodes”, “Coastlines”] distanceValues = 100, 200, 300, 400, 500, \ 1000, 1500 gp.Buffer_analysis(fcList[2], BuffStreams1000, distanceValues[5])