Transcript
Page 1: Python: Beyond the Basics - Esri...Python: Beyond the Basics, 2016 Esri Federal GIS Conference--Presentation, 2016 Esri Federal GIS Conference, Created Date 3/3/2016 4:41:37 PM

Python: Beyond the BasicsCarl Eichenberger

February 24–25, 2016 | Washington, DC

FedGIS Conference

Page 2: Python: Beyond the Basics - Esri...Python: Beyond the Basics, 2016 Esri Federal GIS Conference--Presentation, 2016 Esri Federal GIS Conference, Created Date 3/3/2016 4:41:37 PM

Agenda

• Perform non-GIS and GIS functions in a script tool• Data Access Module: Cursors• Geometries• Hot spot analysis• Mapping Module

Page 3: Python: Beyond the Basics - Esri...Python: Beyond the Basics, 2016 Esri Federal GIS Conference--Presentation, 2016 Esri Federal GIS Conference, Created Date 3/3/2016 4:41:37 PM

Scenario

Create a script tool that performs an Optimized Hotspot Analysis from values originating from a CSV file, add the results of the hotspot analysis to a MXD, and export the MXD to a PDF. This tool will use core Python functions (from Python CSV module) and GIS functions from the ArcPy site package.

Page 4: Python: Beyond the Basics - Esri...Python: Beyond the Basics, 2016 Esri Federal GIS Conference--Presentation, 2016 Esri Federal GIS Conference, Created Date 3/3/2016 4:41:37 PM

Script Workflow

Page 5: Python: Beyond the Basics - Esri...Python: Beyond the Basics, 2016 Esri Federal GIS Conference--Presentation, 2016 Esri Federal GIS Conference, Created Date 3/3/2016 4:41:37 PM

Define parameters for script tool

• Import modules (CSV and arcpy)• arcpy.GetParameterAsText()• Begin with index position 0

Page 6: Python: Beyond the Basics - Esri...Python: Beyond the Basics, 2016 Esri Federal GIS Conference--Presentation, 2016 Esri Federal GIS Conference, Created Date 3/3/2016 4:41:37 PM

Create points from CSV file

• CSV reader object (Python CSV module)- Read coordinates from each row of CSV

• Working with cursors and geometries- Add coordinates to arcpy.Point() object- arcpy.da.InsertCursor()

- Create a new row- Add point object into shape field

Page 7: Python: Beyond the Basics - Esri...Python: Beyond the Basics, 2016 Esri Federal GIS Conference--Presentation, 2016 Esri Federal GIS Conference, Created Date 3/3/2016 4:41:37 PM

Run Optimized Hot Spot Analysis tool

Two hot spot analysis options• Hot Spot Analysis (Getis-Ord Gi*)• Optimized Hot Spot Analysis (new at 10.2) Hot spot vs density• Density shows where features are concentrated• Hot spot identifies spatial clusters statistically

Page 8: Python: Beyond the Basics - Esri...Python: Beyond the Basics, 2016 Esri Federal GIS Conference--Presentation, 2016 Esri Federal GIS Conference, Created Date 3/3/2016 4:41:37 PM

Modify MXD and export to PDF

• arcpy.mapping moduleInventory map documents

Update or repair layer data sources

Update layer symbology

Update or change layout elements

Save a map document to a previous version of ArcGIS

Update map document metadata

Export map contents

Create a map book series in PDF

Page 9: Python: Beyond the Basics - Esri...Python: Beyond the Basics, 2016 Esri Federal GIS Conference--Presentation, 2016 Esri Federal GIS Conference, Created Date 3/3/2016 4:41:37 PM

DemoRun script tool

Page 10: Python: Beyond the Basics - Esri...Python: Beyond the Basics, 2016 Esri Federal GIS Conference--Presentation, 2016 Esri Federal GIS Conference, Created Date 3/3/2016 4:41:37 PM

Resources

• Accessing data with cursors: http://desktop.arcgis.com/en/desktop/latest/analyze/python/data-access-using-cursors.htm

• Working with geometries: http://desktop.arcgis.com/en/desktop/latest/analyze/python/reading-geometries.htm

http://desktop.arcgis.com/en/desktop/latest/analyze/python/writing-geometries.htm• Mapping module: http://desktop.arcgis.com/en/desktop/latest/analyze/arcpy-

mapping/introduction-to-arcpy-mapping.htm• Error Handling: http://desktop.arcgis.com/en/arcmap/latest/analyze/python/error-

handling-with-python.htm

Page 11: Python: Beyond the Basics - Esri...Python: Beyond the Basics, 2016 Esri Federal GIS Conference--Presentation, 2016 Esri Federal GIS Conference, Created Date 3/3/2016 4:41:37 PM

Resources

• Extra info based off of questions

64-bit Background Geoprocessing (If you are processing lots of data)http://desktop.arcgis.com/en/arcmap/latest/analyze/executing-tools/64bit-background.htmWorking with Oracle databaseshttp://cx-oracle.sourceforge.net/index.html


Top Related