intro to python welcome to the wonderful world of gis programing!
TRANSCRIPT
![Page 1: Intro to Python Welcome to the Wonderful world of GIS programing!](https://reader036.vdocuments.site/reader036/viewer/2022062304/56649c7d5503460f9493252b/html5/thumbnails/1.jpg)
Intro to Python
Welcome to the
Wonderful world of GIS programing!
![Page 2: Intro to Python Welcome to the Wonderful world of GIS programing!](https://reader036.vdocuments.site/reader036/viewer/2022062304/56649c7d5503460f9493252b/html5/thumbnails/2.jpg)
Topics
• A brief history of GIS programing• What is Python?• What is PythonWin?• Basics of Python
![Page 3: Intro to Python Welcome to the Wonderful world of GIS programing!](https://reader036.vdocuments.site/reader036/viewer/2022062304/56649c7d5503460f9493252b/html5/thumbnails/3.jpg)
Brief history of ESRI’s GIS software evolution
Arc/Info Coverage 1980’s
Software Data Format Year
ArcView Shapefile 1990’s
ArcGIS 8 & 9 Geodatabase 2000’s
ArcGIS 10 Geodatabase 2010
![Page 4: Intro to Python Welcome to the Wonderful world of GIS programing!](https://reader036.vdocuments.site/reader036/viewer/2022062304/56649c7d5503460f9493252b/html5/thumbnails/4.jpg)
Programming language• SML was used for PC ArcInfo
• AML was 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
![Page 5: Intro to Python Welcome to the Wonderful world of GIS programing!](https://reader036.vdocuments.site/reader036/viewer/2022062304/56649c7d5503460f9493252b/html5/thumbnails/5.jpg)
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
![Page 6: Intro to Python Welcome to the Wonderful world of GIS programing!](https://reader036.vdocuments.site/reader036/viewer/2022062304/56649c7d5503460f9493252b/html5/thumbnails/6.jpg)
Programming Environments• Python files are text files (.py extension)
• Python code can be written in
Text Editor IDLE PythonWi
nPython
Window
• PythonWin is the preferred way!
![Page 7: Intro to Python Welcome to the Wonderful world of GIS programing!](https://reader036.vdocuments.site/reader036/viewer/2022062304/56649c7d5503460f9493252b/html5/thumbnails/7.jpg)
PythonWin Interface1. PyhonWin created specifically for windows with
common tools & menus2. Windows look and feel3. 3 windows:
a. Application windowb. Script windowc. Interactive window
Python.lnk
![Page 8: Intro to Python Welcome to the Wonderful world of GIS programing!](https://reader036.vdocuments.site/reader036/viewer/2022062304/56649c7d5503460f9493252b/html5/thumbnails/8.jpg)
PythonWin: Script Window
• Script window is for writing, saving, & executing code
• Python scripts are saved with .py extension. Ex: (Test.py)
![Page 9: Intro to Python Welcome to the Wonderful world of GIS programing!](https://reader036.vdocuments.site/reader036/viewer/2022062304/56649c7d5503460f9493252b/html5/thumbnails/9.jpg)
PythonWin: Interactive Window
• Interactive window is for
testing code and report
errors messages
• Also report the output of print statement
![Page 10: Intro to Python Welcome to the Wonderful world of GIS programing!](https://reader036.vdocuments.site/reader036/viewer/2022062304/56649c7d5503460f9493252b/html5/thumbnails/10.jpg)
PythonWin: Application/main window
Run Script Check Script
Script ran successfully
![Page 11: Intro to Python Welcome to the Wonderful world of GIS programing!](https://reader036.vdocuments.site/reader036/viewer/2022062304/56649c7d5503460f9493252b/html5/thumbnails/11.jpg)
Basic Python syntax
• Comments• Variables• Strings• Numbers
![Page 12: Intro to Python Welcome to the Wonderful world of GIS programing!](https://reader036.vdocuments.site/reader036/viewer/2022062304/56649c7d5503460f9493252b/html5/thumbnails/12.jpg)
Comments• Lines of code that serve as documentation:• Non-executable• Use a # or ##• It’s a must for your lab
Block of code can be commented-- Highlight the block of code in the script window -- Right click>Source Code>Comment out region
Example: # Name: John Denver
# Date: January 2012
![Page 13: Intro to Python Welcome to the Wonderful world of GIS programing!](https://reader036.vdocuments.site/reader036/viewer/2022062304/56649c7d5503460f9493252b/html5/thumbnails/13.jpg)
Python Statements
Lines of code that perform a taskprint- sends output to the interactive windowimport – import a moduleExample:print “Welcome to Python world”import math (import math module)
![Page 14: Intro to Python Welcome to the Wonderful world of GIS programing!](https://reader036.vdocuments.site/reader036/viewer/2022062304/56649c7d5503460f9493252b/html5/thumbnails/14.jpg)
Variables• Variables store values of different typesfirst = ”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
![Page 15: Intro to Python Welcome to the Wonderful world of GIS programing!](https://reader036.vdocuments.site/reader036/viewer/2022062304/56649c7d5503460f9493252b/html5/thumbnails/15.jpg)
Strings
• An ordered collection of characters
• Can be surrounded by double (“”) or single (‘’) quotes
message = “Welcome to Python”input = “C:/GIS222/Auburn.gdb/roads”
![Page 16: Intro to Python Welcome to the Wonderful world of GIS programing!](https://reader036.vdocuments.site/reader036/viewer/2022062304/56649c7d5503460f9493252b/html5/thumbnails/16.jpg)
Manipulating Strings
Strings can be concatenated
f1 = “C:/GIS222/Auburn/roads”f2 = “.shp”Data = f1 + f2Result= “C:/GIS222/Auburn/roads.shp”
Strings can be repeated
s1 = “Ha!”s1*3Result= “Ha!Ha!Ha!”
![Page 17: Intro to Python Welcome to the Wonderful world of GIS programing!](https://reader036.vdocuments.site/reader036/viewer/2022062304/56649c7d5503460f9493252b/html5/thumbnails/17.jpg)
Common String FunctionsUpper, lower, capitalize,………..
f1 = “AUBURN.shp”f1.upper() Result: “AUBURN.SHP”
There are many more; find them by typing object.
f1.lower() Result: “auburn.shp”
f1.capitalize()Result: “Auburn.shp
f1.replace(“AUBURN”, “OWASCO”)Result: “OWASCO.shp”
![Page 18: Intro to Python Welcome to the Wonderful world of GIS programing!](https://reader036.vdocuments.site/reader036/viewer/2022062304/56649c7d5503460f9493252b/html5/thumbnails/18.jpg)
Built-in Python Functions
2. round() returns a rounded number
xCoord = 450,000.2345round(xCoord) Result: 450,000
1. len() returns the length of a string or a listf1 = “AUBURN.shp”len(f1) Result: 10
3. str() converts an integer to a stringzone = 18strzone = str(zone)print “UTM Zone” + strzone
![Page 19: Intro to Python Welcome to the Wonderful world of GIS programing!](https://reader036.vdocuments.site/reader036/viewer/2022062304/56649c7d5503460f9493252b/html5/thumbnails/19.jpg)
Other Functions to convert values
2. int() returns an integer value
int(“10”) Result: 10
1. float() returns a floating point value
float(“10.0”) Result: 10.0
3. str() converts an integer to a stringstr(18) Result: “18”print “UTM Zone” + str(18)
![Page 20: Intro to Python Welcome to the Wonderful world of GIS programing!](https://reader036.vdocuments.site/reader036/viewer/2022062304/56649c7d5503460f9493252b/html5/thumbnails/20.jpg)
Getting user input
2. str = raw_input(“Enter your name: “)
1. num = input(“Enter you age: “)
You can always check your input with
print num
Or
print str
![Page 21: Intro to Python Welcome to the Wonderful world of GIS programing!](https://reader036.vdocuments.site/reader036/viewer/2022062304/56649c7d5503460f9493252b/html5/thumbnails/21.jpg)
Python Tutorial
Search: “What is Python”ArcGIS Resources Center:
![Page 22: Intro to Python Welcome to the Wonderful world of GIS programing!](https://reader036.vdocuments.site/reader036/viewer/2022062304/56649c7d5503460f9493252b/html5/thumbnails/22.jpg)
Let’s try it!