Introducing the ArcPy Data Access module. Dave Wynne Jason Pardy

Similar documents
Python: Working with Feature Data. Ghislain Prince David Wynne

Python: Beyond the Basics. Michael Rhoades

Using Python with ArcGIS

Python Getting Started

Using Python with ArcGIS

Introduction to Geodatabase and Spatial Management in ArcGIS. Craig Gillgrass Esri

What s New for Developers in ArcGIS Maura Daffern October 16

PYTHON. Scripting for ArcGIS. writeoutput = Inputfc = ar. .ext.{) OUtpUt fc =.. Paul A. Zandbergen. axcpy random. .arcpy, Describe (' is.

Python: Developing Geoprocessing Tools. David Wynne, Jon Bodamer

Using Python in ArcGIS Steven Beothy May 28, 2013

USING PYTHON WITH ARCGIS ADVANCED LEVEL ONLINE TRAINING GIS. Course. Training. .com

Using Python in ArcGIS Oli Helm May 2, 2013

Creating Mosaic Datasets and Publishing Image Services using Python

PUG List. Raster Analysis 3D Analysis Geoprocessing. Steve Kopp

Python: Beyond the Basics. Brittney White, Esri Jordan Douthitt, Pennsylvania State University

Python Raster Analysis. Kevin M. Johnston Nawajish Noman

Working With Raster Data Using Python. Nawajish Noman Ryan DeBruyn

Topology in the Geodatabase: An Introduction

Working with Feature Layers. Russell Brennan Gary MacDougall

Using the Geodatabase

Python - Raster Analysis

Topology in the Geodatabase an Introduction. Erik Hoel Doug Morgenthaler

Python Raster Analysis. Kevin M. Johnston Nawajish Noman

Exercise 8B: Writing Data to a Feature Class with an Insert Cursor

Building Geoprocessing Tools with Python: Beyond the Basics. Dave Wynne

ArcGIS Pro: What s New in Editing and Data Management

WEB GIS DEVELOPER SPECIALIST ONLINE TRAINING. GIS Training. Course. .com

Python Raster Analysis

Python: Beyond the Basics. Brittney White

Integrating ArcGIS Geoprocessing and Mapping Capabilities into Office 365

PYTHON: BUILDING GEOPROCESSING TOOLS. David Wynne, Andrew Ortego

Editing Versioned Geodatabases : An Introduction

An Introduction to Data Interoperability

Accessing and Administering your Enterprise Geodatabase through SQL and Python

SANBI s Enterprise Geodatabase* * And some of the silly mistakes I ve made

Automating Geodatabase Creation with Geoprocessing

Data Interoperability An Introduction

Using SQLite in ArcGIS Python Scripts

TRAINING GUIDE. Data Quality Tools for GIS and Lucity Spatial

Building tools with Python

AutoCAD Map 3D and ESRI ArcSDE

Using Python with ArcGIS

Create a personal geodatabase

By Colin Childs, ESRI Education Services. Catalog

ArcCatalog or the ArcCatalog tab in ArcMap ArcCatalog or the ArcCatalog tab in ArcMap ArcCatalog or the ArcCatalog tab in ArcMap

ArcGIS Pro SDK for.net: An Overview of the Geodatabase API. Colin Zwicker Ling Zhang Nghiep Quang

Working with Metadata in ArcGIS

Python: Working with Raster Data

Lesson 12: ArcGIS Server Capabilities

Advanced Parcel Editing. Amy Andis Tim Hodson

hereby recognizes that Timotej Verbovsek has successfully completed the web course 3D Analysis of Surfaces and Features Using ArcGIS 10

Why use an RDBMS? ❽ Data maintenance ❽ Standardized access ❽ Multi-user access ❽ Data protection

Developer's Guide to Geodata Access in ArcGIS. Craig Gillgrass Brent Pierce Colin Zwicker Russell Brennan Gary MacDougall

Streamlining Editing Workflows. Amber Bethell

Bringing your legacy data into the future.

Python: Working with Raster Data. Nawajish Noman Elizabeth Graham

if row1.parcelid == row2.parcelid: print row.shape.area

Data Synchronization: Autodesk AutoCAD Map 3D Enterprise, FME, and ESRI ArcGIS

Getting the most from the Maplex Label Engine

Leveraging SAP HANA and ArcGIS. Melissa Jarman Eugene Yang

ArcScan. for ArcGIS. GIS by ESRI

Make Your GIS Work for You, First Step: Data Quality

Esri Geodatabase (File Geodatabase API) Reader/Writer

What s New in Desktop 10.1

Easy ArcObjects Turbocharging

Leveraging Relationship Classes in the Geodatabase

Configuring, Tuning and Managing ArcGIS Server. Dan O Leary James Cardona Owen Evans

Administering Your Oracle Geodatabase. Amit Kesarwani Mandar Purohit

Creating Great Labels Using Maplex

ArcGIS. for Desktop. Tips and Shortcuts 10.1

8 Querying and Selecting Data

Building Android Apps Runtime SDK for Android

Editing Parcel Fabrics Tutorial

ArcGIS Runtime SDKs Building Offline Apps. Nick Furness

Best Practices with ArcSDE Technology. Katja Krivoruchko CA/NV/HI Technical Marketing ESRI

ArcGIS Extension User's Guide

Web Editing in ArcGIS for Server. Gary MacDougall Ismael Chivite

ArcGIS Runtime SDK for ios and macos: Building Apps. Suganya Baskaran, Gagandeep Singh

MACBIO Marine and Coastal Biodiversity Management in Pacific Island Countries

Esri s ArcGIS Enterprise. Today s Topics. ArcGIS Enterprise. IT4GIS Keith T. Weber, GISP GIS Director ISU GIS Training and Research Center

Data Interoperability An Introduction

AutoCAD 2009 User InterfaceChapter1:

PYTHON: BUILDING GEOPROCESSING TOOLS. David Wynne, Geri Miller

Esri Production Mapping: Configuring the Solution for Civilian Topographic Agencies. Sean Granata

EFFECTIVE GEODATABASE PROGRAMMING

Best Practices for Designing Effective Map Services

Developers Road Map to ArcGIS Desktop and ArcGIS Engine

Lesson 7: XML Schemas

Design a Geodatabase. Rasu Muthurakku, Enterprise Solutions Architect / Consultant

ArcGIS Pro Editing. Jennifer Cadkin & Phil Sanchez

Python Scripting: Michael Potts, GISP. Geodatabase Administrator.

ESRI China (Hong Kong) Limited

Appendix C: GIS Standards and Procedures

ArcGIS Pro Editing: An Introduction. Jennifer Cadkin & Phil Sanchez

Lab 3: Digitizing in ArcGIS Pro

What's New in ArcGIS 9.2 Service Packs

DEVELOPING A NEW GEOGRAPHICAL OBJECT DATABASE. EXPERIENCES FROM IDEA TO DELIVERING DATASETS TOP10NL

Esri Best Practices: Implementing an Enterprise Geodatabase

LocatorHub. Migrating LocatorHub to Version 5.0. The Transition from ArcObjects Based Plug-Ins to ArcGIS for Server Services

Geodatabase and Object Model Design Using CASE Tools. Julio Andrade Erik Hoel

Transcription:

Introducing the ArcPy Data Access module Dave Wynne Jason Pardy

Abstract In this workshop, see highlights and demonstrations of the new data access module, arcpy.da, a Python module in ArcGIS 10.1 for working with data. The module allows control of edit sessions and operations and improved cursor support and performance, provides functions for converting data to and from NumPy arrays, and supports versioning and replica workflows.

What is arcpy.da? A new arcpy module for working with data 1. Faster cursors 2. Edit session support 3. NumPy array conversion 4. Support for replicas, versions, subtypes, and domains

Cursors Cursors provide record-by-record access - Are a workhorse for many workflows SearchCursor UpdateCursor InsertCursor Read-only access Update or delete rows Insert rows The classic cursor model works, but - Not fast enough - Bottleneck for some Python workflows

Cursor Performance SearchCursor - Up to 30 times faster InsertCursor - Up to 12 times faster

Getting better performance Maximizing performance 1. Use only those fields you need 2. Use geometry tokens - shape@xy, shape@centroid, etc. - Asking for full geometry is expensive

Cursors arcpy.da cursors use lists and tuples - Row values are accessed by index cursor = arcpy.da.insertcursor(table, ["field1", "field2"]) cursor.insertrow([1, 10]) Classic cursors work with row objects - Row values are accessed with setvalue/getvalue properties cursor = arcpy.insertcursor(table) row = cursor.newrow() row.setvalue("field1", 1) row.setvalue("field2", 10) cursor.insertrow(row)

with statements Historically, needed to be careful with database locking and cursors arcpy.da Cursors support with statements - Guarantees close and release of database locks - Regardless of success or failure

with statements for loop cursor = None try: cursor = arcpy.da.searchcursor(table, field) for row in cursor: print row[0] except Exception as err: raise err finally: if cursor: del cursor with statement with arcpy.da.searchcursor(table, field) as cursor: for row in cursor: print row[0]

Demo: Cursors

Editor class Supports edit sessions and edit operations Edits are temporary until saved and permanently applied Can quit an edit session without saving changes

Editor class Editor methods startediting ({with_undo}, {multiuser_mode}) stopediting(save_changes) startoperation() stopoperation() abortoperation() undooperation() redooperation() Starts an edit session. Stops an edit session. Starts an edit operation. Stops an edit operation. Aborts an edit operation. Undo an edit operation (roll back modifications). Redoes an edit operation. If you ve worked with edit sessions in ArcObjects, this will look familiar

Sometimes you just need an edit session To edit feature classes that participate in a - Topology - Geometric network Versioned datasets in ArcSDE geodatabases Some objects and feature classes with class extensions

With statements (part deux) Editor also supports with statements - Handle appropriate start, stop and abort calls for you with arcpy.da.editor(workspace) as edit: #<your edits> Open an edit session and start an edit operation Exception operation is aborted, and edit session is closed without saving No exceptions stop the operation and save and close the edit session

Demo: Editor class

New list functions More list functions (and objects) to support workflows Functions ListDomains ListReplicas ListSubtypes ListVersions Lists the attribute domains belonging to a geodatabase. Lists the replicas in a workspace. Return a dictionary of the subtypes for a table or feature class. List the versions in a workspace.

Demo: arcpy.da list functions

NumPy support NumPy is a 3rd party Python library for scientific computing - A powerful array object - Sophisticated analysis capabilities ArcGIS 10.0 added support for converting rasters to and from numpy arrays - RasterToNumPyArray - NumPyArrayToRaster

NumPy functions At 10.1, arcpy.da provides additional support for tables and feature classes Function FeatureClassToNumPyArray TableToNumPyArray NumPyArrayToFeatureClass NumPyArrayToTable ExtendTable Convert a feature class to an array Convert a table to an array Convert an array to a Feature Class Convert an array to a Table Join an array to a Table

Export to NumPy Can convert tables and feature classes into numpy arrays for further analysis import arcpy import numpy in_fc = "c:/data/usa.gdb/usa/counties" field1 = "INCOME" field2 = "EDUCATION" array = arcpy.da.featureclasstonumpyarray(in_fc, [field1, field2]) # Print correlation coefficients for comparison of 2 fields print numpy.corrcoef((array[field1], array[field2]))

Import from NumPy Take the product of your work in numpy and export it back to ArcGIS array = numpy.array([(1, (471316.3, 5000448.7)), (2, (470402.4, 5000049.2))], numpy.dtype([('idfield', numpy.int32), ('XY', '<f8', 2)])) SR = arcpy.describe(template).spatialreference # Export the numpy array to a feature class using the XY # field to represent the output point feature arcpy.da.numpyarraytofeatureclass(array, outfc, ['XY'], SR)

Demo: Exporting to NumPy

Thank you! ArcGIS Python resource center http://resourcesbeta.arcgis.com/en/communities/python/ Twitter http://twitter.com/#arcpy