2

I have created a simple script like that, which is working fine

import arcpy
from arcpy.sa import *
arcpy.CheckOutExtension("spatial")
arcpy.env.workspace = r'C:/2017/wgs84/project'
direction = arcpy.ListRasters("*WIND*","TIF")
print direction
speed = arcpy.ListRasters("*SPEED*","TIF")
print speed
for k in range(len(direction)):
 outCon = Con(Raster(direction[k]) == 1, Raster(speed[k]), 0)
 outCon.save('speed0' + str(k) + '.TIF')
 print ('done')
print ('done final')

I have different wind direction files(rasters) in different folders and speed files in another one. This code works for what I need, only if I have pasted the speed files and the wind files in the same folder. What if I wanted to create a list from one folder and a list from another so as not having to copy paste every time?

I tried to define also a different workspace for direction and different for speed but apparently its not working(maybe the last env.workspace is "hold" in the memory?)

arcpy.env.workspace = r'C:/speed'
speed = arcpy.ListRasters("*SPEED*","TIF")
print speed
arcpy.env.workspace = r'C:/2017/wgs84/project'
direction = arcpy.ListRasters("*WIND*","TIF")
PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Jul 27, 2018 at 13:47

1 Answer 1

2

This will list the raster names without full path/workspace:

arcpy.env.workspace = r'C:/speed'
speed = arcpy.ListRasters("*SPEED*","TIF")

So when you change workspace afterwards, arcpy will not know where to find them.

Try adding full path to the raster lists using os.path.join and list comprehension:

import os
arcpy.env.workspace = r'C:/speed'
speed = arcpy.ListRasters("*SPEED*","TIF")
speed = [os.path.join(arcpy.env.workspace,r) for r in speed]

And then do the same for the wind rasters in the other folder.

answered Jul 27, 2018 at 14:14
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.