Opened 6 years ago

Closed 13 months ago

#4977 closed defect (fixed)

Negative pixel scale GeoTIFFs load geo info incorrectly

Reported by: tclarke Owned by: warmerdam
Priority: normal Milestone:
Component: GDAL_Raster Version: svn-trunk
Severity: normal Keywords: gtiff
Cc:

Description

See http://pastebin.com/jdmHDQTM for a example of the problem. GeoTIFFs with negative pix scale (south-up) do not load properly do to an ABS() in gdal/frmts/gtiff/geotiff.cpp

Attachments (1)

test_tiffs.zip (976 bytes) - added by Jukka Rahkonen 4 years ago.
Plain tif+tfw (north-up and flipped) and GeoTIFF that should flip but doesn't

Download all attachments as: .zip

Change History (4)

comment:1 Changed 6 years ago by warmerdam

Component: defaultGDAL_Raster
Keywords: gtiff added

From the pastebin:

listgeo
-------
Geotiff_Information:
   Version: 1
   Key_Revision: 1.0
   Tagged_Information:
      ModelTiepointTag (2,3):
         0                0                0                
         -83.999961424697439.0004629695553 0                
      ModelPixelScaleTag (1,3):
         0.000385802437236293-0.0005144032496460230                
      End_Of_Tags.
   Keyed_Information:
      GTModelTypeGeoKey (Short,1): ModelTypeGeographic
      GTRasterTypeGeoKey (Short,1): RasterPixelIsArea
      GeographicTypeGeoKey (Short,1): GCS_WGS_84
      GeogLinearUnitsGeoKey (Short,1): Linear_Meter
      GeogAngularUnitsGeoKey (Short,1): Angular_Degree
      ProjCenterLongGeoKey (Double,1): -83.9997684838075
      ProjCenterLatGeoKey (Double,1): 39.9996913117433
      End_Of_Keys.
   End_Of_Geotiff.
 
