SlideShare a Scribd company logo
Python Programming for Arcgis 1
Daniel Sheehan
dsheehan@mit.edu, gishelp@mit.edu
9:30AM-12:30PM
January 14, 2015
This class was originally developed by David
Quinn and taught by David and Daniel in IAP
2010 and 2011.
Arcgis 10.2.2 and Python
• You need a normal install of Arcgis 10.2.2.
This install includes Python 2.7 and includes
the IDLE interface, which we will use.
• Other installs of Pythons will not have the
‘arcpy’ module and will not work.
Download data for workshop
• http://web.mit.edu/dsheehan/www/
dataForPythonIAP2015.zip
• http://web.mit.edu/dsheehan/www/
PythonProgrammingforArcgis.pdf
Goals for the workshop
• Learning enough Python to
– Access Arcgis commands through Python
– Access individual records from attribute table
– Acccess individual geometries for use in
geoprocessing
• Develop the ability to record and document
your geoprocessing
Outline
• Introduction to Python and Arcgis
• Programming Principles and Modules
• Model Builder
• Reading and Writing data
Schedule
Working with Python and geoprocessing tools
today, working with attribute tables and
individual geometries tomorrow
Python
Python is a language that lets you work more
quickly and integrate your systems more
effectively 1
Documentation at http://docs.python.org and look
for Python 2.7 (used in Arcgis 10.2.2)
1 http://www.python.org
Python + Arcgis
• Python can interact with Arcgis and be used to
repeat many types of analyses.
• Why Python?
• It is an integral part of Arcgis
• Easy to read syntax
• Large user community
• Useful for scripts to control other programs
How does Python work with Arcgis
• At Arcgis 10.2.2
– Fully integrated into Arcgis
– Largely Geoprocessing functions
• Automated mapping is not possible, yet
Logistics
• We will be using the IDLE programming
environment
• Windows: START -> Programs -> Arcgis ->
Python 2.7 -> IDLE
• We are using Arcgis 10.2.2 on lab computers
and assume that you are using 10.2.2 if you
are using your own laptop
Learn by doing
• Try every line of code in the slides
• Create a new file for each different slide to
create a record for yourself (optional)
• Use the Python Help and Arcgis Help and ask
questions
Programming concepts
• Variables
• Control Structures (IF statements and FOR
loops)
• Functions
Python is case sensitive and reads whitespace
for defining programming blocks – use space
bar, not tabs.
The Print Function and Strings
# this is a comment
print “hello world”
“”” Alternative
Commenting
Style “””
The Print function and Strings
# this is a comment
print (“hello world”)
# this is a variable that contains a string
name = “Daniel”
print (name)
Integers and Floats
# declare variables
int_sample = 10
float_sample = 10.0
# printing variables
# cast non-string variable as a string using str()
print “The value of this integer is: “ + str(int_sample)
print “The value of this float is: “ + str(float_sample)
if statement
x = 2
# Condition checks if statement is true
if x == 1:
print ‘x is 1!’
if / elif / else statement
x = 2
# Condition checks if statement is true
if x == 1:
print ‘x is 1!’
elif x == 2:
print ‘x is 2!’
else:
print ‘x is not known’
for loop
for i in range(3):
# convention is to use 4 spaces to indent
# python reads whitespace at the beginning of a line
print i
Python, like most programming languages, uses arrrays that are
zero based.
while loop
# define j
j = 1
# ‘while’ less than some condition
while j < 3:
print j
# increment j
j += 1
Three ways to access a folder
# Accessing a folder
path = “C:folderName”
path = “C:/folderName/”
path = r”C:folderName”
Importing Modules
Use the import command:
# count the number of files in a directory
import os
path = “c:...”
files = os.listdir(path)
print len(files)
A module is a list of Python programs that can be
accessed. Commonly used modules are os, sys,
glob.
glob
import glob # use the glob module
path =
“C:UsersdsheehandesktopPython2015current
”
# loop through all files
ListOfFiles = glob.glob(path + “*”)
for i in ListOfFiles:
print i
Try replacing ‘*’ with ‘*.shp’
Importing the Arcgis module
At 10.2.2
import arcpy
Exercise 1: Reading folder contents
• Download zip file from
http://web.mit.edu/dsheehan/
dataForPythonIAP2015.zip and unzip
• Using the glob module, print out:
– a list of all of the files
– a list of shapefiles
Model Builder
Exercise 2: ModelBuilder
Using ModelBuilder:
• Buffer interstateHighways.shp (500 meters)
– Units of data is meters
• Clip schools.shp with buffer
• Export model as ‘Python’
Catching exceptions
try:
<your code>
except:
print arcpy.GetMessages()
raise
Overwriting files
• from arcpy import env
• env.overwriteOutput = True
Exercise 3: Convert ModelBuilder
Code into a loop
• Using the code from ModelBuilder
• Iterate through a loop 5 times, buffering 500
meters, 1000, etc meters
• Intersect cambridgeSchools.shp with buffer
and make 5 new pairs of shapefiles
Writing to a text file
# Create a file (‘w’ means create a new file, ‘a’
appends to an existing file, will create it if it
doesn’t already exist)
f = open(“C:usersdsheehantest.txt”, ‘w’)
# Write to a file
f.write(“Contents of file” + “n”)
f.flush() # flushes buffer
f.close() # closes file
Exercise 4: File Manipulation
Create a folder called “temp_folder”:
• Make 5 text files in this folder called File1.txt,
File2.txt, etc.
• Write a string in each file

More Related Content

What's hot

