I have a python script that, as part of the code, separates raster bands and then uses Con to identify black pixels; like this:
MyRaster = r"MyRaster.tif" redband = MyRaster + "\Band_1" greenband = MyRaster + "\Band_2" blueband = MyRaster + "\Band_3" BlackPixels = Con (((Raster(redband)==0 & (Raster(greenband)==0..................
However, I'm now trying to make this script into a python toolbox but the bands are not being recognised; like this:
def getParameterInfo(self): inRaster = arcpy.Parameter( displayName="input raster", name="inraster", datatype=["GPRasterLayer","DERasterDataset"], parameterType="Required", direction="Input") ....... return [inRaster] def execute (self,parameters,messages): MyRaster = parameters[0].valueAsText redband = MyRaster + "/Band_1" greenband = MyRaster + "/Band_2" blueband = MyRaster + "/Band_3" BlackPixels = Con (((Raster(redband)==0 & (Raster(greenband)==0..................
I get following message
RuntimeError: ERROR 000732: Input Raster: Dataset MyRaster.tif/Band_1 does not exist.
What am I doing wrong?
Solved! Go to Solution.
print the path to see what is returned
print the path to see what is returned
messages.addMessage("MyRaster = " + MyRaster)
--> MyRaster = MyRaster.tif
this is what I expect. maybe my expectations are wrong.
Since it is a multiband raster, you will have to split it by band or access it by band, if you need to perform the con statement in your execute section, confirm that you can do it manually first, then use the results window.
got ya.
path = arcpy.Describe(MyRaster).path
redband = path + "\\" + MyRaster + "\\Band_1"
Couple of ways to do this easily in the answers to the following GIS Stack Exchange question:
I'll throw this in for future reference for other users as the band names are not always guaranteed to be "Band_[1-N]"