35
MXD, Maps, Layers arcpy.mapping Classe

MXD, Maps, Layers arcpy.mapping Classes. Without opening ArcMap, wouldn’t it be nice to Get or update MapDocument (MXD) properties e.g. title, keywords,

Embed Size (px)

Citation preview

Page 1: MXD, Maps, Layers arcpy.mapping Classes. Without opening ArcMap, wouldn’t it be nice to Get or update MapDocument (MXD) properties e.g. title, keywords,

MXD, Maps, Layers

arcpy.mapping Classes

Page 2: MXD, Maps, Layers arcpy.mapping Classes. Without opening ArcMap, wouldn’t it be nice to Get or update MapDocument (MXD) properties e.g. title, keywords,

Without opening ArcMap, wouldn’t it be nice to

Get or update MapDocument (MXD) properties

e.g. title, keywords, relative path, author, etc

DataFrame propertiese.g. name, coordinate system, etc.

Layer propertiese.g. name, visibility, data source, symbology, etc.

Layout element propertiese.g. size, position,

Add, remove, move, and update layersSave MXD or LYR to earlier version for distributionBuild PDF map books

e.g. Export to PDF or insert into existing PDF

Page 5: MXD, Maps, Layers arcpy.mapping Classes. Without opening ArcMap, wouldn’t it be nice to Get or update MapDocument (MXD) properties e.g. title, keywords,

MapDocument Properties

Page 7: MXD, Maps, Layers arcpy.mapping Classes. Without opening ArcMap, wouldn’t it be nice to Get or update MapDocument (MXD) properties e.g. title, keywords,

MapDocument Properties & Methods

PropertiesactiveDataFrame (ro)

activeView (rw)

author (rw)

credits (rw)

dataDrivenPages (ro)

dateExported (ro)

datePrinted (ro)

dateSaved (ro)

description (rw)

filePath (ro)

hyperlinkBase (rw)

relativePaths (rw)

summary (rw)

tags (rw)

title (rw)

MethodsdeleteThumbnail()

findAndReplaceWorkspacePaths( find_workspace_path, replace_workspace_path, {validate})

makeThumbnail ()

replaceWorkspaces( old_workspace_path, old_workspace_type, new_workspace_path, new_workspace_type, {validate})

save ()

saveACopy( file_name, {version})

(ro) = read-only(rw) = read-write

Page 9: MXD, Maps, Layers arcpy.mapping Classes. Without opening ArcMap, wouldn’t it be nice to Get or update MapDocument (MXD) properties e.g. title, keywords,

DataFrame Properties

Page 10: MXD, Maps, Layers arcpy.mapping Classes. Without opening ArcMap, wouldn’t it be nice to Get or update MapDocument (MXD) properties e.g. title, keywords,

DataFrame Properties & Methods

Propertiescredits (rw)

description (rw)

displayUnits (rw)

elementHeight (rw)

elementPositionX (rw)

elementPositionY (rw)

elementWidth (rw)

extent (rw)

geographicTransformations (rw)

mapUnits (ro)

name (rw)

referenceScale (rw)

rotation (rw)

scale (rw)

spatialReference (rw)

time (ro)

type (ro)

MethodspanToExtent(extent)

zoomToSelectedFeatures()

Page 11: MXD, Maps, Layers arcpy.mapping Classes. Without opening ArcMap, wouldn’t it be nice to Get or update MapDocument (MXD) properties e.g. title, keywords,

Find DataFrames in MapDocument

Page 12: MXD, Maps, Layers arcpy.mapping Classes. Without opening ArcMap, wouldn’t it be nice to Get or update MapDocument (MXD) properties e.g. title, keywords,

Layer Properties

Page 13: MXD, Maps, Layers arcpy.mapping Classes. Without opening ArcMap, wouldn’t it be nice to Get or update MapDocument (MXD) properties e.g. title, keywords,

Find Layers in a DataFrame

i.e. All layers in all DataFrame’s

Page 15: MXD, Maps, Layers arcpy.mapping Classes. Without opening ArcMap, wouldn’t it be nice to Get or update MapDocument (MXD) properties e.g. title, keywords,

Layer Properties & Methods

Propertiesbrightness (rw)

contrast (rw)

credits (rw)

datasetName (rw)

dataSource (rw)

definitionQuery (rw)

description (rw)

isFeatureLayer (ro)

isGroupLayer (ro)

isRasterizingLayer (ro)

isRasterLayer (ro)

labelClasses (rw)

longName (ro)

name (rw)

serviceProperties (ro)

showLabels (rw)

transparency (rw)

visible (rw)

workspacePath (ro)

MethodsfindAndReplaceWorkspacePath( find_workspace_path, replace_workspace_path, {validate})

getExtent( {symbolized_extent})

getSelectedExtent( {symbolized_extent})

replaceDataSource( workspace_path, workspace_type, dataset_name, {validate})

save ()

saveACopy( file_name, {version})

supports( layer_property)

Selected properties

Layer = • .lyr file• Layer in DataFrame

Page 16: MXD, Maps, Layers arcpy.mapping Classes. Without opening ArcMap, wouldn’t it be nice to Get or update MapDocument (MXD) properties e.g. title, keywords,

Finding a specific layer in a DataFrame

Page 17: MXD, Maps, Layers arcpy.mapping Classes. Without opening ArcMap, wouldn’t it be nice to Get or update MapDocument (MXD) properties e.g. title, keywords,

Working with Layers

arcpy.mapping can’tCreate new map layers in DataFrame or .lyr files from scratch Change all layer properties in a script

arcpy.mapping canAdd lyr file to DataFrame & change selected layer properties

dataSource, definitionQuery, etc. (see “(rw)” on previous slide)

Apply symbology from existing lyr files to existing layers in DataFrame

Page 18: MXD, Maps, Layers arcpy.mapping Classes. Without opening ArcMap, wouldn’t it be nice to Get or update MapDocument (MXD) properties e.g. title, keywords,

Adding a Layer to a DataFrame

Page 19: MXD, Maps, Layers arcpy.mapping Classes. Without opening ArcMap, wouldn’t it be nice to Get or update MapDocument (MXD) properties e.g. title, keywords,

Managing Layers in a DataFrame

Function Description

AddLayer Add a layer to a data frame within a map document (.mxd) using simple placement options.

AddLayerToGroup Add a layer to a group layer within a map document (.mxd) using simple placement options.

InsertLayer Insert a layer at a specific location within a data frame or within a group layer in a map document (.mxd).

MoveLayer Move a layer to a specific location within a data frame or group layer in a map document (.mxd).

RemoveLayer Remove a single layer or group layer from a specific data frame. If there is more than one layer that meets the criteria, then only the first layer will be removed unless the script iterates through each layer in a returned list.

UpdateLayer Update all layer properties or just the symbology for a layer in a map document (.mxd) by extracting the information from a source layer.

Page 21: MXD, Maps, Layers arcpy.mapping Classes. Without opening ArcMap, wouldn’t it be nice to Get or update MapDocument (MXD) properties e.g. title, keywords,

Methods for fixing broken data sourcesMapDocument.findAndReplaceWorkspacePaths(find_workspace_path, replace_workspace_path, {validate})

MapDocument.replaceWorkspaces(old_workspace_path, old_workspace_type, new_workspace_path, new_workspace_type,

{validate})

Layer.findAndReplaceWorkspacePath(find_workspace_path, replace_workspace_path, {validate})

Layer.replaceDataSource(workspace_path, workspace_type, dataset_name, {validate})

TableView.findAndReplaceWorkspacePath(find_workspace_path, replace_workspace_path, {validate})

TableView.replaceDataSource(workspace_path, workspace_type, dataset_name,

{validate})

Page 22: MXD, Maps, Layers arcpy.mapping Classes. Without opening ArcMap, wouldn’t it be nice to Get or update MapDocument (MXD) properties e.g. title, keywords,

Fixing broken data source examples

Update all workspace paths for all the mxd’s in a folder from local system to UNC paths

Update all workspace paths to new folder and save to new mxd.

Page 23: MXD, Maps, Layers arcpy.mapping Classes. Without opening ArcMap, wouldn’t it be nice to Get or update MapDocument (MXD) properties e.g. title, keywords,

Page Layout elements

Page 26: MXD, Maps, Layers arcpy.mapping Classes. Without opening ArcMap, wouldn’t it be nice to Get or update MapDocument (MXD) properties e.g. title, keywords,

Text Element

Page 27: MXD, Maps, Layers arcpy.mapping Classes. Without opening ArcMap, wouldn’t it be nice to Get or update MapDocument (MXD) properties e.g. title, keywords,

RefreshActiveView() and RefreshTOC()

After changing the content of a DataFrame or Page Layout … arcpy.RefreshActiveView()

After changing items in the Table of Contents (add, remove, move, update layers) …arcpy.RefreshTOC()

Page 28: MXD, Maps, Layers arcpy.mapping Classes. Without opening ArcMap, wouldn’t it be nice to Get or update MapDocument (MXD) properties e.g. title, keywords,

Exporting maps to images (jpg)

Page 31: MXD, Maps, Layers arcpy.mapping Classes. Without opening ArcMap, wouldn’t it be nice to Get or update MapDocument (MXD) properties e.g. title, keywords,

Creating/Opening PDF Documents

Page 32: MXD, Maps, Layers arcpy.mapping Classes. Without opening ArcMap, wouldn’t it be nice to Get or update MapDocument (MXD) properties e.g. title, keywords,

PDFDocument.appendPages Example

Page 33: MXD, Maps, Layers arcpy.mapping Classes. Without opening ArcMap, wouldn’t it be nice to Get or update MapDocument (MXD) properties e.g. title, keywords,

Working with arcpy.mapping scripts

Python Window has nice help … but pain for defining/calling functions, debugging, etc.

Edit in PyScripter and use Load …

Page 34: MXD, Maps, Layers arcpy.mapping Classes. Without opening ArcMap, wouldn’t it be nice to Get or update MapDocument (MXD) properties e.g. title, keywords,

Help is not perfect

Should be:Find the MAPSURROUND_ELEMENT with the name "ScaleBar" and move it's x position (relative to its anchor point) to the center of the parentDataFrame.  Save this change to the MXD.

Update: ESRI listened to me:

Page 35: MXD, Maps, Layers arcpy.mapping Classes. Without opening ArcMap, wouldn’t it be nice to Get or update MapDocument (MXD) properties e.g. title, keywords,

MapDocument, DataFrame, Layer

DataFrame

MapDocument

Layer

DATAFRAME_ELEMENT

GRAPHIC_ELEMENT

LEGEND_ELEMENT

MAPSURROUND_ELEMENT

PICTURE_ELEMENT

GRAPHIC_ELEMENT

MapDocument.ActiveView = “PAGE_LAYOUT”

1:*

*