0

I'm doing a convolutional neural network classification and all my training tiles (1000 of them) are in geotiff format. I need to get all of them to a numpy array, but I only found code that will do it for one tiff file at a time.

Is there a way to convert a whole folder of tiff files at once?

Thanks!

2 Answers 2

0

Try using a for loop to go through your folder

Sign up to request clarification or add additional context in comments.

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
0

Is your goal to get them into 1000 different numpy arrays, or to 1 numpy array? If you want the latter, it might be easiest to merge them all into a larger .tiff file, then use the code you have to process it.

If you want to get them into 1000 different arrays, this reads through a directory, uses your code to make a numpy array, and sticks them in a list.

import os
arrays_from_files = []
os.chdir("your-folder")
for name in os.listdir():
     if os.path.isfile(name):
         nparr = ##use your code here
         arrays_from_files.append(nparr)

It might be a good idea to use a dictionary and map filenames to arrays to make debugging easier down the road.

import os
arrays_by_filename = {}
os.chdir("your-folder")
for name in os.listdir():
     if os.path.isfile(name):
         nparr = ##use your code here
         arrays_by_filename[name] = nparr

Comments

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.