Wrong pixel dimension after SRS assignment with pyqgis












1














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)









share|improve this question





























    1














    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)









    share|improve this question



























      1












      1








      1







      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)









      share|improve this question















      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)






      qgis pyqgis






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 1 hour ago









      Vince

      14.4k32647




      14.4k32647










      asked 2 hours ago









      ilFonta

      428310




      428310






















          1 Answer
          1






          active

          oldest

          votes


















          1














          Normally I would do this on the command line but you should be able to do it in python too.



          I would simply use gdal_translate -a_srs epsg:3003 file.asc file.tif - there should be no need to specify a projwin or outsize and I suspect that is where things are going wrong, it seems likely that the raster_extent is being interpreted wrongly as you have no projection set at that point.






          share|improve this answer





















          • You are right. I mean: I still used the gdalogr processing from the python shell in QGIS, but just deleting the OUTSIZE and OUTSIZE_PERC from my script was sufficient to preserve the raster resolution. Thanks
            – ilFonta
            1 hour ago













          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "79"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f307294%2fwrong-pixel-dimension-after-srs-assignment-with-pyqgis%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          Normally I would do this on the command line but you should be able to do it in python too.



          I would simply use gdal_translate -a_srs epsg:3003 file.asc file.tif - there should be no need to specify a projwin or outsize and I suspect that is where things are going wrong, it seems likely that the raster_extent is being interpreted wrongly as you have no projection set at that point.






          share|improve this answer





















          • You are right. I mean: I still used the gdalogr processing from the python shell in QGIS, but just deleting the OUTSIZE and OUTSIZE_PERC from my script was sufficient to preserve the raster resolution. Thanks
            – ilFonta
            1 hour ago


















          1














          Normally I would do this on the command line but you should be able to do it in python too.



          I would simply use gdal_translate -a_srs epsg:3003 file.asc file.tif - there should be no need to specify a projwin or outsize and I suspect that is where things are going wrong, it seems likely that the raster_extent is being interpreted wrongly as you have no projection set at that point.






          share|improve this answer





















          • You are right. I mean: I still used the gdalogr processing from the python shell in QGIS, but just deleting the OUTSIZE and OUTSIZE_PERC from my script was sufficient to preserve the raster resolution. Thanks
            – ilFonta
            1 hour ago
















          1












          1








          1






          Normally I would do this on the command line but you should be able to do it in python too.



          I would simply use gdal_translate -a_srs epsg:3003 file.asc file.tif - there should be no need to specify a projwin or outsize and I suspect that is where things are going wrong, it seems likely that the raster_extent is being interpreted wrongly as you have no projection set at that point.






          share|improve this answer












          Normally I would do this on the command line but you should be able to do it in python too.



          I would simply use gdal_translate -a_srs epsg:3003 file.asc file.tif - there should be no need to specify a projwin or outsize and I suspect that is where things are going wrong, it seems likely that the raster_extent is being interpreted wrongly as you have no projection set at that point.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 2 hours ago









          Ian Turton

          47.6k546111




          47.6k546111












          • You are right. I mean: I still used the gdalogr processing from the python shell in QGIS, but just deleting the OUTSIZE and OUTSIZE_PERC from my script was sufficient to preserve the raster resolution. Thanks
            – ilFonta
            1 hour ago




















          • You are right. I mean: I still used the gdalogr processing from the python shell in QGIS, but just deleting the OUTSIZE and OUTSIZE_PERC from my script was sufficient to preserve the raster resolution. Thanks
            – ilFonta
            1 hour ago


















          You are right. I mean: I still used the gdalogr processing from the python shell in QGIS, but just deleting the OUTSIZE and OUTSIZE_PERC from my script was sufficient to preserve the raster resolution. Thanks
          – ilFonta
          1 hour ago






          You are right. I mean: I still used the gdalogr processing from the python shell in QGIS, but just deleting the OUTSIZE and OUTSIZE_PERC from my script was sufficient to preserve the raster resolution. Thanks
          – ilFonta
          1 hour ago




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Geographic Information Systems Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f307294%2fwrong-pixel-dimension-after-srs-assignment-with-pyqgis%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Plaza Victoria

          In PowerPoint, is there a keyboard shortcut for bulleted / numbered list?

          How to put 3 figures in Latex with 2 figures side by side and 1 below these side by side images but in...