python map automation: beyond the basics of arcpy.mapping

23
Python Map Automation: Beyond the Basics of arcpy.mapping and Migration to ArcGIS Pro Jeff Barrette Jeff Moulds March 811, 2016 | Palm Springs, CA Esri Developer Summit

Upload: others

Post on 06-Apr-2022

18 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Python Map Automation: Beyond the Basics of arcpy.mapping

Python Map Automation: Beyond

the Basics of arcpy.mapping and

Migration to ArcGIS Pro

Jeff Barrette

Jeff Moulds

March 8–11, 2016 | Palm Springs, CA

Esri Developer Summit

Page 2: Python Map Automation: Beyond the Basics of arcpy.mapping

arcpy.(m)a(p)ping samples

http://esriurl.com/8899

Page 3: Python Map Automation: Beyond the Basics of arcpy.mapping

DDPwithDynamicTablesAndGraphs_10.1_v1

Page 4: Python Map Automation: Beyond the Basics of arcpy.mapping

MultipleElementLayoutManager_10.0_v1

Page 5: Python Map Automation: Beyond the Basics of arcpy.mapping

GenerateMapBookWithIndexPages_10_v2

Page 6: Python Map Automation: Beyond the Basics of arcpy.mapping

arcpy.(m)a(p)ping samples

http://esriurl.com/8899

Page 7: Python Map Automation: Beyond the Basics of arcpy.mapping

Advanced Web Map Printing with Python

Web API / WebApp Builder

High quality vector output (e.g. PDF)

arcpy.mapping

Page 8: Python Map Automation: Beyond the Basics of arcpy.mapping

Three Web Map printing development paths

Related Session: Enabling High-Quality Printing in Web Applications (Tuesday @ 4:00 – 5:00 Demo Theater 1 - Showcase)

Also search your agenda for “Web AppBuilder” – many sessions!

WebApp Builder + out of the box or hosted print service.

- No coding!

WebApp Builder + custom python print service.

- No JavaScript or html required

ArcGIS JavaScript Web API + custom python print service.

Page 9: Python Map Automation: Beyond the Basics of arcpy.mapping

• Full capabilities of arcpy.mapping:

- Swap out service layers for local vector data for vector PDF output

- Export using advanced options

- Export data driven pages

- Export to PDF and insert additional pages (title page, reports, etc.)

- Controlling the appearance of the legend

- Etc.

• Return a printer-friendly output file (PDF, PNG, etc.)

Advanced server printing with arcpy.mapping

Page 10: Python Map Automation: Beyond the Basics of arcpy.mapping

• Build web apps with customized versions of the out-of-the-box print

service

• Arcpy.mapping method for converting Web Maps to Map Documents:

• ConvertWebMapToMapDocument (webmap_json, {template_mxd},

{notes_gdb}, {extra_conversion_options})

Advanced server printing with arcpy.mapping

Web app / Builder High-quality vector output (e.g. PDF)

arcpy.mapping.

ConvertWebMapToMapDocument

Online help and examples http://esriurl.com/4600

Page 11: Python Map Automation: Beyond the Basics of arcpy.mapping

• Output or print vector layers instead of “flat” image of service layers

Vector layers will be staged in template map document

Demo: Web app to export vector PDF using arcpy.mapping

Map service tiled cache (low dpi)

Vector data (or high dpi image)

Output PDF viewed in Adobe Reader

Page 12: Python Map Automation: Beyond the Basics of arcpy.mapping

Python code used in custom GP service

Demo: Web app to export vector PDF using arcpy.mapping

Get web map JSON

Export PDF

Create new MXD based on

web map

Get template MXD

Remove service layers

Output file of job

Page 13: Python Map Automation: Beyond the Basics of arcpy.mapping

• Two tutorials in the help:

- Basic vector web map printing: http://esriurl.com/4601

- Advanced web map printing: http://esriurl.com/4602

Web app to export vector PDF using arcpy.mapping

Georeferencing

Layers in map

Output format

Layers in legend

Page 14: Python Map Automation: Beyond the Basics of arcpy.mapping

Publishing map services with arcpy.mapping• arcpy.mapping.CreateMapSDDraft(map_document, out_sddraft, service_name,

{server_type}, {connection_file_path}, {copy_data_to_server}, {folder_name}, {summary},

{tags})

• Workflow to convert map document to map service.

• Use python scripts for:

- Scheduled service updates. E.g. nightly.

- Publishing automated analysis results.

- Batch publishing.

Create SDDraft file(and optionally edit XML)

arcpy.mapping.CreateMapSDDraft()

Reference & prepare MXDs

arcpy.mapping.MapDocument()

Stage and Publish Map Service(arcpy server GP tools)

arcpy.StageService_server()

arcpy.UploadServiceDefinition_server()

Page 15: Python Map Automation: Beyond the Basics of arcpy.mapping

Publishing map services with arcpy.mapping

Sample script: CreateMapSDDraft

Reference MXD

Stage and publish

Map Service

Create and analyze

sddraft for errors,

warnings, etc.

Online help and samples: http://esriurl.com/4598

Publish and overwrite a hosted feature service on ArcGIS.com blog post: http://esriurl.com/9754

Server connection,

service properties,

etc.

Page 16: Python Map Automation: Beyond the Basics of arcpy.mapping

Migrating to ArcGIS Pro

arcpy.mp

Page 17: Python Map Automation: Beyond the Basics of arcpy.mapping

ArcGIS Pro arcpy.mp sample

http://esriurl.com/8948

UC2015 - Technical Workshop - Advanced Map Automation with Python

Page 18: Python Map Automation: Beyond the Basics of arcpy.mapping

Function for importing 10.x documents into ArcGIS Pro Projects

• ArcGISProject.importDocument(document_path, {include_layout})

.MXDs

ArcGIS Pro

Projects

Looping through MXDs in a

folder.

Reference a template APRX.

Import MXD into the APRX.

Save the project.

Page 19: Python Map Automation: Beyond the Basics of arcpy.mapping

Function for importing 10.x documents into ArcGIS Pro Projects

• ArcGISProject.importDocument(document_path, {include_layout})

.MXDs

.3DDs.SXDs

ArcGIS Pro

Project

DEMO

Page 20: Python Map Automation: Beyond the Basics of arcpy.mapping

Updating Data Sources in ArcGIS Pro

Project/Map/Layer/Table/LayerFile.updateConnectionProperties (current_connection_info,

new_connection_info,

{auto_update_joins_and_relates}…)

Find this path:

Replace it with this path:

.APRXs

Page 21: Python Map Automation: Beyond the Basics of arcpy.mapping

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 that what is available in

Project/Map/Layer/Table/LayerFile.updateConnectionproperties()

Access a layer in a map.

File Geodatabase layer

connection properties dictionary

Get layer’s connection properties.

DEMO

Page 22: Python Map Automation: Beyond the Basics of arcpy.mapping

Two ways to use the connection properties dictionary – enterprise geodatabase examples

1. Write directly to the dictionary

Get layer connection properties

Update dictionary

Set layer connection properties

Old database info

New database info

Set layer connection properties

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

Page 23: Python Map Automation: Beyond the Basics of arcpy.mapping