0

I am working on a series of geoprocessing tasks and trying to define the output through the concatenation of folders, a geodatabase, and finally a raster dataset. Each way I try it I receive an error stating: TypeError: unsupported operand type(s) for +: 'Result' and 'str'

Below is the code that I have so far with the Project Raster task giving me the error.

import arcpy
import os

#Set Environments
arcpy.env.scratchWorkspace = r"C:/GIS/temp/Subcatchment.gdb"
arcpy.env.overwriteOutput=True

#Create new folder and gdb as well clip and project DEM in WSPLN folder for new project

#Variables
Folder = "C:\GIS\TEMP\Subcatchments"
projectNbr = arcpy.GetParameterAsText(0)
gdbName = arcpy.GetParameterAsText(1)
watershedFC = arcpy.GetParameterAsText(2)
countyDEM = arcpy.GetParameterAsText(3)
outCS = arcpy.GetParameterAsText(4)
outTransformation = arcpy.GetParameterAsText(5)

#Create folder, gdb, and feature classes
projectFolder = arcpy.CreateFolder_management(Folder, str(projectNbr))
arcpy.CreateFolder_management(projectFolder, "MapDocs")
gdbFolder = arcpy.CreateFolder_management(projectFolder, "Geodatabases")
arcpy.CreateFolder_management(projectFolder, "Shapefiles")
gdb = arcpy.CreateFileGDB_management(gdbFolder, gdbName)

#Create buffer and clip county raster in memory
tempBuffer = arcpy.Buffer_analysis(watershedFC, "in_memory" + "\\wsBuffer", "2000 Feet", "FULL", "ROUND", "ALL")
tempRas = arcpy.Clip_management(countyDEM, "#", "in_memory" + "\\tempRas", 
tempBuffer, "#", clipping_geometry="ClippingGeometry")

#Project raster to county coords and change units
DEMname = "DEM"
arcpy.ProjectRaster_management(tempRas, gdbFolder + "\\" + gdb + ".gdb" + "\\" + DEMname, outCS, "", "", outTransformation)
  • 2
    It is difficult to debug this because we cannot see your input parameters. Any chance you can replace the GetParameterAsText() calls with the actual parameter? Also, you should not assign the commands to variables and then try to concatenate those with strings. It is advisable to use os.path.join() to concatenate paths and strings. – Aaron Jun 9 '17 at 22:44
  • Folder = "C:\GIS\TEMP\Subcatchments" This will also cause you issues as '\T' is interpreted as a Tab character. Use forward slashes ('C:/path') , raw strings (r'C:\path') or escape your backslashes ('C:\\path'). – user2856 Jun 10 '17 at 6:12
2

As Aaron has commented, it's hard to know what's happening as you haven't put any paths into your code, only input parameters.

The error is clear though

TypeError: unsupported operand type(s) for +: 'Result' and 'str'

You cannot concatenate a Result object with a string value. Where you have something like gdb = arcpy.CreateFileGDB_management(gdbFolder, gdbName), the gdb could be returned as a result object (the result of the Create File GDB), rather than a string value of the path.

This means you could be getting something like <geoprocessing object 1234567> instead of C:\Temp\MyGeodatabase.gdb

So instead of gdb = arcpy.CreateFileGDB_management(gdbFolder, gdbName), try instead to use something like gdb = os.path.join(gdbFolder, gdbName) to create your gdb path. Then in your Project Raster at the end, use those variables rather than results to construct your path using os.path.join()

gdb = os.path.join(gdbFolder, "{0}.gdb".format(gdbName))

arcpy.ProjectRaster_management(tempRas, os.path.join(gdb, DEMName), outCS, "", "", outTransformation)

Please Note: I am not saying that it is gdb that is causing the problem, it could be any (or all) of your geoprocessing results. You may need to look at replacing all of them, or determine which one is breaking your concatenation.

| improve this answer | |
  • I am a newbie to python so I appreciate the insight on using os.path.join. The gdb variable was the issue. I tried to vote but my reputation isn't high enough. Thanks! – ertl Jun 10 '17 at 13:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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