In ArcMap, I've created a layer group that I would like to add extracted subdatasets from a file to. It is a .grb file and I've successfully done this with the provided "Extract Subdataset" tool. Is it possible to do this in python with a loop to name each out_raster in the group according to index? For example, for subdataset_index = "00", then out_raster = "filename+"010"+" and so on for all indices in the original file? I've seen this done manually with the batch method, but I have 44 subdatasets to extract in each file.

import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
df = mxd.activeDataFrame
idx = 0
while idx < 10:
  in_ras = "C:/Data/gribFile.grb"
  out_ras = "C:/ArcGIS/geoDB.gdb/Grb_+'FL'+idx+'10'"
  arcpy.ExtractSubDataset_management(in_ras, out_ras, idx)
  idx = idx+1

I guess I'm getting stuck on how to grab each index from each file as object. Below is error I'm getting.

Error message: Runtime error Traceback (most recent call last):
File "", line 8, in File "c:\program files (x86)\arcgis\desktop10.4\arcpy\arcpy\management.py", line 14129, in ExtractSubDataset raise e ExecuteError: ERROR 999999: Error executing function. The table name is invalid. No spatial reference exists. Invalid function arguments Invalid function arguments An invalid SQL statement was used. [SELECT ObjectID, UUID, Type FROM GDB_Items WHERE PhysicalName = 'Grb_+'FL'+IDX+'10'' AND Type IN ('{70737809-852C-4A03-9E22-2CECEA5B9BFA}')] Failed to execute (ExtractSubDataset).

Was able to get it working with this:

import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
df = mxd.activeDataFrame
#Levels array
lvs = {myArray}

for ftLevel in lvs:     
level = ftLevel
FL = lvs[ftLevel]
gFile = "C:/filepath"
gFileDate = "G_2016"
gFileHour = "000HR"
gRasterFileloc = "C:/filepath/raster"
in_ras = gFile+gFileDate+gFileHour+".grb"
out_ras = gRasterFileloc+gFileDate+gFileHour+FL
arcpy.ExtractSubDataset_management(in_ras, out_ras, level)

closed as off-topic by PolyGeo Nov 18 '16 at 4:06

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This problem cannot or can no longer be reproduced. Changes to the system or to the asker's circumstances may have rendered the question obsolete, or the question does not include a procedure to enable potential answerers to reproduce the same symptoms. Such questions are off-topic as they are unlikely to help future readers, but editing them to include more details can lead to re-opening." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    What have you tried? Questions asking for help with code should include a snippet of the code you've actually tried, and details on where you are stuck. Please edit your question to include any extra information. The answer to your question "Is it possible to do this in python" is more than likely just "Yes, it is possible" – Midavalo Oct 28 '16 at 18:31
  • thanks Midavalo. I've updated with where I started in arcpy. – Jotter Oct 28 '16 at 18:50
  • Are receiving any errors, if so please include those messages into the question. – artwork21 Oct 28 '16 at 18:55
  • I've attached the error I'm getting. Hoping this is syntax. – Jotter Oct 29 '16 at 21:09