Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

Commit e9f8dd1

Browse files
Merge pull request #41 from 20treeAI/feat/parse_crs
feat: handle parsing of compound crs
2 parents 921e63a + 196a89c commit e9f8dd1

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

s2p/rpc_utils.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import rasterio
88
import numpy as np
99

10+
from pyproj import CRS
1011
import rpcm
1112
import srtm4
1213

@@ -102,11 +103,20 @@ def min_max_heights_from_bbx(im, lon_m, lon_M, lat_m, lat_M, rpc, exogenous_dem_
102103
# open image
103104
dataset = rasterio.open(im, 'r')
104105

106+
proj_crs = CRS.from_user_input(dataset.crs)
107+
if proj_crs.is_compound:
108+
assert len(proj_crs.sub_crs_list) == 2, f"CRS too complex to parse {proj_crs.sub_crs_list}"
109+
assert len([x for x in proj_crs.sub_crs_list if x.is_vertical]) == 1, f"Found more than 1 vertical CRS {proj_crs.sub_crs_list}"
110+
horizontal_crs = [x for x in proj_crs.sub_crs_list if not x.is_vertical][0]
111+
vertical_datum = [x for x in proj_crs.sub_crs_list if x.is_vertical][0]
112+
crs_epsg = f"epsg:{horizontal_crs}+{vertical_datum}"
113+
else:
114+
crs_epsg = proj_crs.to_epsg()
105115
# convert lon/lat to im projection
106116
x_im_proj, y_im_proj = geographiclib.pyproj_transform([lon_m, lon_M],
107117
[lat_m, lat_M],
108118
4326,
109-
dataset.crs.to_epsg())
119+
crs_epsg)
110120

111121
# convert im projection to pixel
112122
pts = []

0 commit comments

Comments
 (0)