semiautomaticgit / SemiAutomaticClassificationPlugin

https://fromgistors.blogspot.com/p/semi-automatic-classification-plugin.html
Other
136 stars 50 forks source link

Update clipmultiplerasters.py #244

Closed osgeokr closed 1 year ago

osgeokr commented 1 year ago

In the 'Clip multiple rasters', I experienced the results like this: clip_T52SCH_A029344_20221019T022253_B02.jp2.tif clip_T52SCH_A029344_20221019T022253_B03.jp2.tif ... For your reference, I downloaded Sentinel-2 images by using SCP 'Download products'.

The next step was Preprocessing following your Land Cover Classification tutorial. However, the Preprocessing functions can't read the bands normally because of the filename(*.jpg.tif), so I suggest to check the name about the case.

# As-Is
f = oD + '/' + outputName + '_' + cfg.utls.fileNameNoExt(l) + '.tif'
# To-Be
f = oD + '/' + outputName + '_' + cfg.utls.fileNameNoExt(l).replace('.jp2', '') + '.tif' 
semiautomaticgit commented 1 year ago

Hello @osgeokr ,

thank you for reporting this. However, I think the issue is related to input path or the system, because the function clipmultiplerasters should already extract the file name without extension with the function fileNameNoExt. Replacing .jp2 in the output name possibly is not the best solution because 'Clip multiple rasters' can work also with other raster extension.

The code of fileNameNoExt is pretty simple:

import os
path = "file_path"
n = os.path.basename(os.path.splitext(path)[0])
print(n)

Could you test the above code replacing file_path with the path of one of the .jp2 raster?

osgeokr commented 1 year ago

I recorded my experiences and you can see the case at this video: https://youtu.be/X0aMEuuwy54

I guess the SCP read the path like this, so the tail of the filename still have "jp2". path = "clip_T52SCH_A029344_20221019T022253_B02.jp2.jp2"

Pls look at my video. Thanks.

import os
path = "clip_T52SCH_A029344_20221019T022253_B02.jp2.jp2"
n = os.path.basename(os.path.splitext(path)[0])
print(n)

clip_T52SCH_A029344_20221019T022253_B02.jp2
osgeokr commented 1 year ago

I share the Sentinel-2 images fille (https://drive.google.com/file/d/1K20O0OeE6B5FU_Wc3zAGJcVY-w1CZ10m/view?usp=share_link). The file was download from SCP plugin. Thank you all about SCP!

semiautomaticgit commented 1 year ago

Thank you very much @osgeokr for your cooperation. I fixed the issue that was in another function of the process. Please update the plugin to version 7.10.10