[GIS] Adding georeferencing data into tiff image

gdalgeotiff-tiffPHPqgis

I want to create a georeferenced .tiff file from a .png file. So I convert the .png into a normal .tiff file using the following command line :

convert image.png image.tiff

Here, all works fine, I have a valid .tiff file, which displays fine. Then, I want to add some georeferencing data in it. To do so, I found a tool called tiff2geotiff, I'm using it like this :

tiff2geotiff -4 "+proj=latlong +ellps=WGS84 +datum=WGS84 +no_defs" -c none -n "-122.5575664 38.5818201 -122.5449425 38.5896175" notgeoreferenced.tiff georeferenced.tiff

This gives me a black image which, imported in QGis, displays fine in the good place, except that it's black everywhere (proof that the georeferenced data have been well added).

Therefore, when I do :

gdalinfo georeferenced.tiff

I obtain :

Warning 1: TIFFReadDirectory:Bogus "StripByteCounts" field, ignoring and calculating from imagelength
Driver: GTiff/GeoTIFF
Files: araujo_tmp.tiff
Size is 1585, 979
Coordinate System is:
GEOGCS["WGS 84",
    DATUM["WGS_1984",
        SPHEROID["WGS 84",6378137,298.257223563,
            AUTHORITY["EPSG","7030"]],
        AUTHORITY["EPSG","6326"]],
    PRIMEM["Greenwich",0],
    UNIT["degree",0.0174532925199433],
    AUTHORITY["EPSG","4326"]]
Origin = (-122.557563781738281,38.589618682861328)
Pixel Size = (0.000007966552118,-0.000007972639275)
Metadata:
  AREA_OR_POINT=Area
  TIFFTAG_DOCUMENTNAME=georeferenced.tiff
Image Structure Metadata:
  INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left  (-122.5575638,  38.5896187) (122d33'27.23"W, 38d35'22.63"N)
Lower Left  (-122.5575638,  38.5818135) (122d33'27.23"W, 38d34'54.53"N)
Upper Right (-122.5449368,  38.5896187) (122d32'41.77"W, 38d35'22.63"N)
Lower Right (-122.5449368,  38.5818135) (122d32'41.77"W, 38d34'54.53"N)
Center      (-122.5512503,  38.5857161) (122d33' 4.50"W, 38d35' 8.58"N)
Band 1 Block=1585x1 Type=Byte, ColorInterp=Red
Band 2 Block=1585x1 Type=Byte, ColorInterp=Green
Band 3 Block=1585x1 Type=Byte, ColorInterp=Blue

I think the first warning may be the problem…

Is there someone who knows why or another way to do this ? I'm looking for solutions in command line or in PHP.

Thank you !


Solution

I found out gdal_translate can add georeferencing data into .tiff images, so here is the command line which convert from png and add georeferencing data (you have to replace the extents (llx ury urx lly), of course):

gdal_translate -a_nodata 0 -of GTiff -a_srs EPSG:4326 -a_ullr llx ury urx lly pngfile.png tifffile.tiff

Best Answer

Rather than using convert, could you try to use gdal_translate to convert the png to tiff and then georeference it using gdal_warp (assuming you've created a tfw file for the tiff)?

Related Question