Skip to content

Instantly share code, notes, and snippets.

@maphew
Created January 10, 2022 15:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maphew/29a73ee7a4517663cef5081c15799fc3 to your computer and use it in GitHub Desktop.
Save maphew/29a73ee7a4517663cef5081c15799fc3 to your computer and use it in GitHub Desktop.
Copy RPC metdata from IN raster to OUT raster
'''Copy RPC metdata from IN raster to OUT raster
Adapted from @user7821537
https://gis.stackexchange.com/questions/264644/transfer-rpc-metadata-from-one-geotiff-to-another
'''
import os
import sys
from osgeo import gdal
gdal.UseExceptions()
if len(sys.argv) < 3:
print(f"Usage: {sys.argv[0]} [in_file] [out_file]")
sys.exit(1)
infile = sys.argv[1] # source filename and path
output = sys.argv[2] # destination file
data_in = gdal.Open(infile, gdal.GA_ReadOnly)
data_out = gdal.Open(output, gdal.GA_Update)
# get the RPCs from the first file ...
rpcs = data_in.GetMetadata('RPC')
# ... write them to the second file
data_out.SetMetadata(rpcs ,'RPC')
# de-reference the datasets, which triggers gdal to save
data_in = None
data_out = None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment