1

I had read posts where give to solution to reprojectin using GDAL but is always like this:

gdalwarp -t_srs '+proj=tmerc +lat_0=21.16666666666667 +lon_0=-158 \
            +k=0.999990 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs' \
            input_raster.tif output_raster.tif

or this:

gdalwarp -t_srs EPSG:2784 input_raster.tif output_raster.tif

but I want to make it on script to add it to my code, not just putting on console, and haven't found any documentation about that.

Also, what are the input parameters exactly? I am trying to reproject Landsat images from UTM 19N to UTM 18S, the proj4.string I have are:

p1 = Proj("+proj=utm +zone=19 +ellps=WGS84 +datum=WGS84 +units=m  ")    #Input projection
p2 = Proj("+proj=utm +zone=18 +south +ellps=WGS84 +datum=WGS84 +units=m ")  #output projection

EDIT: I am working on Python 2.7

  • Maybe you could be a bit more detailed on what code/language you're talking about – Val Jun 14 '17 at 7:46
  • Sorry, already added, on python 2.7 – Ivan Jun 14 '17 at 14:26
  • UTM 18S = EPSG:32718, so what is the problem with the second command you provided ? UPDATE: okay, python .... necessary piece of information ;-) – pLumo Jun 14 '17 at 14:31
  • my question is how to use gdalwarp on script to implement on my code, not on command console as the first code seems like – Ivan Jun 14 '17 at 14:48
  • With python 2.7, you can use os module to run gdalwarp command. – xunilk Jun 15 '17 at 1:47
1

With python 2.7, you can use next code:

import os

source_path = " -of GTiff " + "/home/zeito/pyqgis_data/tiznados_canoa_part.tif"
target_path = "/home/zeito/pyqgis_data/tiznados_canoa_part_reproj.tif"

source_proj = "\'+proj=utm +zone=19 +ellps=WGS84 +datum=WGS84 +units=m  \' "
new_proj = "+proj=utm +zone=18 +south +ellps=WGS84 +datum=WGS84 +units=m "
target_proj = " -t_srs " + '\''+ new_proj + '\''

cmd = "gdalwarp -overwrite -s_srs " + \
                        source_proj + \
                        target_proj + \
                        source_path + \
                        " " + \
                        target_path

print cmd

os.system(cmd)

I tried it out at the Python Console of QGIS with a raster projected in UTM/19 N. At next image, metadata of resulting raster is pointed out that its projection was produced as expected.

enter image description here

  • why you put ¨" -of GTiff "¨? – Ivan Jun 15 '17 at 14:12
  • mmm tried it on Pycharm and got this error: ERROR 1: Translating source or target SRS failed: '+proj=utm Also tried it on python console of QGIS, no error but in the target file got no TIF image – Ivan Jun 15 '17 at 14:56
  • UPDATE: fixed erasing the ( \' ) on the lines, but now new error: ERROR 4: +zone=19: No such file or directory – Ivan Jun 15 '17 at 15:11
  • Use copy/paste and adapt to your paths where it corresponds. – xunilk Jun 15 '17 at 16:22
  • Done that, still error :( – Ivan Jun 15 '17 at 17:00
0

Already find the solution, answer is here that I post in other post of mine

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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