jp2 to GeoTiff
jp2 to GeoTiff
1、读取jp2图片信息:01
S2B_MSIL1C_20230622T023529_N0509_R089_T51STV_20230622T042653.SAFE
T51STV_20230622T023529_TCI.jp2
影像的波段数: 3
影像的列,行数: 10980rows * 10980colums
栅格数据的空间参考:(199980.0, 10.0, 0.0, 4000020.0, 0.0, -10.0)
投影信息:PROJCS["WGS 84 / UTM zone 51N",
GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],
PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],
UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]],
PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",123],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],
UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH],AUTHORITY["EPSG","32651"]]
2、查看jp2文件 :01
./dataS2B_MSIL2A_20230622T023529_N0509_R089_T51STV_20230622T050019.SAFEGRANULEL2A_T51STV_A032862_20230622T024244IMG_DATAR10m
['T51STV_20230622T023529_AOT_10m.jp2', 'T51STV_20230622T023529_B02_10m.jp2', 'T51STV_20230622T023529_B03_10m.jp2', 'T51STV_20230622T023529_B04_10m.jp2', 'T51STV_20230622T023529_B08_10m.jp2', 'T51STV_20230622T023529_TCI_10m.jp2', 'T51STV_20230622T023529_WVP_10m.jp2']
3、罗列2A级数据的jp2文件的绝对路径:01
./data/S2B_MSIL2A_20230622T023529_N0509_R089_T51STV_20230622T050019.SAFE
[
'./dataS2B_MSIL2A_20230622T023529_N0509_R089_T51STV_20230622T050019.SAFEGRANULEL2A_T51STV_A032862_20230622T024244IMG_DATAR20mT51STV_20230622T023529_B02_10m.jp2',
'./dataS2B_MSIL2A_20230622T023529_N0509_R089_T51STV_20230622T050019.SAFEGRANULEL2A_T51STV_A032862_20230622T024244IMG_DATAR20mT51STV_20230622T023529_B03_10m.jp2',
'./dataS2B_MSIL2A_20230622T023529_N0509_R089_T51STV_20230622T050019.SAFEGRANULEL2A_T51STV_A032862_20230622T024244IMG_DATAR20mT51STV_20230622T023529_B04_10m.jp2',
'./dataS2B_MSIL2A_20230622T023529_N0509_R089_T51STV_20230622T050019.SAFEGRANULEL2A_T51STV_A032862_20230622T024244IMG_DATAR20mT51STV_20230622T023529_B08_10m.jp2']
4、转换1个指定jp2文件:01
5、创建函数jp2Totif批量转换20m的jp2文件:01
from osgeo import gdal, osr, ogr
filename = ".S2B_MSIL1C_20230622T023529_N0509_R089_T51STV_20230622T042653.SAFEMTD_MSIL1C.xml"
root_ds = gdal.Open(filename)
print(type(root_ds))
ds_list = root_ds.GetSubDatasets() # 获取子数据集。该数据以数据集形式存储且以子数据集形式组织
visual_ds = gdal.Open(ds_list[0][0]) # 打开第1个数据子集的路径。ds_list有4个子集,内部前段是路径,后段是数据信息
visual_arr = visual_ds.ReadAsArray() # 将数据集中的数据读取为ndarray
print("ds_list:", ds_list)
结果:
[
('SENTINEL2_L1C:.S2B_MSIL1C_20230622T023529_N0509_R089_T51STV_20230622T042653.SAFEMTD_MSIL1C.xml:10m:EPSG_32651', 'Bands B2, B3, B4, B8 with 10m resolution, UTM 51N'),
('SENTINEL2_L1C:.S2B_MSIL1C_20230622T023529_N0509_R089_T51STV_20230622T042653.SAFEMTD_MSIL1C.xml:20m:EPSG_32651', 'Bands B5, B6, B7, B8A, B11, B12 with 20m resolution, UTM 51N'),
('SENTINEL2_L1C:.S2B_MSIL1C_20230622T023529_N0509_R089_T51STV_20230622T042653.SAFEMTD_MSIL1C.xml:60m:EPSG_32651', 'Bands B1, B9, B10 with 60m resolution, UTM 51N'),
('SENTINEL2_L1C:.S2B_MSIL1C_20230622T023529_N0509_R089_T51STV_20230622T042653.SAFEMTD_MSIL1C.xml:TCI:EPSG_32651', 'True color image, UTM 51N')
]