I am trying to accomplish some image stacking task in python. I am not proficient in Python and was hoping I can get some guidance to get started.
So I have large number of landsat images. Landsat images for one particular year are stored in a folder and there are sub-directories for each scene. For each scene there are numerous tif images for different VIs and I need to stack them according to their dates.I can stack images in one single folder by reading each image. But I want to automate the process as different path_rows have different number of images(one path_row might have 5 image but other one might have 10 image).
-
Do they have the same number of rows/columns and cell size? Are they exactly the same geographical area? How many bands does each have? What are you trying to achieve, you say 'stack' does that mean you want oldest (n) bands first/last then newer (n) bands?Michael Stimson– Michael Stimson2016年05月18日 03:17:39 +00:00Commented May 18, 2016 at 3:17
-
Michael, They are images from same landsat path row. So they have same number of rows/colums and are same geographical area. Each image is one band. The images are named according to julian dates( the last three character in the image name is julina days). So i want the earlier dates first.michelle– michelle2016年05月18日 13:39:01 +00:00Commented May 18, 2016 at 13:39
-
Related : gis.stackexchange.com/questions/80620/… look at the accepted answer; You could do this in python with GDAL but I would find it quicker to run the command, all you need do is get the file names in chronological order.Michael Stimson– Michael Stimson2016年05月18日 21:21:09 +00:00Commented May 18, 2016 at 21:21
-
That's great Michelle, now use your experience (and screen shots) to answer your own question and get yourself some well deserved reputation points.Michael Stimson– Michael Stimson2016年05月24日 22:13:16 +00:00Commented May 24, 2016 at 22:13
1 Answer 1
So this was my solution:
test_vrt= ["gdalbuildvrt", "-separate", 'NDVI_test'+ ".vrt"]
image_list = glob.glob('*/*band1.tif')
for myfile in image_list:
test_vrt.append(myfile)
subprocess.call(test_vrt)
img2tiff =["gdal_translate","test.vrt", "test_composite.tif"]
subprocess.call(img2tiff)