Compare commits

..

2 Commits
cs ... main

Author SHA1 Message Date
weixin_46229132
5ff2c94df1 把坐标系转换代码隔离出来 2025-06-12 17:09:43 +08:00
weixin_46229132
db283b40a4 删掉坐标转换功能 2025-06-12 16:49:57 +08:00
8 changed files with 52 additions and 112 deletions

8
.idea/.gitignore generated vendored
View File

@ -1,8 +0,0 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

7
.idea/UAV.iml generated
View File

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module version="4">
<component name="PyDocumentationSettings">
<option name="format" value="PLAIN" />
<option name="myDocStringFormat" value="Plain" />
</component>
</module>

View File

@ -1,46 +0,0 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoredPackages">
<value>
<list size="26">
<item index="0" class="java.lang.String" itemvalue="geopy" />
<item index="1" class="java.lang.String" itemvalue="scipy" />
<item index="2" class="java.lang.String" itemvalue="tornado" />
<item index="3" class="java.lang.String" itemvalue="h5py" />
<item index="4" class="java.lang.String" itemvalue="scikit_learn" />
<item index="5" class="java.lang.String" itemvalue="basemap" />
<item index="6" class="java.lang.String" itemvalue="minio" />
<item index="7" class="java.lang.String" itemvalue="torch" />
<item index="8" class="java.lang.String" itemvalue="numpy" />
<item index="9" class="java.lang.String" itemvalue="mpld3" />
<item index="10" class="java.lang.String" itemvalue="pyyaml" />
<item index="11" class="java.lang.String" itemvalue="basemap_data" />
<item index="12" class="java.lang.String" itemvalue="matplotlib" />
<item index="13" class="java.lang.String" itemvalue="basemap_data_hires" />
<item index="14" class="java.lang.String" itemvalue="openpyxl" />
<item index="15" class="java.lang.String" itemvalue="pandas" />
<item index="16" class="java.lang.String" itemvalue="clickhouse_driver" />
<item index="17" class="java.lang.String" itemvalue="pytz" />
<item index="18" class="java.lang.String" itemvalue="tqdm" />
<item index="19" class="java.lang.String" itemvalue="pyinstaller" />
<item index="20" class="java.lang.String" itemvalue="fiona" />
<item index="21" class="java.lang.String" itemvalue="edt" />
<item index="22" class="java.lang.String" itemvalue="opencv-python" />
<item index="23" class="java.lang.String" itemvalue="pyproj" />
<item index="24" class="java.lang.String" itemvalue="psutil" />
<item index="25" class="java.lang.String" itemvalue="opencv_python" />
</list>
</value>
</option>
</inspection_tool>
<inspection_tool class="PyUnresolvedReferencesInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoredIdentifiers">
<list>
<option value="matrix_factorization.svd.*" />
</list>
</option>
</inspection_tool>
</profile>
</component>

View File

@ -1,6 +0,0 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

7
.idea/misc.xml generated
View File

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Black">
<option name="sdkName" value="uav (2)" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="uav (2)" project-jdk-type="Python SDK" />
</project>

6
.idea/vcs.xml generated
View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

View File

@ -1,8 +1,6 @@
import logging import logging
import os import os
from typing import Dict from typing import Dict
import docker
import rasterio import rasterio
from rasterio.mask import mask from rasterio.mask import mask
from rasterio.transform import Affine, rowcol from rasterio.transform import Affine, rowcol
@ -55,40 +53,10 @@ class MergeTif:
self.output_dir, "orthophoto.tif"), orthophoto_vars) self.output_dir, "orthophoto.tif"), orthophoto_vars)
self.logger.info("所有产品合并完成") self.logger.info("所有产品合并完成")
# self.trans_orthophoto.trans_to_epsg4326(os.path.join(self.output_dir, "orthophoto.tif"), os.path.join(
# self.output_dir, "orthophoto_epsg4326.tif"))
self.process_trans2photo4326()
except Exception as e: except Exception as e:
self.logger.error(f"产品合并过程中发生错误: {str(e)}", exc_info=True) self.logger.error(f"产品合并过程中发生错误: {str(e)}", exc_info=True)
raise raise
def process_trans2photo4326(self):
success = True
try:
client = docker.from_env()
container = client.containers.create(
image='trans_docker',
volumes={
f"{self.output_dir}": {'bind': '/temp', 'mode': 'rw'}
},
)
container.start()
container.wait()
logs = container.logs(tail=50).decode('utf-8')
print(logs)
except Exception as e:
print(f"转换失败, 原因: {e}")
success = False
finally:
try:
container.remove(force=True)
except Exception:
pass # 避免因remove失败导致程序崩溃
if success:
print("正射影像转换完成")
def compute_mask_raster(self, input_raster, vector_mask, output_raster, blend_distance=20, only_max_coords_feature=False): def compute_mask_raster(self, input_raster, vector_mask, output_raster, blend_distance=20, only_max_coords_feature=False):
if not os.path.exists(input_raster): if not os.path.exists(input_raster):
print("Cannot mask raster, %s does not exist" % input_raster) print("Cannot mask raster, %s does not exist" % input_raster)

52
trans_orthophoto.py Normal file
View File

@ -0,0 +1,52 @@
import logging
import argparse
import rasterio
from rasterio.warp import calculate_default_transform, reproject, Resampling
class TransOrthophoto:
def __init__(self):
self.logger = logging.getLogger('UAV_Preprocess.TransOrthophoto')
logging.basicConfig(level=logging.INFO,
format='%(asctime)s %(levelname)s %(message)s')
def trans_to_epsg4326(self, ori_orthophoto_path: str, output_path: str):
# 打开原始文件
with rasterio.open(ori_orthophoto_path) as src:
# 定义目标 CRS
dst_crs = 'EPSG:4326'
# 计算目标变换和元数据
transform, width, height = calculate_default_transform(
src.crs, dst_crs, src.width, src.height, *src.bounds)
kwargs = src.meta.copy()
kwargs.update({
'crs': dst_crs,
'transform': transform,
'width': width,
'height': height
})
# 创建重投影后的文件
with rasterio.open(output_path, 'w', **kwargs) as dst:
for i in range(1, src.count + 1):
reproject(
source=rasterio.band(src, i),
destination=rasterio.band(dst, i),
src_transform=src.transform,
src_crs=src.crs,
dst_transform=transform,
dst_crs=dst_crs,
resampling=Resampling.nearest
)
self.logger.info(f"文件已成功重投影: {output_path}")
parser = argparse.ArgumentParser(description="正射影像投影转换为EPSG:4326")
parser.add_argument('--input_img', required=True, help='输入影像路径')
parser.add_argument('--output_img', required=True, help='输出影像路径')
args = parser.parse_args()
trans = TransOrthophoto()
trans.trans_to_epsg4326(args.input_img, args.output_img)