From 7edae814fee6a178d7c79e1fb984a4a31df8b2c1 Mon Sep 17 00:00:00 2001 From: HKS Date: Sat, 27 May 2023 15:47:41 +0800 Subject: [PATCH] base up --- .idea/.gitignore | 3 + .idea/encodings.xml | 10 + .idea/inspectionProfiles/Project_Default.xml | 17 + .../inspectionProfiles/profiles_settings.xml | 6 + .idea/misc.xml | 4 + .idea/modules.xml | 8 + .idea/shsmi_sysdb_new.iml | 8 + .idea/vcs.xml | 6 + .vscode/settings.json | 3 + ExportGdbSetting.config | 740 ++++++++++++++++++ SdeSyncSetting.config | 13 + functions.py | 96 +++ logger.py | 44 ++ main.py | 42 + sde_fc2fc.py | 30 + sde_sync.py | 557 +++++++++++++ sys_config.py | 78 ++ test_functions.py | 18 + test_sde_sync.py | 96 +++ test_sys_config.py | 52 ++ translate2old.py | 350 +++++++++ 源库SDE连接/shdlg500.sde | Bin 0 -> 3072 bytes 22 files changed, 2181 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/encodings.xml create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/shsmi_sysdb_new.iml create mode 100644 .idea/vcs.xml create mode 100644 .vscode/settings.json create mode 100644 ExportGdbSetting.config create mode 100644 SdeSyncSetting.config create mode 100644 functions.py create mode 100644 logger.py create mode 100644 main.py create mode 100644 sde_fc2fc.py create mode 100644 sde_sync.py create mode 100644 sys_config.py create mode 100644 test_functions.py create mode 100644 test_sde_sync.py create mode 100644 test_sys_config.py create mode 100644 translate2old.py create mode 100644 源库SDE连接/shdlg500.sde diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..032f518 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..9ba0d0e --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,17 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..7ba73c2 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..0359175 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/shsmi_sysdb_new.iml b/.idea/shsmi_sysdb_new.iml new file mode 100644 index 0000000..d0876a7 --- /dev/null +++ b/.idea/shsmi_sysdb_new.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..65dfbcd --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.pythonPath": "c:\\Python27\\ArcGIS10.2\\python.exe" +} \ No newline at end of file diff --git a/ExportGdbSetting.config b/ExportGdbSetting.config new file mode 100644 index 0000000..a59c51c --- /dev/null +++ b/ExportGdbSetting.config @@ -0,0 +1,740 @@ +# 图层对照列表 +[Layer_River_Normal_L] +relationCount=1 +tagLayerName1=River_Line +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME,Manager,Owner,Protector +renameFieldNames1=BiLC:MapScale +[Layer_Pipe_APP_A] +relationCount=1 +tagLayerName1=Pipe_APP_A +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Administrative_Text] +relationCount=1 +tagLayerName1=Administrative_Text +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Building_Text] +relationCount=1 +tagLayerName1=Building_Text +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Control_Text] +relationCount=1 +tagLayerName1=Control_Text +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Device_Text] +relationCount=1 +tagLayerName1=Device_Text +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Land_Text] +relationCount=1 +tagLayerName1=Land_Text +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Other_Text] +relationCount=1 +tagLayerName1=Other_Text +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Pipe_Text] +relationCount=1 +tagLayerName1=Pipe_Text +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Relief_Text] +relationCount=1 +tagLayerName1=Relief_Text +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_River_Text] +relationCount=1 +tagLayerName1=River_Text +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Road_Text] +relationCount=1 +tagLayerName1=Road_Text +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_UPL_Text] +relationCount=1 +tagLayerName1=UPL_Text +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Building_Simple_A] +relationCount=1 +tagLayerName1=Building_Simple +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Building_APP_L] +relationCount=1 +tagLayerName1=Building_APP_L +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Building_APP_A] +relationCount=1 +tagLayerName1=Building_APP_A +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Building_APP_P] +relationCount=1 +tagLayerName1=Building_APP_P +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Pole_A] +relationCount=1 +tagLayerName1=Pole_A +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME,Pole_No +renameFieldNames1=BiLC:MapScale +[Layer_Basement_Entrance_A] +relationCount=1 +tagLayerName1=Basement_Entrance_A +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME,Ent_Name,Ent_No +renameFieldNames1=BiLC:MapScale +[Layer_RailWay_APP_P] +relationCount=1 +tagLayerName1=RailWay_APP_P +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME,AppCode +renameFieldNames1=BiLC:MapScale +[Layer_RailWay_APP_L] +relationCount=1 +tagLayerName1=RailWay_APP_L +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_RailWay_APP_A] +relationCount=1 +tagLayerName1=RailWay_APP_A +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Road_APP_P] +relationCount=1 +tagLayerName1=Road_APP_P +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +expression1=FeatureCode in ('456000','456010','456100','456200','456300','456500','456810','456820','499000') +[Layer_Road_GuideBoard_P] +relationCount=1 +tagLayerName1=Road_APP_P +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME,RoadName,Start_No,End_No +renameFieldNames1=BiLC:MapScale +[Layer_BusStop_P] +relationCount=1 +tagLayerName1=Road_APP_P +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME,RouteStr,StopName +renameFieldNames1=BiLC:MapScale +[Layer_Road_APP_L] +relationCount=1 +tagLayerName1=Road_APP_L +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Overpass_Pole_A] +relationCount=1 +tagLayerName1=Overpass_Pole_A +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME,Pole_No +renameFieldNames1=BiLC:MapScale +[Layer_Road_Edge_Ramp] +relationCount=1 +tagLayerName1=Road_Edge_Ramp +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Road_Edge_Approach] +relationCount=1 +tagLayerName1=Road_Edge_Approach +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Waterway_APP_P] +relationCount=1 +tagLayerName1=Waterway_APP_P +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Waterway_APP_L] +relationCount=1 +tagLayerName1=Waterway_APP_L +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Pipe_APP_P] +relationCount=1 +tagLayerName1=Pipe_APP_P +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME,AppCode,BoxType,Owner +renameFieldNames1=BiLC:MapScale +expression1=FeatureCode in ('511400','512400','513000','514100','514300','516100','516200','517000','519000','519100','523100','524000','525000','526000','526100','531500','532500','533500','533600','533700','533800','544000','544100','544200','544300','544400','554000','562000','572000','581000','582000','583000','599000') +[Layer_Pipe_APP_L] +relationCount=1 +tagLayerName1=Pipe_APP_L +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME,Owner +renameFieldNames1=BiLC:MapScale +[Layer_River_APP_P] +relationCount=1 +tagLayerName1=River_APP_P +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_River_APP_L] +relationCount=1 +tagLayerName1=River_APP_L +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_River_APP_A] +relationCount=1 +tagLayerName1=River_APP_A +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Well_P] +relationCount=1 +tagLayerName1=Well_P +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Well_A] +relationCount=1 +tagLayerName1=Well_A +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_UPL_L] +relationCount=1 +tagLayerName1=UPL_L +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Flood_Wall_P] +relationCount=1 +tagLayerName1=Flood_Wall_P +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_UpdateRegion_A] +relationCount=1 +tagLayerName1=UpdateRegion_A +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Control_Point_P] +relationCount=1 +tagLayerName1=Control_Point +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Building_A] +relationCount=1 +tagLayerName1=Building +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME,Story_E,BuildingArea,ConYear,BaseArea,RiskSource +renameFieldNames1=BiLC:MapScale +[Layer_Building_Construction_A] +relationCount=1 +tagLayerName1=Building +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Building_Shed_A] +relationCount=1 +tagLayerName1=Building_Shed +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Building_Suspended_A] +relationCount=1 +tagLayerName1=Building_Suspended +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Building_Other_A] +relationCount=1 +tagLayerName1=Building_Other +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Wall_L] +relationCount=1 +tagLayerName1=Wall +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME,Height_A,Width +renameFieldNames1=BiLC:MapScale +expression1=FeatureCode in ('241100','241500','242100','243100','243300','245000','246000','247000','248000') +[Layer_Wall_A] +relationCount=1 +tagLayerName1=Wall_A +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Basement_A] +relationCount=1 +tagLayerName1=Basement +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Doorplate_P] +relationCount=1 +tagLayerName1=Doorplate +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Device_Industry_P] +relationCount=1 +tagLayerName1=Device_Point +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME,OWNER,RiskSource +renameFieldNames1=BiLC:MapScale +[Layer_Device_Service_P] +relationCount=1 +tagLayerName1=Device_Point +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME,OWNER,RiskSource +renameFieldNames1=BiLC:MapScale +expression1=FeatureCode in ('346000','347000','352000','352100','352300','352400','352410','358300','359100','359200','377200') +[Layer_Device_Block_P] +relationCount=1 +tagLayerName1=Device_Point +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME,OWNER,RiskSource +renameFieldNames1=BiLC:MapScale +[Layer_Device_Other_P] +relationCount=1 +tagLayerName1=Device_Point +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME,OWNER,RiskSource +renameFieldNames1=BiLC:MapScale +[Layer_Device_Other_L] +relationCount=1 +tagLayerName1=Device_Line +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME,OWNER,RiskSource +renameFieldNames1=BiLC:MapScale +[Layer_Device_Industry_L] +relationCount=1 +tagLayerName1=Device_Line +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME,OWNER,RiskSource +renameFieldNames1=BiLC:MapScale +[Layer_Device_Service_L] +relationCount=1 +tagLayerName1=Device_Line +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME,OWNER,RiskSource +renameFieldNames1=BiLC:MapScale +[Layer_Device_Sights_L] +relationCount=1 +tagLayerName1=Device_Line +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME,OWNER,RiskSource +renameFieldNames1=BiLC:MapScale +[Layer_Device_Block_L] +relationCount=1 +tagLayerName1=Device_Line +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME,OWNER,RiskSource +renameFieldNames1=BiLC:MapScale +[Layer_Device_Industry_A] +relationCount=1 +tagLayerName1=Device_Building +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME,RiskSource +renameFieldNames1=BiLC:MapScale +[Layer_Device_Agriculture_A] +relationCount=1 +tagLayerName1=Device_Building +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME,RiskSource +renameFieldNames1=BiLC:MapScale +[Layer_Device_Service_A] +relationCount=1 +tagLayerName1=Device_Building +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME,RiskSource +renameFieldNames1=BiLC:MapScale +[Layer_Device_Other_A] +relationCount=1 +tagLayerName1=Device_Building +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME,RiskSource +renameFieldNames1=BiLC:MapScale +expression1=FeatureCode in ('234400','345200','351100','351200','352800','356100','399400') +[Layer_Device_Building_Indst_A] +relationCount=1 +tagLayerName1=Device_Building +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME,RiskSource +renameFieldNames1=BiLC:MapScale +[Layer_Device_Building_OS_A] +relationCount=1 +tagLayerName1=Device_Building +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME,Story_U +renameFieldNames1=BiLC:MapScale +[Layer_Device_Building_Sigt_A] +relationCount=1 +tagLayerName1=Device_Building +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME,Story_U +renameFieldNames1=BiLC:MapScale +[Layer_Device_Building_Relig_A] +relationCount=1 +tagLayerName1=Device_Building +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME,Story_U +renameFieldNames1=BiLC:MapScale +[Layer_Device_Building_Other_A] +relationCount=1 +tagLayerName1=Device_Building +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME,Story_U +renameFieldNames1=BiLC:MapScale +[Layer_Device_Land_Service_A] +relationCount=1 +tagLayerName1=Device_Land +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME,Is_BarrierFree,Owner +renameFieldNames1=BiLC:MapScale +expression1=FeatureCode in ('348000','348500','348600','348700','348710','377000','377300','377400') +[Layer_Device_Land_Agricltr_A] +relationCount=1 +tagLayerName1=Device_Land +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME,Owner +renameFieldNames1=BiLC:MapScale +[Layer_Device_Land_Other_A] +relationCount=1 +tagLayerName1=Device_Land +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME,Owner +renameFieldNames1=BiLC:MapScale +expression1=FeatureCode in ('354100') +[Layer_Pool_A] +relationCount=1 +tagLayerName1=Pool_FlatRoof +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME,Owner +renameFieldNames1=BiLC:MapScale +[Layer_FlatRoof_A] +relationCount=1 +tagLayerName1=Pool_FlatRoof +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME,Is_BarrierFree,Owner +renameFieldNames1=BiLC:MapScale +[Layer_RailWay_L] +relationCount=1 +tagLayerName1=RailWay +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Road_Bed_Regular_L] +relationCount=1 +tagLayerName1=Road_Bed_Regular +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Road_Edge_Regular_L] +relationCount=4 +tagLayerName1=Road_Edge_Regular +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +expression1=FeatureCode in ('430100','430200','430300','430400','421100','421500','422100','422500','423100','423500','424100','424500','425100','425500','426100','426500') +tagLayerName2=Road_Edge_Approach +expression2=FeatureCode in ('430530') +tagLayerName3=Road_Edge_Ramp +expression3=FeatureCode in ('430500') +tagLayerName4=Overpass_Edge +expression4=FeatureCode in ('430600') +[Layer_Road_Edge_Normal_L] +relationCount=1 +tagLayerName1=Road_Edge_Normal +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Road_Normal_L] +relationCount=1 +tagLayerName1=Road_Normal +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Road_Center_Line_L] +relationCount=1 +tagLayerName1=Road_Center_Line +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME,Is_Park,Road_Level,Protector,Owner,SpatialType +renameFieldNames1=BiLC:MapScale +[Layer_Road_Polygon_A] +relationCount=1 +tagLayerName1=Road_Polygon +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +expression1=FeatureCode in ('421400','421700','422400','422700','423400','423700','424400','424700','425400','425700','426400','426700','430120','430220','430320','430420','430520','430550','430620','441400','442400','444200','468000') +[Layer_Road_APP_L] +relationCount=1 +tagLayerName1=Road_APP_L +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Road_SeparationFacilt_L] +relationCount=1 +tagLayerName1=Road_APP_L +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME,IsFixed,App_Type,Height +renameFieldNames1=BiLC:MapScale +[Layer_Road_Column_L] +relationCount=1 +tagLayerName1=Road_APP_L +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME,Name,ColumnType,ColumnNum +renameFieldNames1=BiLC:MapScale +[Layer_Parking_A] +relationCount=1 +tagLayerName1=Parking_A +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +expression1=FeatureCode in ('456700') +[Layer_Nav_Road_App_A] +relationCount=1 +tagLayerName1=Road_APP_A +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +expression1=FeatureCode in ('458300') +[Layer_Road_APP_A] +relationCount=1 +tagLayerName1=Road_APP_A +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME,Name +renameFieldNames1=BiLC:MapScale +[Layer_Road_Interior_L] +relationCount=1 +tagLayerName1=Interior_Road +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Overpass_Edge_L] +relationCount=1 +tagLayerName1=Overpass_Edge +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Bridge_L] +relationCount=1 +tagLayerName1=Bridge +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME,LimitA +renameFieldNames1=BiLC:MapScale +[Layer_Ferry_Pier_A] +relationCount=1 +tagLayerName1=Waterway_APP_A +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME,Name,Capacity +renameFieldNames1=BiLC:MapScale +[Layer_Waterway_APP_A] +relationCount=1 +tagLayerName1=Waterway_APP_A +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Ferry_Route_L] +relationCount=1 +tagLayerName1=Ferry_Route +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME,Name,Capacity +renameFieldNames1=BiLC:MapScale +[Layer_Tunnel_L] +relationCount=1 +tagLayerName1=Tunnel +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Pipe_Line_L] +relationCount=1 +tagLayerName1=Pipe_Line +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME,Owner +renameFieldNames1=BiLC:MapScale +[Layer_River_A] +relationCount=1 +tagLayerName1=River +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME,Manager,Owner,Protector +renameFieldNames1=BiLC:MapScale +[Layer_Lake_A] +relationCount=1 +tagLayerName1=River +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME,Manager,Owner,Protector +renameFieldNames1=BiLC:MapScale +[Layer_Reservoir_A] +relationCount=1 +tagLayerName1=River +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME,Manager,Owner,Protector +renameFieldNames1=BiLC:MapScale +[Layer_Ditch_A] +relationCount=1 +tagLayerName1=River +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME,Manager,Owner,Protector +renameFieldNames1=BiLC:MapScale +[Layer_River_Edge_L] +relationCount=1 +tagLayerName1=River_Edge +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +expression1=FeatureCode in ('611200','611400','612200','613200','614300','615100','622500','623000','630100','632000','634200') +[Layer_River_Center_Line_L] +relationCount=1 +tagLayerName1=River_Center_Line +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Flood_Control_Wall_L] +relationCount=1 +tagLayerName1=Flood_Control_Wall +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Bank_L] +relationCount=1 +tagLayerName1=Bank +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Ocean_P] +relationCount=1 +tagLayerName1=Ocean_Point +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Ocean_L] +relationCount=1 +tagLayerName1=Ocean_Line +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Ocean_A] +relationCount=1 +tagLayerName1=Ocean_Polygon +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Administrative_P] +relationCount=1 +tagLayerName1=Administrative_Point +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Administrative_L] +relationCount=1 +tagLayerName1=Administrative_Line +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Administrative_A] +relationCount=1 +tagLayerName1=Administrative_Area +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Other_Area_L] +relationCount=1 +tagLayerName1=Other_Area_Line +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Other_Area_A] +relationCount=1 +tagLayerName1=Other_Area +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Mail_Area_A] +relationCount=1 +tagLayerName1=Mail_Area +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Block_A] +relationCount=1 +tagLayerName1=Block +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Community_Area_A] +relationCount=1 +tagLayerName1=Community_Area +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME,Function +renameFieldNames1=BiLC:MapScale +[Layer_Service_Area_A] +relationCount=1 +tagLayerName1=Service_Area +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME,Function +renameFieldNames1=BiLC:MapScale +expression1=FeatureCode in ('727000','727100','729100','729200','729300') +[Layer_Level_Point_A_P] +relationCount=1 +tagLayerName1=Level_Point_A +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Level_Point_R_P] +relationCount=1 +tagLayerName1=Level_Point_R +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Contour_L] +relationCount=1 +tagLayerName1=Contour +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Relief_P] +relationCount=1 +tagLayerName1=Relief_Point +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Relief_L] +relationCount=1 +tagLayerName1=Relief_Line +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Relief_A] +relationCount=1 +tagLayerName1=Relief_Polygon +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Embankment_L] +relationCount=1 +tagLayerName1=Embankment +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Land_P] +relationCount=1 +tagLayerName1=Land_Point +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Land_L] +relationCount=1 +tagLayerName1=Land_Line +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +expression1=FeatureCode in ('932300','932400','937600','938300','954100','961000','963000','964100','964200','999100','999200','999300','999310') +[Layer_Land_Classification_A] +relationCount=1 +tagLayerName1=Land_Classification +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_AncientTree_P] +relationCount=1 +tagLayerName1=AncientTree_Point +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Device_Sights_P] +relationCount=1 +tagLayerName1=Device_Point +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale +[Layer_Device_Land_Other_P] +relationCount=1 +tagLayerName1=Device_Point +removeFieldNames1=DESCRIPTION,PRECISION,FILENAME3D,PROTIME +renameFieldNames1=BiLC:MapScale + + +# 编码对照 old_code:new_code +[FeatureCode] +relationLayers=Road_Edge_Regular,Road_Bed_Regular,Road_Center_Line,Road_Polygon,Road_Edge_Approach,Overpass_Edge,Overpass_Pole_A,Road_APP_L,Ocean_Polygon,Ocean_Line,RailWay_APP_A,RailWay_APP_P,RailWay_APP_L,Parking_A,Road_Edge_Ramp +relationCount=73 +changeCode1=421100:431100 +changeCode2=421200:431200 +changeCode3=421300:431300 +changeCode4=421400:431400 +changeCode5=421500:431500 +changeCode6=421600:431600 +changeCode7=421700:431700 +changeCode8=422100:432100 +changeCode9=422200:432200 +changeCode10=422300:432300 +changeCode11=422400:432400 +changeCode12=422500:432500 +changeCode13=422600:432600 +changeCode14=422700:432700 +changeCode15=423100:433100 +changeCode16=423200:433200 +changeCode17=423300:433300 +changeCode18=423400:433400 +changeCode19=423500:433500 +changeCode20=423600:433600 +changeCode21=423700:433700 +changeCode22=424100:434100 +changeCode23=424200:434200 +changeCode24=424300:434300 +changeCode25=424400:434400 +changeCode26=424500:434500 +changeCode27=424600:434600 +changeCode28=424700:434700 +changeCode29=425100:435100 +changeCode30=425200:435200 +changeCode31=425300:435300 +changeCode32=425400:435400 +changeCode33=425500:435500 +changeCode34=425600:435600 +changeCode35=425700:435700 +changeCode36=426100:436100 +changeCode37=426200:436200 +changeCode38=426300:436300 +changeCode39=426400:436400 +changeCode40=426500:436500 +changeCode41=426600:436600 +changeCode42=426700:436700 +changeCode43=430500:440000 +changeCode44=430510:440100 +changeCode45=430520:440200 +changeCode46=430530:440500 +changeCode47=430540:440600 +changeCode48=430550:440700 +changeCode49=430600:446000 +changeCode50=430610:446100 +changeCode51=430620:446200 +changeCode52=430630:446300 +changeCode53=430640:446400 +changeCode54=459300:447100 +changeCode55=459310:447200 +changeCode56=616000:487800 +changeCode57=616100:487900 +changeCode58=419501:421100 +changeCode59=419502:421200 +changeCode60=419503:421300 +changeCode61=419504:422100 +changeCode62=419505:422200 +changeCode63=419506:421200 +changeCode64=419507:423200 +changeCode65=419508:424100 +changeCode66=419509:424200 +changeCode67=419510:424300 +changeCode68=419511:425000 +changeCode69=419512:426000 +changeCode70=419513:427000 +changeCode71=419514:428100 +changeCode72=419515:428400 +changeCode73=456700:456720 \ No newline at end of file diff --git a/SdeSyncSetting.config b/SdeSyncSetting.config new file mode 100644 index 0000000..cdab13d --- /dev/null +++ b/SdeSyncSetting.config @@ -0,0 +1,13 @@ +# 同步系统设置 +[System] +eps_path=C:/EPS20221017/eps.exe +python_path=C:/Python27/ArcGIS10.2/python.exe +template_name="上海新型测绘_地理实体.mdt" +eps_vbs=.\上海数据库同步\自动输出MDO.vbs +sde_scheme=SHDLG500 +eps_show=show +sync_type=ALL +[UpdateRegion] +layer_name=UpdateRegion_A +updatetime_field=UpdateTime +updatetime_field_history=DeleteTime diff --git a/functions.py b/functions.py new file mode 100644 index 0000000..f9fbe14 --- /dev/null +++ b/functions.py @@ -0,0 +1,96 @@ +# coding=utf-8 +import json +import os +import socket +import sys +import shutil +import datetime +import subprocess +import time +import ctypes +import urllib +import urllib2 +from imp import reload + +reload(sys) +sys.setdefaultencoding('utf8') + + +def run_command(command): + """call shell-command and either return its output or kill it + if it doesn't normally exit within timeout seconds and return None""" + cmd = command + start = datetime.datetime.now() + process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = process.communicate() + if stderr: + return False, "Error:" + stderr.decode() + else: + return True, stdout.decode() + + +def timeout_command(command, timeout): + """call shell-command and either return its output or kill it + if it doesn't normally exit within timeout seconds and return None""" + cmd = command + start = datetime.datetime.now() + process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + while process.poll() is None: + time.sleep(0.2) + now = datetime.datetime.now() + if (now - start).seconds > timeout: + try: + handle = ctypes.windll.kernel32.OpenProcess(1, False, process.pid) + ctypes.windll.kernel32.TerminateProcess(handle, 0) + except OSError: + print(OSError) + pass + return None + return process.stdout.readlines() + + +def create_dir(path): + """递归创建目录""" + if not os.path.exists(path): + os.makedirs(path) + + +def write_event_log(log_type, log_keyno, log_status, log_filelocalpos, log_remark): + """调用ERP的WriteEventLog通用接口""" + url = 'http://localhost/SG_ERP/sg_webapi/erpsvc/common/erp.common.eventlog.WriteEventLog' + log_soft = "python" + soft_version = "python2.7" + user = "admin" + pc_name = socket.gethostname() + ipaddr = socket.gethostbyname(pc_name) + event_log = [{"log_type": log_type, "log_keyno": log_keyno, "log_status": log_status, "log_soft": log_soft, + "softversion": soft_version, "log_filelocalpos": log_filelocalpos, + "pcname": pc_name, "ipaddr": ipaddr, "user": user, "log_remark": log_remark}] + + json_event_log = json.dumps(event_log, ensure_ascii=False) + values = {'access_token': "", 'api': "erp.common.eventlog.WriteEventLog", 'eventLog': json_event_log} + data = urllib.urlencode(values) + req = urllib2.Request(url + '?' + data) + response = urllib2.urlopen(req) + print(response.read()) + + +def output_map_result(iid, result, filename, maptype): + url = "http://localhost/SG_ERP/sg_webapi/erpsvc/common/erp.pro.shchy.outputmapresult" + values = {'access_token': "", 'api': "erp.pro.shchy.outputmapresult", 'iid': iid, 'result': result, + 'filename': filename, 'maptype': maptype} + data = urllib.urlencode(values) + + req = urllib2.Request(url + '?' + data) + print(url + '?' + data) + response = urllib2.urlopen(req) + print(response.code) + print(str(response.read()).encode('gbk')) + + +def get_tag_tablespace(fc_name): + """根据feature class截取表空间名""" + index1 = fc_name.rfind('\\') + index2 = fc_name.rfind('.') + tablespace = fc_name[index1 + 1:index2 - index1 - 1] + return tablespace diff --git a/logger.py b/logger.py new file mode 100644 index 0000000..24ccb6e --- /dev/null +++ b/logger.py @@ -0,0 +1,44 @@ +# coding=utf-8 +import os +import sys +import logging +from imp import reload + +reload(sys) +sys.setdefaultencoding('utf8') + + +class Logger: + def __init__(self, log_file): + self.logger = logging.getLogger(__name__) + self.logger.setLevel(logging.DEBUG) + formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s') + file_handler = logging.FileHandler(log_file) + file_handler.setLevel(logging.DEBUG) + file_handler.setFormatter(formatter) + self.logger.addHandler(file_handler) + + def log(self, message): + self.logger.info(message) + + def error(self, message): + self.logger.error(message) + + def warning(self, message): + self.logger.warning(message) + + def debug(self, message): + self.logger.debug(message) + + # 关闭日志 + def close(self): + self.logger.removeHandler(self.logger.handlers[0]) + + +if __name__ == '__main__': + logger = Logger('log/TestLog.log') + logger.log(u'################ SdeSynchronous ################\n\n') + logger.log(u"输出增量MDO完成") + logger.error(u"输出层信息失败!") + logger.warning(u"信息不对等,请注意!") + logger.debug(u"这里的数值是1") diff --git a/main.py b/main.py new file mode 100644 index 0000000..83d2899 --- /dev/null +++ b/main.py @@ -0,0 +1,42 @@ +# coding=utf-8 +import inspect +import os +import sys +from imp import reload +from sde_sync import SdeSynchronous +from logger import Logger +from functions import * +from sys_config import SysConfig + +reload(sys) +sys.setdefaultencoding('utf8') + + +if __name__ == '__main__': + """程序入口""" + # 获取当前路径 + caller_file = inspect.getfile(inspect.currentframe()) + work_pathname = os.path.abspath(os.path.dirname(caller_file)) + # 同步开始时间 + curr_sync_date = time.strftime("%Y-%m-%d", time.localtime()) + curr_sync_time = time.strftime("%H-%M-%S", time.localtime()) + # 设置当前工作路径 + config = SysConfig() + config.pathname = work_pathname + config.curr_sync_datetime = curr_sync_date + " " + curr_sync_time + # 日志记录 + create_dir(work_pathname + "\\log") + config.logfile_name = work_pathname + "\\log\\" + config.curr_sync_datetime + "-SdeSynchronous.txt" + logger = Logger(config.logfile_name) + logger.log("==SdeSynchronous Started==") + logger.log("Process begin at " + str(curr_sync_date) + " " + str(curr_sync_time) + ".") + + sde_db_sync = SdeSynchronous(config, logger) + sde_db_sync.run() + + # 同步结束时间 + end_date = time.strftime("%Y-%m-%d", time.localtime()) + end_time = time.strftime("%H-%M-%S", time.localtime()) + logger.log("Process completed at " + str(end_date) + " " + str(end_time) + ".") + + diff --git a/sde_fc2fc.py b/sde_fc2fc.py new file mode 100644 index 0000000..e0bd187 --- /dev/null +++ b/sde_fc2fc.py @@ -0,0 +1,30 @@ +# coding=utf-8 +import sys +from imp import reload +import arcpy + +reload(sys) +sys.setdefaultencoding('utf8') + + +# 获取参数 +args = sys.argv[1:] + +if not args or len(args) < 6: + sys.exit("参数不足:需要文件路径") +else: + src_sde = args[0] + type_name = args[1] + fc_name = args[2] + outLocation = args[3] + fc_cur = args[4] + expression = args[5] + arcpy.env.workspace = src_sde + if type_name == u'feature': + print(' [sde_fc2fc.py]: ' + '##output feature##') + fc_out = arcpy.FeatureClassToFeatureClass_conversion(fc_name, outLocation, fc_cur, expression) + print(' [sde_fc2fc.py]: ' + str(arcpy.GetCount_management(fc_out))) + elif type_name == u'table': + print(' [sde_fc2fc.py]: ' + '##output table##') + fc_out = arcpy.TableToTable_conversion(fc_name, outLocation, fc_cur, expression) + print(' [sde_fc2fc.py]: ' + str(arcpy.GetCount_management(fc_out))) diff --git a/sde_sync.py b/sde_sync.py new file mode 100644 index 0000000..e8668d4 --- /dev/null +++ b/sde_sync.py @@ -0,0 +1,557 @@ +# coding=utf-8 +import fnmatch +import os +import sys +import arcpy +from imp import reload +from functions import * +from sys_config import SysConfig +from logger import Logger + +reload(sys) +sys.setdefaultencoding('utf8') + +# EPS SDE 系统表列表 +g_sys_tb = ['SS_BDCDYHINFO', 'SS_GISDBLINKINFO', 'SS_LOGINFO', 'SS_ROLEINFO', 'SS_ROLEMXDINFO', + 'SS_TABSAPCEPERMISSIONINFO', 'SS_USERINFO', 'SUNWAY_INIINFO', 'SS_LAYERINFO', + 'GE_ENTITYCODE', 'GE_ENTITYIDTB'] + + +class SdeSynchronous: + def __init__(self, conf, log): + self.config = conf + self.logger = log + self.error_count = 0 + self.src_sde = None + self.txt_ct_file = None # 记录数量的txt文件 + self.out_gdb_path = None + self.out_gdb_files = {} + self.only_changed_layers = False + + def run(self): + """同步的主函数""" + # 1.连接SDE数据库 + self.src_sde = self.get_connection(str(u"源库SDE连接")) + if self.src_sde == "" or self.src_sde is None: + self.logger.error("src_sde Connection file not exist!") + else: + self.create_gdb_files() + txt_path = self.out_gdb_path + "\\" + str(u"图层数量统计.txt").encode("utf-8") + self.txt_ct_file = open(txt_path, "wb+", buffering=0) + # 开始编辑SDE + edit = self.start_edit() + # 获取上次同步的时间 + last_sync_datetime = self.get_last_sync_datetime() + if last_sync_datetime == "": + self.config.last_sync_datetime = self.config.curr_sync_datetime + else: + self.config.last_sync_datetime = last_sync_datetime + self.logger.log('===' + self.config.last_sync_datetime + "==TO==" + self.config.curr_sync_datetime + "===") + # 获取fc列表 + fc_list = arcpy.ListFeatureClasses("*", "all") + # 获取同步工程信息 + last_gongch, last_yewbh = self.get_projects_info() + self.write_start_event_logs(last_gongch) + # 输出增量 + self.sde2gdb_feature_list(fc_list) + # 获取数据集列表 + ds_list = arcpy.ListDatasets("*", "Feature") + # 逐个数据集输出 + for DS in ds_list: + str_msg = "Process Dataset: " + DS.encode("gb2312") + print(str_msg) + index = DS.rfind('.') + ds_name = DS[index + 1:] + desc = arcpy.Describe(DS) + sr = desc.spatialReference + # 更改工作空间回到SDE + arcpy.env.workspace = self.src_sde + # 获取数据集中fc列表 + fc_list = arcpy.ListFeatureClasses(feature_dataset=DS) + # 输出增量 + self.sde2gdb_feature_list(fc_list) + # 获取关联关系表列表 + re_table_list = arcpy.ListTables("SHDLG500.*", "all") + self.sde2gdb_table_list(re_table_list) + + bool_save = True if self.error_count == 0 else False + if bool_save: + # 记录同步成功时间 + self.set_last_sync_datetime() + # 停止编辑 + self.stop_edit(edit, bool_save) + + # 执行回调返回gdb增量输出结果 + self.return_result("gdb", bool_save, last_gongch, last_yewbh) + # 结果输出到日志信息 + str_message = u"输出增量GDB完成" if bool_save else u"输出增量GDB失败" + self.logger.log(str_message.encode("gb2312")) + arcpy.env.workspace = self.out_gdb_path + "\\" + self.out_gdb_files["Delete"] + delete_fcs = arcpy.ListFeatureClasses() + for FC in delete_fcs: + arcpy.AddField_management(FC, "FEATUREGUIDCOPY", "TEXT") + arcpy.CalculateField_management(FC, "FEATUREGUIDCOPY", "[FEATUREGUID]", "VB") + arcpy.DeleteIdentical_management(FC, ["FEATUREGUIDCOPY"]) + arcpy.DeleteField_management(FC, ["FEATUREGUIDCOPY"]) + + if bool_save: + # 开始输出mdo + # self.copy_to_mdo(str(self.out_gdb_path).encode('gbk')) + # 转换到旧标准的gdb + self.trans_to_old() + # 输出保密的gdb + self.output_security_gdb() + # TODO 写旧标准输出完成的标记文档 + # WriteFinishFlag + + # 执行回调返回mdo输出结果 + self.return_result("mdo", bool_save, last_gongch, last_yewbh) + # 结果输出到日志信息 + str_message = u"输出增量MDO完成" if bool_save else u"输出增量MDO失败" + self.logger.log(str_message.encode("gb2312")) + + def create_gdb_files(self): + try: + # 创建输出GDB + tt = self.config.curr_sync_datetime + self.out_gdb_path = self.config.pathname + "\\" + u"NEWGDB\\" + tt[:tt.find(' ')] + create_dir(self.out_gdb_path) + self.out_gdb_files = {"Add": "addFeatures.gdb", "Edit": "editFeatures.gdb", "Delete": "deleteFeatures.gdb"} + for key in self.out_gdb_files.keys(): + gdb_path = self.out_gdb_path + "\\" + self.out_gdb_files[key] + if arcpy.Exists(gdb_path): + arcpy.Delete_management(gdb_path) + arcpy.CreateFileGDB_management(self.out_gdb_path, self.out_gdb_files[key]) + except Exception as e: + self.logger.error("create_gdb error:\n" + str(e)) + + def get_connection(self, sub_path): + """获取SDE连接""" + for fileName in os.listdir(self.config.pathname + "\\" + sub_path.encode("gb2312")): + if fnmatch.fnmatch(fileName, '*.sde'): + return self.config.pathname + "\\" + sub_path + "\\" + fileName + return "" + + def start_edit(self): + """开始编辑""" + arcpy.env.workspace = self.src_sde + print(str(self.src_sde).encode('gb2312')) + edit = arcpy.da.Editor(self.src_sde) + edit.startEditing(False, False) + edit.startOperation() + return edit + + def stop_edit(self, edit, bool_save): + """停止编辑""" + arcpy.env.workspace = self.src_sde + # 停止编辑 + edit.stopOperation() + edit.stopEditing(bool_save) + + def write_start_event_logs(self, last_gongch): + """反查更新的项目编号,并写OA事件""" + for GongCH in last_gongch: + write_event_log("OutPutMap_GDB", + GongCH, + u"开始".encode('utf8'), + self.config.logfile_name.decode('gbk').encode('utf8'), + u"增量输出GDB文件开始".encode('utf8')) + # write_event_log("OutPutMap_MDO", + # GongCH, + # u"开始".encode('utf8'), + # self.config.logfile_name.decode('gbk').encode('utf8'), + # u"增量输出MDO文件开始".encode('utf8')) + + def get_projects_info(self): + feature_class = self.config.sde_scheme() + "." + self.config.updateregion() + time_values = {"from_time": self.config.last_sync_datetime, "to_time": self.config.curr_sync_datetime} + time_condition = """UPDATETIME>=TO_DATE('{from_time}','YYYY-MM-DD HH24:MI:SS') and + DOWNLOADTIME=TO_DATE('{last_time}','YYYY-MM-DD HH24:MI:SS') " \ + "and {del_time_field}{}".format(section_name, fc_name, last_value, value)) + + def set_last_max_object_id(self, fc_name, objectid): + """记录最大ObjectID""" + self.set_iniinfo_value_int("SHDB_LayerInfo_LastMaxID", fc_name, objectid) + # 记录同步完成状态 + self.set_iniinfo_value_int("SHDB_LayerInfo_SynchronousStatus", fc_name, 1) + + def set_last_sync_datetime(self): + """记录同步时间""" + section_name = self.config.sde_scheme() + "_Dbsyn_gdb" + key_name = "LastExportTime" + self.set_iniinfo_value_int(section_name, key_name, self.config.curr_sync_datetime) + + def get_max_object_id(self, fc_name): + """获取图层当前最大ObjectID""" + try: + with arcpy.da.SearchCursor(fc_name, "OBJECTID", where_clause="ObjectID>0", + sql_clause=(None, 'ORDER BY OBJECTID DESC')) as cur: + try: + return next(cur)[0] + except StopIteration: + return 0 + except arcpy.ExecuteError as e: + errmsg = str(arcpy.GetMessages(2).encode("gb2312")) + print("Error occurred when accessing {}: {}".format(fc_name, errmsg)) + self.logger.log("Error occurred when accessing {}: {}".format(fc_name, e)) + return 0 + + def get_sys_time_condition(self, is_history): + """当前增量同步时间""" + time_field = self.config.updatetime_field_history() if is_history else self.config.updatetime_field() + str_sql = "{}>=TO_DATE('{}','YYYY-MM-DD HH24:MI:SS') and {}0") + + +if __name__ == '__main__': + unittest.main() diff --git a/test_sys_config.py b/test_sys_config.py new file mode 100644 index 0000000..ba38031 --- /dev/null +++ b/test_sys_config.py @@ -0,0 +1,52 @@ +# coding=utf-8 +import unittest +from sys_config import SysConfig + + +class TestSysConfig(unittest.TestCase): + def setUp(self): + self.config = SysConfig() + + def test_eps_path(self): + self.assertEqual(self.config.eps_path(), u'C:/EPS20221017/eps.exe') + + def test_python_path(self): + self.assertEqual(self.config.python_path(), u'C:/Python27/ArcGIS10.2/python.exe') + + def test_template_name(self): + self.assertEqual(self.config.template_name(), u'"上海新型测绘500.mdt"') + + def test_sde_scheme(self): + self.assertEqual(self.config.sde_scheme(), "SHDLG500") + + def test_eps_show_window(self): + self.assertEqual(self.config.eps_show_window(), u'show') + + def test_sync_mode(self): + self.assertEqual(self.config.sync_mode(), 1) + + def test_sync_type(self): + self.assertEqual(self.config.sync_type(), u'ALL') + + def test_updateregion(self): + self.assertEqual(self.config.updateregion(), u'UpdateRegion_A') # "UpdateRegion_A" + + def test_updatetime_field(self): + self.assertEqual(self.config.updatetime_field(), u'UpdateTime') # u'UpdateTime' + + def test_updatetime_field_history(self): + self.assertEqual(self.config.updatetime_field_history(), u'DeleteTime') # u'DeleteTime' + + def test_attr(self): + self.config.is_debug = True + self.config.changed_layers_only = 1 + self.config.last_sync_datetime = "1990-05-11 12:00:00" + self.config.curr_sync_datetime = "2023-05-11 12:00:00" + self.assertEqual(self.config.is_debug, True) + self.assertEqual(self.config.changed_layers_only, 1) + self.assertEqual(self.config.last_sync_datetime, "1990-05-11 12:00:00") + self.assertEqual(self.config.curr_sync_datetime, "2023-05-11 12:00:00") + + +if __name__ == '__main__': + unittest.main() diff --git a/translate2old.py b/translate2old.py new file mode 100644 index 0000000..1b60f50 --- /dev/null +++ b/translate2old.py @@ -0,0 +1,350 @@ +# coding=utf-8 +import os +import shutil +import time +from imp import reload + +import arcpy +import inspect +import ConfigParser + +import sys + +reload(sys) +sys.setdefaultencoding('utf8') + +# 增删改gdb +add_gdb = 'addFeatures.gdb' +edit_gdb = 'editFeatures.gdb' +delete_gdb = 'deleteFeatures.gdb' + +# 输出gdb +out_folder = 'OldGDB' +out_addedit_gdb = 'addAndeditFeatures.gdb' +out_delete_gdb = 'deleteFeatures.gdb' + +global add_gdb_path +global edit_gdb_path +global delete_gdb_path +global outFolderPath +global output + + +def add_log_info(msg): + """添加日志记录""" + cur_date = time.strftime("%Y-%m-%d", time.localtime()) + cur_time = time.strftime("%H-%M-%S", time.localtime()) + output.write("[" + cur_date + " " + cur_time + "] " + msg + "\n") + output.flush() + + +def create_dir(dir_name): + if os.path.exists(dir_name): + shutil.rmtree(dir_name) + os.mkdir(dir_name) + + +def trim_tablespace_name(fc_name): + """去除表空间名""" + index = fc_name.rfind('.') + if index > 0: + fc_name = fc_name[index + 1:] + return fc_name + + +def start_edit(src_sde): + """开始编辑""" + arcpy.env.workspace = src_sde + # print str(src_sde).decode('gb2312') + edit = arcpy.da.Editor(src_sde) + edit.startEditing(False, False) + edit.startOperation() + return edit + + +def stop_edit(src_sde, edit, bool_save): + """停止编辑""" + arcpy.env.workspace = src_sde + # 停止编辑 + edit.stopOperation() + edit.stopEditing(bool_save) + + +def get_config(section, key): + """从配置文件读取参数""" + config = ConfigParser.ConfigParser() + path = os.path.split(os.path.realpath(__file__))[0] + '/ExportGdbSetting.config' + config.read(path) + try: + return config.get(section, key) + except ConfigParser.Error: + return "" + + +def get_config_int(section, key): + """从配置文件读取参数""" + config = ConfigParser.ConfigParser() + path = os.path.split(os.path.realpath(__file__))[0] + '/ExportGdbSetting.config' + config.read(path) + try: + return config.getint(section, key) + except ConfigParser.Error: + return 0 + + +def get_config_float(section, key): + """从配置文件读取参数""" + config = ConfigParser.ConfigParser() + path = os.path.split(os.path.realpath(__file__))[0] + '/ExportGdbSetting.config' + config.read(path) + try: + return config.getfloat(section, key) + except ConfigParser.Error: + return 0.0 + + +def get_layer_relation_count(fc_name): + """获取图层对照个数""" + layer_name = trim_tablespace_name(fc_name) + index0 = layer_name.find("history") + if index0 == 0: + layer_name = layer_name[index0 + 7:] + count = get_config_int("Layer_" + layer_name, "relationCount") + return count + + +def get_relation_layer(fc_name, index): + """获取对照图层信息""" + layer_name = trim_tablespace_name(fc_name) + index0 = layer_name.find("history") + if index0 == 0: + layer_name = layer_name[index0 + 7:] + tag_layer_name = get_config("Layer_" + layer_name, "tagLayerName" + str(index)) + expression = get_config("Layer_" + layer_name, "expression" + str(index)) + remove_field_names = get_config("Layer_" + layer_name, "removeFieldNames" + str(index)) + rename_field_names = get_config("Layer_" + layer_name, "renameFieldNames" + str(index)) + return tag_layer_name, expression, remove_field_names, rename_field_names + + +def get_relation_code_count(): + """获取编码对照个数""" + code_section = "FeatureCode" + count = get_config_int(code_section, "relationCount") + return count + + +def get_relation_code(index): + """获取对照编码""" + code_section = "FeatureCode" + name = get_config(code_section, "changeCode" + str(index)) + relations = name.split(":") + try: + # old_code, new_code = relations[0], relations[1] + return relations[0], relations[1] + except BaseException as e: + errmsg = str(e.message.encode("gb2312")) + add_log_info(errmsg) + return "", "" + + +def get_change_code_layers(): + """获取换码图层列表""" + code_section = "FeatureCode" + rel_layers = get_config(code_section, "relationLayers") + layers = rel_layers.split(",") + return layers + + +def feature_class_to_feature_class(src_layer_name, out_location, tag_layer_name, where_clause, + remove_field_names, rename_field_names): + """图层转换输出""" + field_mappings = arcpy.FieldMappings() + field_mappings.addTable(src_layer_name) + # 处理删除字段 + remove_list_names = remove_field_names.split(",") + for name in remove_list_names: + index = field_mappings.findFieldMapIndex(name) + if index > -1: + field_mappings.removeFieldMap(index) + # 处理改名字段 + rename_list_names = rename_field_names.split(",") + for name in rename_list_names: + relations = name.split(":") + index0 = field_mappings.findFieldMapIndex(relations[0]) + if index0 > -1: + field_map = field_mappings.getFieldMap(index0) + f_name = field_map.outputField + f_name.name = relations[1] + f_name.aliasName = relations[1] + field_map.outputField = f_name + field_mappings.replaceFieldMap(field_mappings.findFieldMapIndex(relations[0]), field_map) + # 导出数据 + arcpy.FeatureClassToFeatureClass_conversion(src_layer_name, out_location, tag_layer_name, where_clause, + field_mappings) + + +def transform_to_feature_class(fc_name, out_location): + """根据图层对照转换一个fc""" + count = get_layer_relation_count(fc_name) + # 没有对照,按原图层输出 + if count == 0: + return + + # 有对照获取对照输出 + for index in range(1, count + 1): + out_fc, expression, rm_fields, rn_fields = get_relation_layer(fc_name, index) + expression = "ObjectID>0" if expression == "" else expression + # 如果对照为空,则按原图层名 + out_fc = fc_name if out_fc == "" else out_fc + try: + add_log_info(str(fc_name) + "-->" + str(out_fc)) + # 每个图层的FeatureCode字段加索引 + arcpy.AddIndex_management(fc_name, "FEATURECODE", "FeatureCode_Index", "NON_UNIQUE", "NON_ASCENDING") + if arcpy.Exists(os.path.join(out_location, out_fc)): + # 先转换到内存工作空间 + # arcpy.FeatureClassToFeatureClass_conversion(fc_name, "in_memory", "buffer", expression) + feature_class_to_feature_class(fc_name, "in_memory", "buffer", expression, rm_fields, rn_fields) + # 再从内存工作空间转换输出到目标 + arcpy.Append_management("in_memory/buffer", os.path.join(out_location, out_fc), "NO_TEST") + # 及时回收内存工作空间 + arcpy.Delete_management("in_memory") + else: + # arcpy.FeatureClassToFeatureClass_conversion(fc_name, out_location, out_fc, expression) + feature_class_to_feature_class(fc_name, out_location, out_fc, expression, rm_fields, rn_fields) + except BaseException as e: + # error_code = arcpy.GetReturnCode(2) + add_log_info(str(e.message.encode("gb2312"))) + + +def translate_one_gdb(src_gdb_path, gdb_type): + """转换图层输出一个GDB""" + if src_gdb_path == "": + return + # gdb_type 大与0 add; 小于0 delete; 等于0 edit + str_type = "add" if gdb_type > 0 else "delete" + if gdb_type == 0: + str_type = "edit" + + add_log_info("-----------<" + str_type + ">-----------") + arcpy.env.workspace = src_gdb_path + fc_list = arcpy.ListFeatureClasses("*", "all") + for FC in fc_list: + index = FC.rfind('.') + fc_name = FC[index + 1:] + # 跳过实体图层,et_开头的 + if fc_name.lower().find('et_') == 0: + continue + + if gdb_type <= 0: + # 删除和修改输出到删除gdb + out_location = outFolderPath + "\\" + out_delete_gdb + transform_to_feature_class(FC, out_location) + if gdb_type >= 0: + # 新增和修改输出到增改gdb + out_location = outFolderPath + "\\" + out_addedit_gdb + transform_to_feature_class(FC, out_location) + + +def translate_to_old(): + # 创建输出子目录 + create_dir(outFolderPath) + # 创建增改gdb + arcpy.CreateFileGDB_management(outFolderPath, out_addedit_gdb) + # 创建删除gdb + arcpy.CreateFileGDB_management(outFolderPath, out_delete_gdb) + # 修改env变量,改为覆盖输出 + arcpy.env.overwriteOutput = True + # 1.新增数据转换输出 + translate_one_gdb(add_gdb_path, 1) + # 2.删除数据转换输出 + translate_one_gdb(delete_gdb_path, -1) + # 3.修改数据转换输出 + translate_one_gdb(edit_gdb_path, 0) + + +def change_codes_onelayer(fc): + """一个图层所有编码遍历换编码""" + try: + count = get_relation_code_count() + for index in range(1, count + 1): + old_code, new_code = get_relation_code(index) + if old_code == "": + continue + fields = ["FEATURECODE"] + cur = arcpy.da.UpdateCursor(fc, fields, + where_clause="FeatureCode='" + old_code + "'") + for row in cur: + row[0] = new_code + cur.updateRow(row) + print(old_code + "-->" + new_code) + return True + except BaseException as e: + add_log_info(str(e.message.encode("gb2312"))) + return False + + +def change_codes(): + """逐层换编码""" + out_paths = [outFolderPath + "\\" + out_addedit_gdb, outFolderPath + "\\" + out_delete_gdb] + for path in out_paths: + if path != "": + err_count = 0 + edit = start_edit(path) + fc_list = arcpy.ListFeatureClasses("*", "all") + add_log_info("----------change_codes----------") + for fc in fc_list: + # 换码图层过滤 + if fc not in get_change_code_layers(): + continue + add_log_info("Layer: " + str(fc)) + if not change_codes_onelayer(fc): + err_count += 1 + b_save = True if err_count == 0 else False + stop_edit(path, edit, b_save) + + +# 获取参数 +args = sys.argv[1:] + +if not args or len(args) < 1: + sys.exit(str(u"参数不足:需要文件路径").encode("gb2312")) +else: + try: + # 文件路径 + filepath = args[0] + add_gdb_path = filepath + "\\" + add_gdb + edit_gdb_path = filepath + "\\" + edit_gdb + delete_gdb_path = filepath + "\\" + delete_gdb + outFolderPath = filepath + "\\" + out_folder + # 创建日志 + Date = time.strftime("%Y-%m-%d", time.localtime()) + Time = time.strftime("%I:%M:%S %p", time.localtime()) + Time1 = time.strftime("%H-%M-%S", time.localtime()) + caller_file = inspect.getfile(inspect.currentframe()) + pathname = os.path.abspath(os.path.dirname(caller_file)) + out_logfile = pathname + "\\log\\" + Date + " " + Time1 + "-Translate2Old.txt" + if not os.path.exists(pathname + "\\log"): + os.mkdir(pathname + "\\log") + # 打开日志 + output = open(out_logfile, "w") + + # 记录开始时间 + add_log_info('################ Transe2Old ################\n\n') + Date = time.strftime("%Y-%m-%d", time.localtime()) + Time = time.strftime("%H-%M-%S", time.localtime()) + add_log_info("Process begin at " + str(Date) + " " + str(Time) + ".") + + # 换层输出旧标准数据(增删改3文件->增删2文件) + translate_to_old() + + # 逐层换编码 + change_codes() + + # 结束时间日志记录 + Date = time.strftime("%Y-%m-%d", time.localtime()) + Time = time.strftime("%I:%M:%S %p", time.localtime()) + add_log_info("Process completed at " + str(Date) + " " + str(Time) + "." + "\n") + output.close() + except BaseException as e: + errmsg = str(e.message.encode("gb2312")) + add_log_info(errmsg) diff --git a/源库SDE连接/shdlg500.sde b/源库SDE连接/shdlg500.sde new file mode 100644 index 0000000000000000000000000000000000000000..dfdc5390d7907e9207eca585c829794776b6e618 GIT binary patch literal 3072 zcmeHJO-~b16g>q|(ZpC1U9cd;G{$Ib1OovQP3UxFYD!yYS_^ENLJ^u&AT4N2T)XrS zxH9fs=|A8fh$~&{%3mS%oHsMIR%=YV!t_n<`?&AE`*H4jH*@qM`sMZe@vrD;cQK6P z<|t0L@gtmzOuGmSaiaBcv)S~S0H=d?f)MylUzI=6sUVjp$o+wU$jI`c-t2T5w`L2vlFTQ<_40Hcb#e>a5l9ny{u){A$`@7h~CdYkLIW~N; zu6+zck#-2W3U+LS_B+@;Eqk%wlc6q$`mwK^DHY0z-v0i9X#XDq z(Y2Q=uZ})O-#*7-_RYej2+lLx7f2r8rHhBA*Im$UXrRJ335=0a$WSJaMUEDwB$H{$ zEbtxIQN{*pJP`{{{>q)g6t>{=Bp0JThxH(hCCuO!Ki^Uk30g?gqD>2VV@V#iTL7lX zkz|RoS;}Q7ZBaU9RwdRJm$RISM_ilMf9^dw2-gkFLqtmTVdnriTYLHQb2izraa;l3hIF(RD`V_G(Pex6nQ%O);qDj2=4 z(JY@D*k=A}#JnBdoU!krNL?{S(%f%tZ{=oD{TkJleqtBt3dmBRYmBgb3H z=d#l)Th-aM8|C@BQ>j_=dx_OM*TEmd;MRD7pNdS_bz%~yH5>O#jA=#%jFZCbh55Qk ZuWV|R7G>QfHcxnS;>J5N2CWYSegMa7DXahh literal 0 HcmV?d00001