I am creating a custom Python script in ArcGIS that takes a rasters as a multivalue input and have run into a problem which I don't think is a duplicate (having scoured SE for many hours)
My problem is that I want my script to look at the name of the raster and mosaic it if appears more than once in the list of inputs. Note that the directory path can be different, but the raster name the same i.e.
Where I am failing to understand is why it does not seem to preserve the data source (rasterpath) when I use the Counter tool from the collections module. I know I am probably going wrong in terms of how I am indenting here the script but I have script fatigue.
If I have an inputRasters value of:
The print results of
arcpy.AddMessage(rasterpath) will give me a rasterpath value of
'G:\DELIVERABLES\ABC.gdb\RASTER_1'. It's giving me the data source of the third raster.
The print results of arcpy.AddMessage(rasterlist) below are:['RASTER','RASTER','RASTER_1','RASTER_2']
import arcpy, sys,os import re import collections rasterlist =  inputRasters = arcpy.GetParameterAsText(0) for rasterpath in sorted(inputRasters.split(';')): Ras = str(os.path.basename(rasterpath)) rasterlist.append(str(Ras)) rasterlist = sorted(rasterlist) arcpy.AddMessage(rasterlist) counter = collections.Counter(rasterlist) for key, value in counter.items(): if value > 1: arcpy.AddMessage(rasterpath)
Can anyone tell me where I am going wrong?
I have tried varying the indentations to no avail.
Do I have to use split up the rasterpath using a "/" instead of using os.path.basename?