SlideShare a Scribd company logo
Python &  Drive Time Analyses Python 2.6 ArcCatalog 9.3.1 ArcMap 9.3.1 Project technologies Programming language: Software products: Janice Poehlman Division of Forestry, Dept. Natural Resources [email_address]
Use python scripts to summarize the total number of people who are within drive times of a location. 30 Minute 60 Minute 90 Minute 120 Minute Drive Time Service Area Network Analyst }
Data WI, MN, MI, IL, IA Census 2000  Block Groups TIGER 2000 Road PLSS Township
 
 
 
 
 
 
 
 
 
 
 
#--------------------------------------------------------------------- #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. #-----------------------------------------------------------------------
What is a cursor and how does it work.
What is a cursor and how does it work.
What is a cursor and how does it work.
What is a cursor and how does it work.
What is a cursor and how does it work.
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
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
#import modules import arcgisscripting, sys, os, time #create the geoproccessor object and set file overwrite gp = arcgisscripting.create() gp.overwriteoutput = 1 #set workspace variables and add toolboxes gp.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)
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
try: rows = gp.SearchCursor(servicearea) row = rows.Next() while row <> None: ShapeName = str(row.DTR) gp.Select_analysis(servicearea, &quot;xxsel&quot; +ShapeName, '&quot;DTR&quot;=' +ShapeName) gp.clip_analysis(&quot;pop2000&quot;, &quot;xxsel&quot;+ShapeName, &quot;xxclipSEWNN&quot;+ShapeName, &quot;&quot;)  gp.calculatefield_management(&quot;xxclipSEWNN&quot;+ShapeName, &quot;DTR&quot;, row.DTR) gp.delete_management (&quot;xxsel&quot; +ShapeName)  row = rows.next() del row, rows except: if not gp.getmessages() == &quot;”: gp.addmessage(gp.getmessages(2)) if 'row' in dir(): del row if 'rows' in dir(): del rows
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(&quot;ValueTable”) fcList = gp.listfeatureclasses(&quot;xxclipSEWNN*”) fc = fcList.Next() while fc: fcpath = gp.workspace + &quot;\\&quot; + fc vTab.Addrow(fcpath) fc = fcList.Next() gp.merge_management(vTab, &quot;AMergedDriveTime120MinutesSEWNN&quot;, &quot;”) print &quot;Completed merged file for features of %s&quot; %(servicearea) timestamp = time.strftime('%I:%M:%S %p', time.localtime()) log.write('\nFinishing time is ' + timestamp) print&quot;Done.” del vTab del fc del fcpath del servicearea del timestamp log.close()
 
 
A  supply and demand  analysis of location 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 !
Thank you for your attention.

More Related Content

PDF
Illustrator_Sample
PDF
SAADATMAND_PYTHON
PPTX
La R Users Group Survey Of R Graphics
ODP
Use of django at jolt online v3
PDF
Flink meetup
PPTX
Advanced R Graphics
PDF
Graphite
PDF
Semantic search within Earth Observation products databases based on automati...
Illustrator_Sample
SAADATMAND_PYTHON
La R Users Group Survey Of R Graphics
Use of django at jolt online v3
Flink meetup
Advanced R Graphics
Graphite
Semantic search within Earth Observation products databases based on automati...

What's hot (19)

PPTX
GeoTuple a Framework for Web Based Geo-Analytics with R and PostGIS
PPT
150970116028 2140705
PDF
Apache flink: data streaming as a basis for all analytics by Kostas Tzoumas a...
PDF
PG Day'14 Russia, GIN — Stronger than ever in 9.4 and further, Александр Коро...
DOCX
R Data Visualization-Spatial data and Maps in R: Using R as a GIS
PPTX
From Trill to Quill: Pushing the Envelope of Functionality and Scale
PDF
確率的プログラミングライブラリEdward
PDF
Ragel talk
PDF
Using PyPy instead of Python for speed
PDF
Network Analysis with networkX : Real-World Example-2
PPTX
Building a real time Tweet map with Flink in six weeks
PPTX
Megadata With Python and Hadoop
PPT
Hight Work
PDF
Map Analytics in Starcraft II
 
PDF
Resource management
PPTX
Python en la Plataforma ArcGIS
PPT
Schema Design by Chad Tindel, Solution Architect, 10gen
PDF
Building maps for apps in the cloud - a Softlayer Use Case
GeoTuple a Framework for Web Based Geo-Analytics with R and PostGIS
150970116028 2140705
Apache flink: data streaming as a basis for all analytics by Kostas Tzoumas a...
PG Day'14 Russia, GIN — Stronger than ever in 9.4 and further, Александр Коро...
R Data Visualization-Spatial data and Maps in R: Using R as a GIS
From Trill to Quill: Pushing the Envelope of Functionality and Scale
確率的プログラミングライブラリEdward
Ragel talk
Using PyPy instead of Python for speed
Network Analysis with networkX : Real-World Example-2
Building a real time Tweet map with Flink in six weeks
Megadata With Python and Hadoop
Hight Work
Map Analytics in Starcraft II
 
