Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GeoTIFF metadata lost when splitting a GeoTIFF up into tiles #6786

Open
marklit opened this issue Oct 14, 2023 · 4 comments
Open

GeoTIFF metadata lost when splitting a GeoTIFF up into tiles #6786

marklit opened this issue Oct 14, 2023 · 4 comments

Comments

@marklit
Copy link

marklit commented Oct 14, 2023

ImageMagick version

7.1.1-21

Operating system

Linux

Operating system, version and so on

Ubuntu for Windows (Ubuntu 20 effectively)

Description

The GeoTIFF information on the location an image was taken in, its projection, etc.. isn't retained / recalculated when a large GeoTIFF is broken up into tiles.

Steps to Reproduce

$ git clone https://github.com/ImageMagick/ImageMagick
$ cd ImageMagick
$ mkdir -p build
$ ./configure --prefix=`pwd`/build
$ make -j$(nproc)
$ sudo make install

$ wget -c https://maxar-opendata.s3.amazonaws.com/events/New-Zealand-Flooding23/ard/60/213311212331/2022-11-01/104001007C86B200-visual.tif
$ gdalinfo 104001007C86B200-visual.tif
Driver: GTiff/GeoTIFF
Files: /mnt/f/gis/Global/maxar-open-data/104001007C86B200-visual.tif
Size is 17408, 17408
Coordinate System is:
PROJCRS["WGS 84 / UTM zone 60S",
    BASEGEOGCRS["WGS 84",
        DATUM["World Geodetic System 1984",
            ELLIPSOID["WGS 84",6378137,298.257223563,
                LENGTHUNIT["metre",1]]],
        PRIMEM["Greenwich",0,
            ANGLEUNIT["degree",0.0174532925199433]],
        ID["EPSG",4326]],
...
$ build/bin/convert \
    104001007C86B200-visual.tif \
    +repage \
    -crop \
    512x512 \
    104001007C86B200-%04d.tiff
$ gdalinfo 104001007C86B200-0000.tiff
Driver: GTiff/GeoTIFF
Files: /mnt/f/gis/Global/maxar-open-data/104001007C86B200-0000.tiff
Size is 512, 512
Image Structure Metadata:
  INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left  (    0.0,    0.0)
Lower Left  (    0.0,  512.0)
Upper Right (  512.0,    0.0)
Lower Right (  512.0,  512.0)
Center      (  256.0,  256.0)
Band 1 Block=512x5 Type=Byte, ColorInterp=Red
Band 2 Block=512x5 Type=Byte, ColorInterp=Green
Band 3 Block=512x5 Type=Byte, ColorInterp=Blue

Images

https://maxar-opendata.s3.amazonaws.com/events/New-Zealand-Flooding23/ard/60/213311212331/2022-11-01/104001007C86B200-visual.tif

@snibgo
Copy link

snibgo commented Oct 14, 2023

I suggest using magick instead of convert.

Your tiff file contains 14 images. If you want to process just the first, use a [0] suffix.

No, IM does not copy all the metatdata from the input to the output. You can use exiftool for that, like this:

magick 104001007C86B200-visual.tif[0] x.tiff

exiftool -tagsFromFile 104001007C86B200-visual.tif x.tiff

@marklit
Copy link
Author

marklit commented Oct 14, 2023

Copying the metadata wholesale wouldn't be accurate. Each image is offset from the original file's offset.

@snibgo
Copy link

snibgo commented Oct 14, 2023

In that case, a script could adjust the offsets as required.

@fmw42
Copy link

fmw42 commented Oct 14, 2023

Or use EXIFTOOL to copy just the GEOTIFF data

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants