Map

Summary

The Map object is the primary object for referencing and managing layers and tables within an ArcGIS AllSource project.

Discussion

A Map in ArcGIS AllSource represents a collection of tabular and symbolized geographic layers and also persists information such as coordinate system, default views of the data, and various other metadata. The only way to visualize the contents of a map is in either a MapView, that is, as a tab in the application with its own table of contents, or in a map frame on a Layout. The same map can be displayed in multiple map views or map frames. If a layer is added to a map, all map views and map frames that reference that map will display the added layer. If you want a different collection of layers or tables to be displayed in different views, you will need to build and use different maps.

Maps are accessed using the listMaps function from the ArcGISProject object and the function returns a Python list of Map objects. It is important to uniquely name each map so a specific map can be easily referenced with the wildcard parameter that uses the name property. A map can also be accessed from a MapFrame object using the map property.

The createMap method on the ArcGISProject class allows you to create a map in a project. If you run a script from within the application, it will honor the basemap settings. If you run a script outside of the application, it will automatically add a topographic basemap and you will need to remove the basemap layer if not needed.

The openView method is also a way to open a map view. You may want to do a couple of things before calling openView. First, setting the defaultCamera prior to opening a new view will control the initial extent. Second, you may want to close other views with the closeViews method on the ArcGISProject class before opening your new view. The third sample below illustrates this workflow.

There are a number of methods available on the Map object that allow you to manage its collection of tabular and symbolized geographic layers. Layers and tables can be added (addLayer, addLayerToGroup, addTable, or insertLayer), removed (removeLayer or removeTable), and rearranged (moveLayer) within the list of existing layers and tables. The listLayers and listTables methods are how you reference Layers and Tables in a map.

Every map has a mapType property. It either has the value MAP, which represents a 2D map, or the value SCENE, which is a 3D map. One example for needing to know the mapType property is if you want to set the defaultCamera property. You can't apply a 3D Camera object to a 2D map or vice versa. Therefore, you should check the mapType value ahead of time.

The map class also supports getDefinition and setDefinition methods. For more detailed help, see Python CIM access.

Properties

PropertyExplanationData Type
defaultCamera
(Read and Write)

Provides the ability to get or set default Camera settings for a map.

Note:

Modifying the defaultCamera will not affect an existing view. This property is only applied when a new MapView is opened or a new MapFrame is inserted into a layout.

Camera
defaultView
(Read Only)

Used in conjunction with ConvertWebMapToArcGISProject in a web map printing web tool to return a map view to print or export.

MapView
excludeLayersFromClipping
(Read and Write)

A list of Layerobjects that will be excluded from map clipping if clipLayers has been set to True.

List
mapType
(Read Only)

Returns a string that reports the Map object type information. The possible values are:

  • BASEMAPReturned for basemaps
  • MAPReturned for map or stereo maps
  • SCENEReturned for local or global scenes
String
mapUnits
(Read Only)

Returns a string value that represents the map units set for the Map.

String
metadata
(Read and Write)

Get or set the map's Metadata class information.

Note:
Setting metadata is dependent on the ArcGISProject isReadOnly property value.

Metadata
name
(Read and Write)

Provides the ability to get or set the Map object's name as it appears in the table of contents and also the actual name of the element in a layout.

String
referenceScale
(Read and Write)

Provides the ability to get or set the reference scale for the Map. To clear the reference scale, set the value to 0.0

Double
spatialReference
(Read and Write)

Provides the ability to get or set the SpatialReference associated with the map.

SpatialReference
transformations
(Read Only)

Returns the horizontal and vertical transformations associated with the map as a Python Dictionary. The dictionary key for horizontal transformations is 2D and 3D for vertical transformations. To modify the existing transformations, use updateTransformations.

Dictionary
URI
(Read Only)

The Universal Resource Indicator for a map. It is a unique identifier for a map in a project and is sometimes required when using Python CIM access. Once a map is added and the URI is established, the value does not change over time. For example, if you modify the map's name, the URI will not change.

String

Method Overview

MethodExplanation
addBasemap (basemap_name)

The addBasemap method provides the ability to add or replace a basemap layer within a map.

addDataFromPath (data_path, {web_service_type}, {custom_parameters})

addDataFromPath allows you to add a Layer to a map in a project (.aprx) by providing a local path or URL.

addLayer (add_layer_or_layerfile, {add_position})

Provides the ability to add a Layer or LayerFile to a map within a project (.aprx) using basic placement options.

addLayerToGroup (target_group_layer, add_layer_or_layerfile, {add_position})

Provides the ability to add a Layer or the contents of a LayerFile to an existing group layer in a map within a project (.aprx) using basic placement options.

addTable (add_table)

Provides the ability to add a Table to a map within a project (.aprx).

addTableToGroup (target_group_layer, add_table)

Provides the ability to add a Table to an existing group layer in a map within a project (.aprx).

clearSelection ()

Clears the selection for all layers and tables in a map.

clipLayers (clip_object, {selection})

The clipLayers method sets the clipping options for a map.

copyBookmark (bookmark, {name})

The copyBookmark method copies a reference to a bookmark into the map.

createGraphicsLayer ({name})

The createGraphicsLayer method creates a graphics layer in a map.

createGroupLayer (name, {group_layer})

Allows you to create a group layer in a map within a project (.aprx).

exportBookmarks (out_bkmx)

The exportBookmarks method exports all bookmarks associated with the map to a bookmark file (.bkmx).

exportToMAPX (out_mapx)

Exports a Map to a map file.

getDefinition (cim_version)

Gets a map's CIM definition.

getWebLayerSharingDraft (server_type, service_type, service_name, {layers_and_tables})

Creates a sharing draft from a map that can be configured and shared to ArcGIS Enterprise or ArcGIS Online.

importBookmarks (bkmx_path)

The importBookmarks method imports all bookmarks from a bookmark file (.bkmx) into the map.

insertLayer (reference_layer, insert_layer_or_layerfile, {insert_position})

Provides the ability to add a Layer or LayerFile to a map within a project (.aprx) by specifying a specific location.

listBookmarks ({wildcard})

Returns a Python list of bookmark objects in a Map.

listBrokenDataSources ()

Returns a Python list of Layer or Table objects that have broken connections to their original source data within a map.

listLayers ({wildcard})

Returns a Python list of Layer objects that exist within a map.

listTables ({wildcard})

Returns a Python list of Table objects that exist within a map.

moveLayer (reference_layer, move_layer, {insert_position})

Provides the ability to move a layer or group layer in a map to a specific location within the same map.

openView ()

Opens and activates a new map view pane in the application.

removeBookmark (remove_bookmark)

The removeBookmark method allows you to remove a bookmark from a map.

removeLayer (remove_layer)

Provides the ability to remove a layer from a map in a project.

removeTable (remove_table)

Provides the ability to remove a table from a map in a project.

setDefinition (definition_object)

Sets a map's CIM definition.

updateConnectionProperties (current_connection_info, new_connection_info, {auto_update_joins_and_relates}, {validate}, {ignore_case})

The updateConnectionProperties method replaces connection properties using a dictionary or a path to a workspace.

updateTransformations (transformations)

The updateTransformations method replaces a map's transformations using a dictionary.

Methods

addBasemap (basemap_name)
ParameterExplanationData Type
basemap_name

The name of the basemap as it appears in the basemap gallery.

String

The addBasemap method works in the same way as the Basemap control works on the Map ribbon. If a basemap does not exist, a new one will be added. If one or more basemaps already exist, they will be replaced by the one being added.

If you want to add more than one basemap to your map, save a basemap to a layer file and add it using the LayerFile and addLayer methods.

Tip:

To see what basemaps are available, use the listBasemaps method on the ArcGISProject class.

addDataFromPath (data_path, {web_service_type}, {custom_parameters})
ParameterExplanationData Type
data_path

A string that represents a local path or URL.

(The default value is None)

String
web_service_type

A string that represents the type of web service connection. When you are working with a service URL that is hosted on a third-party server and the URL is not deterministic, you must specify the service type from the list to add the data. The default value of AUTOMATIC will not work if the custom_parameters dictionary is provided.

  • ARCGIS_SERVER_WEBAn ArcGIS Server web service
  • AUTOMATICAttempt to automatically match the correct service based on the provided URL
  • KMLKML
  • VECTOR_TILEA vector tile service
  • WMSA WMS OGC web service

(The default value is AUTOMATIC)

String
custom_parameters

A Python dictionary of custom connection parameters. The KML data_service_type does not support custom properties.

(The default value is None)

Dictionary
Return Value
Data TypeExplanation
Layer

A Layer object.

The addDataFromPath method allows you to add a layer to a map in a similar way to how the Add Data From Path button works in the application; it places each layer based on layer weight rules and geometry type. For more precise layer placement control, refer to the moveLayer method.

When you add ArcGIS Server services, vector tile services, or WMS services, you can add custom request parameters. These are key-value pairs that can be appended to the URL for all resources and operations fetched by the service layer. These are often access keys to allow access to restricted data. In some cases, you must specify the access key-value pair to add the data. Contact the administrator of the service for the access keys if you are working with restricted access services.

For more information, see Add layers to a map or scene.

addLayer (add_layer_or_layerfile, {add_position})
ParameterExplanationData Type
add_layer_or_layerfile

A reference to a Layer or LayerFile object representing the layer or layers to be added.

Layer
add_position

A constant that determines the placement of the added layer or layers in a map.

  • AUTO_ARRANGEAutomatically places the layer or layers based on its layer weight rules and geometry.
  • BOTTOMPlaces the layer or layers at the bottom of the TOC layer stack.
  • TOPPlaces the layer or layers at the top of the TOC layer stack.

(The default value is AUTO_ARRANGE)

String
Return Value
Data TypeExplanation
List

A Python list of Layer objects.

The addLayer method provides a way to add a layer or collection of layers into a map. The default add_position adds the layers using the same auto-arrange logic that places layers in a map similarly to how the Add Data button works in the application; it places each layer based on layer weight rules and geometry type. The other placement choices are either at the TOP or the BOTTOM of a the layer stack. For more precise layer placement control, refer to the insertLayer method.

The layer that is added can reference an already existing layer in a the same project or separate project, or reference a layer file (.lyr or .lyrx) on disk. A reference to a layer can be a single layer, a group layer with multiple sublayers, or a collection of root-level layers and group layers if referencing a .lyrx file. Refer to LayerFile for more information on layer files.

The way a layer appears in the table of contents (TOC) after it is added depends on the source layer and how it appears. For example, some layers are completely collapsed and do not display their symbols in the TOC. This setting is built into the layer. If a layer is collapsed, saved to a layer file, and then added to a map, the layer will be collapsed in the new map when added through addLayer.

addLayerToGroup (target_group_layer, add_layer_or_layerfile, {add_position})
ParameterExplanationData Type
target_group_layer

A reference to an existing group Layer object.

Layer
add_layer_or_layerfile

A reference to a Layer or LayerFile object representing the layer or layers to be added.

Layer
add_position

A constant that determines the placement of the added layer or layers in the target_group_layer.

  • AUTO_ARRANGEAutomatically places the layer based on its layer weight rules and geometry.
  • BOTTOMPlaces the layer at the bottom of the TOC layer stack.
  • TOPPlaces the layer at the top of the TOC layer stack.

(The default value is AUTO_ARRANGE)

String

The addLayerToGroup method is the only way to add a layer or collection of layers into an existing, empty group layer in a map. The default add_position adds the layers using the same auto-arrange logic that places layers in a map similarly to how the Add Data button works in the application; it places each layer based on layer weight rules and geometry type. The other placement choices are either at the TOP or the BOTTOM of the layer stack. For more precise layer placement control, refer to the insertLayer method.

The layer that is added can reference an already existing layer in the same project or separate project, or reference a layer file (.lyr or .lyrx) on disk. A reference to a layer can be a single layer, a group layer with multiple sublayers, or a collection of root-level layers and group layers if referencing a .lyrx file. Refer to LayerFile for more information on layer files.

The way a layer appears in the table of contents (TOC) after it is added depends on the source layer and how it appears. For example, some layers are completely collapsed and do not display their symbols in the TOC. This setting is built into the layer. If a layer is collapsed, saved to a layer file, and then added to a map, the layer will be collapsed in the new map when added through addLayerToGroup.

addTable (add_table)
ParameterExplanationData Type
add_table

A reference to a Table object representing the table to be added.

Table
Return Value
Data TypeExplanation
Table

A reference to a Table object.

The addTable method provides a way to add tables into a map. The table you want to add can either be a table in an existing map using the listTables method on the Map object or it can be a table on disk or in a database that is referenced with the Table function.

addTableToGroup (target_group_layer, add_table)
ParameterExplanationData Type
target_group_layer

A reference to an existing group layer.

Layer
add_table

A reference to a Table object.

Table

The addTableToGroup method is the only way to add a table to an existing group layer in a map. The table that is added can reference an already existing table in the same project, a table in a separate project, or a table in a layer file (.lyrx) on disk.

If you reference a table already in the same map and you add the table to a group, it will create a duplicate table and you may want to delete the original table reference.

clearSelection ()

Clears the selection for all layers and tables in a map.

clipLayers (clip_object, {selection})
ParameterExplanationData Type
clip_object

This object can be a polygon feature layer, an extent object, a graphics layer that includes polygons, or a custom polygon object. The clipping options can be cleared if set to None.

Object
selection

Specifies whether a selection will be used for clipping. If set to True and the clip_object value includes a selection, only selected polygon features will be used for clipping. If set to True and the clip_object does not have a selection, clipLayers will be set to None.

Note:

A selection only applies to polygon feature layers and graphics layers that include polygon elements. Also, a selection only applies to graphics layers when a script is run from within the application because a graphic layer element selection is not saved with a project.

(The default value is ALL)

String

The clipLayers method supports clipping layers in a map. The clip_object parameter supports a variety of inputs but they must all be an enclosed area geometry. The clipToIndexFeature property is available on the MapSeries class to specify whether map clipping will use the map series index feature.

Note:
If a map series has clipToIndexFeature set to True, you cannot set the map's clipping layers to None until clipToIndexFeature is set to False.

This sample code sets the clipping layers and the excluded layers for a map that is in a map series. It also sets clipToIndexFeature to enable clipping to the index feature.

p = arcpy.mp.ArcGISProject('current')
m = p.listMaps('Yosemite National Park MS')[0]
indexLyr = m.listLayers('IndexLayer')[0]
excludeLyr = m.listLayers('Topo*')[0]
m.clipLayers(indexLyr)
m.excludedLayersFromClipping = [excludeLyr]

lyt = p.listLayouts('*MS')[0]
ms = lyt.mapSeries
ms.clipToIndexFeature = True
copyBookmark (bookmark, {name})
ParameterExplanationData Type
bookmark

A reference to an existing bookmark in a map either in the same map or a different map.

Bookmark
name

A string that represents the name of the new bookmark. If a name is not provided, the default value will follow the sequencing nomenclature, for example, Bookmark, Bookmark [1], Bookmark [2].

String
Return Value
Data TypeExplanation
Bookmark

A bookmark object.

This method returns a reference to a new bookmark class. The bookmark that is being copied can come from a different map or the same map. You can also copy a bookmark from a map in a different project. See the code example in the Bookmark class help topic.

