GDAL PNG to GeoTIFF Conversion – Converting PNG to GeoTIFF Using GDAL Python

convertgdalgeotiff-tiffpngpython

I want to ask how to convert PNG to GeoTIFF using GDAL in Python. I ran this code but it's not work and I want to export the output into my computer.

How can I fix my code?

ds = gdal.Open('input.png')
gt = gdal.Translate(ds, 'output.tif', projWin = [-180, 90, 180, -90])
gt = None

Best Answer

I'm assuming that your PNG file doesn't have geolocation information embedded but you know what the corners of the data. I think you just had the wrong option for gdal.Translate. Check this out using a random example image that should span the same extent as you had in your example. I also assume that it is in WGS84 Latitude/Longitude (not quite for my example)

inp = "/vsicurl/https://upload.wikimedia.org/" + \ 
      "wikipedia/commons/thumb/2/23/" + \ 
      "Blue_Marble_2002.png/" + \
      "450px-Blue_Marble_2002.png"
ds = gdal.Open(inp)
gt = gdal.Translate(ds, 'output.tif',
                    outputBounds = [-180, 90, 180, -90],
                    outputSRS="EPSG:4326"
                    )
gt = None
Related Question