Top Banner
Gerhard Trichtl Python: Mapautomation in ArcGIS Pro
33

Python Mapautomation in ArcGIS Pro - Esri...Python Mapautomation in ArcGIS Pro Author Esri Subject 2019 European Developer Summit--Presentation Keywords Python Mapautomation in ArcGIS

May 25, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Python Mapautomation in ArcGIS Pro - Esri...Python Mapautomation in ArcGIS Pro Author Esri Subject 2019 European Developer Summit--Presentation Keywords Python Mapautomation in ArcGIS

Gerhard Trichtl

Python:Mapautomation in ArcGIS Pro

Page 2: Python Mapautomation in ArcGIS Pro - Esri...Python Mapautomation in ArcGIS Pro Author Esri Subject 2019 European Developer Summit--Presentation Keywords Python Mapautomation in ArcGIS

Session Contents

• Python in ArcGIS Pro• Language changes between 2x and 3x• Converting your scripts from ArcGIS for Desktop to

ArcGIS Pro• API changes

- arcpy.mapping > arcpy.mp

Page 3: Python Mapautomation in ArcGIS Pro - Esri...Python Mapautomation in ArcGIS Pro Author Esri Subject 2019 European Developer Summit--Presentation Keywords Python Mapautomation in ArcGIS

Python within ArcGIS ProPython is “embedded” within ArcGIS Pro

- Python Window

- GP Tools (Script tools)- GP Tools with Python requirement

(Field Calculator)- Advanced Labeling

Page 4: Python Mapautomation in ArcGIS Pro - Esri...Python Mapautomation in ArcGIS Pro Author Esri Subject 2019 European Developer Summit--Presentation Keywords Python Mapautomation in ArcGIS

Tour of arcpy.mapping / arcpy.mp

• Overview

sada ga mapping/mp

arcpy

Page 5: Python Mapautomation in ArcGIS Pro - Esri...Python Mapautomation in ArcGIS Pro Author Esri Subject 2019 European Developer Summit--Presentation Keywords Python Mapautomation in ArcGIS

arcpy.(m)a(p)ping samples

http://esriurl.com/8899

Page 6: Python Mapautomation in ArcGIS Pro - Esri...Python Mapautomation in ArcGIS Pro Author Esri Subject 2019 European Developer Summit--Presentation Keywords Python Mapautomation in ArcGIS

Migrating to ArcGIS Pro

http://esriurl.com/9785

Page 7: Python Mapautomation in ArcGIS Pro - Esri...Python Mapautomation in ArcGIS Pro Author Esri Subject 2019 European Developer Summit--Presentation Keywords Python Mapautomation in ArcGIS

Language Changes between 2x and 3x: Highlights- Printing

- print >>> print()- Division

- Float is know returned- Dictionaries

- {}.iteritems >>> {}.items- Miscellaneous

- raw_input() >>> input()- range() >>> range object

- Related modules are now packages:- urllib, urllib2, urlparse >>> urllib- pep-3108

- https://docs.python.org/3/whatsnew/3.0.html

Page 8: Python Mapautomation in ArcGIS Pro - Esri...Python Mapautomation in ArcGIS Pro Author Esri Subject 2019 European Developer Summit--Presentation Keywords Python Mapautomation in ArcGIS

Python 2 vs. Python 3

• Python 2.x:- ArcGIS Desktop, ArcGIS Server Map Runtime- End of Support: 01.2020

• Python 3.x:- ArcGIS Pro, ArcGIS Server Pro Runtime, Hosted Notebooks, ArcGIS API for Python

• https://www.esri.com/arcgis-blog/products/arcgis/announcements/how-sunsetting-python-2-affects-arcgis/

• Windows 7/Windows 2008 R2- Support ends form Microsoft with January 2020 – so also ArcGIS would not longer support

those OS‘s – see also Deprection notes- https://support.esri.com/en/technical-article/000017062 - Last version:

http://downloads.esri.com/Support/downloads/other_/DEPRECATED%20FEATURES%20PLAN%20FOR%20ARCGIS%2010.7.x%20and%20ArcGIS%20Runtime%20SDK%20100.x%20Mid-Year%202019%20v1b%20Final%20%2009042019.pdf 8

Page 9: Python Mapautomation in ArcGIS Pro - Esri...Python Mapautomation in ArcGIS Pro Author Esri Subject 2019 European Developer Summit--Presentation Keywords Python Mapautomation in ArcGIS

Function to Import 8.x/9.x/10.x documents into ArcGISProjects

• ArcGISProject.importDocument (document_path, {include_layout})

.MXDsArcGIS Pro

Projects

Looping through MXDs in a folder.

Reference a template APRX.Import MXD into the APRX.Save the project.

DEMO

