Skip to content

Commit

Permalink
Add gp_layer_to_path function
Browse files Browse the repository at this point in the history
The gp_layer_to_path function is the same function than feature_layer_to_path
one but with a more accurate name.
  • Loading branch information
bastiencyr committed Feb 15, 2024
1 parent b1c1c4d commit 311ea64
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion sertit/arcpy.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import logging
import logging.handlers

from sertit.logs import deprecation_warning

# Arcpy types from inside a schema
SHORT = "int32:4"
""" 'Short' type for ArcGis GDB """
Expand Down Expand Up @@ -153,16 +155,46 @@ def emit(self, record):

def feature_layer_to_path(feature_layer) -> str:
"""
.. deprecated:: 1.36.0
Use :func:`gp_layer_to_path` instead.
Convert a feature layer to its source path.
Args:
feature_layer: Feature layer
Returns:
str: Path to the feature layer source
"""
deprecation_warning("This function is deprecated. Use gp_layer_to_path instead.")
# Get path
if hasattr(feature_layer, "dataSource"):
path = feature_layer.dataSource
else:
path = str(feature_layer)

return path


def gp_layer_to_path(feature_layer) -> str:
"""
Convert a GP layer to its source path.
A GP layer in ArcGis is a layer in the content panel. Thus, the user can simply choose the layer in a dropdown menu.
This function adds the possibility to get the source path of this layer if the user chose in the dropdown menu or
drag and drop from the Windows explorer.
Args:
feature_layer: Feature layer or Raster layer
Returns:
str: Path to the feature or raster layer source
Examples:
For python toolbox, in the getParameterInfo() method use GPFeatureLayer or GPRasterLayer datatype.
For python toolbox, in the getParameterInfo() method use GPLayer, GPFeatureLayer or GPRasterLayer datatype.
For vector layer use GPFeatureLayer:
>>> import arcpy
Expand All @@ -185,6 +217,17 @@ def feature_layer_to_path(feature_layer) -> str:
>>> direction="Input",
>>> )
If your layer may be a feature or raster layer, use GPLayer:
>>> import arcpy
>>> dem_path = arcpy.Parameter(
>>> displayName="DEM path as isoline or raster",
>>> name="dem_path",
>>> datatype="GPLayer",
>>> parameterType="Optional",
>>> direction="Input",
>>> )
Then in the execute() method, you can use this function to retrieve the real path to the layer.
>>> aoi_path = feature_layer_to_path(parameters[0].value)
Expand Down

0 comments on commit 311ea64

Please sign in to comment.