SlideShare une entreprise Scribd logo
1  sur  59
Python and GIS
ImprovingYourWorkflow
DVRPC - IREG
9 December 2015
Why Python?
Automation
"HollerithMachine.CHM" by Adam Schuster - Flickr: Proto IBM. CC BY
ArcGIS & ModelBuilder
ArcGIS & ModelBuilder
• Limited iterative capacity
• Limited reusability
• Limited to ArcGIS
• No version control
Why program in Python?
• Extensible nature of the language gives you the
flexibility to change it as you see fit.
• Conversely, others may have already worked on
a similar problem and released their solutions on
the web for you to incorporate.
• Support for various OSs and GISs means that
your tools can be easily migrated to other
platforms and maintained as GIS evolves.
• A strong community supports the software and
its continued development.
From the ArcGIS perspective
• You might have already used Python within
ArcGIS.
• Python can work withinArcGIS –
– Custom field calculator functions
– Scripts within ArcToolbox and PythonToolboxes
– Interactively through the Python prompt
• Python can extendArcGIS functionality –
– Enable scheduled tasks
– Improve upon ETL tasks
– Talk to other software or components
Incorporating Python
into ArcGIS
Python within ArcGIS
• Python is integrated with the ArcGIS Desktop
software and can be accessed in several ways:
– Field calculator
– ArcGISToolbox scripts & PythonToolboxes
– Python Add-ins
– Interactive Prompt
• Understanding Python can help with many
operations.
• Your level of knowledge can vary; expanding
your knowledge will only open up more
opportunities.
The Field Calculator
• The Field Calculator
(and Calculate Field
tool) allow you to
programmatically
change the values
within a layer's or
table's column.
• Python can be used to
calculate new data
from existing fields or
other properties.
Referencing Other Fields
• Fields are delimited
with exclamation marks
in the Python code
block.
• !block! refers to the
Block column.
• A function can be
defined to do additional
processing, with fields
passed as parameters.
• Creating a PAMS_PIN
for NJ parcel data.
https://gist.github.com/johnjreiser/2206339
The SHAPE Field
• The SHAPE field has several methods that can
be accessed within FieldCalculator to retrieve
attributes of the record's geometry.
• !shape.area!, !shape.length!
• Unit type is modifiable:
!shape.area@SQUAREYARDS!
• !shape.partCount!
• !shape.pointCount!
Moving from ModelBuilder
to Python
Great Starting Point
• Exporting from ModelBuilder is a great starting
point for many projects.
• Declare variables/layers/workspaces using
ModelBuilder UI. Start to put the pieces
together.
• Export an incomplete model to Python for final
development.
• The shell will be there – it will produce a valid
(though potentially nonfunctional) arcpy script.
• You can then complete and extend the
functionality.
The arcpy Module
• Importing the arcpy module provides access to the
ArcGIS Engine in Python.
• Functionality provided by arcpy includes the tools
provided by ArcToolbox, as well as some specialized
functionality such as cursors.
• Easy, pythonic way to work with ArcGIS.
import arcpy
arcpy.AddField_management(
"c:/data/Portland.gdb/streets", "LENGTH_MILES",
"TEXT")
arcpy.CalculateField_management(
"c:/data/Portland.gdb/streets",
"LENGTH_MILES","!shape.length@miles!",
"PYTHON_9.3")
Standalone arcpy Scripts
• arcpy can be called from any Python program
that is using the version of Python installed with
ArcGIS.
• Commonly underWindows, the version installed
with ArcGIS is the only Python installed.
• Python and arcpy provides access to
geoprocessing functionality and tasks, with
lower overhead.
• Programs using arcpy can be run without having
any of theArcGIS Desktop suite running.
• Great for scheduled or background tasks.
arcpy Cursors
• Cursors enable you to iterate through a series of
rows, insert new rows, or update existing rows.
• Cursors empower you to perform analysis on the
feature level, as opposed to the layer level.
• Features can be directly accessed, enabling
greater functionality than possible through most
tools.
• Features can also be modified individually.
Geotagged Photos
Feature Shifting
Extending ArcGIS tools
using Python
Python Add-Ins
• At 10.1, ESRI
introduced Python
Add-Ins.
• ReplacingVBA as the
method for creating UI
tools.
• ESRI provides an Add-In
Wizard to help create
these tools.
• ESRI training: "Creating
Desktop Add-ins Using
Python"
Download Imagery
• NJ OIT-OGIS'sWMS services are great, but what
if you want the source tiles?
• Python Add-Ins allow you to pull the data down,
extract it and load it into ArcGIS.
• Allows for interactive selection within a your
map frame, with the data automatically added
to the map once the download is complete.
https://github.com/RowanGeolab/arcgisPythonAddins
Getting Census Data
PythonToolbox
• PythonToolboxes are pure-Python files that
appear as ArcToolbox toolboxes.
• Tools are defined as subclasses.
• A toolbox containing several independent tools
can exist as one text-based file.
• Great format for transparency and version
control.
• Uses .pyt as a file extension.
Moving Beyond ArcGIS
using Python
Make ETL Easy
• Extract, transform, load processes can be
tedious, especially if they are complex and
frequent.
• Python can help assist you with bringing in
outside data, conforming it to your needs and
loading it into your database/storage.
• Python can connect to the web and databases,
as well as process and convert GIS data.
• Python can also be run from Scheduled
Tasks/cron, enabling you to fully automate these
operations.
Fiona
• Fiona is a Python wrapper for the GDAL/OGR
library.
• https://pypi.python.org/pypi/Fiona
• Enables you to convert/project/process a
multitude of spatial data formats.
• Expanding on the previous example, the
downloaded data can then be processed,
converted to/from a specific format,
reprojected, etc.
Web Retrieval & Extraction
• Several modules exist to enable easy
downloading of remote resources.
• urllib (plus urllib2, urllib3, httplib, etc…)
• zipfile is a module for working with PKZIP files.
• Let's look at some code to automate downloads
and extraction.
chupaESRI
psycopg2
• psycopg2 module provides a Pythonic way of
querying a PostgreSQL database.
• PostgreSQL-specific, enables accessingArcSDE
or PostGIS-formatted data.
• Full, secure access to your databases.
• Very easy to use the records returned from a
database query in your Python programs.
Recent Property Sales
Q & A
Books
• Lutz, Mark. Learning
Python, 5th Edition.
O’Reilly Media. ISBN:
978-1-4493-5573-9
• Lubanovic, Bill.
Introducing Python, 1st
Edition. O’Reilly Media.
ISBN: 978-1-4493-5936-2
• Shaw, Zed. Learn Python
the HardWay. Addison-
Wesley. ISBN: 978-
0321884916
OnlineTutorials
• Learning Python:
– Code.org
– Codecademy
• ESRITraining offerings:
– Python for Everyone -
http://training.esri.com/gateway/index.cfm?fa=catal
og.webcoursedetail&courseid=2520
– Using Python in ArcGIS Desktop 10 -
http://training.esri.com/gateway/index.cfm?fa=catal
og.webCourseDetail&courseID=1868
Online Communities
• Blogs
– geospatialpython.com
– sgillies.net
– many more…
• Stack Exchange
– gis.stackexchange.com
– stackoverflow.com
• GeoNet - Python &
Geoprocessing forums
– http://forums.arcgis.co
m/forums/117-Python
Thanks for listening!
• Feel free to follow up with questions:
jreiser@njgeo.org
@johnjreiser onTwitter
github.com/johnjreiser

