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")
1
  • 1
    Can you provide some samples of the output you expect for a few iterations through the main for loop? Commented Jul 26, 2021 at 16:50

1 Answer 1

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}")
Sign up to request clarification or add additional context in comments.

2 Comments

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 (<string>, line 13) ---------------------------------------------------------------------------
I have a feeling it is the second line, MULTI{i} probably needs to be a legit filename

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.