Select to view content in your preferred language

Raster Layer Datasource not changable?

2504
3
02-23-2016 10:02 AM
DaveHighness
Deactivated User

I have a Map Document with a bunch of raster layers referenced by drive letter and need to change them to UNC paths. I've tried all the methods with the Map Document and by Layer to change the paths. The methods work for Feature Layers but not for the Raster Layers. If I add the layers manually to the map document they get added with the UNC path, then I can symbolize, rename and save. That is lame though!

Is this still a bug?

https://community.esri.com/message/205282#comment-205282

tried:

mxd.findAndReplaceWorkspacePaths()

mxd.replaceWorkspaces()

lay.replaceDataSource()

lay.findAndReplaceWorkspacePath()

0 Kudos
3 Replies
DaveHighness
Deactivated User

Ok, so if I do replace the datasource of the layer in the MXD and then write the layer out to a layer file then the datasource is updated in the layer file but not in the MXD. Then I can load the layer file into the MXD and the datasource is update for that layer. That's silly but it works.

0 Kudos
RebeccaStrauch__GISP
MVP Emeritus

What version of ArcGIS are you using.  I have been able to replace rasters (see my addin Python addin for data inventory and “broken-link” repair.​  for my full .py files) .  This could be modified to update non-broken links (I haven't done that yet)

Just a snippet for the raster (from repair broken link tool in my addin) ...it won't do much by itself, but might give you an idea.  To see it in context, check out the addin.

NOTE: indentation of the first else removed for paste in geonet

else: #if lyr.supports("DATASOURCE") and lyr.supports("DATASETNAME"):
    updateStatus = str(updatePath[0])   # used for message only
    if lyr in theTables:
        #myMsgs("  thinks its a table....using findAndReplsWorkspacePath")
        myMsgs("        *Moving {0}: {1} to new: {2}".format(updatePath[3], lyr.dataSource, updatePath[0]))
        reportFile.write("\n   Moving {0}: {1} to new: {2} \n".format(updatePath[3], lyr.dataSource, updatePath[0]))
        lyr.findAndReplaceWorkspacePath(lyr.dataSource, updatePath, False)                    
    elif lyr.isRasterLayer:
        #myMsgs("  thinks its a raster....using findAndReplsWorkspacePath")
        myMsgs("        *Moving {0}: {1} to new: {2}".format(updatePath[3], lyr.dataSource, updatePath[0]))
        reportFile.write("\n   Moving {0}: {1} to new: {2} \n".format(updatePath[3], lyr.dataSource, updatePath[0]))
        newType = "RASTER_WORKSPACE"
        for extType in lstExtDatatype:
            if extType[0] in updatePath[0]:
                newType = extType[1] 
                if extType[0] == '.gdb':
                    newDSPath = newDSPath.split('.gdb', 1)[0] + '.gdb'
                    #newType = extType[1]
                elif extType[0] == '.sde':
                    newDSPath = newDSPath.split('.sde', 1)[0] + '.sde'
                break                      
        lyr.replaceDataSource(newDSPath, newType, newDSName, False)
        if not sameType:
            testOldTOC = updatePath[4].strip('\\')
            if lyr.name == testOldTOC:
                lyr.name = lyr.datasetName
    else:
        newType = updatePath[1] 

btw -- you can replace all   "myMsgs" with "print"

0 Kudos
DaveHighness
Deactivated User

I'm using 10.3.1 and tried essentially the same thing as seen in your code. For some reason the path will not change from drive letter to UNC in the MXD. Both paths are valid and point to the same FGDB so I'm wondering if that is the problem. Like I say if I write the Layer object out to a layer file then the layer file has the UNC path in it. I'm not sure if it's a bug or a feature.

Thanks

0 Kudos