Skip to main content
tidying up
Source Link
JimT
  • 2.4k
  • 2
  • 13
  • 24

The variable rasterpath is a loop variable and contains the last iterated value from the previous loop, and can not contain the path of the reoccuringreoccurring raster.

Try something like this instead [sorry - bit clumsy and not tested]:

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(key)
      for rasterpath in sorted(inputRasters.split(';')):
          Ras = str(os.path.basename(rasterpath))
          if Ras == key:
              #this is where you have identically named rasters and can do the mosaic
              #in this instance the rasterpath variable does contain the path+name of a raster which has the same name as another

  

The variable rasterpath is a loop variable and contains the last iterated value from the previous loop, and can not contain the path of the reoccuring raster.

Try something like this instead [sorry - bit clumsy and not tested]:

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(key)
      for rasterpath in sorted(inputRasters.split(';')):
          Ras = str(os.path.basename(rasterpath))
          if Ras == key:
              #this is where you have identically named rasters and can do the mosaic

  

The variable rasterpath is a loop variable and contains the last iterated value from the previous loop, and can not contain the path of the reoccurring raster.

Try something like this instead [sorry - bit clumsy and not tested]:

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(key)
      for rasterpath in sorted(inputRasters.split(';')):
          Ras = str(os.path.basename(rasterpath))
          if Ras == key:
              #this is where you have identically named rasters and can do the mosaic
              #in this instance the rasterpath variable does contain the path+name of a raster which has the same name as another

  
Source Link
JimT
  • 2.4k
  • 2
  • 13
  • 24

The variable rasterpath is a loop variable and contains the last iterated value from the previous loop, and can not contain the path of the reoccuring raster.

Try something like this instead [sorry - bit clumsy and not tested]:

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(key)
      for rasterpath in sorted(inputRasters.split(';')):
          Ras = str(os.path.basename(rasterpath))
          if Ras == key:
              #this is where you have identically named rasters and can do the mosaic