Skip to content

Instantly share code, notes, and snippets.

@tobwen
Last active January 21, 2022 13:06
Show Gist options
  • Save tobwen/57e8c26eab0f34ca9ea6dc8f9272ad35 to your computer and use it in GitHub Desktop.
Save tobwen/57e8c26eab0f34ca9ea6dc8f9272ad35 to your computer and use it in GitHub Desktop.
`.geoTransform` is off in different raster formats

version

GDAL 3.4.1, released 2021/12/27

get source cache (mbtile)

curl -kJLOR "https://daten.gdz.bkg.bund.de/produkte/topplus_open/TopPlusOpen/aktuell/mercator/9.mbtile"
cp 9.mbtile 9.mbtiles

create extracts

gdal_translate -srcwin 68000 44000 500 500 9.mbtiles vrt.vrt
gdal_translate -srcwin 68000 44000 500 500 9.mbtiles rasterlite.sqlite -co DRIVER=PNG -of rasterlite
gdal_translate -srcwin 68000 44000 500 500 9.mbtiles gpkg.gpkg         -co TILE_FORMAT=PNG
gdal_translate -srcwin 68000 44000 500 500 9.mbtiles mbtiles.mbtiles   -co TILE_FORMAT=PNG
gdal_translate -srcwin 68000 44000 500 500 9.mbtiles geotiff.tif       -co COMPRESS=LZW

get details

gdalinfo -json vrt.vrt           | jq .geoTransform
gdalinfo -json rasterlite.sqlite | jq .geoTransform
gdalinfo -json gpkg.gpkg         | jq .geoTransform
gdalinfo -json mbtiles.mbtiles   | jq .geoTransform
gdalinfo -json geotiff.tif       | jq .geoTransform

list details & differences

{
"vrt.vrt":           [753363.3507786989212036,305.7481131407050157,0.0,6584591.3645982239395380,0.0,-305.7481131407050157],
"rasterlite.sqlite": [753363.3507786989212036,305.7481131407050157,0.0,6584591.3645982239395380,0.0,-305.7481131407050157],
"geotiff.tif":       [753363.3507786989212036,305.7481131407050157,0.0,6584591.3645982239395380,0.0,-305.7481131407050157],
"gpkg.gpkg":         [753363.3507786990376189,305.7481131407050157,0.0,6584591.3645982202142477,0.0,-305.7481131407050157],
"mbtiles.mbtiles":   [753363.3507786989212036,305.7481131407050157,0.0,6584591.3645982258021832,0.0,-305.7481131407050157]
                                     ^^^^^^^^                                          ^^^^^^^^
}

create TFWs

gdal gdal_translate rasterlite.sqlite rasterlite.tif
gdal gdal_translate gpkg.gpkg         gpkg.tif
gdal gdal_translate mbtiles.mbtiles   mbtiles.tif

gdal gdal_translate --config GDAL_PAM_ENABLED NO rasterlite.sqlite rasterlite.tif -co PROFILE=BASELINE -co TFW=YES; \
gdal gdal_translate --config GDAL_PAM_ENABLED NO gpkg.gpkg         gpkg.tif       -co PROFILE=BASELINE -co TFW=YES; \
gdal gdal_translate --config GDAL_PAM_ENABLED NO mbtiles.mbtiles   mbtiles.tif    -co PROFILE=BASELINE -co TFW=YES; \

list details & differences of TFWs

{
"geotiff.tif"   : [305.7481131407 0.0000000000 0.0000000000 -305.7481131407 753516.2248352693 6584438.4905416537],
"rasterlite.tif": [305.7481131407 0.0000000000 0.0000000000 -305.7481131407 753516.2248352693 6584438.4905416537],
"gpkg.tif"      : [305.7481131407 0.0000000000 0.0000000000 -305.7481131407 753516.2248352693 6584438.4905416556],
"mbtiles.tif"   : [305.7481131407 0.0000000000 0.0000000000 -305.7481131407 753516.2248352694 6584438.4905416500]
                                                                                            ^                 ^^
}

analysis

  • Somewhy, .geoTransform is off in gpkg and mbtiles.
  • Even when this is an IEEE754 issue, all the values should be equal.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment