YOU ARE DOWNLOADING DOCUMENT

Please tick the box to continue:

Transcript
Page 1: Python Map Automation - Beyond the Basics of …maps.uky.edu/esri-uc/esri_uc_2k12/Files/476.pdf · Create new MXD based on web map ... -Download sample scripts ... UC, Python Map

Technical Workshops |

Esri International User Conference San Diego, California

Python Map Automation – Beyond the Basics of arcpy.mapping

Jeff Barrette Jeff Moulds

July 24, 2012

Page 2: Python Map Automation - Beyond the Basics of …maps.uky.edu/esri-uc/esri_uc_2k12/Files/476.pdf · Create new MXD based on web map ... -Download sample scripts ... UC, Python Map

What is map scripting (arcpy.mapping)?

• A python scripting API that allows you to: - Manage map documents, layer files, and the content

within them - Automate the exporting and printing of map documents

- Automate map production and create PDF map books - Extend Data Driven Pages

• A simple way to publish mapping tasks to the server environment

Page 3: Python Map Automation - Beyond the Basics of …maps.uky.edu/esri-uc/esri_uc_2k12/Files/476.pdf · Create new MXD based on web map ... -Download sample scripts ... UC, Python Map

Basic rules

• Reference an MXD using a path or “current” keyword - When using CURRENT

- Always run in foreground - May need to refresh (e.g., RefreshActiveView\TOC)

• Uniquely name all the objects you want to reference • Pre-author MXDs with all possible elements

- Can’t create new objects (e.g., north arrow, data frames) - Author the extra elements off the page - No "New Map" function, so keep an empty MXD available

• This is not a replacement for ArcObjects – we are trying to draw a line in the sand

Us You

“The Line”

Page 4: Python Map Automation - Beyond the Basics of …maps.uky.edu/esri-uc/esri_uc_2k12/Files/476.pdf · Create new MXD based on web map ... -Download sample scripts ... UC, Python Map

Jeff Barrette

Sample Application

Page 5: Python Map Automation - Beyond the Basics of …maps.uky.edu/esri-uc/esri_uc_2k12/Files/476.pdf · Create new MXD based on web map ... -Download sample scripts ... UC, Python Map

What’s new at 10.1

