# `gdal raster compare`

Added in version 3.12.

Compare two raster datasets.

## Synopsis

    Usage: gdal raster compare [OPTIONS] <REFERENCE> <INPUT>

    Compare two raster datasets.

    Positional arguments:
      --reference <REFERENCE>              Reference dataset [required]
      -i, --input <INPUT>                  Input raster dataset [required]

    Common Options:
      -h, --help                           Display help message and exit
      --json-usage                         Display usage as JSON document and exit
      --config <KEY>=<VALUE>               Configuration option [may be repeated]
      -q, --quiet                          Quiet mode (no progress bar)

    Options:
      --skip-all-optional                  Skip all optional comparisons
      --skip-binary                        Skip binary file comparison
      --skip-crs                           Skip CRS comparison
      --skip-geotransform                  Skip geotransform comparison
      --skip-overview                      Skip overview comparison
      --skip-metadata                      Skip metadata comparison
      --skip-rpc                           Skip RPC metadata comparison
      --skip-geolocation                   Skip Geolocation metadata comparison
      --skip-subdataset                    Skip subdataset comparison

    Advanced Options:
      --if, --input-format <INPUT-FORMAT>  Input formats [may be repeated]
      --oo, --open-option <KEY>=<VALUE>    Open options [may be repeated]

## Description

gdal raster compare compares two GDAL supported datasets and reports the differences. In addition to reporting differences to the standard output, the program will also return the difference count in its exit value.

As a convention, the first dataset specified as a positional argument, or through `--reference`, is assumed to be the reference/exact/golden dataset. The second dataset specified as a positional argument, or through `--input`, is the dataset compared to the reference dataset.

Image pixels, and various metadata are checked. There is also a byte by byte comparison done which will count as one difference. So, if it is only important that the GDAL visible data is identical, a difference count of 1 (the binary difference) should be considered acceptable, or you may specify `--skip-binary` to omit byte to byte comparison.

This program can also be used as the last step of a raster pipeline.

The following options are available:

### Options

--reference <reference-dataset>

  The dataset that is considered correct, referred to as the reference dataset.

--input <input-dataset>

  The dataset being compared to the reference dataset, referred to as the input dataset.

--skip-all-optional

  Whether to skip all optional tests. This is an alias to defining all other `--skip-XXXX` options.

  The remaining non-optional tests are:

  - checking dataset width, height and band count

  - checking band description, data type, color interpretation and nodata value

  - checking pixel content

--skip-binary

  Whether to skip exact comparison of binary content.

--skip-overview

  Whether to skip comparison of overviews.

--skip-geolocation

  Whether to skip comparison of GEOLOCATION metadata domain.

--skip-geotransform

  Whether to skip comparison of geotransform matrix.

--skip-metadata

  Whether to skip comparison of metadata

--skip-rpc

  Whether to skip comparison of Rational Polynomial Coefficients (RPC) metadata domain.

--skip-crs

  Whether to skip comparison of coordinate reference systems (CRS).

--skip-sds

  Whether to ignore comparison of all subdatasets that are part of the dataset.

## Examples

### Example 1: Comparing two datasets that differ by their data types

    $ gdal raster compare autotest/gcore/data/byte.tif autotest/gcore/data/uint16.tif
    Reference file has size 736 bytes, whereas input file has size 1136 bytes.
    Reference band 1 has data type Byte, but input band has data type UInt16

    $ echo $?
    2

### Example 2: Comparing two datasets while values have different units

    $ gdal raster pipeline read test_in_foot.tif ! calc --calc "X * 0.3048" ! compare --reference=reference_in_meter.tif