CRS not update the config file

本文记录了一次启动Oracle数据库实例过程中遇到的SPFILE加载失败问题。尝试使用特定命令创建并指定SPFILE,但启动时出现错误提示,无法正确识别指定的SPFILE文件路径。错误涉及文件路径配置、文件权限或文件存在性等问题。
create spfile='+DATA0411/spfile' from pfile='/u01/app/base/admin/racstr/scripts/init.ora';
srvctl modify database -d racstr -p +DATA0411/spfile

[cdccrs@node01 trace]$ sqlplus / as sysdba
SQL*Plus: Release 12.1.0.0.2 Beta on Sun Apr 15 19:15:33 2012
Copyright (c) 1982, 2012, Oracle.  All rights reserved.
Connected to an idle instance.
SQL>
SQL> startup mount;
ORA-01078: failure in processing system parameters
ORA-01565: error in identifying file '+DATA0411/racstr/spfileracstr.ora'
ORA-17503: ksfdopn:2 Failed to open file +DATA0411/racstr/spfileracstr.ora
ORA-15056: additional error message
ORA-17503: ksfdopn:2 Failed to open file +DATA0411/racstr/spfileracstr.ora
ORA-15173: entry 'spfileracstr.ora' does not exist in directory 'racstr'
ORA-06512: at line 4


