Skip to content

Commit

Permalink
allow opening rasters that have standalone rpc data
Browse files Browse the repository at this point in the history
  • Loading branch information
Amit Aronovitch committed Dec 26, 2021
1 parent b4be2c0 commit 23012cd
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion rpcm/rpc_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,22 @@ def apply_rfm(num, den, x, y, z):
return apply_poly(num, x, y, z) / apply_poly(den, x, y, z)


def remove_ikonos_units(rpc_dict):
"""
When there is a RPC.txt file along the tif, GDAL will get the rpcs from
the textual file instead of the tif.
However, ikonos textual files contain units along the numbers, and these
are not expected when constructing from GeoTiff.
This function removes the units from the dict.
"""
geotiff_dict = {}
for key, value in rpc_dict.items():
if key.endswith('_OFF') or key.endswith('_SCALE'):
value = value.split()[0]
geotiff_dict[key] = value
return geotiff_dict


def rpc_from_geotiff(geotiff_path):
"""
Read the RPC coefficients from a GeoTIFF file and return an RPCModel object.
Expand All @@ -73,7 +89,7 @@ def rpc_from_geotiff(geotiff_path):
instance of the rpc_model.RPCModel class
"""
with rasterio.open(geotiff_path, 'r') as src:
rpc_dict = src.tags(ns='RPC')
rpc_dict = remove_ikonos_units(src.tags(ns='RPC'))
return RPCModel(rpc_dict)


Expand Down

0 comments on commit 23012cd

Please sign in to comment.