Page 10: Python Mapautomation in ArcGIS Pro - Esri...Python Mapautomation in ArcGIS Pro Author Esri Subject 2019 European Developer Summit--Presentation Keywords Python Mapautomation in ArcGIS

Demo

ImportingDocuments

Page 11: Python Mapautomation in ArcGIS Pro - Esri...Python Mapautomation in ArcGIS Pro Author Esri Subject 2019 European Developer Summit--Presentation Keywords Python Mapautomation in ArcGIS

Demo Source Code

Page 12: Python Mapautomation in ArcGIS Pro - Esri...Python Mapautomation in ArcGIS Pro Author Esri Subject 2019 European Developer Summit--Presentation Keywords Python Mapautomation in ArcGIS

You can get there from here

• The starting points are:- ArcGISProject- LayerFile

• The end result might be:- A modified, saved project- An exported PDF

Page 13: Python Mapautomation in ArcGIS Pro - Esri...Python Mapautomation in ArcGIS Pro Author Esri Subject 2019 European Developer Summit--Presentation Keywords Python Mapautomation in ArcGIS

Referencing projects

ArcGISProject classArcGISProject function

ArcGISProject(aprx_path)MethodsimportDocumentlistBrokenDataSourcessaveupdateConnectionProperties

...

Properties:defaultGeodatabasefilePathhomeFolder

...

Page 14: Python Mapautomation in ArcGIS Pro - Esri...Python Mapautomation in ArcGIS Pro Author Esri Subject 2019 European Developer Summit--Presentation Keywords Python Mapautomation in ArcGIS

Updating Data Sources – improvements at Pro

Project/Map/Layer/Table/LayerFile.updateConnectionProperties (current_connection_info, new_connection_info, {auto_update_joins_and_relates}, {validate})

Find this path:

Replace it with this path:

.APRXs

Page 15: Python Mapautomation in ArcGIS Pro - Esri...Python Mapautomation in ArcGIS Pro Author Esri Subject 2019 European Developer Summit--Presentation Keywords Python Mapautomation in ArcGIS

Updating Data Sources – Improvements

1. Changing a folder

2. Changing FGDB to SDE

3. Changing PGDB to FGDB

Page 16: Python Mapautomation in ArcGIS Pro - Esri...Python Mapautomation in ArcGIS Pro Author Esri Subject 2019 European Developer Summit--Presentation Keywords Python Mapautomation in ArcGIS

Updating Data Sources advanced concepts – Layer.connectionProperties

• New at Pro • The entire layer data source object model is exposed as a Python dictionary.• Use if you need more fine grained control than what’s available in

Project/Map/Layer/Table/LayerFile.updateConnectionproperties()• Useful when dealing with joins and relates or Enterprise Geodatabase

Access a layer in a map.

File Geodatabase layer connection properties dictionary

Get layer’s connection properties.

Page 17: Python Mapautomation in ArcGIS Pro - Esri...Python Mapautomation in ArcGIS Pro Author Esri Subject 2019 European Developer Summit--Presentation Keywords Python Mapautomation in ArcGIS

Updating Data Sources advanced concepts – Layer.connectionProperties• File Geodatabase layer connection Properties (with joins and relates)• It gets complicated!

Layer’s database

List of relates on the layer

Relate properties

Page 18: Python Mapautomation in ArcGIS Pro - Esri...Python Mapautomation in ArcGIS Pro Author Esri Subject 2019 European Developer Summit--Presentation Keywords Python Mapautomation in ArcGIS

Updating Data Sources advanced concepts – Layer.connectionProperties• Two ways to use the connection properties dictionary

1. Write directly to the dictionary

2. UpdateConnectionProperties will also do find and replace for full and partial dictionaries

Access a layer in a map.Get it’s connection properties.

Update connection properties dictionary.

Find this dictionary key/value pair.

Replace it with this key/value pair

Page 19: Python Mapautomation in ArcGIS Pro - Esri...Python Mapautomation in ArcGIS Pro Author Esri Subject 2019 European Developer Summit--Presentation Keywords Python Mapautomation in ArcGIS

Updating Data Sources advanced concepts – Layer.connectionProperties• Enterprise Geodatabase examples – change instance or server

Enterprise Geodatabase connection properties dictionary

Old database info

New database info

Update connection properties for project

Get layer’s connection properties.

Page 20: Python Mapautomation in ArcGIS Pro - Esri...Python Mapautomation in ArcGIS Pro Author Esri Subject 2019 European Developer Summit--Presentation Keywords Python Mapautomation in ArcGIS

Demo

UpdatingDatasources

Page 21: Python Mapautomation in ArcGIS Pro - Esri...Python Mapautomation in ArcGIS Pro Author Esri Subject 2019 European Developer Summit--Presentation Keywords Python Mapautomation in ArcGIS

Updating Data Sources – demo source code

