In QGIS (2.18), I have several raster files (.asc-format) that have no projection information. The images display well at EPSG:5677. My aim is to store all the files in a new folder, using the GeoTIFF format and assigning EPSG:5677.

I have no python experience, however some python coding could help me here, I guess. I read something similar but shapefile-related here: Exporting several files at same time in QGIS?

Of course, this doesn't work with my raster files. So here goes my question: how can I export a bunch of raster files, using the original file names and assigning the desired coordinate reference system without having to export every single file manually?

  • 1
    Do you have ArcGIS? Also, if you have experience in R, I would suggest a very simple workaround. Mar 8, 2017 at 16:30
  • 3
    No, I don't have ArcGIS. I wouldn't call myself experienced in R, but I do use it from time to time. However, I've never worked with geodata in R.
    – yenats
    Mar 8, 2017 at 16:32
  • I have provided a solution in R, since you mentioned that you use it from time to time. Let me know if that helps. It's much quicker than doing it manually in QGIS. Mar 8, 2017 at 16:52
  • Possible duplicate of gis.stackexchange.com/questions/208617/… (which was closed as off-topic, but has answers).
    – AndreJ
    Mar 9, 2017 at 14:38
  • Related: stackoverflow.com/questions/49919166/…
    – Tung
    Mar 22, 2022 at 15:51

2 Answers 2


Based on the User's comment that they would be open to trying this in R, here's the solution:

#Load the three packages below 

#List the files that you want to export from the source folder
files <- list.files(path="C:\\Users\\.", pattern="asc$", full.names=TRUE) #selects all the asc files in the directory
s <- stack(files) # stack all of them using r raster library
proj4string(s) <- CRS("+init=epsg:5677") #Sets it to the projection you wanted
newname<-paste("C:\\Users\\",names(s)) #Saves the previous names
writeRaster(s,newname, bylayer=T, format="GTiff")#Edited based on Fumy's comment    
  • Thank you, this worked for me. However, I preferred to keep the original file names, so I specified the location by > newname<-paste("C:\\Users\\",names(s)) and then stored the files > writeRaster(s,newname, bylayer=T, format="GTiff")
    – yenats
    Mar 9, 2017 at 11:36
  • Thanks @F.Fumy. That's a great suggestion. Updated it to reflect your edits. Mar 9, 2017 at 14:15

Given that you have QGIS, you therefore also have GDAL installed on your machine. So I suggest you adapt the example in this post over on Stackexchange and create a batch file.

In your case, you will also want to set the gdal_translate a_srs switch to 5677 and change the -of switch (see documentation). So the relevant line in the batch file will be something like this:

gdal_translate -of "GTiff" -a_srs 5677 %mypath%!infile! %mypath%!outfile!

If you leave out the -of switch altogether, it will default to GeoTiff anyway. I just wanted to differentiate from the example given in the link. If you do not have an environment variable set for gdal_translate (which in a standard osgeo4w installation probably won't be the case) then you will have to run this command from the osgeo4w bin folder (in my case c:\osgeo4w64\bin).

  • I guess it should be GTiff instead of GTif, should not it? (on edit version May 23'17, accessed June 15'18) Jun 15, 2018 at 11:45
  • Indeed. On this point it is worth noting a small change since I gave this answer originally and that is that GTiff is no longer the default here and GDAL will guess the format based on the extension. Jun 19, 2018 at 7:12

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.