1
path = '/mnt/Data/30_Stages_Encours/2023/ZonesHumides_Sarah/donnee_dezippee/sentinel2/2020/'
dir = os.listdir(path)
for i in dir : 
# i = SENTINEL2X_20200415-000000-000_L3A_T31UES_C_V2-1
        if i.split('.')[-1] != "zip" and i.split('/')[-1] != "traitee":
            print("IMAGE EN COURS:", i)
            for bande in bandes :
# bande = B3 or else
                nom_image = i + '_FRC_' + bande + '.tif' 
                nom_image_r = i + '_FRC_' + bande + '_r.tif' # nom image superimpose 
                image_entree = os.path.join(path, i, nom_image) # path to one image
                image_sortie = os.path.join(path, i, nom_image_r) # path to an image that doesn't exist yet


                os.system('gdalwarp -t_srs EPSG:4326'+image_entree+' '+image_sortie) 

I would like to be able to no rename my output of gdal warp or be able to rename it with a variable. I just want to add '_r' at the end of my input image but with this method I get the error

FAILURE : No target filename specified

EDIT : with an example more clear, this gives me the same error :

 import os 
image_entree = 'path/to/image.tif'
image_sortie = 'path/to/image_r.tif'
os.system('gdalwarp -t_srs EPSG:4326'+image_entree+' '+image_sortie +'r') 
4
  • At least the closing single quote is missing in '+image_sortie
    – user30184
    Jun 9, 2023 at 9:13
  • with os.system that's how input variables works - at least with os.system('otbcli_ExtractROI..) - tried different version and doesn't work otherwise
    – sam
    Jun 9, 2023 at 9:15
  • thanks, @user30184 trying to explain in my head how os.system works helped me spot the error - you need to tell os that there is a gap between the two variables with a string space as such : os.system('gdalwarp -t_srs EPSG:4326 '+image_entree+' '+image_sortie)
    – sam
    Jun 9, 2023 at 9:23
  • Right, I was looking too fast. The true problem was that "image_entree" was added after EPSG:4326 without a space.
    – user30184
    Jun 9, 2023 at 9:27

1 Answer 1

2

thanks, @user30184 trying to explain in my head how os.system works helped me spot the error - you need to tell os that there is a gap between the two variables with a string space as such :

os.system('gdalwarp -t_srs EPSG:4326 '+image_entree+' '+image_sortie) 

With f-string notation:

os.system(f"gdalwarp -t_srs EPSG:4326 {image_entree} {image_sortie}")
1
  • Using f-string notation also improves readability. e.g. os.system(f"gdalwarp -t_srs EPSG:4326 {image_entree} {image_sortie}")
    – PyMapr
    Jun 29, 2023 at 9:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.