使用gdal可以读取栅格数据,并获取投影及仿射变换信息
import sys import gdal dataset = gdal.Open('./zhuhai.tif') if dataset is None: print('Unable to open *.tif') sys.exit(1) projection = dataset.GetProjection() # 获取投影信息 ### 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"]], # AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]] transform = dataset.GetGeoTransform() # 获取放射变换信息 ### (113.39159774577, 5.000000000000014e-06, 0.0, 22.058475004479, 0.0, -5.000000000000014e-06) img_array = dataset.ReadAsArray() # 读取波段数据信息
使用rasterio读取栅格数据,并获取投影及仿射变换信息
import rasterio dataset = rasterio.open('./zhuhai.tif') projection = dataset.crs # EPSG:4326 transform = dataset.transform # | 0.00, 0.00, 113.39| # | 0.00,-0.00, 22.06| # | 0.00, 0.00, 1.00| # dataset.height: 2813 # 影像行数 # dataset.width: 1639 # 影像列数 # dataset.count: 3 # 影像波段数 # dataset.driver: GTiff # 影像格式 # dataset.dtypes: uint8 # 影像数据类型
仿射变换信息的相互转换
# 仿射变换信息从gdal到rasterio from rasterio.transform import Affine rio_trans = Affine.from_gdal(transform[0], transform[1], transform[2], transform[3], transform[4], transform[5]) # 仿射变换信息从rasterio到gdal from rasterio.transform import Affine rio_trans = Affine.to_gdal(transform)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)