Resource management
Python en la Plataforma ArcGIS
Schema Design by Chad Tindel, Solution Architect, 10gen
Building maps for apps in the cloud - a Softlayer Use Case
Ad

Similar to Python Coding Examples for Drive Time Analysis (20)

ODP
PDF
Profiling in Python
PDF
20181212 - PGconfASIA - LT - English
PPT
r,rstats,r language,r packages
PDF
Wprowadzenie do technologii Big Data / Intro to Big Data Ecosystem
PDF
Wprowadzenie do technologi Big Data i Apache Hadoop
PDF
pg_proctab: Accessing System Stats in PostgreSQL
PDF
pg_proctab: Accessing System Stats in PostgreSQL
PDF
Assessing Graph Solutions for Apache Spark
PDF
Nodejs性能分析优化和分布式设计探讨
PPTX
Relational Database Access with Python ‘sans’ ORM
ODP
PHP applications/environments monitoring: APM & Pinba
PDF
Beyond Breakpoints: A Tour of Dynamic Analysis
PDF
pg_proctab: Accessing System Stats in PostgreSQL
PDF
pg_proctab: Accessing System Stats in PostgreSQL
PDF
計算機性能の限界点とその考え方
PDF
Explain this!
PPTX
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak
ODP
Dynamic Tracing of your AMP web site
PPTX
Relational Database Access with Python
Profiling in Python
20181212 - PGconfASIA - LT - English
r,rstats,r language,r packages
Wprowadzenie do technologii Big Data / Intro to Big Data Ecosystem
Wprowadzenie do technologi Big Data i Apache Hadoop
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQL
Assessing Graph Solutions for Apache Spark
Nodejs性能分析优化和分布式设计探讨
Relational Database Access with Python ‘sans’ ORM
PHP applications/environments monitoring: APM & Pinba
Beyond Breakpoints: A Tour of Dynamic Analysis
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQL
計算機性能の限界点とその考え方
Explain this!
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak
Dynamic Tracing of your AMP web site
Relational Database Access with Python
Ad

More from Wisconsin Land Information Association (20)

PPTX
A wikimap of landscape values in the bad river watershed carl sack
PPTX
Workshop using open source software for mobile data collection workshop - a...
PPTX
Wigicc's role in wisconsin jon schwitchtenberg
PPTX
Wi 590 nutrient management web application lisa morrison
PPTX
Surveying and land records management dean roth
PPTX
Mapping spatial patterns of whai finder usage to measure community outreach e...
PPTX
Local gis in the statewide voter registration system sarah whitt
PPTX
Li dar quality control a client's perspective - tyler grosshuesch
PPTX
Li dar meets wisconsinview jc nelson
PPTX
Lakesheds and riverscapes extending wisconsin's hydro database with landsca...
PPTX
Lake habitat mapping with side scan sonar in nine wisconsin lakes - christine...
PPTX
Integrative mapping strategies jeremy bixby
PPTX
Integrating sanitary televising data with utility gis data within the city of...
PPTX
Integrating high accuracy gps with esri's arc gis for windows mobile field so...
PPTX
Implementing arc gis 10.1 for the wisconsin dnr nhi portal levi felling
PPTX
Gis in parks and recreation the proragis website - trish nau
PPTX
Geo moose project update brian fischer
PPTX
Elevation hydrology tools kent pena
PPTX
Developing mobile apps pick your poison - levi felling
A wikimap of landscape values in the bad river watershed carl sack
Workshop using open source software for mobile data collection workshop - a...
Wigicc's role in wisconsin jon schwitchtenberg
Wi 590 nutrient management web application lisa morrison
Surveying and land records management dean roth
Mapping spatial patterns of whai finder usage to measure community outreach e...
Local gis in the statewide voter registration system sarah whitt
Li dar quality control a client's perspective - tyler grosshuesch
Li dar meets wisconsinview jc nelson
Lakesheds and riverscapes extending wisconsin's hydro database with landsca...
Lake habitat mapping with side scan sonar in nine wisconsin lakes - christine...
Integrative mapping strategies jeremy bixby
Integrating sanitary televising data with utility gis data within the city of...
Integrating high accuracy gps with esri's arc gis for windows mobile field so...
Implementing arc gis 10.1 for the wisconsin dnr nhi portal levi felling
Gis in parks and recreation the proragis website - trish nau
Geo moose project update brian fischer
Elevation hydrology tools kent pena
Developing mobile apps pick your poison - levi felling

