You are on page 1of 23

Python Scripting for Map Automation in y g

ArcGIS 10
Michael Grossman Michael Grossman
Jeff Barrette
What is map scripting (aka What is map scripting (aka arcpy mapping arcpy mapping)? )? What is map scripting (aka What is map scripting (aka arcpy.mapping arcpy.mapping)? )?
A new mapping module that is part of the geoprocessing A new mapping module that is part of the geoprocessing
ArcPy ArcPy site site--package package
A th i ti API th t ll t A th i ti API th t ll t A python scripting API that allows our users to: A python scripting API that allows our users to:
Manage map documents, layer files, and the data within them Manage map documents, layer files, and the data within them
Find a layer with data source X and replace with Y Find a layer with data source X and replace with Y Find a layer with data source X and replace with Y Find a layer with data source X and replace with Y
Update a layers symbology in many MXDs Update a layers symbology in many MXDs
Generate reports that lists document information Generate reports that lists document information
Data sources broken layers spatial reference info etc Data sources broken layers spatial reference info etc Data sources, broken layers, spatial reference info, etc. Data sources, broken layers, spatial reference info, etc.
Automate the exporting and printing of map documents Automate the exporting and printing of map documents
A t t d ti d t PDF b k A t t d ti d t PDF b k Automate map production and create PDF map books Automate map production and create PDF map books
Who is arcpy mapping for? Why was it built? Who is arcpy mapping for? Why was it built? Who is arcpy.mapping for? Why was it built? Who is arcpy.mapping for? Why was it built?
An easy to use, productive scripting environment for the An easy to use, productive scripting environment for the
GIS Analyst. GIS Analyst.
Courser grained object model Courser grained object model g j g j
Not a complete replacement for ArcObjects Not a complete replacement for ArcObjects
An environment to use for basic map/layer management An environment to use for basic map/layer management p y g p y g
and map automation tasks and map automation tasks
A simple way to publish mapping tasks to the server A simple way to publish mapping tasks to the server
environment. environment.
arcpy.mapping scripts can be easily published as arcpy.mapping scripts can be easily published as
geoprocessing tools geoprocessing tools g p g g p g
Demonstration #1 Demonstration #1 Demonstration #1 Demonstration #1
Brief introduction to an arcpy.mapping script Brief introduction to an arcpy.mapping script
Find and replace text in an ArcMap layout Find and replace text in an ArcMap layout
Running arcpy mapping scripts Running arcpy mapping scripts Running arcpy.mapping scripts Running arcpy.mapping scripts
arcpy.mapping is part of arcpy.mapping is part of
the Geoprocessing (GP) the Geoprocessing (GP)
framework framework
Run in wide variety of Run in wide variety of
places places
Script tool in ArcMap or Script tool in ArcMap or Script tool in ArcMap or Script tool in ArcMap or
ArcCatalog ArcCatalog
Python Window in ArcMap Python Window in ArcMap
Standalone python Standalone python - - from from
IDE, from the command IDE, from the command
line, or as a scheduled line, or as a scheduled
t k t k task task
Run as a GP Service in Run as a GP Service in
ArcGIS Server ArcGIS Server
Tour of arcpy mapping Tour of arcpy mapping Tour of arcpy.mapping Tour of arcpy.mapping
Overview Overview
arcpy
i core sa ga mapping
Tour of arcpy mapping Tour of arcpy mapping Tour of arcpy.mapping Tour of arcpy.mapping
Managing Documents and Layers Managing Documents and Layers Managing Documents and Layers Managing Documents and Layers
CLASSES CLASSES
FUNCTIONS FUNCTIONS
MapDocument MapDocument
Layer Layer
TableView TableView
MapDocument MapDocument
Layer Layer
ListBrokenDataSources ListBrokenDataSources
LabelClass LabelClass
DataFrame DataFrame
DataFrameTime DataFrameTime
GraphicElement GraphicElement
ListDataFrames ListDataFrames
ListLayers ListLayers
ListLayoutElements ListLayoutElements
ListPrinterNames ListPrinterNames
LegendElement LegendElement
PictureElement PictureElement
TextElement TextElement
MapSurroundElement MapSurroundElement
ListTableViews ListTableViews
AddLayer AddLayer
AddLayerToGroup AddLayerToGroup
InsertLayer InsertLayer
M L M L
PictureElement PictureElement
MoveLayer MoveLayer
RemoveLayer RemoveLayer
UpdateLayer UpdateLayer
Tour of arcpy mapping Tour of arcpy mapping Tour of arcpy.mapping Tour of arcpy.mapping
Printing Exporting Server Publishing Map Books Printing Exporting Server Publishing Map Books Printing, Exporting, Server Publishing, Map Books Printing, Exporting, Server Publishing, Map Books
CLASSES CLASSES
FUNCTIONS FUNCTIONS
DataDrivenPages DataDrivenPages
PDFDocument PDFDocument
ExportToAI ExportToAI
ExportToBMP ExportToBMP
ExportToEMF ExportToEMF
ExportToEPS ExportToEPS
ExportToGIF ExportToGIF
ExportToJPEG ExportToJPEG
ExportToPDF ExportToPDF
GG ExportToPNG ExportToPNG
ExportToSVG ExportToSVG
ExportToTIFF ExportToTIFF
PDFDocumentCreate PDFDocumentCreate
PDFD O PDFD O PDFDocumentOpen PDFDocumentOpen
PrintMap PrintMap
PublishMSDToServer PublishMSDToServer
AnalyzeForMSD AnalyzeForMSD
C tT MSD C tT MSD ConvertToMSD ConvertToMSD
arcpy mapping for Map Documents (MXDs) arcpy mapping for Map Documents (MXDs) arcpy.mapping for Map Documents (MXDs) arcpy.mapping for Map Documents (MXDs)
Opening Map Documents (MXD) with arcpy.mapping Opening Map Documents (MXD) with arcpy.mapping
Use the arcpy.mapping.MapDocument function Use the arcpy.mapping.MapDocument function
Takes a path to MXD file or special keyword " CURRENT" Takes a path to MXD file or special keyword " CURRENT" Takes a path to MXD file or special keyword CURRENT Takes a path to MXD file or special keyword CURRENT
arcpy mapping for Map Documents (MXDs) arcpy mapping for Map Documents (MXDs) arcpy.mapping for Map Documents (MXDs) arcpy.mapping for Map Documents (MXDs)
The CURRENT keyword versus MXDs on disk The CURRENT keyword versus MXDs on disk
Get map from disk Get map from disk Get map from disk Get map from disk
mapDoc = arcpy.mapping.MapDocument( mapDoc = arcpy.mapping.MapDocument(r" C r" C::\\Maps Maps\\LocalGovernmentInfrastructure.mxd" ) LocalGovernmentInfrastructure.mxd" )
Get map from current ArcMap session Get map from current ArcMap session Get ap o cu e t c ap sess o Get ap o cu e t c ap sess o
mapDoc = arcpy.mapping.MapDocument(" CURRENT" ) mapDoc = arcpy.mapping.MapDocument(" CURRENT" )
When using CURRENT When using CURRENT
Always run in foreground (checkbox in script tool props) Always run in foreground (checkbox in script tool props)
Be wary of open conflicts, file contention Be wary of open conflicts, file contention
Limitations and pre Limitations and pre--authoring authoring
No " New Map" function, so keep an empty MXD available No " New Map" function, so keep an empty MXD available
Demonstration #2 Demonstration #2 Demonstration #2 Demonstration #2
Working with Map Documents (MXDs) Working with Map Documents (MXDs)
A standalone script that creates a new MXD for each data frame A standalone script that creates a new MXD for each data frame
Use the Python Window to update a data frame name Use the Python Window to update a data frame name
arcpy mapping for Map Layers and Data Frames arcpy mapping for Map Layers and Data Frames arcpy.mapping for Map Layers and Data Frames arcpy.mapping for Map Layers and Data Frames
The List functions The List functions
ListLayers ListLayers
ListDataFrames ListDataFrames
Watch the list indexes (you may often forget to use [0]) Watch the list indexes (you may often forget to use [0])
df df = = arcpy.mapping.ListDataFrames arcpy.mapping.ListDataFrames(MXD)[0] (MXD)[0]
DataFrame properties and methods DataFrame properties and methods DataFrame properties and methods DataFrame properties and methods
Map Navigation Map Navigation
DataFrameTime DataFrameTime
arcpy mapping for Map Layers and Data Frames arcpy mapping for Map Layers and Data Frames arcpy.mapping for Map Layers and Data Frames arcpy.mapping for Map Layers and Data Frames
Layer functions Layer functions
FUNCTIONS FUNCTIONS
Layer Layer
ListLayers ListLayers
ListTableViews ListTableViews
AddLayer AddLayer
AddLayerToGroup AddLayerToGroup
InsertLayer InsertLayer
MoveLayer MoveLayer
RemoveLayer RemoveLayer
UpdateLayer UpdateLayer
arcpy mapping for Map Layers and Data Frames arcpy mapping for Map Layers and Data Frames arcpy.mapping for Map Layers and Data Frames arcpy.mapping for Map Layers and Data Frames
When and what to pre When and what to pre--author for Map Document scenarios author for Map Document scenarios
Layer Symbology (aka Renderer) properties are not accessible Layer Symbology (aka Renderer) properties are not accessible
Pre Pre- -Author Layer files and use Author Layer files and use UpdateLayer UpdateLayer or data source or data source yy Up y Up y
methods to connect it to data methods to connect it to data
Scenarios for updating layers Scenarios for updating layers Scenarios for updating layers Scenarios for updating layers
changing layer symbology changing layer symbology
changing layer type changing layer type
eg eg. batch replace a traditional . batch replace a traditional featureclass featureclass "" basemap basemap" layer with a " layer with a
basemap basemap layer from a server layer from a server
arcpy mapping for Map Layers and Data Frames arcpy mapping for Map Layers and Data Frames arcpy.mapping for Map Layers and Data Frames arcpy.mapping for Map Layers and Data Frames
Updating Data Sources Updating Data Sources
use arcpy.mapping for migrating Map Documents and Layer use arcpy.mapping for migrating Map Documents and Layer
files to new data sources. Batch migration. files to new data sources. Batch migration.
Fancier scripts can help mitigate migration pain: SQL syntax Fancier scripts can help mitigate migration pain: SQL syntax
changes, etc. changes, etc.
Demonstration #3 Demonstration #3 Demonstration #3 Demonstration #3
Working with Map Layers and Data Frames Working with Map Layers and Data Frames
A script A script that finds a layer and turns it on that finds a layer and turns it on
A script that updates layer data sources A script that updates layer data sources
A script that replaces a layer A script that replaces a layer A script that replaces a layer A script that replaces a layer
arcpy mapping for the Page Layout arcpy mapping for the Page Layout arcpy.mapping for the Page Layout arcpy.mapping for the Page Layout
When and what to pre When and what to pre--author author
for layout manipulation for layout manipulation
scenarios scenarios
Name your layout elements Name your layout elements
Cannot add new elements, so Cannot add new elements, so
pre pre--author and hide off page if author and hide off page if pre pre author and hide off page if author and hide off page if
necessary necessary
Demonstration #4 Demonstration #4 Demonstration #4 Demonstration #4
Working with layout elements Working with layout elements
A script tool to find a picture element and change its data source A script tool to find a picture element and change its data source
arcpy mapping for Printing and Exporting arcpy mapping for Printing and Exporting arcpy.mapping for Printing and Exporting arcpy.mapping for Printing and Exporting
Export functions Export functions
Print Functions Print Functions
FUNCTIONS FUNCTIONS
Print Functions Print Functions
Map Server Publishing Map Server Publishing
Map Books Map Books
ExportToAI ExportToAI
ExportToBMP ExportToBMP
ExportToEMF ExportToEMF
The The PDFDocument PDFDocument
class class
ExportToEPS ExportToEPS
ExportToGIF ExportToGIF
ExportToJPEG ExportToJPEG
ExportToPDF ExportToPDF
GG
CLASSES CLASSES
ExportToPNG ExportToPNG
ExportToSVG ExportToSVG
ExportToTIFF ExportToTIFF
PDFDocumentCreate PDFDocumentCreate
PDFD O PDFD O
CLASSES CLASSES
DataDrivenPages DataDrivenPages
PDFDocument PDFDocument
PDFDocumentOpen PDFDocumentOpen
PrintMap PrintMap
PublishMSDToServer PublishMSDToServer
AnalyzeForMSD AnalyzeForMSD
C tT MSD C tT MSD ConvertToMSD ConvertToMSD
Demonstration #5 Demonstration #5 Demonstration #5 Demonstration #5
Map output and map books Map output and map books
A i t t l t t d t d i t lti PDF A i t t l t t d t d i t lti PDF A script tool to export data driven pages to multipage PDF A script tool to export data driven pages to multipage PDF
A script tool to create a temporal map book A script tool to create a temporal map book
A full custom application ported from VBA A full custom application ported from VBA pp p pp p
Resources available Resources available Resources available Resources available
Desktop help Desktop help
Geoprocessing Geoprocessing The The ArcPy ArcPy site package site package Mapping module Mapping module
Alphabetical lists of classes and functions Alphabetical lists of classes and functions pp
Detailed discussions Detailed discussions
Multiple sample scripts for each class and function topic Multiple sample scripts for each class and function topic
ArcGIS Resource Center ArcGIS Resource Center
Download sample script tools Download sample script tools p p p p
see the Geoprocessing Resource Center Gallery see the Geoprocessing Resource Center Gallery
Watch video demonstrations Watch video demonstrations
Monitor the user forums/discussions Monitor the user forums/discussions Monitor the user forums/discussions Monitor the user forums/discussions
We want your feedback We want your feedback We want your feedback We want your feedback
Get access to ArcGIS 10 Pre Get access to ArcGIS 10 Pre--release release
Try using it for you day to day tasks Try using it for you day to day tasks
Help us indentify future requirements Help us indentify future requirements
Thank you for your attention Thank you for your attention Thank you for your attention. Thank you for your attention.
Questions? Questions? Questions? Questions?

You might also like