[GIS] Repairing paths of unmanaged raster catalog in file geodatabase

arcgis-9.3arcpyfile-geodatabaseraster-catalog

I'm using ArcGIS 9.3.1 and I have an unmanaged file geodatabase with raster catalogs in it. Tiles are loaded inside the catalog and each tile has a "Full Path" property which is environment specific. Are there any examples around that show how to batch update the path property perhaps using the Python arcgisscripting API or some tool already built in to ArcGIS ?

enter image description here


After I posted I found a geoprocessing tool to do this:

Repair Raster Catalog Paths (Data Management)

enter image description here

…And to see what the paths change to after this tool runs:

Export Raster Catalog Paths (Data Management)

enter image description here

This outputs a .DBF file that can be viewed in ArcCatalog.

The problem is that my raster catalog paths are different, for example:

\\dgdbimg\EGD\Data\DTED_2\e041\n32.dt2
\\dgdbimg\EGD\Data\DTED_2\e041\n33.dt2
\\dgdbimg\EGD\Data\DTED_2\e042\n32.dt2
\\dgdbimg\EGD\Data\DTED_2\e042\n33.dt2

After running this tools with * it changes every path to whatever is specified as the new path:

C:\WorkSpace\Andy3\NgaRaster.gdb\DTED_2
C:\WorkSpace\Andy3\NgaRaster.gdb\DTED_2
C:\WorkSpace\Andy3\NgaRaster.gdb\DTED_2
C:\WorkSpace\Andy3\NgaRaster.gdb\DTED_2

I'm trying to find a way to just change the parent folder path like this:

"\\dgdbimg\EGD\Data\DTED_2" --> "C:\WorkSpace\Andy3\Data\DTED_2"

I'm might have to write some more intricate python to get the current path and do my own string manipulation in order to pass in the needed replacement path to the repairRasterCatalogPaths_management function.

It would be nice if the original path and new path parameters accepted regular expressions… I'll give this a try next…

Any recommendations?


Final Solution:

import arcgisscripting
import os.path

gp = arcgisscripting.create()

rasterCatalogPath = r"C:\WorkSpace\Andy\NgaRaster.gdb\DTED_2"
oldBasePath = r"\\server\share\Data"
newBasePath = r"C:\WorkSpace\Andy\Data"

dbfPath = r"C:\BrokenPath.dbf"
dbfXmlPath =  dbfPath + ".xml"

if os.path.exists(dbfPath):
    os.remove(dbfPath)

if os.path.exists(dbfXmlPath):
    os.remove(dbfXmlPath)

result = gp.exportrastercatalogpaths_management(
        rasterCatalogPath,
        "BROKEN",
        dbfPath)

rows = gp.SearchCursor(dbfPath)
row = rows.Next()
while row:
    path = row.GetValue("Path")
    fileParentPath = os.path.dirname(path)
    newPath = fileParentPath.replace(oldBasePath, newBasePath)

    gp.repairRasterCatalogPaths_management(
            rasterCatalogPath,
            "FIX",
            fileParentPath,
            newPath)

    row = rows.Next()

Best Answer

Based on your edit to your question, it looks like you need to parse out parts of the old path to build the new path. How about splitting up the old path into a list, then building the new path with parts of that list:

>>> import os
>>> old_path = "\\dgdbimg\EGD\Data\DTED_2"
>>> old_parts = old_path.split("\\")
>>> old_parts
['', 'dgdbimg', 'EGD', 'Data', 'DTED_2']
>>> new_path = os.path.join("C:\WorkSpace\Andy3", old_parts[3], old_parts[4])
>>> new_path
'C:\\WorkSpace\\Andy3\\Data\\DTED_2'
>>>

EDIT:

Have a meeting in a few minutes so quickly - here's what I'd do. Either manually push the dbf to a file geodatabase table or do it with code, then loop through the records of the table, and for each one use the parts to build the new path, then call the Repair Raster Catalogs Paths tool. Some psuedo-code:

push dbf to FGDB table (may be a tool to do this? or just do it manually in ArcCatalog)
loop through records in table
    parse out old paths parts
    build new path
    repairRasterCatalogPaths_management()

Here is real (untested) code to try:

import arcpy
import os

arcpy.env.overwriteOutput = 1
arcpy.TableToTable_conversion("C:/Temp/CatalogPaths.dbf", "D:/target.gdb", "DbfToTable")

rows = arcpy.SearchCursor("D:/target.gdb/DbfToTable")
for row in rows:
    old_path = str(row.getValue("Old_Path_Field"))
    old_parts = old_path.split("\\")
    new_path = os.path.join("C:\WorkSpace\Andy3", old_parts[3], old_parts[4])
    arcpy.RepairRasterCatalogPaths_management("RepairRC.gdb\\Unmanaged", "FIX", old_path, new_path)
Related Question