Recently uploaded (20)

PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
KodekX | Application Modernization Development
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Empathic Computing: Creating Shared Understanding
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
cuic standard and advanced reporting.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Electronic commerce courselecture one. Pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Diabetes mellitus diagnosis method based random forest with bat algorithm
Chapter 3 Spatial Domain Image Processing.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
KodekX | Application Modernization Development
The AUB Centre for AI in Media Proposal.docx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Review of recent advances in non-invasive hemoglobin estimation
Empathic Computing: Creating Shared Understanding
Digital-Transformation-Roadmap-for-Companies.pptx
cuic standard and advanced reporting.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
20250228 LYD VKU AI Blended-Learning.pptx
Electronic commerce courselecture one. Pdf
Advanced methodologies resolving dimensionality complications for autism neur...
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Mobile App Security Testing_ A Comprehensive Guide.pdf

Python Coding Examples for Drive Time Analysis

  • 1. Python & Drive Time Analyses Python 2.6 ArcCatalog 9.3.1 ArcMap 9.3.1 Project technologies Programming language: Software products: Janice Poehlman Division of Forestry, Dept. Natural Resources [email_address]
  • 2. Use python scripts to summarize the total number of people who are within drive times of a location. 30 Minute 60 Minute 90 Minute 120 Minute Drive Time Service Area Network Analyst }
  • 3. Data WI, MN, MI, IL, IA Census 2000 Block Groups TIGER 2000 Road PLSS Township
  • 4.  
  • 5.  
  • 6.  
  • 7.  
  • 8.  
  • 9.  
  • 10.  
  • 11.  
  • 12.  
  • 13.  
  • 14.  
  • 15. #--------------------------------------------------------------------- #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. #-----------------------------------------------------------------------
  • 16. What is a cursor and how does it work.
  • 17. What is a cursor and how does it work.
  • 18. What is a cursor and how does it work.
  • 19. What is a cursor and how does it work.
  • 20. What is a cursor and how does it work.
  • 21. 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
  • 22. 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
  • 23. #import modules import arcgisscripting, sys, os, time #create the geoproccessor object and set file overwrite gp = arcgisscripting.create() gp.overwriteoutput = 1 #set workspace variables and add toolboxes gp.workspace = &quot;D:\drivetime\RoadsTigerResultsDT120Min_processing4.gdb” gp.addtoolbox(&quot;C:/Program Files/ArcGIS/ArcToolBox/Toolboxes/Data Management Tools.tbx&quot;) gp.addtoolbox(&quot;C:/Program Files/ArcGIS/ArcToolBox/Toolboxes/Analysis Tools.tbx&quot;) servicearea = &quot;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)
  • 24. 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
  • 25. try: rows = gp.SearchCursor(servicearea) row = rows.Next() while row <> None: ShapeName = str(row.DTR) gp.Select_analysis(servicearea, &quot;xxsel&quot; +ShapeName, '&quot;DTR&quot;=' +ShapeName) gp.clip_analysis(&quot;pop2000&quot;, &quot;xxsel&quot;+ShapeName, &quot;xxclipSEWNN&quot;+ShapeName, &quot;&quot;) gp.calculatefield_management(&quot;xxclipSEWNN&quot;+ShapeName, &quot;DTR&quot;, row.DTR) gp.delete_management (&quot;xxsel&quot; +ShapeName) row = rows.next() del row, rows except: if not gp.getmessages() == &quot;”: gp.addmessage(gp.getmessages(2)) if 'row' in dir(): del row if 'rows' in dir(): del rows
  • 26. 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(&quot;ValueTable”) fcList = gp.listfeatureclasses(&quot;xxclipSEWNN*”) fc = fcList.Next() while fc: fcpath = gp.workspace + &quot;\\&quot; + fc vTab.Addrow(fcpath) fc = fcList.Next() gp.merge_management(vTab, &quot;AMergedDriveTime120MinutesSEWNN&quot;, &quot;”) print &quot;Completed merged file for features of %s&quot; %(servicearea) timestamp = time.strftime('%I:%M:%S %p', time.localtime()) log.write('\nFinishing time is ' + timestamp) print&quot;Done.” del vTab del fc del fcpath del servicearea del timestamp log.close()
  • 27.  
  • 28.  
  • 29. A supply and demand analysis of location 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 !
  • 30. Thank you for your attention.