Arcpy导出ArcGIS全部坐标系及目录结构1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465import arcpyimport osimport jsondef checkDir(dir): if not os.path.exists(dir): os.makedirs(dir)# 获取所有内置的坐标系spatial_references = arcpy.ListSpatialReferences()# 输出坐标系文件的目录output_directory = r"D:\file\program\py\ExportSpatialReference\output"# 遍历所有坐标系并导出为.prj文件for spatial_reference in spatial_references: try: # 创建一个空间参考对象 spatial_ref_obj = arcpy.SpatialReference(spatial_reference) # 获取坐标系的WKT(Well-Known Text)表示 wkt = spatial_ref_obj.exportToString() # 构建.prj文件的完整路径 prj_file_name = f"{spatial_reference}.prj" prj_file_path = os.path.join(output_directory, prj_file_name).replace('/','\\') checkDir(os.path.dirname(prj_file_path)) # 将WKT写入.prj文件 with open(prj_file_path, 'w') as prj_file: prj_file.write(wkt) print(f"坐标系文件 {prj_file_path} 已成功导出") except Exception as e: print(str(e))def generate_folder_structure(folder_path): folder_structure = { "type": "folder", "name": os.path.basename(folder_path), "content": [] } for item in os.listdir(folder_path): item_path = os.path.join(folder_path, item) if os.path.isdir(item_path): # 递归处理子文件夹 folder_structure["content"].append(generate_folder_structure(item_path)) else: # 处理文件 file_info = { "type": "file", "name": item } folder_structure["content"].append(file_info) return folder_structure# 生成文件夹结构的JSONfolder_structure_json = generate_folder_structure(output_directory)# 将JSON保存到文件with open(r"D:\file\program\py\ExportSpatialReference\folder_structure.json", "w") as json_file: json.dump(folder_structure_json, json_file, indent=4)print("文件夹结构已保存为folder_structure.json")