EOX GitLab Instance

Skip to content
Snippets Groups Projects
Commit 23c9a7aa authored by Fabian Schindler's avatar Fabian Schindler
Browse files

Step to apply georeference from Browse Report

parent ae754ca1
No related branches found
No related tags found
No related merge requests found
import os
from glob import glob
from os.path import join, basename
from ..util import replace_ext, pairwise, gdal, osr
def browse_georeference(source_dir: os.PathLike, target_dir: os.PathLike, browse: dict):
for filename in glob(join(source_dir, '*')):
target_filename = join(target_dir, replace_ext(basename(filename), '.tif'))
apply_browse_report_georeference(filename, target_filename, browse)
def apply_browse_report_georeference(input_filename: os.PathLike, target_filename: os.PathLike, browse: dict):
ds = gdal.GetDriverByName('GTiff').CreateCopy(target_filename, gdal.Open(input_filename))
type_ = browse['type']
if type_ == 'rectified_browse':
size_x, size_y = ds.RasterXSize, ds.RasterYSize
low, high = browse['rectified']['coord_list']
minx, miny = low
maxx, maxy = high
ds.SetGeoTransform([
minx, (maxx - minx) / size_x, 0,
maxy, 0, (miny - maxy) / size_y,
])
elif type_ == 'footprint_browse':
col_rows = browse['footprint']['col_row_list']
coords = browse['footprint']['coord_list']
gcps = [
gdal.GCP(coord[0], coord[1], 0, col_row[0], col_row[1])
for col_row, coord in zip(col_rows, coords)
]
sr = osr.SpatialReference()
sr.ImportFromEPSG(4326)
ds.SetGCPs(gcps, sr)
elif type_ == 'model_in_geotiff_browse':
# nothing to do in this case
pass
elif type_ == 'regular_grid_browse':
# TODO: not implemented
raise NotImplementedError
else:
raise Exception
del ds
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment