1 / 22

Welcome to the Wonderful world of GIS programing!

Intro to Python. Welcome to the Wonderful world of GIS programing!. Topics. A brief history of GIS programing What is Python? What is PythonWin ? Basics of Python. Software. Year. Data Format. 1980’s. Coverage. Arc/Info. 1990’s. ArcView. Shapefile. 2000’s. 2010.

dunn
Download Presentation

Welcome to the Wonderful world of GIS programing!

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Intro to Python Welcome to the Wonderful world of GIS programing!

  2. Topics • A brief history of GIS programing • What is Python? • What is PythonWin? • Basics of Python

  3. Software Year Data Format 1980’s Coverage Arc/Info 1990’s ArcView Shapefile 2000’s 2010 Geodatabase Geodatabase ArcGIS 8 & 9 ArcGIS 10 Brief history of ESRI’s GIS software evolution

  4. Programming language • SML was used for PC ArcInfo • AMLwas used for Arc/INFO 7.x • Avenue was used for ArcView 3.x • Visual Basic for Application (VBA) is for ArcGIS 8 & 9& packaged with it • Python for ArcGIS10

  5. What is Python? • An object oriented scripting language • Cross-platform: meaning portable & will run on Windows, Unix, and Linux • Python is fully embraced by ESRI at ArcGIS 10 • Comes bundled with ArcGIS • Free

  6. Programming Environments • Python files are text files (.py extension) • Python code can be written in • PythonWin is the preferred way!

  7. PythonWin Interface • PyhonWin created specifically for windows with common tools & menus • Windows look and feel • 3 windows: • a. Application window • b. Script window • c. Interactive window

  8. PythonWin: Script Window • Script window is for writing, saving, & executing code • Python scripts are saved with .py extension. Ex: (Test.py)

  9. PythonWin: Interactive Window • Interactive window is for testing code and report errors messages • Also report the output of print statement

  10. PythonWin: Application/main window Run Script Check Script Script ran successfully

  11. Basic Python syntax • Comments • Variables • Strings • Numbers

  12. Comments • Lines of code that serve as documentation: • Non-executable • Use a # or ## • It’s a must for your lab Example: # Name: John Denver # Date: January 2012 Block of code can be commented -- Highlight the block of code in the script window -- Right click>Source Code>Comment out region

  13. Python Statements Lines of code that perform a task print- sends output to the interactive window import – import a module Example: print “Welcome to Python world” import math (import math module)

  14. Variables • Variables store values of different types first = ”Bob” last = “Brown” age = 30 height = 5.6 source = “C:/Exercises/Auburn.gdb” • Variables are case sensitive Num = 500 & num = 5000 (2 variables) • Variables are dynamically type --do not have to declare the variable -- don’t have to assign a data type

  15. Strings • An ordered collection of characters • Can be surrounded by double (“”) or single (‘’) quotes message = “Welcome to Python” input = “C:/GIS222/Auburn.gdb/roads”

  16. Manipulating Strings Strings can be concatenated f1 = “C:/GIS222/Auburn/roads” f2 = “.shp” Data = f1 + f2 Result= “C:/GIS222/Auburn/roads.shp” Strings can be repeated s1 = “Ha!” s1*3 Result= “Ha!Ha!Ha!”

  17. Common String Functions f1 = “AUBURN.shp” f1.upper() Result: “AUBURN.SHP” Upper, lower, capitalize,……….. f1.lower() Result: “auburn.shp” • f1.capitalize() • Result: “Auburn.shp • f1.replace(“AUBURN”, “OWASCO”) • Result: “OWASCO.shp” There are many more; find them by typing object.

  18. Built-in Python Functions 1. len() returns the length of a string or a list f1 = “AUBURN.shp” len(f1) Result: 10 2. round() returns a rounded number xCoord = 450,000.2345 round(xCoord) Result: 450,000 3. str() converts an integer to a string zone = 18 strzone = str(zone) print “UTM Zone” + strzone

  19. Other Functions to convert values 1. float() returns a floating point value float(“10.0”) Result: 10.0 2. int() returns an integer value int(“10”) Result: 10 3. str() converts an integer to a string str(18) Result: “18” print “UTM Zone” + str(18)

  20. Getting user input num = input(“Enter you age: “) 2. str = raw_input(“Enter your name: “) You can always check your input with print num Or print str

  21. Python Tutorial ArcGIS Resources Center: Search: “What is Python”

  22. Let’s try it!

More Related