Python ppt
Python pptPython ppt
Python ppt
Mohita Pandey
 
What is gis
What is gisWhat is gis
What is gis
Sumant Diwakar
 
Atmospheric correction albufera_web
Atmospheric correction albufera_webAtmospheric correction albufera_web
Atmospheric correction albufera_web
Gabriel Parodi
 
Three dimensional (3D) GIS
Three dimensional (3D) GISThree dimensional (3D) GIS
Three dimensional (3D) GIS
Wellington Gwavava
 
Modification and Climate Change Analysis of surrounding Environment using Rem...
Modification and Climate Change Analysis of surrounding Environment using Rem...Modification and Climate Change Analysis of surrounding Environment using Rem...
Modification and Climate Change Analysis of surrounding Environment using Rem...
iosrjce
 
Web mapping
Web mappingWeb mapping
Web mapping
Musnanda Satar
 
QGIS training class 3
QGIS training class 3QGIS training class 3
QGIS training class 3
Hiroaki Sengoku
 
Geographic information system
Geographic information systemGeographic information system
Geographic information system
Kamrul Islam Karim
 
1.python interpreter and interactive mode
1.python interpreter and interactive mode1.python interpreter and interactive mode
1.python interpreter and interactive mode
ManjuA8
 
GIS - lecture-1.ppt
GIS - lecture-1.pptGIS - lecture-1.ppt
GIS - lecture-1.ppt
sapna kinattinkara
 
Fuzzy In Remote Classification
Fuzzy In Remote ClassificationFuzzy In Remote Classification
Fuzzy In Remote Classification
University of Oradea
 
GIS in Health
GIS in HealthGIS in Health
GIS in Health
Ashwin Raj
 
introduction to GIS
introduction to GIS introduction to GIS
introduction to GIS
niazali15CRP92
 
Python cheat-sheet
Python cheat-sheetPython cheat-sheet
Python cheat-sheet
srinivasanr281952
 
QGIS Module 1
QGIS Module 1QGIS Module 1
QGIS Module 1
CAPSUCSF
 
Python
PythonPython
Python
Aashish Jain
 
GOOGLE EARTH INTRODUCTION
GOOGLE EARTH INTRODUCTIONGOOGLE EARTH INTRODUCTION
GOOGLE EARTH INTRODUCTION
Akshat Singh
 
Hotspot Analysis - OGRS2016
Hotspot Analysis - OGRS2016Hotspot Analysis - OGRS2016
Hotspot Analysis - OGRS2016
Daniele Oxoli
 
Symbology and Classifying data in ARC GIS
Symbology and Classifying data in ARC GISSymbology and Classifying data in ARC GIS
Symbology and Classifying data in ARC GIS
KU Leuven
 

What's hot (20)

Python ppt
Python pptPython ppt
Python ppt
 
What is gis
What is gisWhat is gis
What is gis
 
Atmospheric correction albufera_web
Atmospheric correction albufera_webAtmospheric correction albufera_web
Atmospheric correction albufera_web
 
Three dimensional (3D) GIS
Three dimensional (3D) GISThree dimensional (3D) GIS
Three dimensional (3D) GIS
 
Modification and Climate Change Analysis of surrounding Environment using Rem...
Modification and Climate Change Analysis of surrounding Environment using Rem...Modification and Climate Change Analysis of surrounding Environment using Rem...
Modification and Climate Change Analysis of surrounding Environment using Rem...
 
Web mapping
Web mappingWeb mapping
Web mapping
 
QGIS training class 3
QGIS training class 3QGIS training class 3
QGIS training class 3
 
Geographic information system
Geographic information systemGeographic information system
Geographic information system
 
1.python interpreter and interactive mode
1.python interpreter and interactive mode1.python interpreter and interactive mode
1.python interpreter and interactive mode
 
GIS - lecture-1.ppt
GIS - lecture-1.pptGIS - lecture-1.ppt
GIS - lecture-1.ppt
 
Fuzzy In Remote Classification
Fuzzy In Remote ClassificationFuzzy In Remote Classification
Fuzzy In Remote Classification
 
GIS in Health
GIS in HealthGIS in Health
GIS in Health
 
Gis개론
Gis개론Gis개론
Gis개론
 
introduction to GIS
introduction to GIS introduction to GIS
introduction to GIS
 
Python cheat-sheet
Python cheat-sheetPython cheat-sheet
Python cheat-sheet
 
QGIS Module 1
QGIS Module 1QGIS Module 1
QGIS Module 1
 
Python
PythonPython
Python
 
GOOGLE EARTH INTRODUCTION
GOOGLE EARTH INTRODUCTIONGOOGLE EARTH INTRODUCTION
GOOGLE EARTH INTRODUCTION
 
Hotspot Analysis - OGRS2016
Hotspot Analysis - OGRS2016Hotspot Analysis - OGRS2016
Hotspot Analysis - OGRS2016
 
Symbology and Classifying data in ARC GIS
Symbology and Classifying data in ARC GISSymbology and Classifying data in ARC GIS
Symbology and Classifying data in ARC GIS
 

Viewers also liked

Editing for ArcGIS 10 and 10.1
Editing for ArcGIS 10 and 10.1Editing for ArcGIS 10 and 10.1
Editing for ArcGIS 10 and 10.1
John Schaeffer
 
DUSPviz2012 InDesign
DUSPviz2012 InDesignDUSPviz2012 InDesign
DUSPviz2012 InDesign
DUSPviz
 
