利用bat调用py备份SDE数据到GDB中
@echo off set SDEServer=192.168.0.16 set GeoSDEService=5151 set GeoUserName=USER_Mingkof set GeoUserPassWord=UPWD_Mingkof rem 名称用,分割 set GeoFeatureClassNames=GIS_T1,GIS_T2 echo ————————————————————————————— echo 正在导出空间数据 echo ————————————————————————————— echo ' echo ' echo ' python SDE2GBD.py %SDEServer% %GeoSDEService% %GeoUserName% %GeoUserPassWord% %GeoFeatureClassNames% echo ' echo ' echo ' echo ————————————————————————————— echo 空间数据导出完成! echo ————————————————————————————— echo. & pause
__author__ = 'Mingkof' # coding=cp936 # Import arcpy module import os import arcpy from arcpy import env import time env.overwriteOutput = True #SDE主机地址 SDEServer = arcpy.GetParameterAsText(0) #SDE服务端口号 SDEService = arcpy.GetParameterAsText(1) #SDE用户名 SDEUsername = arcpy.GetParameterAsText(2) #SDE用户密码 SDEPassword = arcpy.GetParameterAsText(3) #需要复制的图层名称 FeatureClass_list = arcpy.GetParameterAsText(4) FeatureClass_list = str.split(FeatureClass_list, ",") try: yyMMdd = time.strftime('%Y%m%d', time.localtime(time.time())) hhmmss = time.strftime('%H%M%S', time.localtime(time.time())) #年月日文件夹 out_GDB_Folder_Path = os.path.abspath('.') + "\\" + yyMMdd SDEFilePath = out_GDB_Folder_Path SDEFileName = hhmmss #时分秒文件 out_GDB_Name = hhmmss #GDB文件路径 out_GDB_Path = out_GDB_Folder_Path + '\\' + out_GDB_Name + '.gdb' #创建目录 if not os.path.exists(out_GDB_Folder_Path): os.mkdir(out_GDB_Folder_Path) print '创建输出目录结束' #创建GDB文件 arcpy.CreateFileGDB_management(out_GDB_Folder_Path, out_GDB_Name, "CURRENT") print '创建GDB文件结束' #.sde文件路径 SDEFilePath_SDE = SDEFilePath + "\\" + SDEFileName + ".sde" if os.path.isfile(SDEFilePath_SDE): os.remove(SDEFilePath_SDE) print '删除已有sde文件结束' #创建SDE文件 arcpy.CreateArcSDEConnectionFile_management(SDEFilePath, SDEFileName, SDEServer, SDEService, "", "DATABASE_AUTH", SDEUsername, SDEPassword, "SAVE_USERNAME", "SDE.DEFAULT", "SAVE_VERSION") print '创建SDE文件结束' print "SDE导出GDB开始" #循环输出 FeatureClass_listCount = len(FeatureClass_list) indexI = 1 for tempFeature in FeatureClass_list: print '正在处理' + str(indexI) + "/" + str(FeatureClass_listCount) + "_" + tempFeature indexI += 1 tempSDE = SDEFilePath_SDE + "\\" + tempFeature tempGBD = out_GDB_Path + "\\" + tempFeature arcpy.CopyFeatures_management(tempSDE, tempGBD, "", "0", "0", "0") #删除sde文件 if os.path.isfile(SDEFilePath_SDE): os.remove(SDEFilePath_SDE) print '删除sde文件结束' print "SDE导出GDB结束" except ValueError: print ValueError
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· .NET周刊【3月第1期 2025-03-02】
· [AI/GPT/综述] AI Agent的设计模式综述