GCS: 4326/WGS 84
Datum: 6326/World Geodetic System 1984
Ellipsoid: 7030/WGS 84 (6378137.00,6356752.31)
Prime Meridian: 8901/Greenwich (0.000000/  0d 0' 0.00"E)
 
Corner Coordinates:
Upper Left    ( 83d59'59.86"W, 39d 0' 1.67"N)
Lower Left    ( 83d59'59.86"W, 40d 0' 1.67"N)
Upper Right   ( 82d59'59.86"W, 39d 0' 1.67"N)
Lower Right   ( 82d59'59.86"W, 40d 0' 1.67"N)
Center        ( 83d29'59.86"W, 39d30' 1.67"N)
 
gdalinfo
--------
Driver: GTiff/GeoTIFF
Files: C:\test.tif
Size is 2592, 1944
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 = (-83.999961424697403,39.000462969555308)
Pixel Size = (0.000385802437236,-0.000514403249646)
Metadata:
  AREA_OR_POINT=Area
Image Structure Metadata:
  INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left  ( -83.9999614,  39.0004630) ( 83d59'59.86"W, 39d 0' 1.67"N)
Lower Left  ( -83.9999614,  38.0004631) ( 83d59'59.86"W, 38d 0' 1.67"N)
Upper Right ( -82.9999615,  39.0004630) ( 82d59'59.86"W, 39d 0' 1.67"N)
Lower Right ( -82.9999615,  38.0004631) ( 82d59'59.86"W, 38d 0' 1.67"N)
Center      ( -83.4999615,  38.5004630) ( 83d29'59.86"W, 38d30' 1.67"N)
Band 1 Block=2592x1 Type=Byte, ColorInterp=Red
Band 2 Block=2592x1 Type=Byte, ColorInterp=Green
Band 3 Block=2592x1 Type=Byte, ColorInterp=Blue

The problem appears to be this code in geotiff.cpp:

        adfGeoTransform[5] = - ABS(padfScale[1]);

This ABS call was added in r395 without explanation but was presumably because some files were encountered with a negative pixelspace[1] when they didn't really mean that. On the other hand, the specification says this about ModelPixelScaleTag?:

""" However, simple reversals of orientation between raster and model space (e.g. horizontal or vertical flips) may be indicated by reversal of sign in the corresponding component of the ModelPixelScaleTag?. GeoTIFF compliant readers must honor this sign-reversal convention. """

This appears to make it clear we should not be disregarding the sign (in general).

comment:2 Changed 4 years ago by Jukka Rahkonen

I think this must be some corner case but I also think that the ticket is valid and amusing to study as well.

I started by creating created a south-up tiff+tfw combination. TFW was this:

1000.0000000000
0.0000000000
0.0000000000
1000.0000000000
50000.0000000000
100000.0000000000

Gdalinfo from this:

Corner Coordinates:
Upper Left  (   49500.000,   99500.000)
Lower Left  (   49500.000,  199500.000)
Upper Right (  149500.000,   99500.000)
Lower Right (  149500.000,  199500.000)
Center      (   99500.000,  149500.000)

It appears that geotifcp (sic!) does not handle this situation:

geotifcp -e small.tfw small.tif small_geo.tif
gdalinfo small_geo.tif

Origin = (49500.000000000000000,100500.000000000000000)
Pixel Size = (1000.000000000000000,-1000.000000000000000)
Image Structure Metadata:
  INTERLEAVE=BAND
Corner Coordinates:
Upper Left  (   49500.000,  100500.000)
Lower Left  (   49500.000,     500.000)
Upper Right (  149500.000,  100500.000)
Lower Right (  149500.000,     500.000)
Center      (   99500.000,   50500.000)

I had to use listgeo + text editor + geotifcp for getting the desired geotiff tags into a new image file. Situation should be the same than with the south-up tiff+tfw

listgeo small2_geo.tif
Geotiff_Information:
   Version: 1
   Key_Revision: 1.0
   Tagged_Information:
      ModelTiepointTag (2,3):
         0.5               0.5               0
         50000             100000            0
      ModelPixelScaleTag (1,3):
         1000              -1000             0
      End_Of_Tags.
   Keyed_Information:
      End_Of_Keys.
   End_Of_Geotiff.

Gdalinfo shows extents as north-up with Y-pixel size as negative

gdalinfo small2_geo.tif
Driver: GTiff/GeoTIFF
Files: small2_geo.tif
Size is 100, 100
Coordinate System is `'
Origin = (49500.000000000000000,100500.000000000000000)
Pixel Size = (1000.000000000000000,-1000.000000000000000)
Image Structure Metadata:
  INTERLEAVE=BAND
Corner Coordinates:
Upper Left  (   49500.000,  100500.000)
Lower Left  (   49500.000,     500.000)
Upper Right (  149500.000,  100500.000)
Lower Right (  149500.000,     500.000)
Center      (   99500.000,   50500.000)

My conclusion is that TFW files are interpreted right but reversed Y-axis is not transferred into GeoTIFF by geotifcp not gdal_translate which I tried as well. And if GeoTIFF contains south-up pixel scale, GDAL does not honour it.

Question is that does this kind of south-up GeoTIFF files exist in real life, and how common are north-up GeoTIFFs which have a faulty, negative Y-pixel size. Correcting GDAL to honour the GeoTIFF specification would flip all images belonging to the latter group.

Changed 4 years ago by Jukka Rahkonen

Attachment: test_tiffs.zip added

Plain tif+tfw (north-up and flipped) and GeoTIFF that should flip but doesn't

comment:3 Changed 13 months ago by Even Rouault

Resolution: fixed
Status: newclosed

In 40842:

GTiff: add a GTIFF_HONOUR_NEGATIVE_SCALEY=YES config option that can be set to honour negative ScaleY value in GeoPixelScale? tag according to the GeoTIFF specification (fixes #4977)

Note: See TracTickets for help on using tickets.