1

My program builds layers from TAB and TIF files, using gdalbuildvrt and gdal_translate tool. The typical TAB file looks like so:

!table
!version 300
!charset WindowsCyrillic

Definition Table
  File "12-a.tif"
  Type "RASTER"
  (-2,14) (186,180) Label "Point 1",
  (-2,13) (211,6072) Label "Point 2",
  (-1,13) (6108,6052) Label "Point 3",
  (-1,14) (6088,161) Label "Point 4"
  CoordSys NonEarth Units "km"
  Units "km"
  RasterStyle 1 86
  RasterStyle 2 100
  RasterStyle 4 1
  RasterStyle 5 0

gdalbuildvrt creates mosaic.vrt file and gdal_translate creates a georeferenced tif. This is how the commands look like:

$ gdalbuildvrt -input_file_list files.txt mosaic.vrt
$ gdal_translate -co "TILED=YES" -co "BIGTIFF=YES" -co "NBITS=1" -co "COMPRESS=CCITTFAX4" mosaic.vrt layer.tiff

This is for example a part of mosaic.vrt file, which corresponds to the above 12-a.tif:

<SimpleSource>
  <SourceFilename relativeToVRT="0">12-A.tif</SourceFilename>
  <SourceBand>1</SourceBand>
  <SourceProperties RasterXSize="5990" RasterYSize="5995" DataType="Byte" BlockXSize="5990" BlockYSize="1" />
  <SrcRect xOff="0" yOff="0" xSize="5990" ySize="5995" />
  <DstRect xOff="22.3535484203381" yOff="0" xSize="5997.59263406113" ySize="6002.59897181911" />
</SimpleSource>

The problem is, when I publish my layer, I see that the tif (for example, this very 12-A.tif), is incorrectly positioned (about 20 meters offset along y axis and about 70 meters offset along x axis). One important thing I should add, is that my algorithm does some conversion of the initial TAB files - first of all, it converts initial local coordinates (with unknown SRID) to some well know coordinate system and it converts absolutely correctly (I checked the precision of coordinates dozens of times and they are perfect) and it switches from "km" units to "m" units. All the rest inside TAB files is left untouched, including pixel offsets like in this line "(-2,14) (186,180) Label "Point 1"". Here is how it looks like:

enter image description here

The gray point on the picture marks where the top left corner should be and, as you can see, it is far away - about 20 meters to the north and 70 meters to the east.

So, my question is what may be wrong with that and how can I possibly fix it?

EDIT

If I apply gdalinfo to my 12-a.tif, I see that coordinates of Upper Left corner are different from those in TAB file. So, is it a correct behaviour of GDAL?

  • The top-left coordinates that gdalinfo reports are extreme left-extreme top. If you look at the ground control points in your tab file you can see that your map is somewhat rotated. – user30184 Mar 27 '17 at 17:46
  • Thanks! I did not know about that. But still why there is such an incorrect positioning? How to debug it and where to look at? – Jacobian Mar 27 '17 at 17:54
  • I would try to run gdalwarp for a few images individually for making them north-up and build the mosaic from those. I have no idea if it works better, but it could be worth trying. – user30184 Mar 27 '17 at 17:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.