Commit 413683f1 authored by Daniel Scheffler's avatar Daniel Scheffler

Merge branch 'bugfix/fix_windows_geometrytrafo' into 'master'

Bugfix/fix windows geometrytrafo

See merge request !10
parents 28ce2c12 4dbf594d
Pipeline #4160 failed with stages
in 18 minutes and 47 seconds
...@@ -597,6 +597,11 @@ class SensorMapGeometryTransformer(object): ...@@ -597,6 +597,11 @@ class SensorMapGeometryTransformer(object):
tgt_epsg = WKT2EPSG(proj4_to_WKT(get_proj4info(proj=tgt_prj))) tgt_epsg = WKT2EPSG(proj4_to_WKT(get_proj4info(proj=tgt_prj)))
tgt_extent = tgt_extent or self._get_target_extent(tgt_epsg) 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: with TemporaryDirectory() as td:
path_xycoords = os.path.join(td, 'xy_coords.bsq') path_xycoords = os.path.join(td, 'xy_coords.bsq')
path_xycoords_vrt = os.path.join(td, 'xy_coords.vrt') path_xycoords_vrt = os.path.join(td, 'xy_coords.vrt')
...@@ -619,14 +624,14 @@ class SensorMapGeometryTransformer(object): ...@@ -619,14 +624,14 @@ class SensorMapGeometryTransformer(object):
# create VRT for X/Y coordinate array # create VRT for X/Y coordinate array
ds_xy_coords = gdal.Open(path_xycoords) ds_xy_coords = gdal.Open(path_xycoords)
drv_vrt = gdal.GetDriverByName("VRT") 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 del ds_xy_coords, vrt
# create VRT for one data band # create VRT for one data band
mask_band = np.ones((data.shape[:2]), np.int32) mask_band = np.ones((data.shape[:2]), np.int32)
write_numpy_to_image(mask_band, path_data, 'ENVI') write_numpy_to_image(mask_band, path_data, 'ENVI')
ds_data = gdal.Open(path_data) 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, vrt.SetMetadata({"X_DATASET": path_xycoords_vrt,
"Y_DATASET": path_xycoords_vrt, "Y_DATASET": path_xycoords_vrt,
"X_BAND": "1", "X_BAND": "1",
...@@ -640,7 +645,7 @@ class SensorMapGeometryTransformer(object): ...@@ -640,7 +645,7 @@ class SensorMapGeometryTransformer(object):
vrt.FlushCache() vrt.FlushCache()
del ds_data, vrt del ds_data, vrt
subcall_with_output('gdalwarp %s %s ' subcall_with_output("gdalwarp '%s' '%s' "
'-geoloc ' '-geoloc '
'-t_srs EPSG:%d ' '-t_srs EPSG:%d '
'-srcnodata 0 ' '-srcnodata 0 '
...@@ -649,22 +654,21 @@ class SensorMapGeometryTransformer(object): ...@@ -649,22 +654,21 @@ class SensorMapGeometryTransformer(object):
'-dstnodata none ' '-dstnodata none '
'-et 0 ' '-et 0 '
'-overwrite ' '-overwrite '
'-te %s' '-te %s '
'%s' % (path_datavrt, path_data_out, tgt_epsg, '%s' % (path_datavrt, path_data_out, tgt_epsg,
' '.join([str(i) for i in tgt_extent]), ' '.join([str(i) for i in tgt_extent]),
' -tr %s %s' % tgt_res if tgt_res else '',), ' -tr %s %s' % tgt_res if tgt_res else '',),
v=True) v=True)
# get output X/Y size # get output X/Y size
ds_out = gdal.Open(path_data_out) ds_out = raiseErr_if_empty(gdal.Open(path_data_out))
if not ds_out:
raise Exception(gdal.GetLastErrorMsg())
x_size = ds_out.RasterXSize x_size = ds_out.RasterXSize
y_size = ds_out.RasterYSize y_size = ds_out.RasterYSize
out_gt = ds_out.GetGeoTransform() 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 # add 1 px buffer around out_extent to avoid cutting the output image
x_size += 2 x_size += 2
......
__version__ = '0.14.17' __version__ = '0.14.18'
__versionalias__ = '20190322_03' __versionalias__ = '20190614_01'
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