0

I'm trying to convert a list of rasters in a geodatabase to integer type and rename them with a specific folder name as the prefix. This first block of code moves the ASCII rasters into the geodatabase. And it works fine.

import arcpy, os
from arcpy import env
from arcpy.sa import *

# Set the environment variables
sr = arcpy.SpatialReference(26911)
env.overwriteOutput=True
env.extent = 'MAXOF'


### Change to the desired scenario/replicate
# "Scenario1_Rep2"
# "Scenario1_Rep6"
# "Scenario2_Rep2"
# "Scenario2_Rep5"
# "Scenario3_Rep2"
# "Scenario3_Rep7"
# "Scenario4_Rep2"
# "Scenario4_Rep9"

# set workspace
scene = "Scenario1_Rep2"
path = "C:\\GIS\\PROJECT\\LakeTahoeWest\\Data\\LANDIS\\WaterQualityAnalysis\\"
env.workspace = os.path.join(path, scene)

# define output gdb
outgdb = "C:\\GIS\\PROJECT\\LakeTahoeWest\\Data\\LANDIS\\WaterQualityAnalysis\\WaterQualityAnalysis.gdb"

# Get a list of rasters from the workspace
rasters = arcpy.ListRasters("*", "ALL")

# loop through raster list 
for raster in rasters:
    # create describe object of each raster
    desc = arcpy.Describe(raster)
    inras = desc.CatalogPath
    print ("Copied " + desc.baseName + " to fgdb.")
    # create new raster in gdb
    arcpy.RasterToGeodatabase_conversion(inras, outgdb)

This next block of code is where the error happens:

import arcpy, os

# Name = "WaterQualityAnalysis"
# wFolder = r"C:\GIS\PROJECT\LakeTahoeWest\Data\LANDIS\WaterQualityAnalysis"
# GDB = os.path.join(str(Name) + ".gdb")

# env.workspace = os.path.join(str(wFolder), str(GDB))
# print (arcpy.Exists(env.workspace))

env.workspace ="C:\\GIS\\PROJECT\\LakeTahoeWest\\Data\\LANDIS\\WaterQualityAnalysis\\WaterQualityAnalysis.gdb"

# Get a list of rasters from the workspace
rasters = arcpy.ListRasters("*_img", "ALL")
print(rasters)
# loop through raster list 
for raster in rasters:

    # create describe object of each raster
    desc = arcpy.Describe(raster)
    inras = desc.CatalogPath
    print(inras)
    # project the raster to UTM Zone 11N
    arcpy.DefineProjection_management(inras, sr)
    # get the new name to print
    dsc = arcpy.Describe(inras)
    year = str(dsc.baseName[0:-4].split('_')[-1])
    event = str(dsc.baseName[0:-4].split('_')[0])

    print ("Created: " + dsc.baseName)

    # convert to integer type and save to gdb
    outras = Int(inras)
    outras.save(outgdb + "\\" + scene + "_" + event + "_" + year)
    # return success message
    desc = arcpy.Describe(outras)
    print ("Created: "+ desc.baseName)
    print ("Deleting " + dsc.baseName)
    arcpy.Delete_management(inras)

As you can see, I've messed around with the path names a bit thinking that was the issue.

Here is the output and error I'm getting:

['fire_intensity_41_img', 'fire_intensity_42_img', 'fire_intensity_43_img', 'fire_intensity_44_img', 'fire_intensity_45_img', 'fire_intensity_46_img', 'fire_intensity_47_img', 'fire_intensity_48_img', 'fire_intensity_49_img', 'fire_intensity_50_img']
C:\GIS\PROJECT\LakeTahoeWest\Data\LANDIS\WaterQualityAnalysis\WaterQualityAnalysis.gdb\fire_intensity_41_img
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-14-44c2fe5a12b6> in <module>
     17 
     18     # create describe object of each raster
---> 19     desc = arcpy.Describe(raster)
     20     inras = desc.CatalogPath
     21     print(inras)

C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\__init__.py in Describe(value, data_type)
   1241        class with the same name. In this case, the data type is used to clarify
   1242        which dataset you want to describe."""
-> 1243     return gp.describe(value, data_type)
   1244 
   1245 def CreateObject(name, options=None):

C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py in describe(self, *args)
    366         from arcpy.arcobjects.arcobjectconversion import convertArcObjectToPythonObject
    367         return convertArcObjectToPythonObject(
--> 368                     self._gp.Describe(*gp_fixargs(args, True)))
    369     def createObject(self, *args):
    370         """GP function CreateObject"""

OSError: "fire_intensity_42_img" does not exist
7
  • Have you tried inspecting "fire_intensity_42_img" in your FGDB to make sure it is not corrupt?
    – Aaron
    Commented Feb 1, 2019 at 4:35
  • Yeah it's a legit raster. I pulled it into ArcMap and was able to do other geoprocessing tasks on it. Commented Feb 1, 2019 at 17:22
  • All of the rasters are showing up in the list generated by arcpy.ListRasters(). Commented Feb 1, 2019 at 17:37
  • How are you implementing the script? Any difference running the script using an IDE vs the ArcGIS interpreter?
    – Aaron
    Commented Feb 1, 2019 at 17:40
  • I've been running it in a Jupyter Notebook against my ArcPro environment. I'll try it as a script in IDLE. I think this might be the issue....Great catch. I'll report back in bit. Commented Feb 1, 2019 at 18:13

1 Answer 1

0

You mentioned in the comments that you are implementing the script using Jupyter. The issue is likely related to a bad or broken call to your arcpy site package. You can test this by running the script first on Jupyter and then on the ArcGIS Python interpreter.

1
  • Thanks for the help. This problem is indeed an issue with the arcpy site package run in a Jupyter notebook. I've opened a ticket with ESRI Tech support. I'll post their answer here. Commented Feb 1, 2019 at 21:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.