Intro to ArcGIS ModelBuilder
Intro to ArcGIS ModelBuilderIntro to ArcGIS ModelBuilder
Intro to ArcGIS ModelBuilder
DUSPviz
 
BK2015 Arcgis pro
BK2015 Arcgis proBK2015 Arcgis pro
BK2015 Arcgis pro
Geodata AS
 
Loading Parcels Into Smallworld GIS via FME
Loading Parcels Into Smallworld GIS via FMELoading Parcels Into Smallworld GIS via FME
Loading Parcels Into Smallworld GIS via FME
Safe Software
 
Avidgeo String Manipulation : Getting Started with Python and ArcGIS
Avidgeo String Manipulation : Getting Started with Python and ArcGISAvidgeo String Manipulation : Getting Started with Python and ArcGIS
Avidgeo String Manipulation : Getting Started with Python and ArcGIS
Guido Stein
 
ArcGIS Lesson 3
ArcGIS Lesson 3ArcGIS Lesson 3
ArcGIS Lesson 3
Joseph Farah
 
Python and ArcGIS 10.1
Python and ArcGIS 10.1Python and ArcGIS 10.1
ArcGIS Python Programming (3Nov11)
ArcGIS Python Programming (3Nov11)ArcGIS Python Programming (3Nov11)
ArcGIS Python Programming (3Nov11)
WV Assocation of Geospatial Professionals
 
Python Scripting for ArcGIS
Python Scripting for ArcGISPython Scripting for ArcGIS
Python Scripting for ArcGIS
siufu
 
Applications of Arc GIS
Applications of Arc GISApplications of Arc GIS
Applications of Arc GIS
ExtraPDFs
 

Viewers also liked (11)

Editing for ArcGIS 10 and 10.1
Editing for ArcGIS 10 and 10.1Editing for ArcGIS 10 and 10.1
Editing for ArcGIS 10 and 10.1
 
DUSPviz2012 InDesign
DUSPviz2012 InDesignDUSPviz2012 InDesign
DUSPviz2012 InDesign
 
Intro to ArcGIS ModelBuilder
Intro to ArcGIS ModelBuilderIntro to ArcGIS ModelBuilder
Intro to ArcGIS ModelBuilder
 
BK2015 Arcgis pro
BK2015 Arcgis proBK2015 Arcgis pro
BK2015 Arcgis pro
 
Loading Parcels Into Smallworld GIS via FME
Loading Parcels Into Smallworld GIS via FMELoading Parcels Into Smallworld GIS via FME
Loading Parcels Into Smallworld GIS via FME
 
Avidgeo String Manipulation : Getting Started with Python and ArcGIS
Avidgeo String Manipulation : Getting Started with Python and ArcGISAvidgeo String Manipulation : Getting Started with Python and ArcGIS
Avidgeo String Manipulation : Getting Started with Python and ArcGIS
 
ArcGIS Lesson 3
ArcGIS Lesson 3ArcGIS Lesson 3
ArcGIS Lesson 3
 
Python and ArcGIS 10.1
Python and ArcGIS 10.1Python and ArcGIS 10.1
Python and ArcGIS 10.1
 
ArcGIS Python Programming (3Nov11)
ArcGIS Python Programming (3Nov11)ArcGIS Python Programming (3Nov11)
ArcGIS Python Programming (3Nov11)
 
Python Scripting for ArcGIS
Python Scripting for ArcGISPython Scripting for ArcGIS
Python Scripting for ArcGIS
 
Applications of Arc GIS
Applications of Arc GISApplications of Arc GIS
Applications of Arc GIS
 

Similar to Python Programming for ArcGIS: Part I

MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides:  Let's build macOS CLI Utilities using SwiftMobileConf 2021 Slides:  Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
Diego Freniche Brito
 
Python Programming for ArcGIS: Part II
Python Programming for ArcGIS: Part IIPython Programming for ArcGIS: Part II
Python Programming for ArcGIS: Part II
DUSPviz
 
Python and Pytorch tutorial and walkthrough
Python and Pytorch tutorial and walkthroughPython and Pytorch tutorial and walkthrough
Python and Pytorch tutorial and walkthrough
gabriellekuruvilla
 
Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)
Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)
Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)
Ahmed El-Arabawy
 
introduction to c #
introduction to c #introduction to c #
introduction to c #
Sireesh K
 
Csharp introduction
Csharp introductionCsharp introduction
Csharp introduction
Sireesh K
 
EKON 25 Python4Delphi_mX4
EKON 25 Python4Delphi_mX4EKON 25 Python4Delphi_mX4
EKON 25 Python4Delphi_mX4
Max Kleiner
 
Intro to Python
Intro to PythonIntro to Python
Python Tutorial Part 2
Python Tutorial Part 2Python Tutorial Part 2
Python Tutorial Part 2
Haitham El-Ghareeb
 
Bioinformatics p1-perl-introduction v2013
Bioinformatics p1-perl-introduction v2013Bioinformatics p1-perl-introduction v2013
Bioinformatics p1-perl-introduction v2013
Prof. Wim Van Criekinge
 
Holy PowerShell, BATman! - dogfood edition
Holy PowerShell, BATman! - dogfood editionHoly PowerShell, BATman! - dogfood edition
Holy PowerShell, BATman! - dogfood edition
Dave Diehl
 
python presntation 2.pptx
python presntation 2.pptxpython presntation 2.pptx
python presntation 2.pptx
Arpittripathi45
 
Python training
Python trainingPython training
Python training
Kunalchauhan76
 
Files and streams
Files and streamsFiles and streams
Files and streams
Pranali Chaudhari
 
