Skip to main content

Layer

Summary

Provides access to basic layer properties and methods.

Discussion

Layers can be referenced from within a project using the listLayers method on the Map class or in a layer file (.lyr or .lyrx) stored on disk using the listLayers method on the LayerFile class.

The Layer object has a single, generic design to work with all layers. There are numerous types of layers, and not all of them support the same set of properties. For example, a feature layer supports a definition query, whereas a raster layer does not, but a raster catalog does. Rather than having to work with different, individual layer objects for all the possible layer types and property combinations, there are some useful properties that allow you to obtain information about a layer and its supported properties. There are many is properties that allow you to determine if a layer fits into a general category, for example, is3DLayer, isFeatureLayer, isGroupLayer, isRasterLayer, isWebLayer, and so on.

There are a few specialized layers and datasets that don't fall into one of these general categories: annotation subclasses, dimension features, terrain datasets, topology datasets, and so on. In these cases, you may need to test other properties to isolate a layer of interest before doing something to it. The supports method is available to help identify which specific layer supports which specific layer property. It gives you the ability to test whether the layer supports a property before trying to get or set its value, reducing the need for additional error trapping. For example, see the following code:

if lyr.supports("BRIGHTNESS"):
    lyr.brightness = 10

The listLayers method on the Map class returns index values that are generated from top to bottom as they appear in the table of contents or as they appear in a layer file. The same applies if a group layer is within another group layer. For example, a map with a single group layer that contains three sublayers will return a list of four layer names, the group layer being the first and the three sublayers being the second, third, and fourth. There are two ways of determining if a layer is a group layer. First, you can check to see if the layer supports the isGroupLayer property. Second, you can evaluate the longName property. A layer's longName value will include the group name in addition to the layer name. For example, a layer named Layer1 in a group layer named Group1 will have a longName value of Group1\Layer1. If the name value is equal to the longName value, the layer is not inside a group layer. When working with the sublayers of composite layers, the longName property will contain both the sublayer and top-level layer name.

ArcGIS Pro can read legacy .lyr file types, but it can only save to .lyrx file types. If a .lyr file type is being referenced and the save method is called, it will be converted to a .lyrx file type but with the same file name.

A feature layer can support zero to many definition queries, but only one definition query can be active. It is also possible that one or many definition queries are present but none are active. There are a couple of ways to manage definition queries. First, you can use the definitionQuery property. If you set a unique SQL string on a layer that does not have a definition query or a layer that has multiple definition queries, the new definition query is added and it becomes the active query. If you set a SQL string on a layer that already has that same query, it sets that as the active definition query, if it is not already active. The second way to manage definition queries is to use the listDefinitionQueries and updateDefinitionQueries functions in combination. The listDefinitionQueries function returns a list of Python dictionaries that represent the properties associated with each query. The dictionary keys are name, sql, and isActive. Definition queries can be added, modified, or removed from the Python list using core Python. The dictionary isActive value can be set to True to set the active query. Again, only one query can be active. If you try setting more than one query to be active, an error will be returned. After changes are made, the updateDefinitionQueries function is used to set the new changes.

Changing a layer's data source is a common requirement. For a more detailed discussion, parameter information, scenarios, and code samples, refer to the Updating and fixing data sources help topic.

Properties

Name Explanation Data type

brightness

(Read and Write)

A layer's brightness value. The default, normal brightness, is 0 percent. Enter any value between +100 percent and -100 percent. Type a plus or minus sign to the left of the value to specify whether it is above or below 0.

Integer

connectionProperties

(Read only)

Returns a layer's data source connection information as a Python dictionary.

Dictionary

contrast

(Read and Write)

A layer's contrast value. The default, neutral contrast, is 0 percent. Enter any value between +100 percent and -100 percent. Type a plus or minus sign to the left of the value to specify whether it is above or below 0.

Integer

dataSource

(Read only)

Returns the complete path for the layer's data source. It includes the full workspace path and name of the dataset. For enterprise geodatabase layers, a string containing the layer's connection information is returned.

Tip:

Enterprise geodatabase layers in an ArcGIS Pro project do not retain the path to the database connection file (.sde) that was used to create the layer.

String

definitionQuery

(Read and Write)

A layer's definition query. If you set a unique SQL string on a layer that does not have a definition query or a layer that has multiple definition queries, the new definition query is added and it becomes the active query. If you set a SQL string on a layer that already has that same query, it simply sets that as the active definition query, if it is not already active.

String

elevation

(Read only)

Returns a layer's LayerElevation object if elevation is supported. Test ahead of time using Layer.supports('ELEVATION').

Object

groupType

(Read only)

Returns the type of group layer. The layer must be a group layer so it is best to first check if isGroupLayer is True. To set the groupType, use the setGroupType method. The possible values are:

  • CHECKBOX—A checkbox style group layer.

  • RADIO—A radio style group layer.

String

is3DLayer

(Read only)

Returns True if a layer is a 3D layer.

Boolean

isBasemapLayer

(Read only)

Returns True if a layer is a basemap layer.

Boolean

isBroken

(Read only)

Returns True if a layer's data source is broken.

Boolean

isFeatureLayer

(Read only)

Returns True if a layer is a feature layer.

Boolean

isGraphicsLayer

(Read only)

Returns True if a layer is a graphics layer.

Boolean

isGroupLayer

(Read only)

Returns True if a layer is a group layer.

Boolean

isNetworkAnalystLayer

(Read only)

Returns True if a layer is an ArcGIS Network Analyst extension layer.

Boolean

isNetworkDatasetLayer

(Read only)

Returns True if a layer is an ArcGIS Network Analyst extension network dataset layer.

Boolean

isParcelFabricLayer

(Read only)

Returns True if a layer is a parcel fabric layer.

Boolean

isRasterLayer

(Read only)

Returns True if a layer is a raster layer.

Boolean

isSceneLayer

(Read only)

Returns True if a layer is a scene layer.

Boolean

isTimeEnabled

(Read only)

Indicates whether time is enabled on the layer. If isTimeEnabled returns True, the time property on the layer can be used to return a LayerTime object. Use the enableTime method to enable time on a layer that contains time information.

Boolean

isTopologyLayer

(Read only)

Returns True if a layer is a topology layer.

Boolean

isWebLayer

(Read only)

Returns True if a layer is a GIS service layer. GIS services are automated geographic information services that are published and accessed over the web using standard technologies and protocols. Esri basemaps are an example.

Boolean

longName

(Read only)

A layer's full name including group layer and composite layer structure.

String

maxThreshold

(Read and Write)

A layer's maximum scale threshold for maps and its maximum distance above ground for scenes. A layer will not display when zoomed in beyond the maximum scale. To clear the maximum scale, set the value to 0.

Note:

Scene values represent height and are based on the elevation units defined by the source data coordinate system.

Double

metadata

(Read and Write)

Get or set the layer's Metadata class information.

Note:

Setting metadata is dependent on the isReadOnly property value.

Metadata

minThreshold

(Read and Write)

A layer's minimum scale threshold for maps and its maximum distance above ground for scenes. A layer will not display when zoomed out beyond the minimum scale. To clear the minimum scale, set the value to 0.

Note:

Scene values represent height and are based on the elevation units defined by the source data coordinate system.

Double

name

(Read and Write)

The name of a layer the way it would appear in the table of contents. Spaces can be included. It is ideal that all layers in a map have a unique name so they can be easily referenced by their names. If unique names are not possible, consider using the URI property instead.

String

pageQuery

(Read only)

Returns a Python-named tuple of page query properties.

  • fieldName—The field name used in the page query.

  • match—A boolean that indicates if the features are filtered when they match the current page of the map series.

Note:

Page query filters are only applied if the layer is in the MapFrame that is referenced in the MapSeries.

tuple

showLabels

(Read and Write)

Controls the display of labels for a layer. If set to True, labels will display; if set to False, labels will not be drawn.

Boolean

symbology

(Read and Write)

Provides access to a layer's symbology.

Object

time

(Read only)

Returns a LayerTime object if time is enabled on the layer.

LayerTime

transparency

(Read and Write)

A layer's transparency value. This enables you to see through a layer. Use values between 0 and 100. A value of 0 is not transparent. A transparency value of more than 90 percent usually results in the layer not being drawn at all.

Integer

URI

(Read only)

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

String

visible

(Read and Write)

Controls the display of a layer. If set to True, the layer will draw; if set to False, the layer will not be drawn.

Boolean

Methods

createLabelClass(name, expression, {sql_query}, {labelclass_language})

The createLabelClass method creates a LabelClass for a layer.

Newly added label classes may not display initially. There are two levels of settings to display labels. First, the Layer class has a property called showLabels and needs to be set to True. Second, each LabelClass has a visible property and it also needs to be set to True. Refer to the LabelClass help topic for more information and code samples.

Name Explanation Data type

name

The name of the new label class. Names must be unique.

String

expression

An expression to be applied. Its syntax must match the labelclass_language value.

The default value is None.

String

sql_query

(Optional)

An optional query that is used for restricting the features that are labeled.

The default value is None.

String

labelclass_language

(Optional)

The following are the supported scripting languages.

  • ARCADE—Arcade

  • JSCRIPT—JScript

  • PYTHON—Python

  • VBSCRIPT—VBScript

The default value is ARCADE.

String

Return value

Data type Explanation

LabelClass

Returns the newly created LabelClass object.

disableTime()

Disables time enabled properties on a Layer object.

The enableTime method can be used to re-enable time properties.

enableTime({startTimeField}, {endTimeField}, {autoCalculateTimeRange}, {timeDimension})

Enables time on a layer if it has time information.

All parameters on the enableTime method are optional. If startTimeField and endTimeField are not specified, the method will evaluate the data and attempt to come up with appropriate default values.

After running the enableTime method, the time property on the layer can be used to return a LayerTime object. If a MapFrame on a Layout contains time-enabled layers, the MapTime class can be used to access map time settings.

Name Explanation Data type

startTimeField

(Optional)

The name of the field containing the start time values. If each feature has a single time field, specify that field name in the startTimeField and leave endTimeField blank. If each feature has a start and end time field, specify both the startTimeField and endTimeField.

The default value is None.

String

endTimeField

(Optional)

The name of the field containing the end time values. Not all layers use an end time field. If each feature has a single time field, specify that field name in the startTimeField and leave endTimeField blank. If each feature has a start and end time field, specify both the startTimeField and endTimeField.

The default value is None.

String

autoCalculateTimeRange

(Optional)

If set to True, the start and end time attribute information is used to calculate the layer's time extent.

The default value is True.

Boolean

timeDimension

(Optional)

The name of the dimension containing time values when using netCDF data.

The default value is None.

String

extrusion({extrusion_type}, {expression})

Extrudes 2D features in a layer to display 3D symbology.

Extrusion is the process of vertically stretching a flat 2D shape to create a 3D object. This provides a method to create three-dimensional symbology from two-dimensional features. Polygon and line features have all five extrusion_type options available; point features don't use MAX_HEIGHT or MIN_HEIGHT options.

Name Explanation Data type

extrusion_type

(Optional)

A string that specifies the extrusion method. Setting the value to NONE turns off layer extrusion.

  • ABSOLUTE_HEIGHT—The feature is extruded to the specified z-value, as a flat top, regardless of the z-values of the feature.

  • BASE_HEIGHT—A z-value is calculated for each vertex of the feature's base, and the feature is extruded to the various z-values creating a multifaceted top.

  • MAX_HEIGHT—Adds extrusion height to the minimum z-value of the feature, and the feature is extruded to a flat top at that value.

  • MIN_HEIGHT—Adds extrusion height to the minimum z-value of the feature, and the feature is extruded to a flat top at that value.

  • NONE—Features are not extruded.

The default value is NONE.

String

expression

(Optional)

A string that defines the extrusion expression, which provides an absolute extrusion height for each feature.

The default value is None.

String

getDefinition(cim_version)

Gets a layer's CIM definition.

CIM-level access to additional object properties was introduced at ArcGIS Pro 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 Pro 2.x, specify the cim_version to be 'V2'. If you are authoring scripts for ArcGIS Pro 3.x, specify the cim_version to be 'V3'. Scripts authored using cim_version 'V2' will continue to work in ArcGIS Pro 3.x.

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

Name Explanation Data type

cim_version

A string that represents the major version of the CIM.

  • V2—The 2.x version of the CIM will be used.

  • V3—The 3.x version of the CIM will be used.

String

Return value

Data type Explanation

Object

Returns the CIM definition for a Layer object.

getSelectionSet()

Returns a layer's selection as a Python set of object IDs.

Return value

Data type Explanation

Set

Returns a layer's selection as a Python set of object IDs. If no features are selected, a NoneType is returned.

getSymbologyDefinition(cim_version)

Return a layer's CIM symbology definition.

This method can be helpful when trying to apply or modify a renderer or colorizer that is not supported in the arcpy.mp API. Refer to the Symbology help topic for more discussion and code samples. For more information about working with the CIM and samples, also see Python CIM access.

Name Explanation Data type

cim_version

A string that represents the major version of the CIM that will be used.

  • V2—The 2.x version of the CIM will be used.

  • V3—The 3.x version of the CIM will be used.

String

Return value

Data type Explanation

Object

Returns the CIM symbology definition for a Layer.

listCharts({wildcard})

Returns a Python list of chart objects in a layer.

Name Explanation Data type

wildcard

(Optional)

A wildcard is based on the chart title 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 type Explanation

List

Returns a Python list of chart objects in a layer.

listDefinitionQueries({wildcard})

Returns a Python list of definition queries associated with a layer.

Definition queries can be added, modified, or removed from the Python list using standard practices. The dictionary isActive value can be set to True to set the active query. Again, only one query can be active. If you try setting more than one query to be active, an error will be returned. After changes are made, the updateDefinitionQueries function is used to set the new changes.

Name Explanation Data type

wildcard

(Optional)

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

The default value is None.

String

Return value

Data type Explanation

List

A Python list of dictionaries that represent the properties associated with each query. The dictionary keys are name, sql, isActive and spatialClause.

listLabelClasses({wildcard})

Returns a Python list of LabelClass objects in a layer.

Name Explanation Data type

wildcard

(Optional)

A wildcard is based on the label class 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 type Explanation

List

Returns a Python list of LabelClass objects in a layer.

listLayers({wildcard})

A method to search for layers within a group layer or composite layer.

The listLayers method returns a list object, even if only one layer is returned. If you want to return a reference to a Layer object, use a unique wildcard value and a list index value of 0. If the name is truly unique, it will always be the first item in a zero-based list. For example, see the following code:

   lyr = grpLyr.listLayers('City Streets')[0]

It is possible that there may be layers in a group or composite layer with the same name. If this is the case, other properties may need to be used to isolate a specific layer. Properties such as a layer's datasource or definitionQuery or URI can be used to do this. It is ideal that all layers be uniquely named for easier reference.

Name Explanation Data type

wildcard

(Optional)

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 type Explanation

List

Returns a Python list of Layer objects from a group layer or composite layer.

listTables({wildcard})

A method to search for tables within a group layer.

The listTables method returns a list object, even if only one table is returned. If you want to return a reference to a Table object, use a unique wildcard value and a list index value of 0. If the name is truly unique, it will always be the first item in a zero-based list. For example, see the following code:

   tab = grpLyr.listTables('2026 Census')[0]

It is possible that there may be tables in a group layer with the same name. If this is the case, other properties may need to be used to isolate a specific table. Properties such as a table's datasource or definitionQuery or URI can be used to do this. It is ideal that all tables be uniquely named for easier reference.

Name Explanation Data type

wildcard

(Optional)

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

The default value is None.

String

Return value

Data type Explanation

List

A Python list of Table objects in a layer.

openTableView({show_selected})

The openTableView method opens and activates a layer's attribute table view in the application.

The table view will only open if the map view the layer is associated with is also opened in the application. If the table view is already opened but not activated, it will become activated.

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 it is run outside of the application.

Name Explanation Data type

show_selected

(Optional)

A Boolean that specifies whether all rows will be displayed in the view or only the selected rows.

The default value is False.

Boolean

pasteProperties(source_layer, {layer_paste_properties[layer_paste_properties,...]})

The pasteProperties method pastes properties from a feature layer to another feature layer.

For more information about pasting feature layer properties, see the Copy and paste properties help topic.

Name Explanation Data type

source_layer

A feature layer with the properties that will be pasted.

Layer

layer_paste_properties[layer_paste_properties,...]

(Optional)

A single string or a list of strings that specify the property or properties that will be pasted. For example, layer_paste_properties="SYMBOLOGY" will paste only symbology properties, whereas layer_paste_properties=["SYMBOLOGY", "LABELING", "VISIBILITY_RANGE"]) will paste multiple properties.

  • ALL—All applicable properties will be pasted.

  • CHARTS—Only chart properties will be pasted.

  • DEFINITION_QUERIES—Only definition query properties will be pasted.

  • DISPLAY_EXPRESSION—Only display expression properties will be pasted.

  • DISPLAY_FILTERS—Only display filter properties will be pasted.

  • FIELD_PROPERTIES—Only field properties will be pasted.

  • LABELING—Only labeling properties will be pasted.

  • POPUPS—Only pop-up configuration properties will be pasted.

  • SYMBOLOGY—Only symbology properties will be pasted.

  • VISIBILITY_RANGE—Only visibility range properties will be pasted.

The default value is ALL.

String

saveACopy(file_name)

Saves a layer to a layer file (.lyrx).

If a group layer is being saved, all of the layers below it in the TOC will also be saved to the layer file (.lyrx).

Name Explanation Data type

file_name

A string that includes the location and name of the output layer file (.lyrx).

String

setDefinition(definition_object)

Sets a layer's CIM definition.

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

Name Explanation Data type

definition_object

A modified CIM definition object originally retrieved using getDefinition.

Object

setGroupType(group_type)

The setGroupType method sets a layer's group type.

When creating group layers, the default group layer type is CHECKBOX. This style allows multiple layers in the same group to be visible at the same time. The RADIO style allows only one layer in the group to be visible at a time. The RADIO style is required when creating a thematic map series.

Name Explanation Data type

group_type

A string that specifies the selection method that will be used.

  • CHECKBOX—The group layer will be set to a check box style.

  • RADIO—The group layer will be set to a radio style.

String

setPageQuery({field_name}, {match})

The setPageQuery method sets a page query filter for the layer.

Page query filters are only applied if a MapSeries is enabled on a Layout and the layer is used in the MapFrame that the map series is set to. If a field_name is not provided, the page query gets reset to None.

Name Explanation Data type

field_name

(Optional)

The name of the field that contains values that match the map series page name field in the index layer.

The default value is None.

String

match

(Optional)

If set to True, features with the same map series page name will be displayed, if False, the inverse set of features will be displayed.

The default value is True.

Boolean

setSelectionSet({oidList}, {method})

Sets a layer's selection using a Python list of Object IDs.

This method provides an easy way to manage a layer's selection. To clear the selection, use the NEW selection method with an empty list or don't set any parameters.

Note: Python Lists are used for setting the oidList but Python Sets get returned from the getSelectionSet method on the Layer object.

Name Explanation Data type

oidList

(Optional)

A Python list of Object IDs to use along with the appropriate selection method.

The default value is None.

List

method

(Optional)

A string that specifies which selection method to use.

  • NEW—Creates a new feature selection from the oidList.

  • DIFFERENCE—Selects the features that are not in the current selection but are in the oidList.

  • INTERSECT—Selects the features that are in the current selection and the oidList.

  • SYMDIFFERENCE—Selects the features that are in the current selection or the oidList but not both.

  • UNION—Selects all the features in both the current selection and those in the oidList.

The default value is NEW.

String

setSymbologyDefinition(definition_object)

Sets a layer's CIM symbology definition.

This method can be helpful when trying to apply or modify a renderer or colorizer that is not supported in the arcpy.mp API. Refer to the Symbology help topic for more discussion and code samples. For more information about working with the CIM and samples, also see Python CIM access.

Name Explanation Data type

definition_object

A modified CIM definition object originally retrieved using getSymbologyDefinition.

Object

supports(layer_property)

Used to determine if a particular layer type supports a property on the layer object. Not all layers support the same set of properties; the supports property can be used to test if a layer supports that property before attempting to set it.

There are numerous types of layers and not all of them support the same properties. For example, a feature layer supports a definition query, whereas a raster layer does not, but a raster catalog does. Rather than creating individual layer objects for all possible layer types and property combinations, a supports method was created to help identify which layer types support which properties. The support method gives you the option of testing the property before trying to get or set its value on a layer type that doesn't support it. The supports property will return a True if a layer supports that property.

Boolean properties don't need to be tested using supports because if a layer property isn't supported for that layer type, a False value gets returned.

Name Explanation Data type

layer_property

The name of a particular layer property that will be tested.

  • BRIGHTNESS—A raster layer's brightness value.

  • CONNECTIONPROPERTIES—A Layer's connection information.

  • CONTRAST—A raster layer's contrast value

  • DATASOURCE—A layer's file path or connection file.

  • DEFINITIONQUERY—A layer's definition query string.

  • ELEVATION—A layer that LayerElevation can be accessed.

  • LONGNAME—A layer's path including the group layers it may be nested within.

  • MAXTHRESHOLD—A layer's maximum threshold to display the features.

  • METADATA—A layer that can persist metadata.

  • MINTHRESHOLD—A layer's minimum threshold to display the features.

  • NAME—A layer's name.

  • SHOWLABELS—A layer that can display labels.

  • SYMBOLOGY—A layer that symbology can be accessed.

  • TIME—A layer's time properties.

  • TRANSPARENCY—A layer's transparency value.

  • URI—A layer's Universal Resource Identifier.

  • VISIBLE—A layer's visibility state.

The default value is name.

String

Return value

Data type Explanation

Boolean

Returns True if a layer supports that property.

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.

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

Name Explanation Data 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

(Optional)

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

The default value is True.

Boolean

validate

(Optional)

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

(Optional)

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

updateDefinitionQueries(definitionQueries[definitionQueries,...])

Updates a layer's collection of definition queries.

This function is typically used to apply the changes that have been made to the results returned by the listDefinitionQueries function.

Name Explanation Data type

definitionQueries[definitionQueries,...]

Updates a list of dictionaries that represent the properties of each definition query.

List

updateLayerFromJSON(json_data)

Updates a Layer from a JSON string.

This function is intended to be used in a web tool that uses the ConvertWebMapToArcGISProject function in web map printing applications that support changing the renderer (or other properties) of dynamic web service layers. If your web tool replaces the service layers with staged vector layers after running ConvertWebMapToArcGISProject, updateLayerFromJSON will apply the renderer (or other layer properties) as specified in the webmap_json to the corresponding vector layers staged in the layout template. For more information and a code sample, see ConvertWebMapToArcGISProject.

Name Explanation Data type

json_data

The layer definition in JavaScript Object Notation (JSON) format. See the ExportWebMap JSON specification for more information. ArcGIS API for JavaScript and ArcGIS Web AppBuilder allow you to get this JSON string from the web app. The layer definition is a subset of the webmap_json used in the ConvertWebMapToArcGISProject function. You don't need to create the web map JSON; the APIs take care of it for you. However, you need to extract the layer definition from the full webmap_json.

String

Code sample

Layer example 1

The following script prints the name of each map in a project and lists the names of the layers in each map. The script also appends a (BROKEN) prefix to the layer name if it has a broken data source.

import arcpy
aprx = arcpy.mp.ArcGISProject(r"C:\Projects\YosemiteNP\Yosemite.aprx")
for m in aprx.listMaps():
    print("Map: {0} Layers".format(m.name))
    for lyr in m.listLayers():
        if lyr.isBroken:
            print("(BROKEN) " + lyr.name)
        else:
            print("  " + lyr.name)
del aprx
Layer example 2

The following script clears all layer definition queries and turns off labels for all layers in a map named Yosemite National Park:

import arcpy
aprx = arcpy.mp.ArcGISProject(r"C:\Projects\YosemiteNP\Yosemite.aprx")
m = aprx.listMaps("Yosemite National Park")[0]
for lyr in m.listLayers():
    if lyr.supports("DEFINITIONQUERY"):
        lyr.definitionQuery = ""
    if lyr.supports("SHOWLABELS"):
        lyr.showLabels = False
aprx.save()
del aprx
Layer example 3

The following script adds a new definition query to a layer or sets the same query to be the active definition query if the SQL string already exists:

p = arcpy.mp.ArcGISProject('current')
m = p.listMaps()[0]
l = m.listLayers()[0]
if l.supports('DefinitionQuery'):
  l.definitionQuery = "AREA > 3000000"
Layer example 4

The following script creates a new definition query by appending a Python dictionary to the existing list queries. Because a query may already be active, it is important to first clear existing active queries before setting the new active query.

p = arcpy.mp.ArcGISProject('current')
m = p.listMaps()[0]
l = m.listLayers()[0]
if l.supports('DefinitionQuery'):
  #Get the list of definition queries
  dql = l.listDefinitionQueries()
  #Clear active definition queries otherwise the update will fail if there is already an active query
  for dq in dql:
    dq['isActive'] = False
  #Create a new definition query and append it to the list
  dql.append({'name': 'Appended Query', 'sql': "name = 'Lake Superior'", 'isActive': True})
  #Update the definition queries with the newly modified list
  l.updateDefinitionQueries(dql)