Contenu connexe

Tendances

Tendances (20)

Advanced Analytics - Smart Analytics - Esri UK Annual Conference 2017
Advanced Analytics - Smart Analytics - Esri UK Annual Conference 2017Advanced Analytics - Smart Analytics - Esri UK Annual Conference 2017
Advanced Analytics - Smart Analytics - Esri UK Annual Conference 2017
 
Exploring KML Transformers
Exploring KML TransformersExploring KML Transformers
Exploring KML Transformers
 
Introduction to apache spark
Introduction to apache sparkIntroduction to apache spark
Introduction to apache spark
 
Understanding and Improving Code Generation
Understanding and Improving Code GenerationUnderstanding and Improving Code Generation
Understanding and Improving Code Generation
 
A Tale of Three Deep Learning Frameworks: TensorFlow, Keras, & Deep Learning ...
A Tale of Three Deep Learning Frameworks: TensorFlow, Keras, & Deep Learning ...A Tale of Three Deep Learning Frameworks: TensorFlow, Keras, & Deep Learning ...
A Tale of Three Deep Learning Frameworks: TensorFlow, Keras, & Deep Learning ...
 
Kubeflow: portable and scalable machine learning using Jupyterhub and Kuberne...
Kubeflow: portable and scalable machine learning using Jupyterhub and Kuberne...Kubeflow: portable and scalable machine learning using Jupyterhub and Kuberne...
Kubeflow: portable and scalable machine learning using Jupyterhub and Kuberne...
 
Scaling and Unifying SciKit Learn and Apache Spark Pipelines
Scaling and Unifying SciKit Learn and Apache Spark PipelinesScaling and Unifying SciKit Learn and Apache Spark Pipelines
Scaling and Unifying SciKit Learn and Apache Spark Pipelines
 
Citizen Science in your Pocket - Addy Pope
Citizen Science in your Pocket - Addy PopeCitizen Science in your Pocket - Addy Pope
Citizen Science in your Pocket - Addy Pope
 
dev_int_96
dev_int_96dev_int_96
dev_int_96
 
Low cost solutions for Lidar and GIS analysis
Low cost solutions for Lidar and GIS analysisLow cost solutions for Lidar and GIS analysis
Low cost solutions for Lidar and GIS analysis
 
H2O Rains with Databricks Cloud - Parisoma SF
H2O Rains with Databricks Cloud - Parisoma SFH2O Rains with Databricks Cloud - Parisoma SF
H2O Rains with Databricks Cloud - Parisoma SF
 
An Introduction to the Heatmap / Histogram Plugin
An Introduction to the Heatmap / Histogram PluginAn Introduction to the Heatmap / Histogram Plugin
An Introduction to the Heatmap / Histogram Plugin
 
How Spark Enables the Internet of Things- Paula Ta-Shma
How Spark Enables the Internet of Things- Paula Ta-ShmaHow Spark Enables the Internet of Things- Paula Ta-Shma
How Spark Enables the Internet of Things- Paula Ta-Shma
 
Project Progress
Project ProgressProject Progress
Project Progress
 
H2O Rains with Databricks Cloud - NY 02.16.16
H2O Rains with Databricks Cloud - NY 02.16.16H2O Rains with Databricks Cloud - NY 02.16.16
H2O Rains with Databricks Cloud - NY 02.16.16
 
FME Applications in New York City GIS
FME Applications in New York City GISFME Applications in New York City GIS
FME Applications in New York City GIS
 
Data Agility—A Journey to Advanced Analytics and Machine Learning at Scale
Data Agility—A Journey to Advanced Analytics and Machine Learning at ScaleData Agility—A Journey to Advanced Analytics and Machine Learning at Scale
Data Agility—A Journey to Advanced Analytics and Machine Learning at Scale
 
Yggdrasil: Faster Decision Trees Using Column Partitioning In Spark
Yggdrasil: Faster Decision Trees Using Column Partitioning In SparkYggdrasil: Faster Decision Trees Using Column Partitioning In Spark
Yggdrasil: Faster Decision Trees Using Column Partitioning In Spark
 
More Data Science with Less Engineering: Machine Learning Infrastructure at N...
More Data Science with Less Engineering: Machine Learning Infrastructure at N...More Data Science with Less Engineering: Machine Learning Infrastructure at N...
More Data Science with Less Engineering: Machine Learning Infrastructure at N...
 
What is Spark
What is SparkWhat is Spark
What is Spark
 

En vedette

Classification Systems
Classification SystemsClassification Systems
Classification Systems
John Reiser
 
Reading Topographic Maps
Reading Topographic MapsReading Topographic Maps
Reading Topographic Maps
duncanpatti
 
Are indian stock market driven more by sentiments than fundamentals- A Resear...
Are indian stock market driven more by sentiments than fundamentals- A Resear...Are indian stock market driven more by sentiments than fundamentals- A Resear...
Are indian stock market driven more by sentiments than fundamentals- A Resear...
Akash Jauhari
 
How culture can make or break a company
How culture can make or break a companyHow culture can make or break a company
How culture can make or break a company
Akash Jauhari
 

En vedette (20)

Beyond arcpy, Python for GIS, Grant Miller-Francisco
Beyond arcpy, Python for GIS, Grant Miller-FranciscoBeyond arcpy, Python for GIS, Grant Miller-Francisco
Beyond arcpy, Python for GIS, Grant Miller-Francisco
 
Python and GIS
Python and GISPython and GIS
Python and GIS
 
Leveraging Open Source GIS with Python: A QGIS Approach
Leveraging Open Source GIS with Python: A QGIS ApproachLeveraging Open Source GIS with Python: A QGIS Approach
Leveraging Open Source GIS with Python: A QGIS Approach
 
Solving Geophysics Problems with Python
Solving Geophysics Problems with PythonSolving Geophysics Problems with Python
Solving Geophysics Problems with Python
 
Using Dashboards to Understand Spatial Data
Using Dashboards to Understand Spatial DataUsing Dashboards to Understand Spatial Data
Using Dashboards to Understand Spatial Data
 
Map Projections
Map ProjectionsMap Projections
Map Projections
 
Classification Systems
Classification SystemsClassification Systems
Classification Systems
 
Intro to GIS and Remote Sensing
Intro to GIS and Remote SensingIntro to GIS and Remote Sensing
Intro to GIS and Remote Sensing
 
Milos Miljkovic - Analyzing satellite images with python scientific stack
Milos Miljkovic - Analyzing satellite images with python scientific stackMilos Miljkovic - Analyzing satellite images with python scientific stack
Milos Miljkovic - Analyzing satellite images with python scientific stack
 
Time Triggered Protocol
Time Triggered ProtocolTime Triggered Protocol
Time Triggered Protocol
 
Sistema de arquivos - HPFS e ReiserFS/4
Sistema de arquivos - HPFS e ReiserFS/4Sistema de arquivos - HPFS e ReiserFS/4
Sistema de arquivos - HPFS e ReiserFS/4
 
Transformation of traditional village into eco-village
Transformation of traditional village into eco-villageTransformation of traditional village into eco-village
Transformation of traditional village into eco-village
 
Reading Topographic Maps
Reading Topographic MapsReading Topographic Maps
Reading Topographic Maps
 
Are indian stock market driven more by sentiments than fundamentals- A Resear...
Are indian stock market driven more by sentiments than fundamentals- A Resear...Are indian stock market driven more by sentiments than fundamentals- A Resear...
Are indian stock market driven more by sentiments than fundamentals- A Resear...
 
How culture can make or break a company
How culture can make or break a companyHow culture can make or break a company
How culture can make or break a company
 
Location analytics: A New Dimension for your Applications
Location analytics: A New Dimension for your ApplicationsLocation analytics: A New Dimension for your Applications
Location analytics: A New Dimension for your Applications
 
C-Si Module Manufacturers in India
C-Si Module Manufacturers in IndiaC-Si Module Manufacturers in India
C-Si Module Manufacturers in India
 
New paradigm for national mapping organization
New paradigm for national mapping organizationNew paradigm for national mapping organization
New paradigm for national mapping organization
 
The New Paradigm Towards Geo Enabled Economy
 The New Paradigm Towards Geo Enabled Economy The New Paradigm Towards Geo Enabled Economy
The New Paradigm Towards Geo Enabled Economy
 
Week 1.2 course description 02 251-101
Week 1.2 course description 02 251-101 Week 1.2 course description 02 251-101
Week 1.2 course description 02 251-101
 

Similaire à Python and GIS: Improving Your Workflow

Automation in ArcGIS using Arcpy
Automation in ArcGIS using ArcpyAutomation in ArcGIS using Arcpy
Automation in ArcGIS using Arcpy
Geodata AS
 
Netflix oss season 2 episode 1 - meetup Lightning talks
Netflix oss   season 2 episode 1 - meetup Lightning talksNetflix oss   season 2 episode 1 - meetup Lightning talks
Netflix oss season 2 episode 1 - meetup Lightning talks
Ruslan Meshenberg
 

Similaire à Python and GIS: Improving Your Workflow (20)

Esri South Africa Python for Everyone
Esri South Africa Python for EveryoneEsri South Africa Python for Everyone
Esri South Africa Python for Everyone
 
Automation in ArcGIS using Arcpy
Automation in ArcGIS using ArcpyAutomation in ArcGIS using Arcpy
Automation in ArcGIS using Arcpy
 
Top 10 python ide
Top 10 python ideTop 10 python ide
Top 10 python ide
 
workshop_8_c__.pdf
workshop_8_c__.pdfworkshop_8_c__.pdf
workshop_8_c__.pdf
 
Geotalk presentation
Geotalk presentationGeotalk presentation
Geotalk presentation
 
A slide share pig in CCS334 for big data analytics
A slide share pig in CCS334 for big data analyticsA slide share pig in CCS334 for big data analytics
A slide share pig in CCS334 for big data analytics
 
PyData Boston 2013
PyData Boston 2013PyData Boston 2013
PyData Boston 2013
 
dbt Python models - GoDataFest by Guillermo Sanchez
dbt Python models - GoDataFest by Guillermo Sanchezdbt Python models - GoDataFest by Guillermo Sanchez
dbt Python models - GoDataFest by Guillermo Sanchez
 
Scala at Treasure Data
Scala at Treasure DataScala at Treasure Data
Scala at Treasure Data
 
Creating Reusable Geospatial Pipelines
Creating Reusable Geospatial PipelinesCreating Reusable Geospatial Pipelines
Creating Reusable Geospatial Pipelines
 
Introduction to Python Programming
Introduction to Python ProgrammingIntroduction to Python Programming
Introduction to Python Programming
 
Apache Spark Tutorial
Apache Spark TutorialApache Spark Tutorial
Apache Spark Tutorial
 
Netflix oss season 2 episode 1 - meetup Lightning talks
Netflix oss   season 2 episode 1 - meetup Lightning talksNetflix oss   season 2 episode 1 - meetup Lightning talks
Netflix oss season 2 episode 1 - meetup Lightning talks
 
Agile Oracle to PostgreSQL migrations (PGConf.EU 2013)
Agile Oracle to PostgreSQL migrations (PGConf.EU 2013)Agile Oracle to PostgreSQL migrations (PGConf.EU 2013)
Agile Oracle to PostgreSQL migrations (PGConf.EU 2013)
 
python full stack course in hyderabad...
python full stack course in hyderabad...python full stack course in hyderabad...
python full stack course in hyderabad...
 
python full stack course in hyderabad...
python full stack course in hyderabad...python full stack course in hyderabad...
python full stack course in hyderabad...
 
Apache PIG
Apache PIGApache PIG
Apache PIG
 
