Change the name of a rasterdataset in an rastercatalog

1540
7
06-18-2013 01:33 AM
gismoe
by
Occasional Contributor
Hello,

i want to convert all rasterdatasets from tif to png. These rasterdataset are part of a rastercatalog.

This is a my code snippet that works pretty well.

 datasetList = arcpy.ListDatasets("*","All")
 for dataset in datasetList:
  arcpy.RasterToOtherFormat_conversion(arcpy.Describe(dataset).file,test_PNG","PNG")


But i don't know to rename the rasterdatasets from 1.tif to 1.png

I tried describe.file and describe.name but there ist only: Raster.OBJECTID=404. I can't find the real name that is shown in the column called "name".

Any suggestions?
Tags (2)
0 Kudos
7 Replies
JamesCrandall
MVP Frequent Contributor
I could be incorrect but I was under the impression that rasters in a Raster Catalog are rows in a table (in a FGDB), stored in the Raster Column.  That is, there is no file type like .png, .tif, etc... and searching for such files will turn up nothing because you "load" the cataog with those rasters, but the FGDB does not maintain them as individual .tif/.png files.

Edit: if the rasters in the Raster Catalog are not "managed", then the catalog simply maintains links to individual rasters (.tif, .png's) on disk.  In this case, you could specify the location/folder on disk, search for and replace the file extensions for each of the rasters.  Is this what you need to to do?

james
0 Kudos
gismoe
by
Occasional Contributor
Have a look:

[ATTACH=CONFIG]25331[/ATTACH]

I can see the name in ArcCatalog but i can't find a way to work with it in python.
0 Kudos
JamesCrandall
MVP Frequent Contributor
Have a look:

[ATTACH=CONFIG]25331[/ATTACH]

I can see the name in ArcCatalog but i can't find a way to work with it in python.


Since the container in the Raster Catalog that maintains the individual rasters is a table, then maybe you can run an UpdateCursor on the table's field that holds the name of the rasters?  Not sure and would have to test some things, but this snip lists out the individual raster names in one of my raster catalogs:

rascat = r"C:\RasCat_05282013.gdb\May2013"
with arcpy.da.SearchCursor(rascat, "Name") as cursor:
    for row in cursor:
        print("{0}".format(row[0]))
0 Kudos
JamesCrandall
MVP Frequent Contributor
Okay --- I tested this and it renames each raster in my raster catalog with a ".tif" extension to ".png"


import arcpy
import os, sys

rascat = r"C:\RasCat_05282013.gdb\May2013"
with arcpy.da.UpdateCursor(rascat, "Name") as updcursor:
    for row in updcursor:
        curname = row[0]
        curname = curname.replace(".tif", ".png") 
        row[0] = str(curname)
        updcursor.updateRow(row)

0 Kudos
gismoe
by
Occasional Contributor
I made some little changes and it works pretty well!!!
Thank you very much.
0 Kudos
JamesCrandall
MVP Frequent Contributor
I made some little changes and it works pretty well!!!
Thank you very much.


Let's see it then!  I like knowing other methods too.
j
0 Kudos
gismoe
by
Occasional Contributor
I've had some little trouble with
row[0]
. => !underlying Database......index....! and so on.

So here is my new code:
rows = arcpy.UpdateCursor("d:/rasterdata.sde/BLP_Rasterdaten_PNG") 
for row in rows:
  curname = row.NAME
  curname = curname.replace(".tif", ".png") 
  row.NAME = str(curname)
  rows.updateRow(row)


That's all. Mostly copied from ESRI-Help and nothing new. Sorry!
0 Kudos