createGraphicsLayer ({name})
ParameterExplanationData Type
name

The name of the new graphics layer. If no name is provided, the default name value will follow the automatic sequencing nomenclature, for example, Graphics Layer, Graphics Layer 2, Graphics Layer 3, and so on.

String
Return Value
Data TypeExplanation
Layer

A reference to the new graphics layer.

The graphics layer will be created at the first position in the map's table of contents. If you are creating multiple layers, provide a unique name for each layer in the map so they can be easily referenced by their names, for example, when using the wildcard parameter in the listLayers method.

createGroupLayer (name, {group_layer})
ParameterExplanationData Type
name

A string that represents the name of the new group layer.

String
group_layer

A reference to an existing group layer into which to insert the new group layer. Use this parameter to create nested group layers.

Layer
Return Value
Data TypeExplanation
Layer

A reference to the new group layer.

The createGroupLayer method allows you to create a group layer in a map. The group layer will be created at the first position in the map's table of contents. The group layer can also be created within an existing group layer to create nested group layers. After the group layer is created, it can be moved to another position in the map's table of contents by using the moveLayer method.

exportBookmarks (out_bkmx)
ParameterExplanationData Type
out_bkmx

A string that represents the path and file name for the output bookmark file (.bkmx).

String

This method in conjunction with importBookmarks allows you to transfer all bookmarks from one map to another map in the same project or in a different project. See the code example in the Bookmark class help topic.

exportToMAPX (out_mapx)
ParameterExplanationData Type
out_mapx

A string used to save a Map to a map file (.mapx).

String

This method is useful if you want to save a map to a map file that can be imported later into a project using the ArcGISProject importDocument method.

getDefinition (cim_version)
ParameterExplanationData Type
cim_version

A string that represents the major version of the CIM.

String
Return Value
Data TypeExplanation
Object

Returns the CIM definition for a Map object.

CIM-level access to additional object properties was introduced at ArcGIS AllSource 2.4. When you want to return an object's CIM definition, you must specify a cim_version. Esri follows the semantic versioning specification. This means that at major releases—for example, 3.0—breaking API changes are allowed. This allows Python script authors control over which version of the CIM is used during a script run if there is a possibility breaking changes may be introduced in the new version. If you are authoring scripts for ArcGIS AllSource 2.x, specify the cim_version to be 'V2'. If you are authoring scripts for ArcGIS AllSource 3.x, specify the cim_version to be 'V3'. Scripts authored using cim_version 'V2' will continue to work in ArcGIS AllSource 3.x.

For more information about working with the CIM and samples, see Python CIM access.

getWebLayerSharingDraft (server_type, service_type, service_name, {layers_and_tables})
ParameterExplanationData Type
server_type

A string representing the server type. The following server types are supported:

  • HOSTING_SERVERSupports publishing either a web feature layer, a web tile layer, or a web scene layer to ArcGIS Enterprise or ArcGIS Online. Use this option when specifying FEATURE, TILE, or SCENE_LAYER in the service_type parameter.
  • FEDERATED_SERVERSupports publishing a map image layer or web scene layer to an ArcGIS Enterprise portal federated server. Use this option when specifying MAP_IMAGE or SCENE_LAYER in the service_type parameter.
Tip:

The getWebLayerSharingDraft function does not support publishing map services to ArcGIS Server. Instead, use the arcpy.sharing.CreateSharingDraft function.

String
service_type

A string representing the service type. The following service types are supported:

String
service_name

A string that represents the name of the service. This is the name people will see and use to identify the service. The name can contain alphanumeric characters, spaces, and underscores. No special characters are allowed. The name cannot be more than 120 characters in length.

String
layers_and_tables

A list of layers and tables from the map. If left blank, the entire map will be published. This parameter allows you to choose a subset of layers and tables from the map to publish. The layers and tables must be from the same map that is being published.

Note:

If you specify a layer or table that participates in a relationship class when publishing a web feature layer or a map image layer, all layers or tables involved in the relationship class will be published.

List
Return Value
Data TypeExplanation
Object

Returns either a FeatureSharingDraft, TileSharingDraft, MapImageSharingDraft, or SceneLayerSharingDraft class object.

The getWebLayerSharingDraft function creates a sharing draft from a map in an ArcGIS AllSource project. A sharing draft is a configurable set of properties for a web layer. After the sharing draft has been configured, it can then be saved to a service definition draft (.sddraft) file using the exportToSDDraft function from the FeatureSharingDraft, TileSharingDraft, or MapImageSharingDraft classes. It can then be staged and shared to either ArcGIS Enterprise or ArcGIS Online using the Stage Service and Upload Service Definition tools. If you created a sharing draft using the SceneLayerSharingDraft class, use the Publish function to share the web scene layer. For more information, see Introduction to arcpy.sharing.

importBookmarks (bkmx_path)
ParameterExplanationData Type
bkmx_path

A string that represents the path and file name to a bookmark file (.bkmx).

String

This method in conjunction with exportBookmarks allows you to transfer all bookmarks from one map to another map in the same project or in a different project. See the code example in the Bookmark class help topic.

insertLayer (reference_layer, insert_layer_or_layerfile, {insert_position})
ParameterExplanationData Type
reference_layer

A Layer object representing an existing layer that determines the location where the new layer will be inserted.

Layer
insert_layer_or_layerfile

A reference to a Layer or LayerFile object representing the layer or layers to be added.

Layer
insert_position

A constant that determines the placement of the added layer or layers relative to the reference_layer.

  • AFTERInserts the new layer after or below the reference layer.
  • BEFOREInserts the new layer before or above the reference layer.

(The default value is BEFORE)

String

The insertLayer method is a more precise way of positioning a layer into a map or a group layer because a reference_layer is used to specify the exact location. The layer is either added before or after the reference_layer.

If the reference_layer references a layer at the root level of a map, the inserted layer will be added to the root level. If the reference_layer references a layer within a group layer, the inserted layer will be added into the group. Because a reference_layer is a required parameter, it is not possible to use insert_layer to add a layer into an empty map or an empty group layer. UseaddLayer or addLayerToGroup methods to add a layer or collection of layers into an empty map or group layer, respectively.

The layer that is inserted can reference an already existing layer in a the same project or separate project, or reference a layer file (.lyr or .lyrx) on disk. A reference to a layer can be a single layer, a group layer with multiple sublayers, or a collection of root-level layers and group layers if referencing a .lyrx file. Refer to LayerFile for more information on layer files.

The way a layer appears in the table of contents (TOC) after it is added depends on the source layer and how it appears. For example, some layers are completely collapsed and do not display their symbols in the TOC. This setting is built into the layer. If a layer is collapsed, saved to a layer file, and then added to a map, the layer will be collapsed in the new map when added through insertLayer.

listBookmarks ({wildcard})
ParameterExplanationData Type
wildcard

A wildcard is based on the bookmark name and is not case sensitive. A combination of asterisks (*) and characters can be used to help limit the resulting list.

(The default value is None)

String
Return Value
Data TypeExplanation
List

The listBookmarks method always returns a Python list object even if only one broken layer or table is returned.

Returns a Python list of bookmark objects in a Map.

listBrokenDataSources ()
Return Value
Data TypeExplanation
List

A Python list of Layer or Table objects.

The listBrokenDataSources method always returns a Python list object even if only one broken layer or table is returned.

listLayers ({wildcard})
ParameterExplanationData Type
wildcard

A wildcard is based on the layer name and is not case sensitive. A combination of asterisks (*) and characters can be used to help limit the resulting list.

(The default value is None)

String
Return Value
Data TypeExplanation
List

Returns a Python list of Layer objects in a map.

Returns a Python list of Layer objects that exist in a map. ListLayers always returns a list object even if only one table is returned.

It is possible that there might be layers in a map that have the same name. If that is the case, then other properties may need to be used to isolate a specific layer. Properties such as a layer's datasource or definitionQuery could be used to do this. It is ideal that all layers in a map be uniquely named.

listTables ({wildcard})
ParameterExplanationData Type
wildcard

A wildcard is based on the layer name and is not case sensitive. A combination of asterisks (*) and characters can be used to help limit the resulting list.

(The default value is None)

String
Return Value
Data TypeExplanation
List

A Python list of Table objects in a map.

Returns a Python list of Table objects that exist within a map. ListTables always returns a list object even if only one table is returned.

It is possible that there might be tables in a map that have the same name. If that is the case, then other properties may need to be used to isolate a specific layer. Properties such as a tables's datasource or definitionQuery could be used to do this. It is ideal that all tables in a map be uniquely named.

moveLayer (reference_layer, move_layer, {insert_position})
ParameterExplanationData Type
reference_layer

A Layer object representing an existing layer that determines where the move_layer is positioned based on the insert_position value.

Layer
move_layer

A reference to a Layer object representing the layer to be moved.

Layer
insert_position

A constant that determines the placement of the moved layer relative to the reference_layer.

  • AFTERMoves the layer after or below the reference layer.
  • BEFOREMoves the layer before or above the reference layer.

(The default value is BEFORE)

String

The move_layer and reference_layer layer object must reside in the same map. A layer cannot be moved from one map to a different map even within the same project. Use addLayer, addLayerToGroup, or insertLayer to move layers between maps. The moveLayer method can not move layers into an empty group layer. You will need to use addLayerToGroup and then use removeLayer to remove the layer from the original position after it was added to the group.

openView ()

This is useful if the map view is not already open or another view is active in the application. The method creates a map view zoomed to its default extent and activates it. To close other, existing views before opening a new view, use the ArcGISProject closeViews method.

There are two techniques for controlling the desired extent of your map view. First, prior to opening the view, you can set the defaultCamera for your map. Second, you can change the MapView camera extent after it is opened.

Note:

This method is designed to be run in the application using a script tool, Notebook, or the Python window. It will have no effect if run outside of the application.

removeBookmark (remove_bookmark)
ParameterExplanationData Type
remove_bookmark

A reference to a Bookmark object representing the bookmark to be removed.

Bookmark

The removeBookmark method removes a single bookmark from a map. To remove all bookmarks from a map, you need to iterate through all bookmarks and remove one at a time.

removeLayer (remove_layer)
ParameterExplanationData Type
remove_layer

A reference to a Layer object representing the layer to be removed.

Layer

RemoveLayer will remove a single layer or group layer from a specific map. 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.

removeTable (remove_table)
ParameterExplanationData Type
remove_table

A reference to a Table object representing the layer to be removed.

Table

RemoveTable will remove a single table from a specific map. If there is more than one table that meets the criteria, then only the first table will be removed unless the script iterates through each table in a returned list.

setDefinition (definition_object)
ParameterExplanationData Type
definition_object

A modified CIM definition object originally retrieved using getDefinition.

Object

For more information about working with the CIM and samples, see Python CIM Access.

updateConnectionProperties (current_connection_info, new_connection_info, {auto_update_joins_and_relates}, {validate}, {ignore_case})
ParameterExplanationData Type
current_connection_info

A string that represents the workspace path or a Python dictionary that contains connection properties to the source you want to update. If an empty string or None is used in current_connection_info, all connection properties will be replaced with the new_workspace_info, depending on the value of the validate parameter.

String
new_connection_info

A string that represents the workspace path or a Python dictionary that contains connection properties with the new source information.

String
auto_update_joins_and_relates

If set to True, the updateConnectionProperties method will also update the connections for associated joins or relates.

(The default value is True)

Boolean
validate

If set to True, the connection properties will only be updated if the new_connection_info value is a valid connection. If it is not valid, the connection will not be replaced. If set to False, the method will set all connections to match the new_connection_info value, regardless of a valid match. In this case, if a match does not exist, the data sources would be broken.

(The default value is True)

Boolean
ignore_case

Determines whether searches will be case sensitive. By default, queries are case sensitive. To perform queries that are not case sensitive, set ignore_case to True.

(The default value is False)

Boolean

For more detailed discussion, parameter information, scenarios, and code samples, see Updating and fixing data sources.

updateTransformations (transformations)
ParameterExplanationData Type
transformations

The dictionary keys are defined below.

  • 2DHorizontal transformations, if any exist
  • 3DVertical transformations, if any exist
Dictionary

To update a map's transformations, you must set the entire set of transformations. You cannot add, remove, or update a single transformation at a time. You can build a new dictionary from scratch or you can modify the dictionary returned by the transformations property and push the entire dictionary back to the map using the updateTransformations method.

Code sample

Map example 1

The following script references a layer file and inserts the layer into a map above a layer that already exists in the map:

import arcpy
aprx = arcpy.mp.ArcGISProject(r"C:\Projects\YosemiteNP\Yosemite.aprx")
insertLyr = arcpy.mp.LayerFile(r"C:\Projects\YosemiteNP\LayerFiles\Ranger Stations.lyrx")
m = aprx.listMaps("Yosemite National Park")[0]
refLyr = m.listLayers("Points of Interest")[0]
m.insertLayer(refLyr, insertLyr, "BEFORE")
aprx.saveACopy(r"C:\Projects\YosemiteNP\Yosemite_updated.aprx")
Map example 2

The following script will set the defaultCamera property for all maps and scenes currently in a project. The camera properties will be copied from existing map frames that have the desired viewer settings. All maps will be copied from a 2D map frame, and all scene viewer settings will be copied from a 3D map frame.

import arcpy
aprx = arcpy.mp.ArcGISProject(r"C:\Projects\YosemiteNP\Yosemite.aprx")
lyt = aprx.listLayouts("Main Attractions*")[0]
mpFrm2D = lyt.listElements("mapframe_element", "Yose*")[0]
mpFrm3D = lyt.listElements("mapframe_element", "Inset1")[0]
for m in aprx.listMaps():
    if m.mapType == "MAP":
        m.defaultCamera = mpFrm2D.camera
    elif m.mapType == "SCENE":
        m.defaultCamera = mpFrm3D.camera
aprx.save()
del aprx
Map example 3

The following script uses the keyword current, so it should be run from the Python window. The script creates a new map and adds new layers to it. The map's default camera property is updated, which controls the extent of newly opened views. The map view is then exported to PDF. The newly created map is then removed from the project.

aprx = arcpy.mp.ArcGISProject("CURRENT")

#Create a copy of an existing map
newMap = aprx.createMap("Ranger Stations", "Map")

#Add ranger stations layer file
lyrx1 = arcpy.mp.LayerFile(r"C:\Projects\YosemiteNP\LayerFiles\Park Boundary.lyrx")
newMap.addLayer(lyrx1)
lyrx2 = arcpy.mp.LayerFile(r"C:\Projects\YosemiteNP\LayerFiles\Ranger Stations.lyrx")
newMap.addLayer(lyrx2)

#Close any current map or layout views
aprx.closeViews("MAPS_AND_LAYOUTS")

#Set the default map camera to the extent of the park boundary before opening the new view
#default camera only affects newly opened views
lyr = newMap.listLayers("*Park Boundary")[-1]
newMap.defaultCamera.setExtent(arcpy.Describe(lyr).extent)
newMap.openView()

#export the newly opened active view to PDF, then delete the new map
mv = aprx.activeView
mv.exportToPDF(r"C:\Temp\RangerStations.pdf", width=700, height=500, resolution=96)
aprx.deleteItem(newMap)