AnsweredAssumed Answered

Programmatically get the data source from a lyr file pointing to an Esri GRID format raster uing Python 2.7 and ArcMap 10.5

Question asked by howeitzer on Nov 16, 2018
Latest reply on Nov 16, 2018 by howeitzer

I'm trying to get the data source from a bunch of lyr files pointing to various raster formats. Using the lyr.dataSource method on a feature layer after creating a layer object I can get the data source for TIFs fine but Esri GRID format rasters are seen as being directories. My goal is to re-path the lyr files to the same raster that has been copied to another location using the lyr.replaceDatasource method.

 

  1. import arcpy lyr = r”\\gis\test.lyr”
    layer = arcpy.mapping.Layer(lyr)
    print layer.dataSource

    Runtime error Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "c:\program files (x86)\arcgis\desktop10.5\arcpy\arcpy\arcobjects\_base.py", line 78, in _get(attr_name, self.__class__.__name__))
    NameError: The attribute 'dataSource' is not supported on this instance of Layer.


Is there a clever way to get the full data source for the lyr file?

Outcomes