0

I am working with ArcGIS, but this should be applicable to any situation with an iterator and a string. I have pairs of images which I want to run through this function, which have the same name and then increasing numbers within parenthesis. I am trying to use an iterator which would update the number on each loop, so the process would run each loop on 2 different images.

Here is my code:

def my_filter(iterable):
    result=[]
    for i in iterable:
        result.append(i)
        if i==400:
            continue
        yield result
        result=[]

idx = iter(range(0, 400))

for i in my_filter(idx):
    arcpy.management.CompositeBands("'Visual ("[i]").tif';'Thermal ("[i]").tif'",
        r"C:\Users\calma\Documents\ArcGIS\Projects\RasterMerge\RasterMerge.gdb\Multi"[i])
}

Essentially, is there a way for me to put the is in this string that would recognize it as a part of the string and get the correct photo?

Here is what it normally looks like:

arcpy.management.CompositeBands("'Visual (23).tif';'Thermal (23).tif'", r"C:\Users\calma\Documents\ArcGIS\Projects\RasterMerge\RasterMerge.gdb\Multi23")
calmacc
  • 1
  • 1

1 Answers1

1

You mean like?

arcpy.management.CompositeBands(f"'Visual ("{i}").tif';'Thermal ("{i}").tif'",
    f"C:\Users\calma\Documents\ArcGIS\Projects\RasterMerge\RasterMerge.gdb\Multi{i}")
martineau
  • 119,623
  • 25
  • 170
  • 301
eatmeimadanish
  • 3,809
  • 1
  • 14
  • 20
  • This might be the right syntax, but the interpreter in ArcGIS is throwing an error message at this. --------------------------------------------------------------------------- SyntaxError Traceback (most recent call last) File C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\ast.py, in parse: Line 35: return compile(source, filename, mode, PyCF_ONLY_AST) SyntaxError: invalid syntax (, line 13) --------------------------------------------------------------------------- – calmacc Jul 26 '21 at 18:10
  • I have a feeling it is the second line, MULTI{i} probably needs to be a legit filename – eatmeimadanish Jul 26 '21 at 18:14