Skip to content

Instantly share code, notes, and snippets.

@kapadia
Last active August 29, 2015 14:14
Show Gist options
  • Save kapadia/d330275be1c0e913a134 to your computer and use it in GitHub Desktop.
Save kapadia/d330275be1c0e913a134 to your computer and use it in GitHub Desktop.
Compare geotiffs
import sys
import numpy as np
import rasterio as rio
def compare(srcpath1, srcpath2):
with rio.drivers():
src1 = rio.open(srcpath1)
src2 = rio.open(srcpath2)
# Compare metadata
# Compare pixels
props = ['count', 'crs', 'dtypes', 'driver', 'bounds', 'height', 'width', 'shape', 'nodatavals']
for prop in props:
assert src1.__getattribute__(prop) == src2.__getattribute__(prop)
for bidx in range(1, src1.count + 1):
band1 = src1.read_band(1)
band2 = src2.read_band(1)
assert np.array_equal(band1, band2)
src1.close()
src2.close()
if __name__ == '__main__':
sys.argv.pop(0)
if len(sys.argv) != 2:
print "Usage: python compare_geotiff.py [srcpath] [dstpath]"
sys.exit()
compare(*sys.argv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment