Python Coding Examples for Drive Time Analysis
-
Upload
wisconsin-land-information-association -
Category
Technology
-
view
1.948 -
download
5
description
Transcript of Python Coding Examples for Drive Time Analysis
![Page 1: Python Coding Examples for Drive Time Analysis](https://reader033.fdocuments.in/reader033/viewer/2022061201/5478b9a1b4af9f8a5a8b48a3/html5/thumbnails/1.jpg)
Python & Drive Time Analyses
Python 2.6ArcCatalog 9.3.1ArcMap 9.3.1
Project technologiesProgramming language:
Software products:
Janice PoehlmanDivision of Forestry, Dept. Natural [email protected]
![Page 2: Python Coding Examples for Drive Time Analysis](https://reader033.fdocuments.in/reader033/viewer/2022061201/5478b9a1b4af9f8a5a8b48a3/html5/thumbnails/2.jpg)
Use python scripts to summarize the total number of people who are
within drive times of a location.
30 Minute60 Minute90 Minute
120 Minute
Drive Time Service AreaNetwork Analyst}
![Page 3: Python Coding Examples for Drive Time Analysis](https://reader033.fdocuments.in/reader033/viewer/2022061201/5478b9a1b4af9f8a5a8b48a3/html5/thumbnails/3.jpg)
Data
WI, MN, MI, IL, IA
• Census 2000
Block Groups
• TIGER 2000 Road
• PLSS Township
![Page 4: Python Coding Examples for Drive Time Analysis](https://reader033.fdocuments.in/reader033/viewer/2022061201/5478b9a1b4af9f8a5a8b48a3/html5/thumbnails/4.jpg)
![Page 5: Python Coding Examples for Drive Time Analysis](https://reader033.fdocuments.in/reader033/viewer/2022061201/5478b9a1b4af9f8a5a8b48a3/html5/thumbnails/5.jpg)
![Page 6: Python Coding Examples for Drive Time Analysis](https://reader033.fdocuments.in/reader033/viewer/2022061201/5478b9a1b4af9f8a5a8b48a3/html5/thumbnails/6.jpg)
![Page 7: Python Coding Examples for Drive Time Analysis](https://reader033.fdocuments.in/reader033/viewer/2022061201/5478b9a1b4af9f8a5a8b48a3/html5/thumbnails/7.jpg)
![Page 8: Python Coding Examples for Drive Time Analysis](https://reader033.fdocuments.in/reader033/viewer/2022061201/5478b9a1b4af9f8a5a8b48a3/html5/thumbnails/8.jpg)
![Page 9: Python Coding Examples for Drive Time Analysis](https://reader033.fdocuments.in/reader033/viewer/2022061201/5478b9a1b4af9f8a5a8b48a3/html5/thumbnails/9.jpg)
![Page 10: Python Coding Examples for Drive Time Analysis](https://reader033.fdocuments.in/reader033/viewer/2022061201/5478b9a1b4af9f8a5a8b48a3/html5/thumbnails/10.jpg)
![Page 11: Python Coding Examples for Drive Time Analysis](https://reader033.fdocuments.in/reader033/viewer/2022061201/5478b9a1b4af9f8a5a8b48a3/html5/thumbnails/11.jpg)
![Page 12: Python Coding Examples for Drive Time Analysis](https://reader033.fdocuments.in/reader033/viewer/2022061201/5478b9a1b4af9f8a5a8b48a3/html5/thumbnails/12.jpg)
![Page 13: Python Coding Examples for Drive Time Analysis](https://reader033.fdocuments.in/reader033/viewer/2022061201/5478b9a1b4af9f8a5a8b48a3/html5/thumbnails/13.jpg)
![Page 14: Python Coding Examples for Drive Time Analysis](https://reader033.fdocuments.in/reader033/viewer/2022061201/5478b9a1b4af9f8a5a8b48a3/html5/thumbnails/14.jpg)
![Page 15: Python Coding Examples for Drive Time Analysis](https://reader033.fdocuments.in/reader033/viewer/2022061201/5478b9a1b4af9f8a5a8b48a3/html5/thumbnails/15.jpg)
#---------------------------------------------------------------------#Author: JP ##Last Update: December, 2010##Purpose: #Use cursors to select individual records (rows) in feature class. The#individual record is saved to an individual feature class and used to#clip census block groups. A town-range field is added and calculated#for each census block group feature class. The block group individual#files are merged into a single feature class, which can be summarized#by DTR for total population for each drive time service area.#-----------------------------------------------------------------------
![Page 16: Python Coding Examples for Drive Time Analysis](https://reader033.fdocuments.in/reader033/viewer/2022061201/5478b9a1b4af9f8a5a8b48a3/html5/thumbnails/16.jpg)
What is a cursor and how does it work.
![Page 17: Python Coding Examples for Drive Time Analysis](https://reader033.fdocuments.in/reader033/viewer/2022061201/5478b9a1b4af9f8a5a8b48a3/html5/thumbnails/17.jpg)
What is a cursor and how does it work.
![Page 18: Python Coding Examples for Drive Time Analysis](https://reader033.fdocuments.in/reader033/viewer/2022061201/5478b9a1b4af9f8a5a8b48a3/html5/thumbnails/18.jpg)
What is a cursor and how does it work.
![Page 19: Python Coding Examples for Drive Time Analysis](https://reader033.fdocuments.in/reader033/viewer/2022061201/5478b9a1b4af9f8a5a8b48a3/html5/thumbnails/19.jpg)
What is a cursor and how does it work.
![Page 20: Python Coding Examples for Drive Time Analysis](https://reader033.fdocuments.in/reader033/viewer/2022061201/5478b9a1b4af9f8a5a8b48a3/html5/thumbnails/20.jpg)
What is a cursor and how does it work.
![Page 21: Python Coding Examples for Drive Time Analysis](https://reader033.fdocuments.in/reader033/viewer/2022061201/5478b9a1b4af9f8a5a8b48a3/html5/thumbnails/21.jpg)
1.The cursor selects an individual record in a feature class and uses the python
tool to create a new feature class with one feature. (data export selected set):
gp.SearchCursor
![Page 22: Python Coding Examples for Drive Time Analysis](https://reader033.fdocuments.in/reader033/viewer/2022061201/5478b9a1b4af9f8a5a8b48a3/html5/thumbnails/22.jpg)
What the python script does inside the cursor with one record:
2. Creates a new feature class from the record
gp.Select_Analysis
3. Clips block groups by the new feature class
gp.Clip_Analysis
4. Calculates a total population for the service area
gp.Calculate_Field 40417
![Page 23: Python Coding Examples for Drive Time Analysis](https://reader033.fdocuments.in/reader033/viewer/2022061201/5478b9a1b4af9f8a5a8b48a3/html5/thumbnails/23.jpg)
#import modulesimport arcgisscripting, sys, os, time
#create the geoproccessor object and set file overwritegp = arcgisscripting.create()gp.overwriteoutput = 1
#set workspace variables and add toolboxesgp.workspace = "D:\drivetime\RoadsTigerResultsDT120Min_processing4.gdb”gp.addtoolbox("C:/Program Files/ArcGIS/ArcToolBox/Toolboxes/Data
Management Tools.tbx")gp.addtoolbox("C:/Program Files/ArcGIS/ArcToolBox/Toolboxes/Analysis
Tools.tbx")servicearea = "DriveTime120Minutes_SEW_NN”
log = open('D:/drivetime/logprocessing.log', 'a’)log.write('\n\nFile is ' + servicearea)timestamp = time.strftime('%I:%M:%S %p', time.localtime())log.write('\nStarting time is ' + timestamp)
![Page 24: Python Coding Examples for Drive Time Analysis](https://reader033.fdocuments.in/reader033/viewer/2022061201/5478b9a1b4af9f8a5a8b48a3/html5/thumbnails/24.jpg)
What the python script does inside the cursor with one record:
2. Creates a new feature class from the record
gp.Select_Analysis
3. Clips block groups by the new feature class
gp.Clip_Analysis
4. Calculates a total population for the service area
gp.Calculate_Field 40417
![Page 25: Python Coding Examples for Drive Time Analysis](https://reader033.fdocuments.in/reader033/viewer/2022061201/5478b9a1b4af9f8a5a8b48a3/html5/thumbnails/25.jpg)
try:
rows = gp.SearchCursor(servicearea)
row = rows.Next()
while row <> None:
ShapeName = str(row.DTR)
gp.Select_analysis(servicearea, "xxsel" +ShapeName, '"DTR"=' +ShapeName)
gp.clip_analysis("pop2000", "xxsel"+ShapeName, "xxclipSEWNN"+ShapeName, "") gp.calculatefield_management("xxclipSEWNN"+ShapeName, "DTR", row.DTR)
gp.delete_management ("xxsel" +ShapeName)
row = rows.next()
del row, rows
except:
if not gp.getmessages() == "”:
gp.addmessage(gp.getmessages(2))
if 'row' in dir():
del row
if 'rows' in dir():
del rows
![Page 26: Python Coding Examples for Drive Time Analysis](https://reader033.fdocuments.in/reader033/viewer/2022061201/5478b9a1b4af9f8a5a8b48a3/html5/thumbnails/26.jpg)
After the cursor is used for geoprocessing every record, the individual feature classes containing block groups for each service area are merged together using a value table. gp.merge_management
vTab = gp.createobject("ValueTable”)fcList = gp.listfeatureclasses("xxclipSEWNN*”)fc = fcList.Next()while fc: fcpath = gp.workspace + "\\" + fc vTab.Addrow(fcpath) fc = fcList.Next()gp.merge_management(vTab, "AMergedDriveTime120MinutesSEWNN", "”)print "Completed merged file for features of %s" %(servicearea)timestamp = time.strftime('%I:%M:%S %p', time.localtime())log.write('\nFinishing time is ' + timestamp)print"Done.”del vTabdel fcdel fcpathdel serviceareadel timestamplog.close()
![Page 27: Python Coding Examples for Drive Time Analysis](https://reader033.fdocuments.in/reader033/viewer/2022061201/5478b9a1b4af9f8a5a8b48a3/html5/thumbnails/27.jpg)
![Page 28: Python Coding Examples for Drive Time Analysis](https://reader033.fdocuments.in/reader033/viewer/2022061201/5478b9a1b4af9f8a5a8b48a3/html5/thumbnails/28.jpg)
![Page 29: Python Coding Examples for Drive Time Analysis](https://reader033.fdocuments.in/reader033/viewer/2022061201/5478b9a1b4af9f8a5a8b48a3/html5/thumbnails/29.jpg)
A supply and demand analysis oflocation to people.
•Using hunting or fishing licensing information to determine if quality or quantity of lands support types of recreation.•Using the density of people to determine where to build facilities or infrastructure.
Voila!
![Page 30: Python Coding Examples for Drive Time Analysis](https://reader033.fdocuments.in/reader033/viewer/2022061201/5478b9a1b4af9f8a5a8b48a3/html5/thumbnails/30.jpg)
Thank you for your attention.