• What’s new à Mapping à What’s new for automating map workflows (http://esriurl.com/4634)

Page 6: Python Map Automation - Beyond the Basics of …maps.uky.edu/esri-uc/esri_uc_2k12/Files/476.pdf · Create new MXD based on web map ... -Download sample scripts ... UC, Python Map

What’s new in 10.1: cloning elements

• You can now clone text and graphic elements • This allows you to automate things like dynamic tables • Example: vertl = arcpy.mapping.ListLayoutElements(

mxd, “GRAPHIC_ELEMENT”, “VerticalLine”)[0]

vertl.elementPositionX = xPos;

vertl.elementPositionY = 4

vert1.elementHeight = 3

for line in range(1, numColumns+1):

vert_clone = vertLine.clone("_clone")

xPos = xPos + colWidth

vert_clone.elementPositionX = xPos

Page 7: Python Map Automation - Beyond the Basics of …maps.uky.edu/esri-uc/esri_uc_2k12/Files/476.pdf · Create new MXD based on web map ... -Download sample scripts ... UC, Python Map

What’s new in 10.1: symbology classes

• Layer.symbologyType r/o : string – Returns:

• GRADUATED_COLORS, GRADUATED_SYMBOLS, UNIQUE_VALUES • RASTER_CLASSIFIED, OTHER

• Layer.symbology r/o : Symbology Class • Example:

if lyr.symbologyType == “GRADUATED_COLORS”: lyr.symbology.numClasses = 10 lyr.symbology.valueField = “POP2007”

• General notes, can NOT change: - Symbology class - Individual symbols use arcpy.mapping.UpdateLayer - Classification methods

Page 8: Python Map Automation - Beyond the Basics of …maps.uky.edu/esri-uc/esri_uc_2k12/Files/476.pdf · Create new MXD based on web map ... -Download sample scripts ... UC, Python Map

Deployment - arcpy.mapping and Python Add-Ins

• ArcGIS 10.1 – Python Add-Ins - Add-in deployment of mapping

tools - Mechanism for deploying ArcMap

customizations - Online help: http://esriurl.com/4638 - Take mouse input, respond to app

events - FinishDrawing, DPP PageChange,

etc.

Python Add-in Wizard Download from: http://esriurl.com/4635

Related Session: Migrating your VBA applications to Desktop Add-ins

Page 9: Python Map Automation - Beyond the Basics of …maps.uky.edu/esri-uc/esri_uc_2k12/Files/476.pdf · Create new MXD based on web map ... -Download sample scripts ... UC, Python Map

What’s new in 10.1: legend items

• A referenced legend item in a .style file can then be used to update already existing legend items in a layout.

• Example: mxd = arcpy.mapping.MapDocument("current")

legend = arcpy.mapping.ListLayoutElements(mxd, "LEGEND_ELEMENT")[0]

styleItem = arcpy.mapping.ListStyleItems(

"USER_STYLE", "Legend Items", "MyNewStyle")[0]

for lyr in legend.listLegendItemLayers():

legend.updateItem(lyr, styleItem)

Page 10: Python Map Automation - Beyond the Basics of …maps.uky.edu/esri-uc/esri_uc_2k12/Files/476.pdf · Create new MXD based on web map ... -Download sample scripts ... UC, Python Map

Authoring geoprocessing tasks with Python scripts

• Things to consider help topic: http://esriurl.com/4656 • Before import arcpy path = r”C:\Project\maps” ... arcpy.mapping.ExportToPDF(mxd, path + "\\output.pdf")

• After import arcpy path = arcpy.env.scratchWorkspace

... arcpy.mapping.ExportToPDF(mxd, path + "\\output.pdf") arcpy.SetParameterAsText(1,path + "\\output.pdf")

Related Session: Geoprocessing with ArcGIS for Server

Page 11: Python Map Automation - Beyond the Basics of …maps.uky.edu/esri-uc/esri_uc_2k12/Files/476.pdf · Create new MXD based on web map ... -Download sample scripts ... UC, Python Map

New functions in 10.1 for server publishing and printing

- CreateMapSDDraft - Automate publishing map documents to map services

Map document arcpy.mapping Map service

- ConvertWebMapToMapDocument - Use with the ArcGIS web APIs for advanced web map printing

workflows

Web application High-quality output (e.g. PDF) arcpy.mapping

Page 12: Python Map Automation - Beyond the Basics of …maps.uky.edu/esri-uc/esri_uc_2k12/Files/476.pdf · Create new MXD based on web map ... -Download sample scripts ... UC, Python Map

Server printing out-of-the-box

• ArcGIS Server 10.1 and the ArcGIS web APIs support effortless web map printing via print services.

- Out-of-the-box print service and template maps ship with Server - Print services sample: http://esriurl.com/4651

Page 13: Python Map Automation - Beyond the Basics of …maps.uky.edu/esri-uc/esri_uc_2k12/Files/476.pdf · Create new MXD based on web map ... -Download sample scripts ... UC, Python Map

High quality server printing with arcpy.mapping

• Build customized versions of the new print services built into 10.1 server

• New arcpy.mapping method for converting Web Maps to MapDocuments: ConvertWebMapToMapDocument ()

• ConvertWebMapToMapDocument (webmap_json, {template_mxd}, {notes_gdb}, {extra_conversion_options})

Page 14: Python Map Automation - Beyond the Basics of …maps.uky.edu/esri-uc/esri_uc_2k12/Files/476.pdf · Create new MXD based on web map ... -Download sample scripts ... UC, Python Map

High quality server printing with arcpy.mapping

• Convert the web map to a map document • Full capabilities of arcpy.mapping on the document

- Modify content (e.g. replace service layers with high quality local vector data)

- Export using custom options - Export data driven pages - Export to PDF and insert additional pages

• Return the output file (PDF, PNG, etc.) or map book • Online help and examples

- http://esriurl.com/4600

Related Session: Supporting High-Quality Printing in Web Applications with ArcGIS 10.1 for Server

Page 15: Python Map Automation - Beyond the Basics of …maps.uky.edu/esri-uc/esri_uc_2k12/Files/476.pdf · Create new MXD based on web map ... -Download sample scripts ... UC, Python Map

Demo: High quality server printing with arcpy.mapping

Map service tiled cache Vector data

• Print high quality vector layers instead of tiled image cache of service layers § Vector layers will be staged in template map documents

Page 16: Python Map Automation - Beyond the Basics of …maps.uky.edu/esri-uc/esri_uc_2k12/Files/476.pdf · Create new MXD based on web map ... -Download sample scripts ... UC, Python Map

Demo: High quality server printing with arcpy.mapping • Reference the custom arcpy.mapping based GP service

Page 17: Python Map Automation - Beyond the Basics of …maps.uky.edu/esri-uc/esri_uc_2k12/Files/476.pdf · Create new MXD based on web map ... -Download sample scripts ... UC, Python Map

Demo: High quality server printing with arcpy.mapping

Arcpy.mapping code used in custom geoprocessing service

Get web map JSON

Export PDF

Create new MXD based on web map

Get template MXD

Remove service layers

Output file of job

Page 18: Python Map Automation - Beyond the Basics of …maps.uky.edu/esri-uc/esri_uc_2k12/Files/476.pdf · Create new MXD based on web map ... -Download sample scripts ... UC, Python Map

High quality server printing with arcpy.mapping

• Use the web help - updated samples and discussion - two new tutorials:

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

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

Page 19: Python Map Automation - Beyond the Basics of …maps.uky.edu/esri-uc/esri_uc_2k12/Files/476.pdf · Create new MXD based on web map ... -Download sample scripts ... UC, Python Map

Publishing map services with arcpy.mapping

• arcpy.mapping.CreateMapSDDraft • Workflow from map document to map service • Use python for:

- Publishing automated analysis results - Scheduled service upgrades - Batch migration from 10.0 to 10.1

Create SDDraft and edit XML

(arcpy.mapping)

arcpy.mapping.CreateMapSDDraft()

Prepare MXDs (arcpy.mapping)

arcpy.mapping.MapDocument()

Stage and Publish Map Service

(arcpy server GP tools) arcpy.StageService_server() arcpy.UploadServiceDefinition_server()

Page 20: Python Map Automation - Beyond the Basics of …maps.uky.edu/esri-uc/esri_uc_2k12/Files/476.pdf · Create new MXD based on web map ... -Download sample scripts ... UC, Python Map

Publishing map services with arcpy.mapping

Sample: CreateMapSDDraft (arcpy.mapping)

Reference a MXD

Stage and publish Map Service

Create and analyze SDDraft for errors

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

Page 21: Python Map Automation - Beyond the Basics of …maps.uky.edu/esri-uc/esri_uc_2k12/Files/476.pdf · Create new MXD based on web map ... -Download sample scripts ... UC, Python Map

Publishing other service types with python

• Two new functions coming at 10.1 sp1: - arcpy.CreateGPSDDraft()

- Create geoprocessing services with Python - arcpy.CreateGeocodeSDDraft()

- Create geocoding services with Python

Page 22: Python Map Automation - Beyond the Basics of …maps.uky.edu/esri-uc/esri_uc_2k12/Files/476.pdf · Create new MXD based on web map ... -Download sample scripts ... UC, Python Map

Resources available

• ArcGIS Resource Center (web help) - http://esriurl.com/4623

- Alphabetical lists of classes and functions - Detailed discussions - Multiple sample scripts for each class and function topic

• ArcGIS Resource Center (forums) - Map Automation: http://esriurl.com/4624 - Python: http://esriurl.com/4625

• ArcGIS Online – arcpy.mapping / Map Automation group - http://esriurl.com/4626

- Download sample scripts

Page 23: Python Map Automation - Beyond the Basics of …maps.uky.edu/esri-uc/esri_uc_2k12/Files/476.pdf · Create new MXD based on web map ... -Download sample scripts ... UC, Python Map

Related sessions

Wednesday • 8:30-9:45 – Geoprocessing with ArcGIS for Server (Room 4) • 8:30-9:45 – Introduction to arcpy.mapping (Room 6D) • 8:30-9:45 – Supporting High-Quality Printing in Web Applications

for ArcGIS 10.1 for Server (Room 7A/B) • 10:15-11:30 – Building Map Books (Room 6F) Thursday • 8:30-9:45 – Geoprocessing with ArcGIS for Server (Room 9) • 8:30-9:45 – Introduction to arcpy.mapping (Room 8) • 8:30-9:45 – Supporting High-Quality Printing in Web Applications

for ArcGIS 10.1 for Server (Room 7A/B) • 10:15-11:30 Migrating your VBA Applications to Desktop Add-ins

(Room 6A) • 3:15-4:30 – Building Map Books (Room 8)

Page 24: Python Map Automation - Beyond the Basics of …maps.uky.edu/esri-uc/esri_uc_2k12/Files/476.pdf · Create new MXD based on web map ... -Download sample scripts ... UC, Python Map

• Thank you for attending

• Have fun at UC2012

• Open for Questions

• Please fill out the evaluation:

www.esri.com/ucsessionsurveys

First Offering ID: 624

Second Offering ID: 1796


Related Documents