检查以下代码bug,是否需要优化,怎么优化。 ```python import os import subprocess import time import logging from watchdog.observers import Observer from watchdog.events import FileSystemEventHandler import configparser import concurrent.futures import sys import json import subprocess from osgeo import gdal, osr import rasterio # 创建 logger logger = logging.getLogger() logger.setLevel(logging.INFO) # 创建文件处理器并设置编码 file_handler = logging.FileHandler('application.log', encoding='utf-8') formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s') file_handler.setFormatter(formatter) # 将文件处理器添加至 logger logger.addHandler(file_handler) # 裁剪tif文件 cutline_path = "result\squares.geojson" # with open(cutline_path, "w") as f: # json.dump(geojson, f) # 获取图像信息(分辨率、坐标系) def get_info(path): with rasterio.open(path) as src: return { 'crs': src.crs.to_string(), 'res': (abs(src.transform.a), abs(src.transform.e)), 'bounds': src.bounds } # 裁剪函数 def crop_with_cutline(input_path, output_path, cutline, target_crs, target_res): warp_options = gdal.WarpOptions( format='GTiff', cutlineDSName=cutline, cropToCutline=True, dstSRS=target_crs, xRes=target_res[0], yRes=target_res[1], resampleAlg='bilinear', # dstAlpha=True, # 关键修改:添加alpha通道 # dstNodata=None # 可选:显式设置为None,让GDAL自动处理 ) ds = gdal.Warp(output_path, input_path, options=warp_options) ds = None def caijian_main(file1, file2, out1, out2): # 获取统一的 CRS 和分辨率 info1 = get_info(file1) info2 = get_info(file2) target_crs = info1['crs'] target_res = (min(info1['res'][0], info2['res'][0]), min(info1['res'][1], info2['res'][1])) # 使用自定义多边形裁剪两个图像 crop_with_cutline(file1, out1, cutline_path, target_crs, target_res) crop_with_cutline(file2, out2, cutline_path, target_crs, target_res) print("✅ 裁剪完成,输出图像已对齐!") def run_command(command): try: print(f"运行命令: {command}") result = subprocess.run(command, shell=True, check=True) return result.returncode except subprocess.CalledProcessError as e: logger.error(f"命令 {command} 执行失败: {e}") return e.returncode def get_folder_size(folder_path): try: total_size = 0 for dirpath, _, filenames in os.walk(folder_path): for f in filenames: fp = os.path.join(dirpath, f) total_size += os.path.getsize(fp) return total_size except Exception as e: logger.error(f"获取文件夹大小时出错: {e}") return None def process_folder(folder_name, folder_full_path, config,config_build): logger.info(f"开始处理文件夹: {folder_name}") # # 获取Python的安装路径 # python_install_path = sys.executable # # 获取Python安装路径的上级目录,即包含Scripts文件夹的目录 # python_base_path = os.path.dirname(python_install_path) # # 拼接Scripts/gdal2tiles.py路径 # qietu_path = os.path.join(python_base_path, 'Scripts', 'gdal2tiles.py') gdal_translate_path = config_build['settings']['gdal_translate_path'] qietu_path = config_build['settings']['gdal2tiles_path'] logger.info(f"切图工具路径: {qietu_path}") logger.info(f"转化工具路径: {gdal_translate_path}") # 强制转换字符串为布尔值 istype_zhengshe = config['settings']['zhengshe'] == 'True' istype_qingxie = config['settings']['qingxie'] == 'True' istype_quanjian = config['settings']['quanjian'] == 'True' istype_ndvi = config['settings']['ndvi'] == 'True' jingdu = config['settings']['precision'] print(f"建模类型: {istype_zhengshe}, {istype_qingxie}, {istype_quanjian}, {istype_ndvi}, 精度: {jingdu}") isNIR=False isRED=False precision_mapping = { "快速": 'lowest', "普通": 'lowest', "精细": 'high' } jingdu_value = precision_mapping.get(jingdu, 'lowest') # 只建正射 if istype_zhengshe: # 建模型 # 建模型 if folder_name == "allimages": # 如果新文件夹名是 allimages,允许运行 docker 命令并生成 orthophoto command_docker = ( f"docker run -ti --rm -v {config['settings']['projectpath']}:/datasets --gpus all opendronemap/odm:gpu " f"--project-path /datasets \"/datasets/{config['settings']['taskqueuepath']}/allimages\" --skip-report --skip-3dmodel " f"--feature-quality {jingdu_value} --copy-to \"/datasets/{config['settings']['resultNameDir']}\"" ) logger.info(f"只建正射 运行 docker 命令command_docker: {command_docker}") return_code = run_command(command_docker) if return_code == 0: # 如果命令成功,再运行 node 789.js command33 = ( rf"python {qietu_path} -z 1-21 " rf"{config['settings']['imagesfolderpath']}/{folder_name}/odm_orthophoto/odm_orthophoto.original.tif " rf"{config['settings']['projectpath']}/{config['settings']['resultNameDir']}/tiles " rf"--xyz --processes 4" ) logger.info(f"运行 gdal2tiles.py 命令command33: {command33}") run_command(command33) update_progress_ini("allimages", 1) # 更新 Progress.ini 文件 else: command3 = ( f"docker run -ti --rm -v {config['settings']['projectpath']}:/datasets --gpus all opendronemap/odm:gpu " f"--project-path /datasets \"/datasets/{config['settings']['taskqueuepath']}/{folder_name}\" --skip-report --skip-3dmodel --pc-rectify --pc-ept --pc-quality lowest " f"--feature-quality lowest" ) logger.info(f"只建正射 运行 docker 命令command3: {command3}") return_code2 = run_command(command3) if return_code2 == 0: # 如果命令成功,再运行 gdal2tiles.py command2 = ( rf"python {qietu_path} -z 10-18 " rf"{config['settings']['imagesfolderpath']}/{folder_name}/odm_orthophoto/odm_orthophoto.original.tif " rf"{config['settings']['projectpath']}/{config['settings']['resultNameDir']}/tiles " rf"--xyz --processes 4" ) logger.info(f"运行 gdal2tiles.py 命令command2: {command2}") run_command(command2) update_progress_ini(None, 1) # 更新 Progress.ini 文件 # 只建倾斜 elif istype_qingxie: # 建模型 # 建模型 if folder_name == "allimages": # 如果新文件夹名是 allimages,允许运行 docker 命令并生成 orthophoto command_docker = ( f"docker run -ti --rm -v {config['settings']['projectpath']}:/datasets --gpus all opendronemap/odm:gpu " f"--project-path /datasets \"/datasets/{config['settings']['taskqueuepath']}/allimages\" --skip-report --skip-orthophoto --pc-rectify --pc-ept --pc-quality {jingdu_value} " f"--feature-quality {jingdu_value} --3d-tiles --copy-to \"/datasets/{config['settings']['resultNameDir']}\"" ) logger.info(f"只建倾斜001 运行 docker 命令command_docker: {command_docker}") return_code = run_command(command_docker) logger.info(f"allimages第一次失败的时间时分秒:,{time.time()}") if return_code == 0: update_progress_ini("allimages", 1) # 更新 Progress.ini 文件 else: # 如果失败等两秒在运行一次命令 time.sleep(20) logger.info(f"allimages第二次重建的时间时分秒:,{time.time()}") command_docker = ( f"docker run -ti --rm -v {config['settings']['projectpath']}:/datasets --gpus all opendronemap/odm:gpu " f"--project-path /datasets \"/datasets/{config['settings']['taskqueuepath']}/allimages\" --skip-report --skip-orthophoto --pc-rectify --pc-ept --pc-quality {jingdu_value} " f"--feature-quality {jingdu_value} --rerun-all --3d-tiles --copy-to \"/datasets/{config['settings']['resultNameDir']}\"" ) logger.info(f"只建倾斜失败运行第二次002 运行 docker 命令command_docker: {command_docker}") return_code = run_command(command_docker) if return_code == 0: update_progress_ini("allimages", 1) # 更新 Progress.ini 文件 else: command3 = ( f"docker run -ti --rm -v {config['settings']['projectpath']}:/datasets --gpus all opendronemap/odm:gpu " f"--project-path /datasets \"/datasets/{config['settings']['taskqueuepath']}/{folder_name}\" --skip-report --skip-3dmodel --pc-rectify --pc-ept --pc-quality lowest " f"--feature-quality lowest" ) logger.info(f"只建倾斜003 运行 docker 命令command3: {command3}") return_code2 = run_command(command3) logger.info(f"imgs1第一次失败的时间时分秒:,{time.time()}") if return_code2 == 0: # 如果命令成功,再运行 gdal2tiles.py command2 = ( rf"python {qietu_path} -z 10-18 " rf"{config['settings']['imagesfolderpath']}/{folder_name}/odm_orthophoto/odm_orthophoto.original.tif " rf"{config['settings']['projectpath']}/{config['settings']['resultNameDir']}/tiles " rf"--xyz --processes 4" ) logger.info(f"运行 gdal2tiles.py004 命令command2: {command2}") run_command(command2) update_progress_ini(None, 1) # 更新 Progress.ini 文件 elif return_code2 != 0 and folder_name == "imgs1": logger.info("imgs1 切图失败,尝试重新运行") hhimg="imgs1" time.sleep(20) logger.info(f"imgs1第二次重建的时间时分秒:,{time.time()}") # 如果失败等两秒在运行一次命令 command3 = ( f"docker run -ti --rm -v {config['settings']['projectpath']}:/datasets --gpus all opendronemap/odm:gpu " f"--project-path /datasets \"/datasets/{config['settings']['taskqueuepath']}/{hhimg}\" --rerun-all --skip-report --skip-3dmodel --pc-rectify --pc-ept --pc-quality lowest " f"--feature-quality lowest" ) logger.info(f"只建倾斜 运行005 docker 命令command3: {command3}") return_code2 = run_command(command3) if return_code2 == 0: # 如果命令成功,再运行 gdal2tiles.py command2 = ( rf"python {qietu_path} -z 10-18 " rf"{config['settings']['imagesfolderpath']}/{hhimg}/odm_orthophoto/odm_orthophoto.original.tif " rf"{config['settings']['projectpath']}/{config['settings']['resultNameDir']}/tiles " rf"--xyz --processes 4" ) logger.info(f"运行 gdal2tiles.py006 命令command2: {command2}") run_command(command2) update_progress_ini(None, 1) # 更新 Progress.ini 文件 # 全建 elif istype_quanjian: # 建模型 # 建模型 if folder_name == "allimages": # 如果新文件夹名是 allimages,允许运行 docker 命令并生成 orthophoto command_docker = ( f"docker run -ti --rm -v {config['settings']['projectpath']}:/datasets --gpus all opendronemap/odm:gpu " f"--project-path /datasets \"/datasets/{config['settings']['taskqueuepath']}/allimages\" --skip-report --pc-rectify --pc-ept --pc-quality {jingdu_value} " f"--feature-quality {jingdu_value} --3d-tiles --copy-to \"/datasets/{config['settings']['resultNameDir']}\"" ) logger.info(f"全建 运行 docker 命令command_docker: {command_docker}") return_code = run_command(command_docker) if return_code == 0: # 如果命令成功,再运行 node 789.js command33 = ( rf"python {qietu_path} -z 1-21 " rf"{config['settings']['imagesfolderpath']}/{folder_name}/odm_orthophoto/odm_orthophoto.original.tif " rf"{config['settings']['projectpath']}/{config['settings']['resultNameDir']}/tiles " rf"--xyz --processes 4" ) logger.info(f"运行 gdal2tiles.py 命令command33: {command33}") run_command(command33) update_progress_ini("allimages", 1) # 更新 Progress.ini 文件 else: command3 = ( f"docker run -ti --rm -v {config['settings']['projectpath']}:/datasets --gpus all opendronemap/odm:gpu " f"--project-path /datasets \"/datasets/{config['settings']['taskqueuepath']}/{folder_name}\" --skip-report --skip-3dmodel --pc-rectify --pc-ept --pc-quality lowest " f"--feature-quality lowest" ) logger.info(f"全建 运行 docker 命令command3: {command3}") return_code2 = run_command(command3) if return_code2 == 0: # 如果命令成功,再运行 gdal2tiles.py command2 = ( rf"python {qietu_path} -z 10-18 " rf"{config['settings']['imagesfolderpath']}/{folder_name}/odm_orthophoto/odm_orthophoto.original.tif " rf"{config['settings']['projectpath']}/{config['settings']['resultNameDir']}/tiles " rf"--xyz --processes 4" ) logger.info(f"运行 gdal2tiles.py 命令command2: {command2}") run_command(command2) update_progress_ini(None, 1) # 更新 Progress.ini 文件 # 只建NDVI elif istype_ndvi: if folder_name == "NIR_allimages": # 如果新文件夹名是 allimages,允许运行 docker 命令并生成 orthophoto NIRcommand_docker = ( f"docker run -ti --rm -v {config['settings']['projectpath']}:/datasets --gpus all opendronemap/odm:gpu " f"--project-path /datasets \"/datasets/{config['settings']['taskqueuepath']}/NIR_allimages\" --skip-report --skip-3dmodel " # f"--copy-to \"/datasets/{config['settings']['resultNameDir']}/NIR\"" # f"--feature-quality {jingdu_value}" ) logger.info(f"只建正射 运行 docker 命令command_docker: {NIRcommand_docker}") return_code = run_command(NIRcommand_docker) if return_code == 0: isNIR=True if isNIR and isRED: file1 = f"{config['settings']['imagesfolderpath']}/NIR_allimages/odm_orthophoto/odm_orthophoto.original.tif" file2 = f"{config['settings']['imagesfolderpath']}/RED_allimages/odm_orthophoto/odm_orthophoto.original.tif" out1 =f"{config['settings']['imagesfolderpath']}/RED_allimages/odm_orthophoto/odm_orthophoto.original_NIR.tif" out2 =f"{config['settings']['imagesfolderpath']}/RED_allimages/odm_orthophoto/odm_orthophoto.original_red.tif" caijian_main(file1, file2, out1, out2) # 计算NDVI_command NDVI_command = f"python D:/Python39/Scripts/gdal_calc.py -A {out1} -B {out2} --outfile={config['settings']['resultnamedir']}/NDVI.tif --calc=\"(A-B)/(A+B)\"" logger.info(f"运行 计算NDVI_command 命令: {NDVI_command}") NDVI_code= run_command(NDVI_command) if NDVI_code == 0: # 如果命令成功,再运行 node 789.js command33 = ( rf"python {qietu_path} -z 1-21 " rf"{config['settings']['resultnamedir']}/NDVI.tif " rf"{config['settings']['projectpath']}/{config['settings']['resultNameDir']}/tiles " rf"--xyz --processes 10" ) logger.info(f"运行 gdal2tiles.py 命令command33: {command33}") run_command(command33) update_progress_ini("allimages", 1) # 更新 Progress.ini 文件 elif folder_name== "NIR_allimages": # 如果新文件夹名是 allimages,允许运行 docker 命令并生成 orthophoto NIRcommand_docker = ( f"docker run -ti --rm -v {config['settings']['projectpath']}:/datasets --gpus all opendronemap/odm:gpu " f"--project-path /datasets \"/datasets/{config['settings']['taskqueuepath']}/NIR_allimages\" --skip-report --skip-3dmodel " # f"--copy-to \"/datasets/{config['settings']['resultNameDir']}/NIR\"" # f"--feature-quality {jingdu_value}" ) logger.info(f"只建正射 运行 docker 命令command_docker: {NIRcommand_docker}") return_code = run_command(NIRcommand_docker) if return_code == 0: isRED=True if isNIR and isRED: file1 = f"{config['settings']['imagesfolderpath']}/NIR_allimages/odm_orthophoto/odm_orthophoto.original.tif" file2 = f"{config['settings']['imagesfolderpath']}/RED_allimages/odm_orthophoto/odm_orthophoto.original.tif" out1 =f"{config['settings']['imagesfolderpath']}/RED_allimages/odm_orthophoto/odm_orthophoto.original_NIR.tif" out2 =f"{config['settings']['imagesfolderpath']}/RED_allimages/odm_orthophoto/odm_orthophoto.original_red.tif" caijian_main(file1, file2, out1, out2) # 计算NDVI_command NDVI_command = f"python {config['settings']['gdal_calc_path']} -A {out1} -B {out2} --outfile={config['settings']['resultnamedir']}/NDVI.tif --calc=\"(A-B)/(A+B)\"" logger.info(f"运行 计算NDVI_command 命令: {NDVI_command}") NDVI_code= run_command(NDVI_command) if NDVI_code == 0: # 如果命令成功,再运行 node 789.js command33 = ( rf"python {qietu_path} -z 1-21 " rf"{config['settings']['resultnamedir']}/NDVI.tif " rf"{config['settings']['projectpath']}/{config['settings']['resultNameDir']}/tiles " rf"--xyz --processes 10" ) logger.info(f"运行 gdal2tiles.py 命令command33: {command33}") run_command(command33) update_progress_ini("allimages", 1) # 更新 Progress.ini 文件 # else是imgs1,imgs2、、、、、、等前缀是imgs,避免出现其他文件夹 elif folder_name.startswith('NIRimgs'): command3 = ( f"docker run -ti --rm -v {config['settings']['projectpath']}:/datasets --gpus all opendronemap/odm:gpu " f"--project-path /datasets \"/datasets/{config['settings']['taskqueuepath']}/{folder_name}\" --skip-report --skip-3dmodel --pc-rectify --pc-ept" # f" --pc-quality lowest --feature-quality lowest" ) logger.info(f"只建NIR 运行 docker 命令command3: {command3}") return_code2 = run_command(command3) if return_code2 == 0: # 转化为RGBA带透明通道tif tif_command = ( rf"{gdal_translate_path} -b 1 -b 1 -b 1 -b 2 -colorinterp red,green,blue,alpha -a_nodata 0 {config['settings']['imagesfolderpath']}/{folder_name}/odm_orthophoto/odm_orthophoto.original.tif {config['settings']['imagesfolderpath']}/{folder_name}/odm_orthophoto/odm_orthophoto.original_NIR.tif" ) logger.info(f"运行 gdal_translate 命令tif_command: {tif_command}") Translator_command= run_command(tif_command) if Translator_command == 0: # 如果命令成功,再运行 gdal2tiles.py command2 = ( rf"python {qietu_path} -z 10-18 " rf"{config['settings']['imagesfolderpath']}/{folder_name}/odm_orthophoto/odm_orthophoto.original_NIR.tif " rf"{config['settings']['projectpath']}/{config['settings']['resultNameDir']}/tiles " rf"--xyz --processes 10" ) logger.info(f"运行 gdal2tiles.py 命令command2: {command2}") run_command(command2) update_progress_ini(None, 1) # 更新 Progress.ini 文件 def update_progress_ini(folder_name, value): config_progress = configparser.ConfigParser() progress_file = 'Progress.ini' if os.path.exists(progress_file): with open(progress_file, 'r', encoding='utf-8') as progressfile: config_progress.read_file(progressfile) else: config_progress.add_section('Progress') if folder_name == "allimages": config_progress.set('Progress', 'allimages', str(value)) else: # 查找下一个 imgs 键,例如 imgs1, imgs2, ... last_imgs_key = None for key in config_progress['Progress']: if key.startswith('imgs'): last_imgs_key = int(key[4:]) if last_imgs_key is not None: new_imgs_key = f"imgs{last_imgs_key + 1}" else: new_imgs_key = "imgs1" config_progress.set('Progress', new_imgs_key, str(value)) with open(progress_file, 'w', encoding='utf-8') as progressfile: config_progress.write(progressfile) logger.info(f"更新 Progress.ini 文件: {new_imgs_key if folder_name != 'allimages' else 'allimages'} = {value}") class NewFolderHandler(FileSystemEventHandler): def __init__(self, folder_path): super().__init__() self.folder_path = folder_path self.folder_sizes = {} # 用于存储文件夹大小 self.size_check_interval = 2 self.size_check_threshold = 5 self.executor = concurrent.futures.ThreadPoolExecutor(max_workers=10) # 设置最大线程数 def on_created(self, event): if event.is_directory and os.path.basename(event.src_path) != 'config.ini': folder_name = os.path.basename(event.src_path) folder_full_path = os.path.join(self.folder_path, folder_name) logger.info(f"新文件夹创建: {folder_name}") # 初始化文件夹大小 current_size = get_folder_size(folder_full_path) if current_size is not None: self.folder_sizes[folder_name] = { 'size': current_size, 'last_checked': time.time() } logger.info(f"初始文件夹大小: {folder_name}, 大小: {self.folder_sizes[folder_name]['size']} bytes") def check_folder_size(self): current_time = time.time() for folder_name, size_info in list(self.folder_sizes.items()): folder_full_path = os.path.join(self.folder_path, folder_name) current_size = get_folder_size(folder_full_path) if current_size is None: continue last_checked = size_info['last_checked'] if current_size != size_info['size']: logger.info(f"文件夹大小发生变化: {folder_name}, 大小: {current_size} bytes") self.folder_sizes[folder_name] = { 'size': current_size, 'last_checked': current_time } elif current_time - last_checked > self.size_check_threshold: logger.info(f"文件夹大小在 {self.size_check_threshold} 秒内没有变化: {folder_name}, 大小: {current_size} bytes") config = configparser.ConfigParser() # 读入配置文件时,使用 open() 函数指定编码 with open('config.ini', 'r', encoding='utf-8') as configfile: config.read_file(configfile) # 加载配置文件读取切图工具路径 config_build = configparser.ConfigParser() # 读入配置文件时,使用 open() 函数指定编码 with open('build.ini', 'r', encoding='utf-8') as configfile: config_build.read_file(configfile) # 提交任务到线程池 self.executor.submit(process_folder, folder_name, folder_full_path, config, config_build) # 从字典中移除已经处理的文件夹 del self.folder_sizes[folder_name] def main(): config = configparser.ConfigParser() try: with open('config.ini', 'r', encoding='utf-8') as configfile: config.read_file(configfile) except Exception as e: print(f"读取配置文件时出错: {e}") return folder_path = config.get('settings', 'imagesFolderPath', fallback=None) if not folder_path: print("配置文件中未找到 imagesFolderPath,请检查配置文件。") return if not os.path.exists(folder_path): print(f"文件夹路径 {folder_path} 不存在,请检查配置文件。") return print(f"监控文件夹: {folder_path}") # 生成geojson文件===================================start import xml.etree.ElementTree as ET import json def kml_to_geojson(kml_file): tree = ET.parse(kml_file) root = tree.getroot() namespace = {'kml': 'http://www.opengis.net/kml/2.2'} geojson = {"type": "FeatureCollection", "features": []} for placemark in root.findall('.//kml:Placemark', namespace): feature = {"type": "Feature", "properties": {}, "geometry": {}} name = placemark.find('kml:name', namespace) if name is not None: feature['properties']['name'] = name.text point = placemark.find('.//kml:Point/kml:coordinates', namespace) if point is not None: coordinates = point.text.strip().split(',') feature['geometry']['type'] = 'Point' feature['geometry']['coordinates'] = [float(coordinates[0]), float(coordinates[1])] else: polygon = placemark.find('.//kml:Polygon/kml:outerBoundaryIs/kml:LinearRing/kml:coordinates', namespace) if polygon is not None: coordinates = polygon.text.strip().split() feature['geometry']['type'] = 'Polygon' feature['geometry']['coordinates'] = [[list(map(float, coord.split(','))) for coord in coordinates]] if feature['geometry']: geojson['features'].append(feature) return geojson def save_geojson(geojson, filename): print('Saving GeoJSON to file:', geojson ) with open(filename, 'w', encoding='utf-8') as f: json.dump(geojson, f, ensure_ascii=False, indent=4) def extract_first_point(kml_file): tree = ET.parse(kml_file) root = tree.getroot() namespace = {'kml': 'http://www.opengis.net/kml/2.2'} for placemark in root.findall('.//kml:Placemark', namespace): point = placemark.find('.//kml:Point/kml:coordinates', namespace) if point is not None: coordinates = point.text.strip().split(',') return float(coordinates[0]), float(coordinates[1]) else: polygon = placemark.find('.//kml:Polygon/kml:outerBoundaryIs/kml:LinearRing/kml:coordinates', namespace) if polygon is not None: coordinates = polygon.text.strip().split() first_point_coords = coordinates[0].split(',') return float(first_point_coords[0]), float(first_point_coords[1]) return None, None def write_to_config(centerpointlongitude, centerpointlatitude, config_file): config = configparser.ConfigParser() # 读入配置文件时,使用 open() 函数指定编码 if os.path.exists(config_file): with open(config_file, 'r', encoding='utf-8') as configfile: config.read_file(configfile) else: config.add_section('DEFAULT') # 设置 centerpointlongitude 和 centerpointlatitude 的值 config.set('settings', 'centerpointlongitude', str(centerpointlongitude)) config.set('settings', 'centerpointlatitude', str(centerpointlatitude)) # 将配置写入 config.ini 文件 with open(config_file, 'w', encoding='utf-8') as configfile: config.write(configfile) # 示例使用 kml_file_path = config.get('settings', 'kmlpath', fallback=None) # 替换为你的 KML 文件路径 geojson_result = kml_to_geojson(kml_file_path) save_geojson(geojson_result, './result/squares.geojson') # 保存为 GeoJSON 文件 if kml_file_path: centerpointlongitude, centerpointlatitude = extract_first_point(kml_file_path) if centerpointlongitude is not None and centerpointlatitude is not None: write_to_config(centerpointlongitude, centerpointlatitude, 'config.ini') else: print("未找到点的坐标") else: print("配置文件中未找到 kmlpath,请检查配置文件。") # 生成geojson文件===================================end handler = NewFolderHandler(folder_path) observer = Observer() observer.schedule(handler, path=folder_path, recursive=False) observer.start() try: while True: time.sleep(handler.size_check_interval) # 根据配置文件中的间隔时间检查一次 handler.check_folder_size() # 检查文件夹大小是否有变化 except KeyboardInterrupt: observer.stop() observer.join() # 关闭线程池 handler.executor.shutdown(wait=True) logger.info("监听器已停止") if __name__ == "__main__": main() ```
09-20
ERROR - ❌ 程序发生严重错误: cannot access local variable 'tid' where it is not associated with a value Traceback (most recent call last): File "C:\Users\Administrator\PyCharmMiscProject\geetest2.py", line 216, in manage_tasks tid, task = future.result() ^^^^^^^^^^^^^^^ File "C:\Users\Administrator\AppData\Local\Programs\Python\Python312\Lib\concurrent\futures\_base.py", line 449, in result return self.__get_result() ^^^^^^^^^^^^^^^^^^^ File "C:\Users\Administrator\AppData\Local\Programs\Python\Python312\Lib\concurrent\futures\_base.py", line 401, in __get_result raise self._exception File "C:\Users\Administrator\AppData\Local\Programs\Python\Python312\Lib\concurrent\futures\thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Administrator\PyCharmMiscProject\geetest2.py", line 163, in export_gridded_image task = ee.batch.Export.image.toDrive( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Administrator\PyCharmMiscProject\.venv\Lib\site-packages\ee\batch.py", line 505, in toDrive config = _prepare_image_export_config(image, config, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Administrator\PyCharmMiscProject\.venv\Lib\site-packages\ee\batch.py", line 1209, in _prepare_image_export_config request['fileExportOptions'] = _build_image_file_export_options( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Administrator\PyCharmMiscProject\.venv\Lib\site-packages\ee\batch.py", line 1499, in _build_image_file_export_options raise ee_exception.EEException( ee.ee_exception.EEException: Unknown file format options: {'tileSize': 256, 'maxFileSize': 10737418240}. During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Users\Administrator\PyCharmMiscProject\geetest2.py", line 616, in <module> main() File "C:\Users\Administrator\PyCharmMiscProject\geetest2.py", line 552, in main task_manager = manage_tasks(task_manager, executor) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Administrator\PyCharmMiscProject\geetest2.py", line 225, in manage_tasks task_manager['failed'].append((tid, str(e))) ^^^ UnboundLocalError: cannot access local variable 'tid' where it is not associated with a value
最新发布
11-26
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值