Unverified Commit 1227cfba authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

Fixed Windows incompatibility of SensorMapGeometryTransformer.

parent 28ce2c12
Pipeline #4154 passed with stages
in 1 minute and 17 seconds
......@@ -597,6 +597,11 @@ class SensorMapGeometryTransformer(object):
tgt_epsg = WKT2EPSG(proj4_to_WKT(get_proj4info(proj=tgt_prj)))
tgt_extent = tgt_extent or self._get_target_extent(tgt_epsg)
def raiseErr_if_empty(gdal_ds):
if not gdal_ds:
raise Exception(gdal.GetLastErrorMsg())
return gdal_ds
with TemporaryDirectory() as td:
path_xycoords = os.path.join(td, 'xy_coords.bsq')
path_xycoords_vrt = os.path.join(td, 'xy_coords.vrt')
......@@ -619,14 +624,14 @@ class SensorMapGeometryTransformer(object):
# create VRT for X/Y coordinate array
ds_xy_coords = gdal.Open(path_xycoords)
drv_vrt = gdal.GetDriverByName("VRT")
vrt = drv_vrt.CreateCopy(path_xycoords_vrt, ds_xy_coords)
vrt = raiseErr_if_empty(drv_vrt.CreateCopy(path_xycoords_vrt, ds_xy_coords))
del ds_xy_coords, vrt
# create VRT for one data band
mask_band = np.ones((data.shape[:2]), np.int32)
write_numpy_to_image(mask_band, path_data, 'ENVI')
ds_data = gdal.Open(path_data)
vrt = drv_vrt.CreateCopy(path_datavrt, ds_data)
vrt = raiseErr_if_empty(drv_vrt.CreateCopy(path_datavrt, ds_data))
vrt.SetMetadata({"X_DATASET": path_xycoords_vrt,
"Y_DATASET": path_xycoords_vrt,
"X_BAND": "1",
......@@ -640,7 +645,7 @@ class SensorMapGeometryTransformer(object):
vrt.FlushCache()
del ds_data, vrt
subcall_with_output('gdalwarp %s %s '
subcall_with_output("gdalwarp '%s' '%s' "
'-geoloc '
'-t_srs EPSG:%d '
'-srcnodata 0 '
......@@ -649,22 +654,21 @@ class SensorMapGeometryTransformer(object):
'-dstnodata none '
'-et 0 '
'-overwrite '
'-te %s'
'-te %s '
'%s' % (path_datavrt, path_data_out, tgt_epsg,
' '.join([str(i) for i in tgt_extent]),
' -tr %s %s' % tgt_res if tgt_res else '',),
v=True)
# get output X/Y size
ds_out = gdal.Open(path_data_out)
if not ds_out:
raise Exception(gdal.GetLastErrorMsg())
ds_out = raiseErr_if_empty(gdal.Open(path_data_out))
x_size = ds_out.RasterXSize
y_size = ds_out.RasterYSize
out_gt = ds_out.GetGeoTransform()
del ds_out
# noinspection PyUnusedLocal
ds_out = None
# add 1 px buffer around out_extent to avoid cutting the output image
x_size += 2
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment