Layer

Zusammenfassung

Provides access to basic layer properties and methods.

Auswertung

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: is3DLayer, isFeatureLayer, isGroupLayer, isRasterLayer, and isServiceLayer.

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 if 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 the way 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.

Changing a layer's data source is a common requirement. There is a method and a property on the Layer object that help with this. For a more detailed discussion, parameter information, scenarios, and code samples, refer to the Updating and fixing data sources help topic.

Eigenschaften

EigenschaftErklärungDatentyp
brightness
(Lesen und schreiben)

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
(Nur lesen)

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

Dictionary
contrast
(Lesen und schreiben)

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
(Nur lesen)

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.

Tipp:

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
(Lesen und schreiben)

A layer's definition query.

String
is3DLayer
(Nur lesen)

Returns True if a layer is a 3D layer.

Boolean
isBasemapLayer
(Nur lesen)

Returns True if a layer is a basemap layer.

Boolean
isBroken
(Nur lesen)

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

Boolean
isFeatureLayer
(Nur lesen)

Returns True if a layer is a feature layer.

Boolean
isGroupLayer
(Nur lesen)

Returns True if a layer is a group layer.

Boolean
isNetworkAnalystLayer
(Nur lesen)

Returns True if a layer is an Erweiterung "ArcGIS Network Analyst" layer.

Boolean
isNetworkDatasetLayer
(Nur lesen)

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

Boolean
isRasterLayer
(Nur lesen)

Returns True if a layer is a raster layer.

Boolean
isSceneLayer
(Nur lesen)

Returns True if a layer is a scene layer.

Boolean
isWebLayer
(Nur lesen)

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
(Nur lesen)

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

String
maxThreshold
(Lesen und schreiben)

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

Double
metadata
(Lesen und schreiben)

Get or set the layer's Metadata class information.

Hinweis:

Setting metadata is dependent on the isReadOnly property value.

Metadata
minThreshold
(Lesen und schreiben)

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

Double
name
(Lesen und schreiben)

The name of a layer the way it would appear in the table of contents. Spaces can be included. It is important that all layers in a map have a unique name so they can be easily referenced by their names.

String
showLabels
(Lesen und schreiben)

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
(Lesen und schreiben)

Provides access to a layer's symbology.

Object
transparency
(Lesen und schreiben)

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
visible
(Lesen und schreiben)

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

Methodenübersicht

MethodeErklärung
extrusion ({extrusion_type}, {expression})

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

getDefinition (cim_version)

Gets a layer's CIM definition.

getSelectionSet ()

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

listLabelClasses ({wildcard})

Returns a Python list of LabelClass objects in a layer.

listLayers ({wildcard})

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

saveACopy (file_name)

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

setDefinition (definition_object)

Sets a layer's CIM definition.

setSelectionSet ({oidList}, {method})

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

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.

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

Replaces connection properties using a dictionary or a path to a workspace.

updateLayerFromJSON (json_data)

Updates a Layer from a JSON string.

Methoden

extrusion ({extrusion_type}, {expression})
ParameterErklärungDatentyp
extrusion_type

A string that specifies the extrusion method. The default value is NONE which turns off layer extrusion.

  • ABSOLUTE_HEIGHTThe feature is extruded to the specified z-value, as a flat top, regardless of the z-values of the feature.
  • BASE_HEIGHTA 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_HEIGHTAdds extrusion height to the minimum z-value of the feature, and the feature is extruded to a flat top at that value.
  • MIN_HEIGHTAdds extrusion height to the minimum z-value of the feature, and the feature is extruded to a flat top at that value.
  • NONEFeatures are not extruded.

(Der Standardwert ist NONE)

String
expression

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

(Der Standardwert ist None)

String

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.

getDefinition (cim_version)
ParameterErklärungDatentyp
cim_version

A string that represents the major version of the CIM.

String

CIM-level access to additional object properties was introduced at version 2.4. Esri follows the semantic versioning specification. This means that until the next major release—for example, 3.0—when breaking API changes are allowed, the value to be used with cim_version is V2. Once 3.0 is released, a new V3 option will become available. This gives Python script authors control over the CIM version that will be used during execution if there is a possibility that breaking changes may be introduced in the new version.

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

getSelectionSet ()

Provides an easy way to retrieve the layer's current selection.

listLabelClasses ({wildcard})
ParameterErklärungDatentyp
wildcard

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.

(Der Standardwert ist None)

String
Rückgabewert
DatentypErklärung
List

Returns a Python list of LabelClass objects in a layer.

Returns a Python list of LabelClass objects in a layer.

listLayers ({wildcard})
ParameterErklärungDatentyp
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.

(Der Standardwert ist None)

String
Rückgabewert
DatentypErklärung
List

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

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

saveACopy (file_name)
ParameterErklärungDatentyp
file_name

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

String

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).

setDefinition (definition_object)
ParameterErklärungDatentyp
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.

setSelectionSet ({oidList}, {method})
ParameterErklärungDatentyp
oidList
[oidList,...]

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

(Der Standardwert ist None)

Integer
method

A string that specifies which selection method to use.

  • NEWCreates a new feature selection from the oidList.
  • DIFFERENCESelects the features that are not in the current selection but are in the oidList.
  • INTERSECTSelects the features that are in the current selection and the oidList.
  • SYMDIFFERENCESelects the features that are in the current selection or the oidList but not both.
  • UNIONSelects all the features in both the current selection and those in the oidList.

(Der Standardwert ist NEW)

String

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.

supports (layer_property)
ParameterErklärungDatentyp
layer_property

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

  • BRIGHTNESSA raster layer's brightness value.
  • CONNECTIONPROPERTIESA Layer's connection information.
  • CONTRASTA raster layer's contrast value
  • DATASOURCEA layer's file path or connection file.
  • DEFINITIONQUERYA layer's definition query string.
  • LONGNAMEA layer's path including the group layers it may be nested within.
  • MAXTHRESHOLDA layer's maximum threshold to display the features.
  • MINTHRESHOLDA layer's minimum threshold to display the features.
  • NAMEA layer's name.
  • TRANSPARENCYA layer's transparency value.

(Der Standardwert ist name)

String
Rückgabewert
DatentypErklärung
Boolean

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.

updateConnectionProperties (current_connection_info, new_connection_info, {auto_update_joins_and_relates}, {validate}, {ignore_case})
ParameterErklärungDatentyp
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.

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.

(Der Standardwert ist 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, regardless of a valid match. In this case, if a match does not exist, then the data sources would be broken.

(Der Standardwert ist True)

Boolean
ignore_case

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

(Der Standardwert ist False)

Boolean

For more detailed discussion, parameter information, scenarios, and code samples, refer to the Updating and fixing data sources help topic.

updateLayerFromJSON (json_data)
ParameterErklärungDatentyp
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

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.

Codebeispiel

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