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 ?
After I posted I found a geoprocessing tool to do this:
Repair Raster Catalog Paths (Data Management)
…And to see what the paths change to after this tool runs:
Export Raster Catalog Paths (Data Management)
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:
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:
Here is real (untested) code to try: