diff --git a/py_tools_ds/geo/map_info.py b/py_tools_ds/geo/map_info.py index 650434c28155cfd050af2c63ea91f7196c6ba8b6..3f16fce6832aee8174439e80ca70a7bf234027e1 100644 --- a/py_tools_ds/geo/map_info.py +++ b/py_tools_ds/geo/map_info.py @@ -244,41 +244,43 @@ def geotransform2mapinfo(gt, prj): :returns: ENVI geo info, e.g. [ UTM , 1 , 1 , 256785.0 , 4572015.0 , 30.0 , 30.0 , 43 , North , WGS-84 ] :rtype: list """ - try: - return Geocoding(gt=gt, prj=prj).to_mapinfo() - - except KeyError: # KeyError: 'datum' - in case of, e.g., ETRS/LAEA projection - fn_bsq = "py_tools_ds__geotransform2mapinfo_temp.bsq" - fn_hdr = os.path.splitext(fn_bsq)[0] + '.hdr' - fdir = os.path.join(os.path.abspath(os.curdir)) - - try: - ds_out = gdal.GetDriverByName('ENVI').Create(fn_bsq, 2, 2, 1, gdal.GDT_Int32) - ds_out.SetGeoTransform(gt) - ds_out.SetProjection(prj) - ds_out.FlushCache() - del ds_out - - with open(fn_hdr, 'r') as inF: - content = inF.read() - if 'map info' in content: - res = re.search("map info = {(.*?)}", content, re.I).group(1) - map_info = [i.strip() for i in res.split(',')] - - for i, ele in enumerate(map_info): - try: - map_info[i] = float(ele) - except ValueError: - pass - else: - map_info = ['Arbitrary', 1.0, 1.0, 0.0, 0.0, 1.0, 1.0] - - finally: - for fn in [fn_bsq, fn_hdr]: - if os.path.exists(os.path.join(fdir, fn)): - gdal.Unlink(os.path.join(fdir, fn)) - - return map_info + # try: + return Geocoding(gt=gt, prj=prj).to_mapinfo() + + # except KeyError: # KeyError: 'datum' - in case of, e.g., ETRS/LAEA projection + # fn_bsq = "py_tools_ds__geotransform2mapinfo_temp.bsq" + # fn_hdr = os.path.splitext(fn_bsq)[0] + '.hdr' + # fdir = os.path.join(os.path.abspath(os.curdir)) + # + # try: + # ds_out = gdal.GetDriverByName('ENVI').Create(fn_bsq, 2, 2, 1, gdal.GDT_Int32) + # ds_out.SetGeoTransform(gt) + # ds_out.SetProjection(prj) + # ds_out.FlushCache() + # + # # noinspection PyUnusedLocal + # ds_out = None + # + # with open(fn_hdr, 'r') as inF: + # content = inF.read() + # if 'map info' in content: + # res = re.search("map info = {(.*?)}", content, re.I).group(1) + # map_info = [i.strip() for i in res.split(',')] + # + # for i, ele in enumerate(map_info): + # try: + # map_info[i] = float(ele) + # except ValueError: + # pass + # else: + # map_info = ['Arbitrary', 1.0, 1.0, 0.0, 0.0, 1.0, 1.0] + # + # finally: + # for fn in [fn_bsq, fn_hdr]: + # if os.path.exists(os.path.join(fdir, fn)): + # gdal.Unlink(os.path.join(fdir, fn)) + # + # return map_info def mapinfo2geotransform(map_info): @@ -300,7 +302,9 @@ def mapinfo2geotransform(map_info): ds_out = gdal.GetDriverByName('ENVI').Create(fn_bsq, 2, 2, 1) ds_out.GetRasterBand(1).WriteArray(np.array([[1, 2], [2, 3]])) ds_out.FlushCache() - del ds_out + + # noinspection PyUnusedLocal + ds_out = None with open(fn_hdr, 'r') as InHdr: lines = InHdr.readlines()