Habitat Overview
Habitat OverviewHabitat Overview
Habitat Overview
 
Introduction to Google Cloud Platform
Introduction to Google Cloud PlatformIntroduction to Google Cloud Platform
Introduction to Google Cloud Platform
 
Why real integration developers ride Camels
Why real integration developers ride CamelsWhy real integration developers ride Camels
Why real integration developers ride Camels
 

Plus de John Reiser

Habitat Change Analysis Project
Habitat Change Analysis ProjectHabitat Change Analysis Project
Habitat Change Analysis Project
John Reiser
 
GIS Day at BCC 2012
GIS Day at BCC 2012GIS Day at BCC 2012
GIS Day at BCC 2012
John Reiser
 
Going Mobile with HTML5
Going Mobile with HTML5Going Mobile with HTML5
Going Mobile with HTML5
John Reiser
 
GIS & Facilities - NJAPPA Talk - April 26 2012
GIS & Facilities - NJAPPA Talk - April 26 2012GIS & Facilities - NJAPPA Talk - April 26 2012
GIS & Facilities - NJAPPA Talk - April 26 2012
John Reiser
 
Introduction to 3D Data
Introduction to 3D DataIntroduction to 3D Data
Introduction to 3D Data
John Reiser
 
Data Models - GIS I
Data Models - GIS IData Models - GIS I
Data Models - GIS I
John Reiser
 
Network Analysis in ArcGIS
Network Analysis in ArcGISNetwork Analysis in ArcGIS
Network Analysis in ArcGIS
John Reiser
 
Measurement and Scale
Measurement and ScaleMeasurement and Scale
Measurement and Scale
John Reiser
 
Data Storage and Processing
Data Storage and ProcessingData Storage and Processing
Data Storage and Processing
John Reiser
 

Plus de John Reiser (20)

Habitat Change Analysis Project
Habitat Change Analysis ProjectHabitat Change Analysis Project
Habitat Change Analysis Project
 
Doing more with SQL
Doing more with SQLDoing more with SQL
Doing more with SQL
 
NJ MAP: Building a different kind of GIS platform using open source tools.
NJ MAP: Building a different kind of GIS platform using open source tools.NJ MAP: Building a different kind of GIS platform using open source tools.
NJ MAP: Building a different kind of GIS platform using open source tools.
 
Portfolio Workshop
Portfolio WorkshopPortfolio Workshop
Portfolio Workshop
 
GIS Day at BCC 2012
GIS Day at BCC 2012GIS Day at BCC 2012
GIS Day at BCC 2012
 
Mapping the Human Environment
Mapping the Human EnvironmentMapping the Human Environment
Mapping the Human Environment
 
NJAPPA 2012 - Campus Facilities
NJAPPA 2012 - Campus FacilitiesNJAPPA 2012 - Campus Facilities
NJAPPA 2012 - Campus Facilities
 
Mapping the Way - ESRI EdUC 2011
Mapping the Way - ESRI EdUC 2011Mapping the Way - ESRI EdUC 2011
Mapping the Way - ESRI EdUC 2011
 
Going Mobile with HTML5
Going Mobile with HTML5Going Mobile with HTML5
Going Mobile with HTML5
 
GIS & Facilities - NJAPPA Talk - April 26 2012
GIS & Facilities - NJAPPA Talk - April 26 2012GIS & Facilities - NJAPPA Talk - April 26 2012
GIS & Facilities - NJAPPA Talk - April 26 2012
 
Introduction to 3D Data
Introduction to 3D DataIntroduction to 3D Data
Introduction to 3D Data
 
GPS - Fall 2011
GPS - Fall 2011GPS - Fall 2011
GPS - Fall 2011
 
Data Models - GIS I
Data Models - GIS IData Models - GIS I
Data Models - GIS I
 
Mapping the Way
Mapping the WayMapping the Way
Mapping the Way
 
