66 lines
2.8 KiB
Python
66 lines
2.8 KiB
Python
|
|
||
|
from xml.etree.ElementTree import ElementTree
|
||
|
import os
|
||
|
|
||
|
class DictXml:
|
||
|
def __init__(self, xml_path):
|
||
|
self.xml_path = xml_path
|
||
|
self.__tree = ElementTree()
|
||
|
self.__root = None
|
||
|
self.init_xml()
|
||
|
|
||
|
def init_xml(self):
|
||
|
self.__root = self.__tree.parse(self.xml_path)
|
||
|
if self.__root is None:
|
||
|
raise Exception("get root failed")
|
||
|
|
||
|
def get_extend(self):
|
||
|
productInfo = self.__root.find("imageinfo")
|
||
|
if productInfo is None:
|
||
|
raise Exception("get imageInfo failed")
|
||
|
|
||
|
corner = productInfo.find("corner")
|
||
|
if corner is None:
|
||
|
raise Exception("get corner failed")
|
||
|
|
||
|
topLeft = corner.find("topLeft")
|
||
|
if topLeft is None:
|
||
|
raise Exception("get topLeft failed")
|
||
|
|
||
|
topRight = corner.find("topRight")
|
||
|
if topRight is None:
|
||
|
raise Exception("get topRight failed")
|
||
|
|
||
|
bottomLeft = corner.find("bottomLeft")
|
||
|
if bottomLeft is None:
|
||
|
raise Exception("get bottomLeft failed")
|
||
|
|
||
|
bottomRight = corner.find("bottomRight")
|
||
|
if bottomRight is None:
|
||
|
raise Exception("get bottomRight failed")
|
||
|
|
||
|
point_upleft = [float(topLeft.find("longitude").text), float(topLeft.find("latitude").text)]
|
||
|
point_upright = [float(topRight.find("longitude").text), float(topRight.find("latitude").text)]
|
||
|
point_downleft = [float(bottomLeft.find("longitude").text), float(bottomLeft.find("latitude").text)]
|
||
|
point_downright = [float(bottomRight.find("longitude").text), float(bottomRight.find("latitude").text)]
|
||
|
scopes = [point_upleft, point_upright, point_downleft, point_downright]
|
||
|
|
||
|
point_upleft_buf = [float(topLeft.find("longitude").text) - 0.5, float(topLeft.find("latitude").text) + 0.5]
|
||
|
point_upright_buf = [float(topRight.find("longitude").text) + 0.5, float(topRight.find("latitude").text) + 0.5]
|
||
|
point_downleft_buf = [float(bottomLeft.find("longitude").text) - 0.5, float(bottomLeft.find("latitude").text) - 0.5]
|
||
|
point_downright_buf = [float(bottomRight.find("longitude").text) + 0.5, float(bottomRight.find("latitude").text) - 0.5]
|
||
|
scopes_buf = [point_upleft_buf, point_upright_buf, point_downleft_buf, point_downright_buf]
|
||
|
return scopes, scopes_buf
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
xml_path = r'E:\MicroWorkspace\GF3A_nanjing\GF3_SAY_QPSI_011444_E118.9_N31.4_20181012_L1A_AHV_L10003515422\GF3_SAY_QPSI_011444_E118.9_N31.4_20181012_L1A_AHV_L10003515422.meta.xml'
|
||
|
scopes, scopes_buf = DictXml(xml_path).get_extend()
|
||
|
print(scopes)
|
||
|
print(scopes_buf)
|
||
|
# path = r'D:\BaiduNetdiskDownload\GZ\lon.rdr'
|
||
|
# path2 = r'D:\BaiduNetdiskDownload\GZ\lat.rdr'
|
||
|
# path3 = r'D:\BaiduNetdiskDownload\GZ\lon_lat.tif'
|
||
|
# s = ImageHandler().band_merge(path, path2, path3)
|
||
|
# print(s)
|
||
|
# pass
|