ArcGIS 10.2 - arcpy.ListRasters() returns nothing for a Raster Catalog in FGDB!

5772
8
Jump to solution
12-15-2015 08:22 AM
VincentLaunstorfer
Occasional Contributor III

Hi,

In a script, the rasters = arcpy.ListRasters() returns nothing for a Raster Catalog held in a File GDB? The workspace references to the Raster Catalog itself and I would expect to list the rasters in that Raster Catalog... But the list is empty!

rasters = arcpy.ListRasters("*", "All")
arcpy.AddMessage("Rasters: " + str(rasters))
i = 0
for raster in rasters:
    i = i + 1
arcpy.AddMessage("Count Rasters: " + str(i) + "\n")

returns

Rasters: []

Count Rasters: 0

Is there anything wrong I am doing?

Thank you

0 Kudos
1 Solution

Accepted Solutions
LukeSturtevant
Occasional Contributor III

You would treat a raster catalog as a table. To get a list of rasters in the catalog you would use a search cursor:

rasCatalog = # path to raster catalog
rasterList = [row[0] for row in arcpy.da.SearchCursor(rasCatalog,["Name"])]

View solution in original post

8 Replies
LukeSturtevant
Occasional Contributor III

You would treat a raster catalog as a table. To get a list of rasters in the catalog you would use a search cursor:

rasCatalog = # path to raster catalog
rasterList = [row[0] for row in arcpy.da.SearchCursor(rasCatalog,["Name"])]
VincentLaunstorfer
Occasional Contributor III

Thanks

Your syntax does work for listing the rasters in the Raster Catalog, but now I cannot go further:

for raster in rasters:
    arcpy.gp.ExtractValuesToPoints(fc, raster, fc_tmp)

...because I would imagine that rasters contains only string and not Raster object.

Any guess?

0 Kudos
LukeSturtevant
Occasional Contributor III

Right working with raster catalogs are kind of a pain. Do do any operations with the rasters in the catalog you would need to export the raster then do the operation and if you do not want to keep the exported raster you would need to delete it afterwards. Something like this would work

rasCatalog = # path to raster
rasterList = [row[0] for row in arcpy.da.SearchCursor(rasCatalog,["Name"])]
fc = # path to feature layer

for raster in rasterList:
     expression = "Name = '{0}'".format(raster)
     arcpy.RasterCatalogToRasterDataset_management(rasCatalog,PathForExportRaster,expression)
     arcpy.gp.ExtractValuesToPoints(fc,PathForExportRaster, fc_tmp)  
JoshuaBixby
MVP Esteemed Contributor

If you set your workspace to a raster catalog, then ListDatasets will list the contents of the raster catalog.  It seems a bit goofy, but it works.  That said, I like to use the Walk function that is part of the Data Access module.

rasCatalog = # path to raster 
_, _, rasterList = next(arcpy.da.Walk(rasCatalog))
VincentLaunstorfer
Occasional Contributor III

Hi,

The ListDatasets function works very well to run through a RasterCatalog. It took 3h58min to extract elevation from 1320 tiled DEMs...

Now, I would like to test the Walk function in order to see if the processing would be faster because the Data Access module is supposed to access data much faster according to ESRI documentation.

However,

_, _, rasters = next(arcpy.da.Walk(rasCatalog))

for raster in rasters:
     arcpy.gp.ExtractValuesToPoints(fc, raster, fc_tmp)

did not work with workspace set a the Raster Catalog path...

And I have to admit that I am not familiar with the Data Access module syntax!

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

The time it takes for your script to run is being driven by geoprocessing, not finding/listing/enumerating your rasters.  You may shave a few minutes here or there, but I don't expect any real change in runtime based on ListDataSets or Walk.

Regarding using Walk, can you elaborate on "did not work?"  Did it generate an error?  If so, what error?  What backend storage is holding your raster catalog?  File geodatabase?  Enterprise geodatabase (SDE)?

0 Kudos
VincentLaunstorfer
Occasional Contributor III

Hi,

The Raster Catalog is in a File GDB v10.2.

With a Mosaic Dataset, it takes just a few minutes to run the script versus a few hours with the Raster Catalog. However, I would prefer to use Raster Catalog because it can manage the rasters within the File GDB and compress the rasters smartly. The Mosaic Dataset just point to the rasters on disk...

The error I receive is:

<function GetMessages at 0x1ACABF70>
Completed script RasterValuesToPointsCATALOG...
Succeeded at Tue Dec 22 11:44:46 2015 (Elapsed Time: 1.48 seconds)

when the script tries:

arcpy.gp.ExtractValuesToPoints(fc, raster, fc_tmp)

This is the reason why I suspect the rasters object genereted with the Walk functions not containing the proper raster...

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

The "error" you posted isn't an error, e.g., "completed script" and "succeeded."  If there is an actual error message, it would be helpful to see.  Or, is it the results aren't what you expect?

0 Kudos