1

When running gdalinfo without the -json parameter, a field called "Pixel Size" is included in the output. When including the -json parameter, Pixel Size does not appear to be included in the output.

Is there a way to calculate Pixel Size from information in the JSON output or to include Pixel Size in the JSON output?

sample gdalinfo output

1 Answer 1

2

If the raster is not rotated, the pixel x & y dimensions are the 2nd and 6th elements in the geoTransform:

gdalinfo -json utm.tif

Output:

{
  "description":"utm.tif",
  "driverShortName":"GTiff",
  "driverLongName":"GeoTIFF",
  "files":[
    "utm.tif"
  ],
  "size":[
    512,
    512
  ],
  "geoTransform":[
    440720.0,
    60.0,  # <--- pixel width
    0.0,
    3751320.0,
    0.0,
    -60.0  # <--- pixel height (negative because image coordinates are top down, but map coordinates are bottom up)
  ], <snip>

Note for rotated rasters:

In a GDAL geotransform, the second and last values are not actually "the pixel size". They are parameters of an affine transformation. However they are equal to the pixel size where there's no rotation.

The Wikipedia entry on ESRI world files has a good explanation (note GDAL geotransforms are in CABFDE order):

The generic meaning of the six parameters in a world file (as defined by Esri) are:

  • C: x-coordinate of the center of the upper left pixel
  • A: pixel size in the x-direction in map units/pixel
  • B: rotation about x-axis
  • F: y-coordinate of the center of the upper left pixel
  • D: rotation about y-axis
  • E: pixel size in the y-direction in map units, almost always negative

This description is however misleading in that the D and B parameters are not angular rotations, and that the A and E parameters do not correspond to the pixel size if D or B are not zero. The A, D, B and E parameters are sometimes named "x-scale", "y-skew", "x-skew" and "y-scale".

A better description of the A, D, B and E parameters are:

  • A: x-component of the pixel width (x-scale)
  • B: x-component of the pixel height (x-skew)
  • D: y-component of the pixel width (y-skew)
  • E: y-component of the pixel height (y-scale), typically negative

All four parameters are expressed in the map units, which are described by the spatial reference system for the raster.

When D or B are non-zero the pixel width is given by:

enter image description here

and the pixel height by:

enter image description here

enter image description here

3
  • Could you check if this is right? With rotated images the pixel size is Square root (pixel_width^2 + next_term^2) for x and Square root (pixel_hight^2 + previous_term^2) for y.
    – user30184
    Commented Sep 10, 2020 at 7:21
  • I was thinking that perhaps you would like to include also the rotated case into your answer. I was not sure about the formula.
    – user30184
    Commented Sep 10, 2020 at 19:56
  • @user30184 ok, added.
    – user2856
    Commented Sep 10, 2020 at 21:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.