函数如下首先调用的函数是lon_lat_fuc,在python环境下运行没有任何问题,通过pyinstaller打包后会报错
def lon_lat_fuc(self):
try:
if not self.line_red.text() and not self.line_nir.text():
QMessageBox.warning(self, "提示", "没有任何遥感数据")
return 0
transform_file = self.line_red.text() if self.line_red.text() else self.line_nir.text()
red_dataset = gdal.Open(transform_file)
srs = osr.SpatialReference(wkt=red_dataset.GetProjection())
src_epsg = int(srs.GetAttrValue('AUTHORITY', 1))
transform, rever_transform = self.transform_to_wgs84(src_epsg, red_dataset)
ul_lon, lr_lat, lr_lon, ul_lat = self.get_lat_lon_bounds(red_dataset, transform)
self.lon_lat.setText(f"经纬度范围: \n({lr_lon}, {lr_lat}) - ({ul_lon}, {ul_lat}) ")
except Exception as e:
QMessageBox.warning(self, "提示", f"出现异常:{e}")
return 0
def transform_to_wgs84(self, src_epsg, dataset):
src_srs = osr.SpatialReference()
src_srs.ImportFromEPSG(src_epsg)
tgt_srs = osr.SpatialReference()
tgt_srs.ImportFromEPSG(4326)
transform = osr.CoordinateTransformation(src_srs, tgt_srs)
rever_transform = osr.CoordinateTransformation(tgt_srs, src_srs)
return transform, rever_transform
def get_lat_lon_bounds(self, dataset, transform):
gt = dataset.GetGeoTransform()
x_size = dataset.RasterXSize
y_size = dataset.RasterYSize
x_min, y_max = gt[0], gt[3]
x_max, y_min = gt[0] + x_size * gt[1], gt[3] + y_size * gt[5]
print(x_min,y_max,x_max,y_min)
print(transform.TransformPoint(x_min, y_max))
(ul_lon, ul_lat, _) = transform.TransformPoint(x_min, y_max)
(lr_lon, lr_lat, _) = transform.TransformPoint(x_max, y_min)
根据copilot的修改意见,修改了两个变量,但仍然是相同的报错
提示
出现异: Wrong number or type of arguments for overloaded functionCoordinateTransformation TransformPoint!.Possible C/C++ prototypes are:OSRCoordinateTransformationShadow::TransformPoint(double [3])OSRCoordinateTransformationShadow.:TransformPoint(double (4])OSRCoordinateTransformationShadow.TransformPoint(double(3]double,double,double)
OSRCoordinateTransformationShadow.:TransformPoint(double41double,double,doubledouble)
(ul_lon, ul_lat, _) = transform.TransformPoint((x_min, y_max, 0))
(lr_lon, lr_lat, _) = transform.TransformPoint((x_max, y_min, 0))