New Jersey Land Change Viewer
New Jersey Land Change ViewerNew Jersey Land Change Viewer
New Jersey Land Change Viewer
 
Network Analysis in ArcGIS
Network Analysis in ArcGISNetwork Analysis in ArcGIS
Network Analysis in ArcGIS
 
Measurement and Scale
Measurement and ScaleMeasurement and Scale
Measurement and Scale
 
Geodatabases
GeodatabasesGeodatabases
Geodatabases
 
GIS Modeling
GIS ModelingGIS Modeling
GIS Modeling
 
Data Storage and Processing
Data Storage and ProcessingData Storage and Processing
Data Storage and Processing
 

Dernier

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Dernier (20)

Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 

Python and GIS: Improving Your Workflow

  • 3. Automation "HollerithMachine.CHM" by Adam Schuster - Flickr: Proto IBM. CC BY
  • 5. ArcGIS & ModelBuilder • Limited iterative capacity • Limited reusability • Limited to ArcGIS • No version control
  • 6.
  • 7.
  • 8.
  • 9. Why program in Python? • Extensible nature of the language gives you the flexibility to change it as you see fit. • Conversely, others may have already worked on a similar problem and released their solutions on the web for you to incorporate. • Support for various OSs and GISs means that your tools can be easily migrated to other platforms and maintained as GIS evolves. • A strong community supports the software and its continued development.
  • 10. From the ArcGIS perspective • You might have already used Python within ArcGIS. • Python can work withinArcGIS – – Custom field calculator functions – Scripts within ArcToolbox and PythonToolboxes – Interactively through the Python prompt • Python can extendArcGIS functionality – – Enable scheduled tasks – Improve upon ETL tasks – Talk to other software or components
  • 12. Python within ArcGIS • Python is integrated with the ArcGIS Desktop software and can be accessed in several ways: – Field calculator – ArcGISToolbox scripts & PythonToolboxes – Python Add-ins – Interactive Prompt • Understanding Python can help with many operations. • Your level of knowledge can vary; expanding your knowledge will only open up more opportunities.
  • 13. The Field Calculator • The Field Calculator (and Calculate Field tool) allow you to programmatically change the values within a layer's or table's column. • Python can be used to calculate new data from existing fields or other properties.
  • 14. Referencing Other Fields • Fields are delimited with exclamation marks in the Python code block. • !block! refers to the Block column. • A function can be defined to do additional processing, with fields passed as parameters. • Creating a PAMS_PIN for NJ parcel data.
  • 16. The SHAPE Field • The SHAPE field has several methods that can be accessed within FieldCalculator to retrieve attributes of the record's geometry. • !shape.area!, !shape.length! • Unit type is modifiable: !shape.area@SQUAREYARDS! • !shape.partCount! • !shape.pointCount!
  • 18. Great Starting Point • Exporting from ModelBuilder is a great starting point for many projects. • Declare variables/layers/workspaces using ModelBuilder UI. Start to put the pieces together. • Export an incomplete model to Python for final development. • The shell will be there – it will produce a valid (though potentially nonfunctional) arcpy script. • You can then complete and extend the functionality.
  • 19.
  • 20.
  • 21. The arcpy Module • Importing the arcpy module provides access to the ArcGIS Engine in Python. • Functionality provided by arcpy includes the tools provided by ArcToolbox, as well as some specialized functionality such as cursors. • Easy, pythonic way to work with ArcGIS. import arcpy arcpy.AddField_management( "c:/data/Portland.gdb/streets", "LENGTH_MILES", "TEXT") arcpy.CalculateField_management( "c:/data/Portland.gdb/streets", "LENGTH_MILES","!shape.length@miles!", "PYTHON_9.3")
  • 22. Standalone arcpy Scripts • arcpy can be called from any Python program that is using the version of Python installed with ArcGIS. • Commonly underWindows, the version installed with ArcGIS is the only Python installed. • Python and arcpy provides access to geoprocessing functionality and tasks, with lower overhead. • Programs using arcpy can be run without having any of theArcGIS Desktop suite running. • Great for scheduled or background tasks.
  • 23. arcpy Cursors • Cursors enable you to iterate through a series of rows, insert new rows, or update existing rows. • Cursors empower you to perform analysis on the feature level, as opposed to the layer level. • Features can be directly accessed, enabling greater functionality than possible through most tools. • Features can also be modified individually.
  • 27. Python Add-Ins • At 10.1, ESRI introduced Python Add-Ins. • ReplacingVBA as the method for creating UI tools. • ESRI provides an Add-In Wizard to help create these tools. • ESRI training: "Creating Desktop Add-ins Using Python"
  • 28. Download Imagery • NJ OIT-OGIS'sWMS services are great, but what if you want the source tiles? • Python Add-Ins allow you to pull the data down, extract it and load it into ArcGIS. • Allows for interactive selection within a your map frame, with the data automatically added to the map once the download is complete.
  • 29.
  • 32.
  • 33.
  • 34. PythonToolbox • PythonToolboxes are pure-Python files that appear as ArcToolbox toolboxes. • Tools are defined as subclasses. • A toolbox containing several independent tools can exist as one text-based file. • Great format for transparency and version control. • Uses .pyt as a file extension.
  • 35.
  • 36.
  • 37.
  • 39. Make ETL Easy • Extract, transform, load processes can be tedious, especially if they are complex and frequent. • Python can help assist you with bringing in outside data, conforming it to your needs and loading it into your database/storage. • Python can connect to the web and databases, as well as process and convert GIS data. • Python can also be run from Scheduled Tasks/cron, enabling you to fully automate these operations.
  • 40. Fiona • Fiona is a Python wrapper for the GDAL/OGR library. • https://pypi.python.org/pypi/Fiona • Enables you to convert/project/process a multitude of spatial data formats. • Expanding on the previous example, the downloaded data can then be processed, converted to/from a specific format, reprojected, etc.
  • 41. Web Retrieval & Extraction • Several modules exist to enable easy downloading of remote resources. • urllib (plus urllib2, urllib3, httplib, etc…) • zipfile is a module for working with PKZIP files. • Let's look at some code to automate downloads and extraction.
  • 43. psycopg2 • psycopg2 module provides a Pythonic way of querying a PostgreSQL database. • PostgreSQL-specific, enables accessingArcSDE or PostGIS-formatted data. • Full, secure access to your databases. • Very easy to use the records returned from a database query in your Python programs.
  • 44.
  • 45.
  • 46.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53. Q & A
  • 54. Books • Lutz, Mark. Learning Python, 5th Edition. O’Reilly Media. ISBN: 978-1-4493-5573-9 • Lubanovic, Bill. Introducing Python, 1st Edition. O’Reilly Media. ISBN: 978-1-4493-5936-2 • Shaw, Zed. Learn Python the HardWay. Addison- Wesley. ISBN: 978- 0321884916
  • 55. OnlineTutorials • Learning Python: – Code.org – Codecademy • ESRITraining offerings: – Python for Everyone - http://training.esri.com/gateway/index.cfm?fa=catal og.webcoursedetail&courseid=2520 – Using Python in ArcGIS Desktop 10 - http://training.esri.com/gateway/index.cfm?fa=catal og.webCourseDetail&courseID=1868
  • 56.
  • 57.
  • 58. Online Communities • Blogs – geospatialpython.com – sgillies.net – many more… • Stack Exchange – gis.stackexchange.com – stackoverflow.com • GeoNet - Python & Geoprocessing forums – http://forums.arcgis.co m/forums/117-Python
  • 59. Thanks for listening! • Feel free to follow up with questions: jreiser@njgeo.org @johnjreiser onTwitter github.com/johnjreiser

Notes de l'éditeur

  1. https://arcpy.wordpress.com/2012/11/15/shifting-features/