Hello,
I have several thousands of file geodatabases with different FGDBR Datasets I want to identify and copy into a central file geodatabase. Unfortunately my ArcPy skills are not so advanced to get the nested loops to run from one file geodatabase to the next, selecting and copying the FGDBR into my targed file geodatabase.
I started with this code snipped, but it does not find any of my selected FGDBRs. What am I missing?
Any help is greatly appreciated!
import arcpy
from arcpy import env
import os
arcpy.env.overwriteOutput = True
arcpy.env.parallelProcessingFactor = "75%"
#
#
#--------------------
#Setting up first directories for source and destination for iterative raster data loop no 1
dir = r"F:\Daten_Wolff\Topographische_Gefaehrdungsanalyse\Test_Source"
arcpy.env.workspace = dir
folder001 = r"F:\Daten_Wolff\Topographische_Gefaehrdungsanalyse\BlueSpot_050.gdb"+ "\\"
gdbList = arcpy.ListWorkspaces('*','FileGDB')
for gdb in gdbList:
arcpy.env.workspace = gdb #--change working directory to each GDB in list
datasetList = arcpy.ListDatasets('*','Raster') #--make a list of all (if any) rastere datasets that exist in current GDB
for dataset in datasetList:
arcpy.env.workspace = dataset #--change working directory to each dataset (if any) in list
for Raster in arcpy.ListRasters('*050*'):
arcpy.env.workspace = dataset
for Raster in arcpy.ListRasters('*050*'):
print("processing raster: %s" %os.path.join("env.workspace",Raster))
outRasterdataset = folder001 + str(Raster.rsplit("_",0)[0])
arcpy.CopyRaster_management (Raster, outRasterdataset, "DEFAULTS", "", "-999", "NONE", "NONE" , "32_BIT_FLOAT", "NONE", "NONE" )
walk = arcpy.da.Walk(workspace, topdown=True, datatype="RasterDataset")
So that doesn't work then? (from the help)
I am assuming that it is a file geodatabase raster dataset
Exactly, the rasters are file geodatabase raster datasets (fgdbr)...
I manage to get all fgdbrs properly displayed with "print", but with the list approach I can't write the fgdbrs into the correct targed directory and withe the walk-approach I can't read the fgdbrs properly ...
Would be lovely to get some official help from as the error code suggests.
Cheers
Ingo
Can you elaborate on what isn't working with reading raster datasets with ArcPy Walk?
Hi!
I got this error-message:
arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Input Raster: Dataset bluespot_T2718199_050 does not exist or is not supported
Failed to execute (CopyRaster).
I think it is due to the fgdbr Format. But this is rather strange, as it is an ESRI dataformat which should easily be readable in arcpy...
How are you building the path to the data set before passing to Copy Raster? By the looks of it, you are passing only the data set name and not the data set full path. When using ArcPy Walk, just like when using Python Walk, you need to use os.path.join to get the full path from the root directory and file name.
Hi Joshua,
the scripts jumps first into the workspace directory with
dir = r"F:\Daten_Wolff\Topographische_Gefaehrdungsanalyse\Test_Source"
arcpy.env.workspace = dir
Then, inside the workspace directory, the list of gdbs is called by
gdbList = arcpy.ListWorkspaces('*','FileGDB')
for gdb in gdbList:
arcpy.env.workspace = gdb #--change working directory to each GDB in list
Now it goes from gdb to gdb.
For each gdb, I then apply the classical list of Raster loop, not befor telling the target directory as "folder":
folder = r"F:\Daten_Wolff\Topographische_Gefaehrdungsanalyse\BlueSpot_50.gdb"+ "\\"
RasterList = arcpy.ListRasters('*_050')
for Raster in RasterList:
print("processing raster: %s" %os.path.join("env.workspace",Raster))
outRasterdataset = folder + arcpy.Describe(Raster).baseName
arcpy.CopyRaster_management (Raster, outRasterdataset, "DEFAULTS", "", "-999", "NONE", "NONE" , "32_BIT_FLOAT", "NONE", "NONE" )
This works in ArcPy 2.7.14 quite nicely so far.
I have exatly 5107 gdbs to be searched für fgdbr Raster with the name suffix '*_050' or '*_100' and so on. Not in all of thes gdbs are thes Raster with that exact suffices, but the script shecks them all! So far, from my 5107 gdbs the script copied nicely 4936 fgdbrs with the suffix '*_050' into my targed gdb. I directly added the same loops for more suffices, and its working calm and steadily on my VM.
All the best!
Ingo
You have to file a case with Tech Support.
They normally don't troll around here looking for problems to solve
Ok, it appears I found a solution!
Just run everything with ArcPy 2.7.xx instead of ArcPy3.6.xx... for the first time it occured to me, that ArcPy 3.6.xx cannot solve a task ArcPy 2.7.xx can solve.
Here the working script, tested on a good dozen of gdbs:
import arcpy
from arcpy import env
import os
arcpy.env.overwriteOutput = True
arcpy.env.parallelProcessingFactor = "75%"
#
#
#--------------------
#Setting up first directories for source and destination for iterative raster data loop no 1
dir = r"F:\Daten_Wolff\Topographische_Gefaehrdungsanalyse\Test_Source"
arcpy.env.workspace = dir
gdbList = arcpy.ListWorkspaces('*','FileGDB')
for gdb in gdbList:
arcpy.env.workspace = gdb #--change working directory to each GDB in list
folder = r"F:\Daten_Wolff\Topographische_Gefaehrdungsanalyse\BlueSpot_50.gdb"+ "\\"
RasterList = arcpy.ListRasters('*_100')
for Raster in RasterList:
print("processing raster: %s" %os.path.join("env.workspace",Raster))
outRasterdataset = folder + arcpy.Describe(Raster).baseName
arcpy.CopyRaster_management (Raster, outRasterdataset, "DEFAULTS", "", "-999", "NONE", "NONE" , "32_BIT_FLOAT", "NONE", "NONE" )
This might explain, why the error message beforehand told me to go to Esri Support. Possibly a bug in ArcGISPro.
However, many thanks for your kind replies!
Ingo