DEMO

Page 22: Python Mapautomation in ArcGIS Pro - Esri...Python Mapautomation in ArcGIS Pro Author Esri Subject 2019 European Developer Summit--Presentation Keywords Python Mapautomation in ArcGIS

Maps and Layers

• Use “List” functions on appropriate objectsmp = aprx.listMaps(“parc*”)[0]lyr = mp.listLayers()[0]

- Warning - it is easy to forget to use [0]

• Common properties are available- Layers:

- definitionQuery, saveACopy, visible- Map:

- AddLayer, ClearSelection, defaultCamera

Page 23: Python Mapautomation in ArcGIS Pro - Esri...Python Mapautomation in ArcGIS Pro Author Esri Subject 2019 European Developer Summit--Presentation Keywords Python Mapautomation in ArcGIS

Layer

Symbology

Simple

UniqueValue

GraduatedColor

GraduatedSymbol

SymbolClassBreak

Group Item

ColorRamp

.symbology

.renderer / .updateRenderer

Renderer

.symbol

.classBreaks

.backgroundSymbol

.symbolTemplate

.groups .items.colorRamp

.symbol

.symbol

.applySymbolFromGallery()

Symbology Model

Page 24: Python Mapautomation in ArcGIS Pro - Esri...Python Mapautomation in ArcGIS Pro Author Esri Subject 2019 European Developer Summit--Presentation Keywords Python Mapautomation in ArcGIS

DemoUpdate Symbology

Page 25: Python Mapautomation in ArcGIS Pro - Esri...Python Mapautomation in ArcGIS Pro Author Esri Subject 2019 European Developer Summit--Presentation Keywords Python Mapautomation in ArcGIS

Sample to Update Symbology – demo source code

Page 26: Python Mapautomation in ArcGIS Pro - Esri...Python Mapautomation in ArcGIS Pro Author Esri Subject 2019 European Developer Summit--Presentation Keywords Python Mapautomation in ArcGIS

Layouts and layout elements

• Support zero to many- lyt = aprx.listLayouts(“Landscape”)[0]

• Find elements on a layout- txtElm = lyt.listElements(“text_element”, “title”)[0]- txtElm.text = “Some new title”

• Each element has a unique name

Page 27: Python Mapautomation in ArcGIS Pro - Esri...Python Mapautomation in ArcGIS Pro Author Esri Subject 2019 European Developer Summit--Presentation Keywords Python Mapautomation in ArcGIS

Map Frame and Camera

• Reference map frame on a layout- mf = lyt.listElements(“mapframe_element”)[0]

• Zoom to Bookmark / Layer- bkmk = mf.map.listBookmarks(“bookmark”)[0]- mf.zoomToBookmark(bkmk)- lyrExt = mf.getLayerExtent(lyr, True)- mf.camera.setExtent(lyrExt)

• Modify camera- cam = mf.camera- cam.X = x; cam.Y = y; cam.scale = sc- mf.camera = cam

Page 28: Python Mapautomation in ArcGIS Pro - Esri...Python Mapautomation in ArcGIS Pro Author Esri Subject 2019 European Developer Summit--Presentation Keywords Python Mapautomation in ArcGIS

Managing PDF documents

• Can create or open existing PDFs- myPDF = arcpy.mp.PDFDocumentCreate(r”C:\Temp\new.pdf”)- myPDF.appendPages(r”C:\Temp\someOther.pdf”)- myPDF.saveAndClose()

Page 29: Python Mapautomation in ArcGIS Pro - Esri...Python Mapautomation in ArcGIS Pro Author Esri Subject 2019 European Developer Summit--Presentation Keywords Python Mapautomation in ArcGIS

ModifyLayout & Export

Page 30: Python Mapautomation in ArcGIS Pro - Esri...Python Mapautomation in ArcGIS Pro Author Esri Subject 2019 European Developer Summit--Presentation Keywords Python Mapautomation in ArcGIS

SampleCode

Page 31: Python Mapautomation in ArcGIS Pro - Esri...Python Mapautomation in ArcGIS Pro Author Esri Subject 2019 European Developer Summit--Presentation Keywords Python Mapautomation in ArcGIS

Questions ?

Page 32: Python Mapautomation in ArcGIS Pro - Esri...Python Mapautomation in ArcGIS Pro Author Esri Subject 2019 European Developer Summit--Presentation Keywords Python Mapautomation in ArcGIS

Complete answersand select “Submit”

Scroll down to find the feedback section

Select the session you attended

Download the Esri Events app and find your event

Please Take Our Survey on the App

Page 33: Python Mapautomation in ArcGIS Pro - Esri...Python Mapautomation in ArcGIS Pro Author Esri Subject 2019 European Developer Summit--Presentation Keywords Python Mapautomation in ArcGIS