python loop - saving output

6137
3
12-17-2017 12:24 PM
by Anonymous User
Not applicable

The script is intended to subtract the loop variable from a raster and save the raster using an appropriate name.

I tried quite a few work-arounds, but all methods seem the hit a wall. The attached image shows that the same simple tool in modelbuilde casts the same error.

Anyone that made something similar?

Via this simple python loop:

import arcpy
stepper = 5
for stepper in range (20):

      name="AFVdtm"+str(stepper)
      name= arcpy.sa.Minus("DTM_frostkærLocal.tif",stepper)
      stepper += stepper
      rod = "c:/testmappe/"
      name=name
      eft=".tif"
      sti=rod+name+eft
      name.save(sti)

Traceback (most recent call last):

File "<string>", line 10, in <module>

File "c:\program files\arcgis 2.0\pro\Resources\arcpy\arcpy\sa\Functions.py", line 4331, in Plus

in_raster_or_constant2)

File "c:\program files\arcgis 2.0\pro\Resources\arcpy\arcpy\sa\Utils.py", line 53, in swapper

result = wrapper(*args, **kwargs)

File "c:\program files\arcgis 2.0\pro\Resources\arcpy\arcpy\sa\Functions.py", line 4328, in Wrapper

["Plus", in_raster_or_constant1, in_raster_or_constant2])

RuntimeError: ERROR 000732: Input Raster: Dataset c:/testmappe/ does not exist or is not supported

I have tried using relative and absolute paths, which doesn't change anything in the error.

 Running it like:

 

import arcpy

stepper = 5

for stepper in range (20😞

     name="AFVdtm"+str(stepper)

    name= arcpy.sa.Minus("DTM_frostkærLocal.tif",stepper)

    stepper += stepper

    name.save("c:/testmappe/%name%.tif")

Produces the intended output, but continously overwrites it

Tags (1)
0 Kudos
3 Replies
DanPatterson_Retired
MVP Emeritus

Code formatting the basics++ 

Because it looks off.. and your paths don't look correct to begin with.  I would throw some print statements in to get an idea of what the actual inputs and outputs look like

0 Kudos
by Anonymous User
Not applicable

I just updated it, does that help?

Please don't pay attention to indentation, it is obviuosly somethings that happens when pasting.

When using the modelbuilder solution I see that Minus/Raster Calculator interpretes the output of the For loop as a string  Jeez, ESRI.

I edit it to int(%Vakue%) which solves the calculation-part of the problem. Not the saving-part.

0 Kudos
DanPatterson_Retired
MVP Emeritus

name is still wrong... try to create one using a base name.. 

outName = "thisfile"

then you can append to that file with your stepper

sti = "/".join([rod, outname+str(stepper), eft])
0 Kudos