Advanced Map Automation with Python Brooke Reams
Advanced Map Automation with PythonBrooke Reams
Topics
• Use Cases
• Guidelines
• ArcMap vs. Pro
• Demos
- Import Documents to ArcGIS Pro
- Update Join Table Primary Key
- Update Data Sources
- Modify symbology
Map Automation Use Cases
map automation
• Generate report
- Layers, data sources, extents
• Update or replace data sources
• Find/replace text/picture elements
• Automate map creation for
daily/weekly situation reports
- Hurricanes, wildfires, flooding, etc
• Create a map book
- Map pages + title page, table of
contents, tabular info, etc
Map Automation Guidelines
Must work with
*existing* maps
and/or layer files
"CURRENT"
or
Reference a project
on disk or use
CURRENT key word
Author all objects
with a unique name
– use wildcard
Map Automation – ArcMap vs. Pro
• Objects (and concepts)
• Sub Module Name
• API Design
• Python Version
Objects (and concepts)
Map Document
ArcMap
2D Only
Data Frame
Single Layout
Pro
ArcGIS Project
2D & 3D
Multiple Layouts
Map Frame
Map
Map
ArcGIS Project
Map
Frame
Layout
Map
Frame
ArcGIS Project
Sub Module Name
Pro
arcpy.mp
ArcMap
arcpy.mapping
arcpy.mp API
• Get map
layer’s data
source
arcpy.mp
• Get map layer’s data source
# Create ArcGISProject objectaprx = arcpy.mp.ArcGISProject("CURRENT")
# Get Government Services mapmap = aprx.listMaps("Govern*")[0]
# Get Police Stations layerlyr = map.listLayers("Police*")[0]
# Print layer's data sourceprint (lyr.dataSource)
D:\DEMO\LGIM.gdb\PoliceStations
API Design
Functions
ArcMap Pro
Methods
Python Version
Pro
Python 3.x
ArcMap
Python 2.x
Map Automation – ArcMap vs. Pro
• Objects (and concepts)
• Sub Module Name
• API Design
• Python Version
Import Documents to ArcGIS Pro
.mxd
.3dd.sxd
.aprx.aprx
.aprx
.aprx
Import existing documents to Pro with arcpy.mp
• importDocument – method of the ArcGIS Project Class
Import
Documents to
ArcGIS Pro
Image Source: http://www.newsheadlines.com.ng
connectionProperties
• Property
• Layer & Table Classes
• Read/Write
• Returns Dictionary
import arcpy, pprint
aprx = arcpy.mp.ArcGISProject("D:\Demo\TaxMap.aprx")map = aprx.listMaps("Parcel Map")[0]lyr = map.listLayers("Parcels")[0]pprint.pprint(lyr.connectionProperties)
>>> {'connection_info': {'database': 'C:\\Data\\LocalGovernment.gdb'},
'dataset': 'Parcels',
'workspace_factory': 'File Geodatabase'}
.shp
.gdb
.sde
Workspace Type
Joins & Relates
connectionProperties
• File Geodatabase
• SDE Geodatabase
>>> {'connection_info': {'authentication_mode': 'OSA',
'database': 'LocalGovernment',
'db_connection_properties': 'breams\\sqlexpress',
'dbclient': 'sqlserver',
'instance': 'sde:sqlserver:breams\\sqlexpress',
'server': 'breams',
'version': 'dbo.DEFAULT'},
'dataset': 'LocalGovernment.DBO.Parcels',
'workspace_factory': 'SDE'}
>>> {'connection_info': {'database': 'C:\\Data\\LocalGovernment.gdb'},
'dataset': 'Parcels',
'workspace_factory': 'File Geodatabase'}
connectionProperties
• Layer that participates in a join
>>> {'cardinality': 'one_to_many',
'destination': {'connection_info': {'database': 'C:\\DATA\\LocalGovernment.gdb'},
'dataset': 'ParkRecComment',
'workspace_factory': 'File Geodatabase'},
'foreign_key': 'FACILITYID',
'join_forward': False,
'join_type': 'left_outer_join',
'primary_key': 'FACILITYID',
'source': {'connection_info': {'database': 'C:\\DATA\\LocalGovernment.gdb'},
'dataset': 'Park',
'workspace_factory': 'File Geodatabase'}}
• Layer that does NOT participate in a join
>>> {'connection_info': {'database': 'C:\\Data\\LocalGovernment.gdb'},
'dataset': 'Parcels',
'workspace_factory': 'File Geodatabase'}
updateConnectionProperties()
• Method on:
- ArcGISProject class
- LayerFile class
- Map class
Symbology with arcpy.mp
• New at Pro 1.4
• Change layer renderer type:
- GraduateColorsRenderer
- GraduatedSymbolsRenderer
- SimpleRenderer
- UniqueValueRenderer
• Change renderer properties
• Change symbols!!!
Simple
Graduated
Colors
Graduated
Symbols
Unique
Value
Re
nd
ere
r Typ
es
Symbology RendererLayer
Review
• Map automation guidelines
• Migrating from ArcMap to Pro
• Import Documents to Pro
• Update connection properties
• Modify symbology
Questions?
Please Take Our Survey on the Esri Events App!
Select the session
you attended
Scroll down to find
the survey
Complete Answers
and Select “Submit”
Download the Esri Events
app and find your event
Print Your Certificate of Attendance
Print stations located in the 140 Concourse
Monday
12:30 PM – 6:30 PM
GIS Solutions Expo,
Hall B
5:15 PM– 6:30 PM
Expo Social,
Hall B
Tuesday
10:45 AM– 5:15 PM
GIS Solutions Expo,
Hall B
6:30 PM– 9:30 PM
Networking Reception,
Smithsonian National Air
and Space Museum