Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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
share|improve this question
    
about your question if there are gdal php bindings, PHP is not currently properly supported by GDAL/OGR. trac.osgeo.org/gdal/wiki/GdalOgrInPhp –  nickves Dec 17 '12 at 17:30
add comment

2 Answers

up vote 6 down vote accepted

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)?

share|improve this answer
    
Here is the command line I use now : gdal_translate -scale pngfile.png tifffile.tiff –  Julien Fouilhé Sep 25 '12 at 10:52
add comment

Do you know the extents of the image? If you know the bounding coordinates of the image you can us gdal_translate with the -a_srs (this assigns the projection) and -a_ullr (this is the bounding coordinates). I have used this to convert .jpg of sonar images from a low cost fishing sonar unit to geotiffs.

share|improve this answer
1  
So you're saying that I don't need to use tiff2geotiff to add the extents of the image (yes I have them) ? :) Cool ! Yes I see that in the documentation, I will use it instead of tiff2geotiff, thank you ! –  Julien Fouilhé Sep 27 '12 at 9:05
    
No problem, I am glad this will help –  Ryan Garnett Sep 27 '12 at 14:22
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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