pythontraining-201jn026043638.pptx
pythontraining-201jn026043638.pptxpythontraining-201jn026043638.pptx
pythontraining-201jn026043638.pptx
RohitKumar639388
 
Deliver Python Apps with Docker
Deliver Python Apps with DockerDeliver Python Apps with Docker
Deliver Python Apps with Docker
Anton Egorov
 
Introduction to the intermediate Python - v1.1
Introduction to the intermediate Python - v1.1Introduction to the intermediate Python - v1.1
Introduction to the intermediate Python - v1.1
Andrei KUCHARAVY
 
Programming Language
Programming  LanguageProgramming  Language
Programming Language
Adeel Hamid
 
File handling.pptx
File handling.pptxFile handling.pptx
File handling.pptx
VishuSaini22
 
iOS Application Exploitation
iOS Application ExploitationiOS Application Exploitation
iOS Application Exploitation
Positive Hack Days
 

Similar to Python Programming for ArcGIS: Part I (20)

MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides:  Let's build macOS CLI Utilities using SwiftMobileConf 2021 Slides:  Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
 
Python Programming for ArcGIS: Part II
Python Programming for ArcGIS: Part IIPython Programming for ArcGIS: Part II
Python Programming for ArcGIS: Part II
 
Python and Pytorch tutorial and walkthrough
Python and Pytorch tutorial and walkthroughPython and Pytorch tutorial and walkthrough
Python and Pytorch tutorial and walkthrough
 
Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)
Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)
Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)
 
introduction to c #
introduction to c #introduction to c #
introduction to c #
 
Csharp introduction
Csharp introductionCsharp introduction
Csharp introduction
 
EKON 25 Python4Delphi_mX4
EKON 25 Python4Delphi_mX4EKON 25 Python4Delphi_mX4
EKON 25 Python4Delphi_mX4
 
Intro to Python
Intro to PythonIntro to Python
Intro to Python
 
Python Tutorial Part 2
Python Tutorial Part 2Python Tutorial Part 2
Python Tutorial Part 2
 
Bioinformatics p1-perl-introduction v2013
Bioinformatics p1-perl-introduction v2013Bioinformatics p1-perl-introduction v2013
Bioinformatics p1-perl-introduction v2013
 
Holy PowerShell, BATman! - dogfood edition
Holy PowerShell, BATman! - dogfood editionHoly PowerShell, BATman! - dogfood edition
Holy PowerShell, BATman! - dogfood edition
 
python presntation 2.pptx
python presntation 2.pptxpython presntation 2.pptx
python presntation 2.pptx
 
Python training
Python trainingPython training
Python training
 
Files and streams
Files and streamsFiles and streams
Files and streams
 
pythontraining-201jn026043638.pptx
pythontraining-201jn026043638.pptxpythontraining-201jn026043638.pptx
pythontraining-201jn026043638.pptx
 
Deliver Python Apps with Docker
Deliver Python Apps with DockerDeliver Python Apps with Docker
Deliver Python Apps with Docker
 
Introduction to the intermediate Python - v1.1
Introduction to the intermediate Python - v1.1Introduction to the intermediate Python - v1.1
Introduction to the intermediate Python - v1.1
 
Programming Language
Programming  LanguageProgramming  Language
Programming Language
 
File handling.pptx
File handling.pptxFile handling.pptx
File handling.pptx
 
iOS Application Exploitation
iOS Application ExploitationiOS Application Exploitation
iOS Application Exploitation
 

More from DUSPviz

Intro to inkscape
Intro to inkscapeIntro to inkscape
Intro to inkscape
DUSPviz
 
Intro to Tableau Public
Intro to Tableau PublicIntro to Tableau Public
Intro to Tableau Public
DUSPviz
 
Mapping with Adobe CC
Mapping with Adobe CCMapping with Adobe CC
Mapping with Adobe CC
DUSPviz
 
Intro to Microsoft Access
Intro to Microsoft AccessIntro to Microsoft Access
Intro to Microsoft Access
DUSPviz
 
Intro to Adobe Photoshop
Intro to Adobe PhotoshopIntro to Adobe Photoshop
Intro to Adobe Photoshop
DUSPviz
 
Intro to Adobe Illustrator
Intro to Adobe IllustratorIntro to Adobe Illustrator
Intro to Adobe Illustrator
DUSPviz
 
Intro to AutoCAD
Intro to AutoCADIntro to AutoCAD
Intro to AutoCAD
DUSPviz
 
Google Fusion Tables
Google Fusion TablesGoogle Fusion Tables
Google Fusion Tables
DUSPviz
 
Habits of Effective Designers - Handout
Habits of Effective Designers - HandoutHabits of Effective Designers - Handout
Habits of Effective Designers - Handout
DUSPviz
 
Habits of Effective Designers
Habits of Effective DesignersHabits of Effective Designers
Habits of Effective Designers
DUSPviz
 
Intro to Adobe Illustrator
Intro to Adobe IllustratorIntro to Adobe Illustrator
Intro to Adobe Illustrator
DUSPviz
 
Intro to Adobe Photoshop
Intro to Adobe PhotoshopIntro to Adobe Photoshop
Intro to Adobe Photoshop
DUSPviz
 
Introduction to InDesign
Introduction to InDesignIntroduction to InDesign
Introduction to InDesign
DUSPviz
 
The DUSP GIS Data Drive
The DUSP GIS Data DriveThe DUSP GIS Data Drive
The DUSP GIS Data Drive
DUSPviz
 
