Created
January 10, 2022 15:56
-
-
Save maphew/29a73ee7a4517663cef5081c15799fc3 to your computer and use it in GitHub Desktop.
Copy RPC metdata from IN raster to OUT raster
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'''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