dms-client/util/remote_sensing_util.py
XinYi Song c5481ead05 1、搭建flask框架。
2、整合JPSS,葵花8,GF3,哨兵1,哨兵2,哨兵3,资源2号,环境1号,SNPP等遥感数据解析算法。
3、flask中添加扫描各个卫星扫描任务,定时扫描,数据入库
2021-12-01 14:27:49 +08:00

92 lines
5.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
Author : XinYi Song
Time : 2021/11/4 16:59
Desc:
"""
import rasterio
import requests
from util.xml_util import xml_to_dict, dict_to_xml
def gf4_pmi_001(file_name, xml_name):
"""
:param file_name: 扫描文件传过来的遥感数据源文件的路径
:param xmlPath: 解析出的xml文件存储的路径
:param ThumbnailPath: 解析出的缩略图文件存储的路径
:return:
"""
file_path = 'E:/sensing/GF4_PMI_001/'
with rasterio.open(file_path+file_name, 'r') as ds:
# 存放xml缩略图的文件夹由根文件夹+数据集代码命名的文件夹组成
print('该栅格数据的基本数据集信息:')
CollectionCode = 'GF4_PMI_001' # 数据集代码
DataFormat = ds.driver # DataFormat 数据格式
NumberBands = ds.count # NumberBands 波段数目
ImageWidth = ds.width # ImageWidth 影像宽度
ImageHeight = ds.height # ImageHeight 影像高度
GeographicScope = ds.bounds # GeographicScope 地理范围
ReflectionParameter = ds.transform # ReflectionParameter 反射变换参数(六参数模型)
ProjectionDefinition = ds.crs # ProjectionDefinition 投影定义
# print(CRS.from_epsg(4326))
# 获取第一个波段数据跟GDAL一样索引从1开始
# 直接获得numpy.ndarray类型的二维数组表示如果read()函数不加参数,则得到所有波段(第一个维度是波段)
band1 = ds.read(1)
FirstBindMax = band1.max() # FirstBindMax 第一波段的最大值
FirstBindMin = band1.min() # FirstBindMin 第一波段的最小值
FirstBindAverage = band1.mean() # FirstBindAverage 第一波段的平均值
# 根据地理坐标得到行列号
x, y = (ds.bounds.left + 300, ds.bounds.top - 300) # 距离左上角东300米南300米的投影坐标
row, col = ds.index(x, y) # 对应的行列号
print(f'(投影坐标{x}, {y})对应的行列号是({row}, {col})')
ProjectedCoordinates = x, y # ProjectedCoordinates 投影坐标
RowNumber = row, col # RowNumber 对应的行列号
# 根据行列号得到地理坐标
x, y = ds.xy(row, col) # 中心点的坐标
print(f'行列号({row}, {col})对应的中心投影坐标是({x}, {y})') #
CenterProjectionCoordinates = x, y # CenterProjectionCoordinates 中心投影坐标
# 'C:/Users/HP/Desktop/Number tube/GF4_PMI_E119.8_N35.3_20210908_L1A0000417337/GF4_PMS_E119.8_N35.3_20210908_L1A0000417337.xml'
# 传入xml文件路径解析xml文件
# xml_name 存储后的xml文件的路径+文件名
xml_dict = xml_to_dict(file_path+xml_name)
StartTime = xml_dict['ProductMetaData']['StartTime'] # 开始采集时间
EndTime = xml_dict['ProductMetaData']['EndTime'] # 结束采集时间
CloudPercent = xml_dict['ProductMetaData']['CloudPercent'] # 云覆盖量百分比
TopLeftLatitude = xml_dict['ProductMetaData']['TopLeftLatitude'] # 左上纬度
TopLeftLongitude = xml_dict['ProductMetaData']['TopLeftLongitude'] # 左上经度
TopRightLatitude = xml_dict['ProductMetaData']['TopRightLatitude'] # 右上纬度
TopRightLongitude = xml_dict['ProductMetaData']['TopRightLongitude'] # 右上经度
BottomRightLatitude = xml_dict['ProductMetaData']['BottomRightLatitude'] # 右下纬度
BottomRightLongitude = xml_dict['ProductMetaData']['BottomRightLongitude'] # 右下经度
BottomLeftLatitude = xml_dict['ProductMetaData']['BottomLeftLatitude'] # 左下纬度
BottomLeftLongitude = xml_dict['ProductMetaData']['BottomLeftLongitude'] # 左下经度
boundaryGeomStr = f'POLYGON(({TopLeftLatitude} {TopLeftLongitude},' \
f'{TopRightLatitude} {TopRightLongitude},' \
f'{BottomRightLatitude} {BottomRightLongitude},' \
f'{BottomLeftLatitude} {BottomLeftLongitude},' \
f'{TopLeftLatitude} {TopLeftLongitude}))'
# ThumbnailPath 存储后的缩略图的路径+文件名 ThumbnailName 缩略图文件名称
# xmlPath 存储后的xml文件路径+文件名 xmlFileName xml文件名称
sensing_dict = {'StartTime': StartTime, 'EndTime': EndTime, 'CloudPercent': CloudPercent,
'boundaryGeomStr': boundaryGeomStr, 'DataFormat': DataFormat, 'NumberBands': NumberBands,
'ImageWidth': ImageWidth, 'ImageHeight': ImageHeight, 'GeographicScope': GeographicScope,
#'ReflectionParameter': ReflectionParameter, 'ProjectionDefinition': ProjectionDefinition,
#'FirstBindMax': FirstBindMax, 'FirstBindMin': FirstBindMin,
'FirstBindAverage': FirstBindAverage,
'ProjectedCoordinates': ProjectedCoordinates, 'RowNumber': RowNumber,
#'CenterProjectionCoordinates': CenterProjectionCoordinates,
'CollectionCode': CollectionCode,
"ThumbnailPath": file_path+"GF4_IRS_E119.8_N35.3_20210908_L1A0000417337_thumb.jpg",
"ThumbnailName": "GF4_IRS_E119.8_N35.3_20210908_L1A0000417337_thumb.jpg",
"xmlPath": "", "xmlFileName": "",
'DirectoryDepth': 'day'}
return sensing_dict
if __name__ == '__main__':
file_path = 'C:/Users/HP/Desktop/Number tube/GF4_PMI_E119.8_N35.3_20210908_L1A0000417337/GF4_PMS_E119.8_N35.3_20210908_L1A0000417337.tiff'
xml_path = 'C:/Users/HP/Desktop/Number tube/GF4_PMI_E119.8_N35.3_20210908_L1A0000417337/GF4_PMS_E119.8_N35.3_20210908_L1A0000417337.xml'
gf4_pmi_001(file_path, xml_path)