GIS Orientation 2015
GIS Orientation 2015GIS Orientation 2015
GIS Orientation 2015
DUSPviz
 
Setting up your DUSP ArcGIS Environment
Setting up your DUSP ArcGIS EnvironmentSetting up your DUSP ArcGIS Environment
Setting up your DUSP ArcGIS Environment
DUSPviz
 
AFS Connection Instructions
AFS Connection InstructionsAFS Connection Instructions
AFS Connection Instructions
DUSPviz
 
DUSPviz Rhino 3D Workshop
DUSPviz Rhino 3D WorkshopDUSPviz Rhino 3D Workshop
DUSPviz Rhino 3D Workshop
DUSPviz
 
Drawing for planners_ivanov
Drawing for planners_ivanovDrawing for planners_ivanov
Drawing for planners_ivanov
DUSPviz
 
Review presentation for Orientation 2014
Review presentation for Orientation 2014Review presentation for Orientation 2014
Review presentation for Orientation 2014
DUSPviz
 

More from DUSPviz (20)

Intro to inkscape
Intro to inkscapeIntro to inkscape
Intro to inkscape
 
Intro to Tableau Public
Intro to Tableau PublicIntro to Tableau Public
Intro to Tableau Public
 
Mapping with Adobe CC
Mapping with Adobe CCMapping with Adobe CC
Mapping with Adobe CC
 
Intro to Microsoft Access
Intro to Microsoft AccessIntro to Microsoft Access
Intro to Microsoft Access
 
Intro to Adobe Photoshop
Intro to Adobe PhotoshopIntro to Adobe Photoshop
Intro to Adobe Photoshop
 
Intro to Adobe Illustrator
Intro to Adobe IllustratorIntro to Adobe Illustrator
Intro to Adobe Illustrator
 
Intro to AutoCAD
Intro to AutoCADIntro to AutoCAD
Intro to AutoCAD
 
Google Fusion Tables
Google Fusion TablesGoogle Fusion Tables
Google Fusion Tables
 
Habits of Effective Designers - Handout
Habits of Effective Designers - HandoutHabits of Effective Designers - Handout
Habits of Effective Designers - Handout
 
Habits of Effective Designers
Habits of Effective DesignersHabits of Effective Designers
Habits of Effective Designers
 
Intro to Adobe Illustrator
Intro to Adobe IllustratorIntro to Adobe Illustrator
Intro to Adobe Illustrator
 
Intro to Adobe Photoshop
Intro to Adobe PhotoshopIntro to Adobe Photoshop
Intro to Adobe Photoshop
 
Introduction to InDesign
Introduction to InDesignIntroduction to InDesign
Introduction to InDesign
 
The DUSP GIS Data Drive
The DUSP GIS Data DriveThe DUSP GIS Data Drive
The DUSP GIS Data Drive
 
GIS Orientation 2015
GIS Orientation 2015GIS Orientation 2015
GIS Orientation 2015
 
Setting up your DUSP ArcGIS Environment
Setting up your DUSP ArcGIS EnvironmentSetting up your DUSP ArcGIS Environment
Setting up your DUSP ArcGIS Environment
 
AFS Connection Instructions
AFS Connection InstructionsAFS Connection Instructions
AFS Connection Instructions
 
DUSPviz Rhino 3D Workshop
DUSPviz Rhino 3D WorkshopDUSPviz Rhino 3D Workshop
DUSPviz Rhino 3D Workshop
 
Drawing for planners_ivanov
Drawing for planners_ivanovDrawing for planners_ivanov
Drawing for planners_ivanov
 
Review presentation for Orientation 2014
Review presentation for Orientation 2014Review presentation for Orientation 2014
Review presentation for Orientation 2014
 

Recently uploaded

🚂🚘 Premium Girls Call Nashik 🛵🚡000XX00000 💃 Choose Best And Top Girl Service...
🚂🚘 Premium Girls Call Nashik  🛵🚡000XX00000 💃 Choose Best And Top Girl Service...🚂🚘 Premium Girls Call Nashik  🛵🚡000XX00000 💃 Choose Best And Top Girl Service...
🚂🚘 Premium Girls Call Nashik 🛵🚡000XX00000 💃 Choose Best And Top Girl Service...
kuldeepsharmaks8120
 
the potential of the development of the Ford–Fulkerson algorithm to solve the...
the potential of the development of the Ford–Fulkerson algorithm to solve the...the potential of the development of the Ford–Fulkerson algorithm to solve the...
the potential of the development of the Ford–Fulkerson algorithm to solve the...
huseindihon
 
all about the data science process, covering the steps present in almost ever...
all about the data science process, covering the steps present in almost ever...all about the data science process, covering the steps present in almost ever...
all about the data science process, covering the steps present in almost ever...
palaniappancse
 
the unexpected potential of Dijkstra's Algorithm
the unexpected potential of Dijkstra's Algorithmthe unexpected potential of Dijkstra's Algorithm
the unexpected potential of Dijkstra's Algorithm
huseindihon
 
Female Service Girls Call Navi Mumbai 9930245274 Provide Best And Top Girl Se...
Female Service Girls Call Navi Mumbai 9930245274 Provide Best And Top Girl Se...Female Service Girls Call Navi Mumbai 9930245274 Provide Best And Top Girl Se...
Female Service Girls Call Navi Mumbai 9930245274 Provide Best And Top Girl Se...
dizzycaye
 
DU degree offer diploma Transcript
DU degree offer diploma TranscriptDU degree offer diploma Transcript
DU degree offer diploma Transcript
uapta
 
transgenders community data in india by govt
transgenders community data in india by govttransgenders community data in india by govt
transgenders community data in india by govt
palanisamyiiiier
 
BDSM Girls Call Delhi 🎈🔥9711199171 🔥💋🎈 Provide Best And Top Girl Service And ...
BDSM Girls Call Delhi 🎈🔥9711199171 🔥💋🎈 Provide Best And Top Girl Service And ...BDSM Girls Call Delhi 🎈🔥9711199171 🔥💋🎈 Provide Best And Top Girl Service And ...
BDSM Girls Call Delhi 🎈🔥9711199171 🔥💋🎈 Provide Best And Top Girl Service And ...
fatima shekh$A17
 
Potential Uses of the Floyd-Warshall Algorithm as appropriate
Potential Uses of the Floyd-Warshall Algorithm as appropriatePotential Uses of the Floyd-Warshall Algorithm as appropriate
Potential Uses of the Floyd-Warshall Algorithm as appropriate
huseindihon
 
Nipissing University degree offer Nipissing diploma Transcript
Nipissing University degree offer Nipissing diploma TranscriptNipissing University degree offer Nipissing diploma Transcript
Nipissing University degree offer Nipissing diploma Transcript
zyqedad
 
Best Girls Call Navi Mumbai 9930245274 Provide Best And Top Girl Service And ...
Best Girls Call Navi Mumbai 9930245274 Provide Best And Top Girl Service And ...Best Girls Call Navi Mumbai 9930245274 Provide Best And Top Girl Service And ...
Best Girls Call Navi Mumbai 9930245274 Provide Best And Top Girl Service And ...
sharonblush
 
Female Girls Call Mumbai 9920725232 Unlimited Short Providing Girls Service A...
Female Girls Call Mumbai 9920725232 Unlimited Short Providing Girls Service A...Female Girls Call Mumbai 9920725232 Unlimited Short Providing Girls Service A...
Female Girls Call Mumbai 9920725232 Unlimited Short Providing Girls Service A...
45unexpected
 
🚂🚘 Premium Girls Call Bangalore 🛵🚡000XX00000 💃 Choose Best And Top Girl Serv...
🚂🚘 Premium Girls Call Bangalore  🛵🚡000XX00000 💃 Choose Best And Top Girl Serv...🚂🚘 Premium Girls Call Bangalore  🛵🚡000XX00000 💃 Choose Best And Top Girl Serv...
🚂🚘 Premium Girls Call Bangalore 🛵🚡000XX00000 💃 Choose Best And Top Girl Serv...
bhupeshkumar0889
 
VIP Kanpur Girls Call Kanpur 0X0000000X Doorstep High-Profile Girl Service Ca...
VIP Kanpur Girls Call Kanpur 0X0000000X Doorstep High-Profile Girl Service Ca...VIP Kanpur Girls Call Kanpur 0X0000000X Doorstep High-Profile Girl Service Ca...
VIP Kanpur Girls Call Kanpur 0X0000000X Doorstep High-Profile Girl Service Ca...
satpalsheravatmumbai
 
Welcome back to Instagram. Sign in to check out what your
Welcome back to Instagram. Sign in to check out what yourWelcome back to Instagram. Sign in to check out what your
Welcome back to Instagram. Sign in to check out what your
Virni Arrora
 
Celebrity Girls Call Noida 9873940964 Unlimited Short Providing Girls Service...
Celebrity Girls Call Noida 9873940964 Unlimited Short Providing Girls Service...Celebrity Girls Call Noida 9873940964 Unlimited Short Providing Girls Service...
Celebrity Girls Call Noida 9873940964 Unlimited Short Providing Girls Service...
ginni singh$A17
 
Fine-Tuning of Small/Medium LLMs for Business QA on Structured Data
Fine-Tuning of Small/Medium LLMs for Business QA on Structured DataFine-Tuning of Small/Medium LLMs for Business QA on Structured Data
Fine-Tuning of Small/Medium LLMs for Business QA on Structured Data
kevig
 
CHAPTER-1-Introduction-to-Marketing.pptx
CHAPTER-1-Introduction-to-Marketing.pptxCHAPTER-1-Introduction-to-Marketing.pptx
CHAPTER-1-Introduction-to-Marketing.pptx
girewiy968
 
DataScienceConcept_Kanchana_Weerasinghe.pptx
DataScienceConcept_Kanchana_Weerasinghe.pptxDataScienceConcept_Kanchana_Weerasinghe.pptx
DataScienceConcept_Kanchana_Weerasinghe.pptx
Kanchana Weerasinghe
 
Oracle Database Desupported Features on 23ai (Part A)
Oracle Database Desupported Features on 23ai (Part A)Oracle Database Desupported Features on 23ai (Part A)
Oracle Database Desupported Features on 23ai (Part A)
Alireza Kamrani
 

Recently uploaded (20)

🚂🚘 Premium Girls Call Nashik 🛵🚡000XX00000 💃 Choose Best And Top Girl Service...
🚂🚘 Premium Girls Call Nashik  🛵🚡000XX00000 💃 Choose Best And Top Girl Service...🚂🚘 Premium Girls Call Nashik  🛵🚡000XX00000 💃 Choose Best And Top Girl Service...
🚂🚘 Premium Girls Call Nashik 🛵🚡000XX00000 💃 Choose Best And Top Girl Service...
 
the potential of the development of the Ford–Fulkerson algorithm to solve the...
the potential of the development of the Ford–Fulkerson algorithm to solve the...the potential of the development of the Ford–Fulkerson algorithm to solve the...
the potential of the development of the Ford–Fulkerson algorithm to solve the...
 
all about the data science process, covering the steps present in almost ever...
all about the data science process, covering the steps present in almost ever...all about the data science process, covering the steps present in almost ever...
all about the data science process, covering the steps present in almost ever...
 
the unexpected potential of Dijkstra's Algorithm
the unexpected potential of Dijkstra's Algorithmthe unexpected potential of Dijkstra's Algorithm
the unexpected potential of Dijkstra's Algorithm
 
Female Service Girls Call Navi Mumbai 9930245274 Provide Best And Top Girl Se...
Female Service Girls Call Navi Mumbai 9930245274 Provide Best And Top Girl Se...Female Service Girls Call Navi Mumbai 9930245274 Provide Best And Top Girl Se...
Female Service Girls Call Navi Mumbai 9930245274 Provide Best And Top Girl Se...
 
DU degree offer diploma Transcript
DU degree offer diploma TranscriptDU degree offer diploma Transcript
DU degree offer diploma Transcript
 
transgenders community data in india by govt
transgenders community data in india by govttransgenders community data in india by govt
transgenders community data in india by govt
 
BDSM Girls Call Delhi 🎈🔥9711199171 🔥💋🎈 Provide Best And Top Girl Service And ...
BDSM Girls Call Delhi 🎈🔥9711199171 🔥💋🎈 Provide Best And Top Girl Service And ...BDSM Girls Call Delhi 🎈🔥9711199171 🔥💋🎈 Provide Best And Top Girl Service And ...
BDSM Girls Call Delhi 🎈🔥9711199171 🔥💋🎈 Provide Best And Top Girl Service And ...
 
Potential Uses of the Floyd-Warshall Algorithm as appropriate
Potential Uses of the Floyd-Warshall Algorithm as appropriatePotential Uses of the Floyd-Warshall Algorithm as appropriate
Potential Uses of the Floyd-Warshall Algorithm as appropriate
 
Nipissing University degree offer Nipissing diploma Transcript
Nipissing University degree offer Nipissing diploma TranscriptNipissing University degree offer Nipissing diploma Transcript
Nipissing University degree offer Nipissing diploma Transcript
 
Best Girls Call Navi Mumbai 9930245274 Provide Best And Top Girl Service And ...
Best Girls Call Navi Mumbai 9930245274 Provide Best And Top Girl Service And ...Best Girls Call Navi Mumbai 9930245274 Provide Best And Top Girl Service And ...
Best Girls Call Navi Mumbai 9930245274 Provide Best And Top Girl Service And ...
 
Female Girls Call Mumbai 9920725232 Unlimited Short Providing Girls Service A...
Female Girls Call Mumbai 9920725232 Unlimited Short Providing Girls Service A...Female Girls Call Mumbai 9920725232 Unlimited Short Providing Girls Service A...
Female Girls Call Mumbai 9920725232 Unlimited Short Providing Girls Service A...
 
🚂🚘 Premium Girls Call Bangalore 🛵🚡000XX00000 💃 Choose Best And Top Girl Serv...
🚂🚘 Premium Girls Call Bangalore  🛵🚡000XX00000 💃 Choose Best And Top Girl Serv...🚂🚘 Premium Girls Call Bangalore  🛵🚡000XX00000 💃 Choose Best And Top Girl Serv...
🚂🚘 Premium Girls Call Bangalore 🛵🚡000XX00000 💃 Choose Best And Top Girl Serv...
 
VIP Kanpur Girls Call Kanpur 0X0000000X Doorstep High-Profile Girl Service Ca...
VIP Kanpur Girls Call Kanpur 0X0000000X Doorstep High-Profile Girl Service Ca...VIP Kanpur Girls Call Kanpur 0X0000000X Doorstep High-Profile Girl Service Ca...
VIP Kanpur Girls Call Kanpur 0X0000000X Doorstep High-Profile Girl Service Ca...
 
Welcome back to Instagram. Sign in to check out what your
Welcome back to Instagram. Sign in to check out what yourWelcome back to Instagram. Sign in to check out what your
Welcome back to Instagram. Sign in to check out what your
 
Celebrity Girls Call Noida 9873940964 Unlimited Short Providing Girls Service...
Celebrity Girls Call Noida 9873940964 Unlimited Short Providing Girls Service...Celebrity Girls Call Noida 9873940964 Unlimited Short Providing Girls Service...
Celebrity Girls Call Noida 9873940964 Unlimited Short Providing Girls Service...
 
Fine-Tuning of Small/Medium LLMs for Business QA on Structured Data
Fine-Tuning of Small/Medium LLMs for Business QA on Structured DataFine-Tuning of Small/Medium LLMs for Business QA on Structured Data
Fine-Tuning of Small/Medium LLMs for Business QA on Structured Data
 
CHAPTER-1-Introduction-to-Marketing.pptx
CHAPTER-1-Introduction-to-Marketing.pptxCHAPTER-1-Introduction-to-Marketing.pptx
CHAPTER-1-Introduction-to-Marketing.pptx
 
DataScienceConcept_Kanchana_Weerasinghe.pptx
DataScienceConcept_Kanchana_Weerasinghe.pptxDataScienceConcept_Kanchana_Weerasinghe.pptx
DataScienceConcept_Kanchana_Weerasinghe.pptx
 
Oracle Database Desupported Features on 23ai (Part A)
Oracle Database Desupported Features on 23ai (Part A)Oracle Database Desupported Features on 23ai (Part A)
Oracle Database Desupported Features on 23ai (Part A)
 

Python Programming for ArcGIS: Part I

  • 1. Python Programming for Arcgis 1 Daniel Sheehan dsheehan@mit.edu, gishelp@mit.edu 9:30AM-12:30PM January 14, 2015 This class was originally developed by David Quinn and taught by David and Daniel in IAP 2010 and 2011.
  • 2. Arcgis 10.2.2 and Python • You need a normal install of Arcgis 10.2.2. This install includes Python 2.7 and includes the IDLE interface, which we will use. • Other installs of Pythons will not have the ‘arcpy’ module and will not work.
  • 3. Download data for workshop • http://web.mit.edu/dsheehan/www/ dataForPythonIAP2015.zip • http://web.mit.edu/dsheehan/www/ PythonProgrammingforArcgis.pdf
  • 4. Goals for the workshop • Learning enough Python to – Access Arcgis commands through Python – Access individual records from attribute table – Acccess individual geometries for use in geoprocessing • Develop the ability to record and document your geoprocessing
  • 5. Outline • Introduction to Python and Arcgis • Programming Principles and Modules • Model Builder • Reading and Writing data
  • 6. Schedule Working with Python and geoprocessing tools today, working with attribute tables and individual geometries tomorrow
  • 7. Python Python is a language that lets you work more quickly and integrate your systems more effectively 1 Documentation at http://docs.python.org and look for Python 2.7 (used in Arcgis 10.2.2) 1 http://www.python.org
  • 8. Python + Arcgis • Python can interact with Arcgis and be used to repeat many types of analyses. • Why Python? • It is an integral part of Arcgis • Easy to read syntax • Large user community • Useful for scripts to control other programs
  • 9. How does Python work with Arcgis • At Arcgis 10.2.2 – Fully integrated into Arcgis – Largely Geoprocessing functions • Automated mapping is not possible, yet
  • 10. Logistics • We will be using the IDLE programming environment • Windows: START -> Programs -> Arcgis -> Python 2.7 -> IDLE • We are using Arcgis 10.2.2 on lab computers and assume that you are using 10.2.2 if you are using your own laptop
  • 11. Learn by doing • Try every line of code in the slides • Create a new file for each different slide to create a record for yourself (optional) • Use the Python Help and Arcgis Help and ask questions
  • 12. Programming concepts • Variables • Control Structures (IF statements and FOR loops) • Functions Python is case sensitive and reads whitespace for defining programming blocks – use space bar, not tabs.
  • 13. The Print Function and Strings # this is a comment print “hello world” “”” Alternative Commenting Style “””
  • 14. The Print function and Strings # this is a comment print (“hello world”) # this is a variable that contains a string name = “Daniel” print (name)
  • 15. Integers and Floats # declare variables int_sample = 10 float_sample = 10.0 # printing variables # cast non-string variable as a string using str() print “The value of this integer is: “ + str(int_sample) print “The value of this float is: “ + str(float_sample)
  • 16. if statement x = 2 # Condition checks if statement is true if x == 1: print ‘x is 1!’
  • 17. if / elif / else statement x = 2 # Condition checks if statement is true if x == 1: print ‘x is 1!’ elif x == 2: print ‘x is 2!’ else: print ‘x is not known’
  • 18. for loop for i in range(3): # convention is to use 4 spaces to indent # python reads whitespace at the beginning of a line print i Python, like most programming languages, uses arrrays that are zero based.
  • 19. while loop # define j j = 1 # ‘while’ less than some condition while j < 3: print j # increment j j += 1
  • 20. Three ways to access a folder # Accessing a folder path = “C:folderName” path = “C:/folderName/” path = r”C:folderName”
  • 21. Importing Modules Use the import command: # count the number of files in a directory import os path = “c:...” files = os.listdir(path) print len(files) A module is a list of Python programs that can be accessed. Commonly used modules are os, sys, glob.
  • 22. glob import glob # use the glob module path = “C:UsersdsheehandesktopPython2015current ” # loop through all files ListOfFiles = glob.glob(path + “*”) for i in ListOfFiles: print i Try replacing ‘*’ with ‘*.shp’
  • 23. Importing the Arcgis module At 10.2.2 import arcpy
  • 24. Exercise 1: Reading folder contents • Download zip file from http://web.mit.edu/dsheehan/ dataForPythonIAP2015.zip and unzip • Using the glob module, print out: – a list of all of the files – a list of shapefiles
  • 26. Exercise 2: ModelBuilder Using ModelBuilder: • Buffer interstateHighways.shp (500 meters) – Units of data is meters • Clip schools.shp with buffer • Export model as ‘Python’
  • 28. Overwriting files • from arcpy import env • env.overwriteOutput = True
  • 29. Exercise 3: Convert ModelBuilder Code into a loop • Using the code from ModelBuilder • Iterate through a loop 5 times, buffering 500 meters, 1000, etc meters • Intersect cambridgeSchools.shp with buffer and make 5 new pairs of shapefiles
  • 30. Writing to a text file # Create a file (‘w’ means create a new file, ‘a’ appends to an existing file, will create it if it doesn’t already exist) f = open(“C:usersdsheehantest.txt”, ‘w’) # Write to a file f.write(“Contents of file” + “n”) f.flush() # flushes buffer f.close() # closes file
  • 31. Exercise 4: File Manipulation Create a folder called “temp_folder”: • Make 5 text files in this folder called File1.txt, File2.txt, etc. • Write a string in each file