I use pyQGIS (Python 2. with QGIS 2.18) to assign the same reference system to some raster files in .asc format (that came out without any SRS). Each .asc file has 1m pixel dimension.
I use this pyqgis script to convert the raster in GeoTIFF and assigning the EPSG:3003.
It works but output files have a final resolution of 16.2 x 15.6. How to preserve the original pixel dimension?
import os
import processing
from qgis.core import *
raster_filepath = "/home/giacomo/Desktop/Livorno/QGIS/Raster/DEM_Lidar/new/prova"
outputDir = "/home/giacomo/Desktop/Livorno/QGIS/Raster/DEM_Lidar/new/"
for i in os.listdir(raster_filepath):
if i.endswith (".asc"):
#name fileOut
ii = i[:-4]
fileOut = outputDir + "/" + ii + "_rep.tif"
layercount = os.path.join(raster_filepath, i)
raster_layer = QgsRasterLayer(layercount, 'raster')
# assessing the raster dimension
raster_extent = raster_layer.extent()
xmin = raster_extent.xMinimum()
xmax = raster_extent.xMaximum()
ymin = raster_extent.yMinimum()
ymax = raster_extent.yMaximum()
# processing
processing.runalg("gdalogr:translate", \
{"INPUT":raster_layer, \
"OUTSIZE":100, \
"OUTSIZE_PERC":False, \
"EXPAND":0, \
"PROJWIN": "%f,%f,%f,%f"%(xmin,xmax,ymin,ymax), \
"SRS":"EPSG:3003", \
"OUTPUT":fileOut})
print(fileOut)