gp_layer_to_path#
- gp_layer_to_path(feature_layer) str [source]#
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.
- Parameters:
feature_layer – Feature layer or Raster layer
- Returns:
Path to the feature or raster layer source
- Return type:
Examples
For python toolbox, in the getParameterInfo() method use GPLayer, GPFeatureLayer or GPRasterLayer datatype.
For vector layer use GPFeatureLayer:
>>> import arcpy >>> aoi = arcpy.Parameter( >>> displayName="Aoi", >>> name="aoi", >>> datatype="GPFeatureLayer", >>> parameterType="Required", >>> direction="Input", >>> )
For raster layer, use GPRasterLayer:
>>> import arcpy >>> nir_path = arcpy.Parameter( >>> displayName="Nir infrared band", >>> name="nir_path", >>> datatype="GPRasterLayer", >>> parameterType="Optional", >>> 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) >>> print(aoi_path) D:/data/project/aoi/aoi.shp