[gdal-dev] TIFs with TABs problem

Frank Warmerdam warmerdam at pobox.com
Tue May 28 10:15:06 PDT 2013


Nick,

I haven't tried the .TAB files locally, but I see they are both resulting
in georeferencing info.  The one is expressed as a geotransform with
rotation and shear while the other is expressed as ground control points.

I believe that the .TAB reader attempts to compute a geotransform from the
points in the TAB and if it can do so with minimal error then that is what
is returned - a solution easier to utilize in QGIS and other applications.

If the control points do not represent a clean affine transformation for
the image then it falls back to returning them as ground control points
which relatively few applications can utilize directly.

One "solution" is to run gdalwarp to transform the image that isn't
currently working so well into a north up affine transformation style
image.

eg.

gdalwarp 33044071.TIF 33044071_northup.TIF

This warp will be done using the control points (ironically also using a
best fit first order polynomial).

The code responsible for the decision is this from gdal/gcore/gdal_misc.cpp:

/* -------------------------------------------------------------------- */
/*      Try to convert the GCPs into a geotransform definition, if      */
/*      possible.  Otherwise we will need to use them as GCPs.          */
/* -------------------------------------------------------------------- */
    if( !GDALGCPsToGeoTransform( nCoordinateCount, asGCPs,
padfGeoTransform,
                                 FALSE ) )
    {
        if (pnGCPCount && ppasGCPs)
        {
            CPLDebug( "GDAL",
                "GDALLoadTabFile(%s) found file, wasn't able to derive a\n"
                "first order geotransform.  Using points as GCPs.",
                pszFilename );

            *ppasGCPs = (GDAL_GCP *)
                CPLCalloc( sizeof(GDAL_GCP),nCoordinateCount );
            memcpy( *ppasGCPs, asGCPs, sizeof(GDAL_GCP) * nCoordinateCount
);
            *pnGCPCount = nCoordinateCount;
        }
    }
    else
    {
        GDALDeinitGCPs( nCoordinateCount, asGCPs );
    }

I suspect if you change the FALSE to TRUE in the arguments to
GDALGCPsToGeoTransform() you wlil always get an affine transform even when
it is not a very good fit.


Best regards,
Frank


On Tue, May 28, 2013 at 7:43 AM, Nick Hopton <nhopton at gmail.com> wrote:

> A friend, a relative newcomer to GIS, is having problems loading some of
> the TIFs created with Mapinfo into QGIS. Each TIF has a TAB file and in
> some cases the TAB file is interpreted correctly and in other cases the TAB
> file is (apparently) not recognised.
>
> I think this might be a problem with Gdal rather than a problem with QGIS.
> Taking just two of the TIFs, the output from gdalinfo when run on
> 33044061.TIF indicates that things are working as they should. However,
> when gdalinfo is run on 33044071.TIF the spatial data in its TAB file is
> not recognised. See the listings below.
>
> The strange thing is that all of the TIFs can successfully be converted
> from TIF to GeoTIFF using gdalwarp. (But it is important to my friend that
> he should be able to open Mapinfo raster images directly.)
>
> Any ideas?
>
> Regards,
> Nick.
>
>
> Contents of 33044061.TAB:
> ------------------------
> !table
> !version 300
> !charset WindowsLatin1
>
> Definition Table
>   File "33044061.tif"
>   Type "RASTER"
>   (582429,263569) (1,7594) Label "Pt 1",
>   (582372,265177) (1,0) Label "Pt 2",
>   (584784,265263) (11335,1) Label "Pt 3",
>   (584841,263655) (11335,7594) Label "Pt 4"
>   CoordSys Earth Projection 8, 79, "m", -2, 49, 0.9996012717, 400000,
> -100000
>   Units "m"
>
> Results of running gdalinfo on 33044061.TIF:
> -------------------------------------------
> nick at nick-6150M2MA:~/Desktop/tabstuff$ gdalinfo 33044061.TIF
> Warning 1: TIFFFetchNormalTag:ASCII value for tag "ImageDescription"
> contains null byte in value; value incorrectly truncated during reading due
> to implementation limitations
> Driver: GTiff/GeoTIFF
> Files: 33044061.TIF
> Size is 11335, 7594
> Coordinate System is:
> PROJCS["unnamed",
>     GEOGCS["unnamed",
>         DATUM["OSGB_1936",
>             SPHEROID["Airy 1930",6377563.396,299.3249646],
>             TOWGS84[375,-111,431,-0,-0,-0,0]],
>         PRIMEM["Greenwich",0],
>         UNIT["degree",0.0174532925199433]],
>     PROJECTION["Transverse_Mercator"],
>     PARAMETER["latitude_of_origin",49],
>     PARAMETER["central_meridian",-2],
>     PARAMETER["scale_factor",0.9996012717],
>     PARAMETER["false_easting",400000],
>     PARAMETER["false_northing",-100000],
>     UNIT["Meter",1]]
> GeoTransform =
>   582371.785312838, 0.2128106799708935, 0.007506419931892793
>   265177.0453393974, 0.007597130759524194, -0.2117600570261751
> Metadata:
>   TIFFTAG_IMAGEDESCRIPTION=
>   TIFFTAG_XRESOLUTION=300
>   TIFFTAG_YRESOLUTION=300
>   TIFFTAG_MINSAMPLEVALUE=0
>   TIFFTAG_MAXSAMPLEVALUE=1
>   TIFFTAG_RESOLUTIONUNIT=2 (pixels/inch)
> Image Structure Metadata:
>   COMPRESSION=CCITTFAX4
>   INTERLEAVE=BAND
>   MINISWHITE=YES
> Corner Coordinates:
> Upper Left  (  582371.785,  265177.045) (  0d40'19.83"E, 52d15'14.75"N)
> Lower Left  (  582428.789,  263568.939) (  0d40'19.71"E, 52d14'22.68"N)
> Upper Right (  584783.994,  265263.159) (  0d42'27.09"E, 52d15'14.63"N)
> Lower Right (  584840.998,  263655.053) (  0d42'26.92"E, 52d14'22.57"N)
> Center      (  583606.392,  264416.049) (  0d41'23.39"E, 52d14'48.66"N)
> Band 1 Block=512x512 Type=Byte, ColorInterp=Palette
>   Image Structure Metadata:
>     NBITS=1
>   Color Table (RGB with 2 entries)
>     0: 255,255,255,255
>     1: 0,0,0,255
> nick at nick-6150M2MA:~/Desktop/tabstuff$
>
> Contents of 33044071.TAB:
> ------------------------
> !table
> !version 300
> !charset WindowsLatin1
>
> Definition Table
>   File "33044071.tif"
>   Type "RASTER"
>   (584841,263655) (1,7576) Label "Pt 1",
>   (584784,265263) (1,0) Label "Pt 2",
>   (587197,265349) (11335,1) Label "Pt 3",
>   (587254,263740) (11335,7576) Label "Pt 4"
>   CoordSys Earth Projection 8, 79, "m", -2, 49, 0.9996012717, 400000,
> -100000
>   Units "m"
>
> Results of running gdalinfo on 33044071.TIF:
> -------------------------------------------
> nick at nick-6150M2MA:~/Desktop/tabstuff$ gdalinfo 33044071.TIF
> Warning 1: TIFFFetchNormalTag:ASCII value for tag "ImageDescription"
> contains null byte in value; value incorrectly truncated during reading due
> to implementation limitations
> Driver: GTiff/GeoTIFF
> Files: 33044071.TIF
> Size is 11335, 7576
> Coordinate System is `'
> GCP Projection =
> PROJCS["unnamed",
>     GEOGCS["unnamed",
>         DATUM["OSGB_1936",
>             SPHEROID["Airy 1930",6377563.396,299.3249646],
>             TOWGS84[375,-111,431,-0,-0,-0,0]],
>         PRIMEM["Greenwich",0],
>         UNIT["degree",0.0174532925199433]],
>     PROJECTION["Transverse_Mercator"],
>     PARAMETER["latitude_of_origin",49],
>     PARAMETER["central_meridian",-2],
>     PARAMETER["scale_factor",0.9996012717],
>     PARAMETER["false_easting",400000],
>     PARAMETER["false_northing",-100000],
>     UNIT["Meter",1]]
> GCP[  0]: Id=Pt 1, Info=
>           (1,7576) -> (584841,263655,0)
> GCP[  1]: Id=Pt 2, Info=
>           (1,0) -> (584784,265263,0)
> GCP[  2]: Id=Pt 3, Info=
>           (11335,1) -> (587197,265349,0)
> GCP[  3]: Id=Pt 4, Info=
>           (11335,7576) -> (587254,263740,0)
> Metadata:
>   TIFFTAG_IMAGEDESCRIPTION=
>   TIFFTAG_XRESOLUTION=300
>   TIFFTAG_YRESOLUTION=300
>   TIFFTAG_MINSAMPLEVALUE=0
>   TIFFTAG_MAXSAMPLEVALUE=1
>   TIFFTAG_RESOLUTIONUNIT=2 (pixels/inch)
> Image Structure Metadata:
>   COMPRESSION=CCITTFAX4
>   INTERLEAVE=BAND
>   MINISWHITE=YES
> Corner Coordinates:
> Upper Left  (    0.0,    0.0)
> Lower Left  (    0.0, 7576.0)
> Upper Right (11335.0,    0.0)
> Lower Right (11335.0, 7576.0)
> Center      ( 5667.5, 3788.0)
> Band 1 Block=512x512 Type=Byte, ColorInterp=Palette
>   Image Structure Metadata:
>     NBITS=1
>   Color Table (RGB with 2 entries)
>     0: 255,255,255,255
>     1: 0,0,0,255
> nick at nick-6150M2MA:~/Desktop/tabstuff$
>
> --
> Nick Hopton, Caversham, Reading, England.
>
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>



-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam,
warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Software Developer
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20130528/90bb4d38/attachment-0001.html>


More information about the gdal-dev mailing list