This commit is contained in:
HKS 2023-05-27 15:47:41 +08:00
commit 7edae814fe
22 changed files with 2181 additions and 0 deletions

3
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

10
.idea/encodings.xml Normal file
View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/log/2023-05-27 15-01-43-SdeSynchronous.txt" charset="GBK" />
<file url="file://$PROJECT_DIR$/log/2023-05-27 15-09-33-SdeSynchronous.txt" charset="GBK" />
<file url="file://$PROJECT_DIR$/log/2023-05-27 15-11-29-Translate2Old.txt" charset="GBK" />
<file url="file://$PROJECT_DIR$/log/2023-05-27 15-20-40-Translate2Old.txt" charset="GBK" />
<file url="file://$PROJECT_DIR$/log/2023-05-27 15-32-50-SdeSynchronous.txt" charset="GBK" />
</component>
</project>

View File

@ -0,0 +1,17 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PyUnresolvedReferencesInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoredIdentifiers">
<list>
<option value="arcpy.da.SearchCursor" />
<option value="arcpy.ExecuteError" />
<option value="arcpy.da.InsertCursor" />
<option value="arcpy.da.UpdateCursor" />
<option value="arcpy.da.Editor" />
<option value="arcpy.env" />
</list>
</option>
</inspection_tool>
</profile>
</component>

View File

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

4
.idea/misc.xml Normal file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 2.7" project-jdk-type="Python SDK" />
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/shsmi_sysdb_new.iml" filepath="$PROJECT_DIR$/.idea/shsmi_sysdb_new.iml" />
</modules>
</component>
</project>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

6
.idea/vcs.xml Normal file
View File

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

3
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,3 @@
{
"python.pythonPath": "c:\\Python27\\ArcGIS10.2\\python.exe"
}

740
ExportGdbSetting.config Normal file
View File

@ -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

13
SdeSyncSetting.config Normal file
View File

@ -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

96
functions.py Normal file
View File

@ -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

44
logger.py Normal file
View File

@ -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")

42
main.py Normal file
View File

@ -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) + ".")

30
sde_fc2fc.py Normal file
View File

@ -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)))

557
sde_sync.py Normal file
View File

@ -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('{to_time}','YYYY-MM-DD HH24:MI:SS')""".format(**time_values)
f1, f2, f3 = "OBJECTID", "GONGCH", "YEWBH"
try:
with arcpy.da.SearchCursor(feature_class, [f1, f2, f3], where_clause=time_condition,
sql_clause=(None, 'ORDER BY OBJECTID DESC')) as cur:
gongch_list = [row[1] for row in cur]
yewbh_list = [row[2] for row in cur]
except arcpy.ExecuteError:
print(arcpy.GetMessages().encode('gb2312'))
self.logger.error(arcpy.GetMessages().encode('gb2312'))
return gongch_list, yewbh_list
def sde2gdb_feature_list(self, fc_list):
"""根据fc列表同步输出增量"""
for FC in fc_list:
str_msg = "Process Dataset: " + FC.encode("gb2312")
index = FC.rfind('.')
fc_name = FC[index + 1:]
# 跳过非指定表空间中的fc
tablespace_name = get_tag_tablespace(FC)
if tablespace_name != self.config.sde_scheme():
continue
# 跳过updateregion_qp
if fc_name in ['UpdateRegion_QP', 'NewCity', 'NewCity_A', 'PlanRegion']:
continue
# 只同步图元时跳过Et_ historyEt_开头的图层
index_et = fc_name.lower().rfind('et_')
index_h_et = fc_name.lower().rfind('historyet_')
if self.config.sync_type() == "TUY":
if index_h_et == 0 or index_et == 0:
continue
# 调试时筛选图层输出
if self.config.is_debug:
if fc_name not in ['Building_A', 'historyBuilding_A']:
continue
# 记录图层地物个数
self.record_count(fc_name)
print(str_msg)
# 输出增删改三文件数据
self.export_one_layer_3f(fc_name)
def sde2gdb_table_list(self, table_list):
"""增量同步table表记录"""
for TB in table_list:
str_msg = "Process Table: " + TB.encode("gb2312")
tb_name = TB[TB.rfind('.') + 1:]
# 跳过系统表
if tb_name in g_sys_tb:
continue
# 跳过二三维模型关联表 Re3D_ historyRe3D_ 开头的图层
index_3d = tb_name.lower().rfind('re3d_')
index_h_3d = tb_name.lower().rfind('historyre3d_')
if index_3d == 0 or index_h_3d == 0:
continue
# 只同步图元时跳过所有table
if self.config.sync_type == "TUY":
continue
# 调试时筛选表输出
if self.config.is_debug:
if tb_name not in ['Re_Building_A',
'historyRe_Building_A',
'ReEnt_Building_A',
'historyReEnt_Building_A']:
continue
# 记录图层地物个数
self.record_count(tb_name)
print(str_msg)
# 输出增删改三文件数据
self.export_one_table_3f(tb_name)
def export_one_layer_3f(self, fc_name):
"""输出一个FeatureClass的增量"""
last_max_object_id = self.get_last_max_object_id(fc_name)
index0 = fc_name.find("history")
if index0 == 0:
return
fc_history = "history" + fc_name
expression_add, expression_edit, expression_delete = self.get_export_expression(fc_name)
self.logger.log("Exporting Layer:" + fc_name.encode("gb2312"))
try:
if self.is_export_one_layer(fc_name):
# 输出新增数据
add_gdb_path = self.out_gdb_path + "\\" + self.out_gdb_files["Add"]
self.featureclass_to_featureclass(fc_name, add_gdb_path, fc_name, expression_add)
# 输出修改数据
edit_gdb_path = self.out_gdb_path + "\\" + self.out_gdb_files["Edit"]
self.featureclass_to_featureclass(fc_name, edit_gdb_path, fc_name, expression_edit)
# 记录最大ObjectID
max_object_id = self.get_max_object_id(fc_name)
self.set_last_max_object_id(fc_name, max_object_id)
self.logger.log("LastMaxObjectID:" + str(last_max_object_id) + ", CurMaxObjectID:" + str(max_object_id))
elif self.is_export_one_layer(fc_history):
# 输出删除数据
delete_gdb_path = self.out_gdb_path + "\\" + self.out_gdb_files["Delete"]
self.featureclass_to_featureclass(fc_history, delete_gdb_path, fc_name, expression_delete)
max_object_id_his = self.get_max_object_id(fc_history)
self.set_last_max_object_id(fc_history, max_object_id_his)
self.logger.log(
"LastMaxObjectID:" + str(last_max_object_id) + ", CurMaxObjectID:" + str(max_object_id_his))
else:
self.logger.log("No Change Detected!")
except arcpy.ExecuteError:
str1 = str(arcpy.GetMessages().encode("gb2312"))
self.logger.error(str1)
self.error_count += 1
except Exception as e:
str1 = str(e.args[0]).encode("gb2312")
self.logger.error(str1)
self.error_count += 1
def export_one_table_3f(self, tb_name):
self.logger.log("TableToTable:" + tb_name.encode('gb2312'))
index0 = tb_name.find("history")
if index0 == 0:
return
tb_history = "history" + tb_name
entity_index = tb_name.find("ReEnt_")
tb_type = "entity_rela" if entity_index == 0 else "elem_rela"
expression_add, expression_edit, expression_delete = self.get_export_expression(tb_name, tb_type)
try:
# 输出增删改三文件数据
add_gdb_path = self.out_gdb_path + "\\" + self.out_gdb_files["Add"]
self.table_to_table(tb_name, add_gdb_path, tb_name, expression_add)
edit_gdb_path = self.out_gdb_path + "\\" + self.out_gdb_files["Edit"]
self.table_to_table(tb_name, edit_gdb_path, tb_name, expression_edit)
delete_gdb_path = self.out_gdb_path + "\\" + self.out_gdb_files["Delete"]
self.table_to_table(tb_history, delete_gdb_path, tb_name, expression_delete)
except arcpy.ExecuteError:
errmsg = str(arcpy.GetMessages().encode("gb2312"))
self.logger.error(errmsg)
self.error_count += 1
def get_export_expression(self, fc_name, fc_type="fc"):
"""获取输出表达式"""
fc_history = "history" + fc_name
fc_current = fc_name
sql_dic = {"sys_time": self.get_sys_time_condition(False),
"sys_time_his": self.get_sys_time_condition(True),
"fc": fc_current,
"his_fc": fc_history,
"is_in_his": "NOT IN",
"last_time": self.config.last_sync_datetime,
"curr_time": self.config.curr_sync_datetime,
"up_time_field": self.config.updatetime_field(),
"del_time_field": self.config.updatetime_field_history(),
"guid_field": "FeatureGuid"}
if fc_type == "entity_rela":
sql_dic.update(guid_field="EntityRelaGUID")
elif fc_type == "elem_rela":
sql_dic.update(guid_field="ElemRelaGUID")
expression_his = "{sys_time_his} " \
"and ({his_fc}.{up_time_field}<TO_DATE('{last_time}','YYYY-MM-DD HH24:MI:SS') " \
"or {his_fc}.{up_time_field} IS NULL) " \
"and ({guid_field} NOT IN (SELECT {guid_field} FROM {fc}))"
expression_cur = "{sys_time} and {guid_field} {is_in_his} (SELECT {guid_field} FROM {his_fc} " \
"WHERE {del_time_field}>=TO_DATE('{last_time}','YYYY-MM-DD HH24:MI:SS') " \
"and {del_time_field}<TO_DATE('{curr_time}','YYYY-MM-DD HH24:MI:SS') " \
"and ({up_time_field}<TO_DATE('{last_time}','YYYY-MM-DD HH24:MI:SS') " \
"or {up_time_field} IS NULL))"
expression_del = expression_his.format(**sql_dic)
# 新增地物现势表存在,历史表不存在
expression_add = expression_cur.format(**sql_dic)
# 修改地物现势表存在,历史表也存在
sql_dic.update(is_in_his="IN")
expression_edit = expression_cur.format(**sql_dic)
return expression_add, expression_edit, expression_del
def get_last_max_object_id(self, fc_name):
"""获取上次同步记录的最大ObjectID"""
section_name = "{}_SHDB_LayerInfo_LastMaxID".format(self.config.sde_scheme())
with arcpy.da.SearchCursor("SUNWAY_INIINFO", ["STRINGVALUE"],
"SECTION='{}' and KEYNAME='{}'".format(section_name, fc_name)) as cur:
for row in cur:
last_id = int(row[0])
return last_id
return 0
def get_last_sync_datetime(self):
section_name = self.config.sde_scheme() + "_Dbsyn_gdb"
key_name = "LastExportTime"
expression = "SECTION='{}' and KEYNAME='{}'".format(section_name, key_name)
with arcpy.da.SearchCursor("SUNWAY_INIINFO", "STRINGVALUE", expression) as cur:
last_time = [row[0] for row in cur]
return last_time[0] if last_time else ""
def set_iniinfo_value_int(self, section_suffix, fc_name, value):
"""Helper function to update or insert a value."""
section_name = "{}_{}".format(self.config.sde_scheme(), section_suffix)
fields = ["SECTION", "KEYNAME", "STRINGVALUE"]
with arcpy.da.UpdateCursor("SUNWAY_INIINFO",
fields,
where_clause="SECTION='{}' and KEYNAME='{}'".format(section_name, fc_name)) as cur:
try:
row = next(cur)
last_value = row[2]
row[2] = str(value)
cur.updateRow(row)
except StopIteration: # If the cursor is empty
with arcpy.da.InsertCursor("SUNWAY_INIINFO", fields) as insert_cur:
insert_cur.insertRow((section_name, fc_name, str(value)))
last_value = ""
print("{}:{} {}-->{}".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 {}<TO_DATE('{}','YYYY-MM-DD HH24:MI:SS')"
time_condition = str_sql.format(time_field, self.config.last_sync_datetime,
time_field, self.config.curr_sync_datetime)
return time_condition
def record_count(self, layer):
count = 0
layer_lower = layer.lower()
if layer_lower.find('history') == 0:
return
try:
with arcpy.da.SearchCursor(layer, ['ObjectID']) as rows:
for row in rows:
count += 1
msg = str(layer).encode("gb2312")
self.txt_ct_file.write(
str(u"{0}:{1}\r\n").encode('gb2312').format(msg, count))
except BaseException as e:
self.txt_ct_file.write(e)
def is_export_one_layer(self, fc_name):
"""控制图层是否输出"""
last_max_object_id = self.get_last_max_object_id(fc_name)
max_object_id = self.get_max_object_id(fc_name)
print("last_max_id:" + str(last_max_object_id) + " || current_max_id:" + str(max_object_id))
if self.only_changed_layers:
return last_max_object_id != max_object_id
else:
return True
def featureclass_to_featureclass(self, fc_name, out, fc_cur, expression):
"""启动python子进程输出feature到gdb"""
return self.fc2fc(fc_name, out, fc_cur, expression, u'feature')
def table_to_table(self, fc_name, out, fc_cur, expression):
"""启动python子进程输出table到gdb"""
return self.fc2fc(fc_name, out, fc_cur, expression, u'table')
def fc2fc(self, fc_name, out, fc_cur, expression, fc_type):
"""启动python子进程输出feature或者table到gdb"""
python_path = str(self.config.python_path() + u' ').encode('gb2312')
script = str(u'sde_fc2fc.py ').encode('gb2312')
src_sde = str(self.src_sde + u' ')
type_cmd = str(fc_type + u' ').encode('gb2312')
fc_name_cmd = str(fc_name + u' ').encode('gb2312')
out_cmd = str(out + u' ').encode('gb2312')
fc_cur_cmd = str(fc_cur + u' ').encode('gb2312')
exp_cmd = str(u'"' + expression + u'" ')
# 启动命令参数
command_string = python_path + script + src_sde + type_cmd + fc_name_cmd + out_cmd + fc_cur_cmd + exp_cmd
success, out_msg = run_command(command_string)
print(out_msg)
if not success:
# 使外部可以捕获异常
raise Exception(out_msg)
return success
def return_result(self, file_type, b_save, gongch_list, yewbh_list):
"""返回信息"""
# file_type "gdb" "mdo" b_save true false
log_type = "OutPutMap_GDB" if file_type == "gdb" else "OutPutMap_MDO"
log_status = u"成功" if b_save else u"失败"
log_remark = u"增量输出文件成功" if b_save else u"增量输出文件失败"
result = "true" if b_save else "false"
for GongCH in gongch_list:
write_event_log(log_type,
GongCH,
log_status.encode('utf8'),
self.config.logfile_name.decode('gbk').encode('utf8'),
log_remark.encode('utf8'))
for YeWBH in yewbh_list:
output_map_result(YeWBH, "true", "", file_type)
def copy_to_mdo(self, path_name):
"""启动EPS输出MDO"""
eps_path = str(self.config.eps_path() + u' ').encode('gb2312')
template_name = self.config.template_name()
runscript = str(u'/runscript ' + template_name + u' ').encode('gb2312')
script_path = str(u'"' + self.config.eps_vbs() + u'" ').encode('gb2312')
show_setting = str(u'/showwindow "' + self.config.eps_show_window() + u'" /autoexit ').encode('gb2312')
share_parameter = str(u'/WriteShareParameter ProjectInfo,pathname,').encode('gb2312')
# 启动命令参数
command1 = eps_path + runscript + script_path + show_setting + share_parameter + path_name
timeout_command(command1, 28800)
def trans_to_old(self):
# 标准降级输出
self.logger.log("--Start Translate TO old--")
"""启动Python输出OldGDB"""
python_path = str(self.config.python_path() + u' ').encode('gb2312')
script = str(u'translate2old.py ').encode('gb2312')
# 启动命令参数
command1 = python_path + script + self.out_gdb_path.encode('gb2312')
run_command(command1)
self.logger.log("--End Translate TO old--")
# 移动文件
# remove_file(g_outFolderPath + "\\" + "OldGDB", g_outNewFolderPath)
def output_security_gdb(self):
# 开始输出保密增删gdb
out_security_new_folder_path = self.out_gdb_path + "\\OldGDB\\SecurityGdb"
create_dir(out_security_new_folder_path)
add_and_edit_gdb = self.out_gdb_path + "\\OldGDB\\addAndEditFeatures.gdb"
delete_gdb = self.out_gdb_path + "\\OldGDB\\deleteFeatures.gdb"
security_add_and_edit_gdb = out_security_new_folder_path + "\\securityaddAndEditFeatures.gdb"
security_delete_gdb = out_security_new_folder_path + "\\securitydeleteFeatures.gdb"
arcpy.CreateFileGDB_management(out_security_new_folder_path, "securityaddAndEditFeatures.gdb") # 建立汇总数据库
arcpy.CreateFileGDB_management(out_security_new_folder_path, "securitydeleteFeatures.gdb")
# "增改"文件
arcpy.env.workspace = add_and_edit_gdb
fcs = arcpy.ListFeatureClasses()
print("=== start security trans ===")
for fc in fcs:
print("addandedit " + fc)
if fc == 'Pool_FlatRoof':
expression = "FEATURECode not in ('338100','338300')"
# 输出"保密增改"文件
arcpy.FeatureClassToFeatureClass_conversion(fc, security_add_and_edit_gdb, fc, expression)
elif fc not in ["Device_Point", "Device_Line", "Device_Building", "Device_Text", "Pipe_Text",
"Ocean_Polygon",
"Control_Point", "Control_Text", "UPL_L", "UPL_Text", "Level_Point_A", "Level_Point_R",
"Contour", "UpdateRegion_A"]:
# 输出"保密增改"文件
arcpy.FeatureClassToFeatureClass_conversion(fc, security_add_and_edit_gdb, fc)
# "删"文件
arcpy.env.workspace = delete_gdb
fcs = arcpy.ListFeatureClasses()
for fc in fcs:
print("delete " + fc)
if fc == 'Pool_FlatRoof':
expression = "FEATURECode not in ('338100','338300')"
# 输出"保密删"文件
arcpy.FeatureClassToFeatureClass_conversion(fc, security_delete_gdb, fc, expression)
elif fc not in ["Device_Point", "Device_Line", "Device_Building", "Device_Text", "Pipe_Text",
"Ocean_Polygon",
"Control_Point", "Control_Text", "UPL_L", "UPL_Text", "Level_Point_A", "Level_Point_R",
"Contour", "UpdateRegion_A"]:
# 输出"保密删"文件
arcpy.FeatureClassToFeatureClass_conversion(fc, security_delete_gdb, fc)
print("=== end security trans ===")

78
sys_config.py Normal file
View File

@ -0,0 +1,78 @@
# coding=utf-8
import os
import sys
import ConfigParser
from imp import reload
reload(sys)
sys.setdefaultencoding('utf8')
class BaseConfig(object):
def __init__(self, file):
config_path = os.path.split(os.path.realpath(__file__))[0] + '/' + file
self.__config = ConfigParser.ConfigParser()
self.__config.read(config_path)
def _get_config(self, section, key):
"""从配置文件读取参数 字符串类型"""
try:
return self.__config.get(section, key)
except ConfigParser.Error:
return ""
def _get_config_int(self, section, key):
"""从配置文件读取参数 int类型"""
try:
return self.__config.getint(section, key)
except ConfigParser.Error:
return 0
def _get_config_float(self, section, key):
"""从配置文件读取参数 float类型"""
try:
return self.__config.getfloat(section, key)
except ConfigParser.Error:
return 0.0
class SysConfig(BaseConfig):
def __init__(self):
super(SysConfig, self).__init__('SdeSyncSetting.config')
# 公共成员变量
self.is_debug = True
self.changed_layers_only = 0
self.last_sync_datetime = None
self.curr_sync_datetime = None
self.pathname = None
self.logfile_name = None
def eps_path(self):
return self._get_config('System', 'eps_path')
def python_path(self):
return self._get_config('System', 'python_path')
def template_name(self):
return self._get_config('System', 'template_name')
def sde_scheme(self):
return self._get_config('System', 'sde_scheme')
def eps_show_window(self):
return self._get_config('System', 'eps_show')
def eps_vbs(self):
return self._get_config('System', 'eps_vbs')
def sync_type(self):
return self._get_config('System', 'sync_type')
def updateregion(self):
return self._get_config('UpdateRegion', 'layer_name') # "UpdateRegion_A"
def updatetime_field(self):
return self._get_config('UpdateRegion', 'updatetime_field') # u'UpdateTime'
def updatetime_field_history(self):
return self._get_config('UpdateRegion', 'updatetime_field_history') # u'DeleteTime'

18
test_functions.py Normal file
View File

@ -0,0 +1,18 @@
# coding=utf-8
import unittest
from functions import *
class TestFunctions(unittest.TestCase):
def test_run_command(self):
python_path = str(u'C:/Python27/ArcGIS10.2/python.exe ').encode('gb2312')
script = str(u'sde_fc2fc.py ').encode('gb2312')
type_cmd = str(u'feature ').encode('gb2312')
fc_name_cmd = str(u'Building_A ').encode('gb2312')
out_cmd = str(u'Building_A ').encode('gb2312')
fc_cur_cmd = str(u'Building_A ').encode('gb2312')
# exp_cmd = str(u'"" ')
command_string = python_path + script + type_cmd + fc_name_cmd + out_cmd + fc_cur_cmd
rst, out = run_command(command_string)
print(out)
self.assertEqual(rst, True)

96
test_sde_sync.py Normal file
View File

@ -0,0 +1,96 @@
# coding=utf-8
import unittest
import inspect
import arcpy
from functions import *
from sys_config import SysConfig
from logger import Logger
from sde_sync import SdeSynchronous
class TestSdeSynchronous(unittest.TestCase):
def setUp(self):
# 获取当前路径
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) + ".")
self.sde_db_sync = SdeSynchronous(config, logger)
self.sde_db_sync.src_sde = self.sde_db_sync.get_connection(str(u"源库SDE连接").encode('gb2312'))
arcpy.env.workspace = self.sde_db_sync.src_sde
self.sde_db_sync.config.last_sync_datetime = self.sde_db_sync.get_last_sync_datetime()
self.edit = self.sde_db_sync.start_edit()
def tearDown(self):
self.sde_db_sync.stop_edit(self.edit, False)
self.sde_db_sync.logger.close()
# 删除log日志文件
os.remove(self.sde_db_sync.config.logfile_name)
def test_get_last_max_object_id(self):
self.assertEqual(self.sde_db_sync.get_last_max_object_id("Building_A"), 11)
def test_get_last_sync_datetime(self):
print(self.sde_db_sync.get_last_sync_datetime())
def test_get_projects_info(self):
self.sde_db_sync.config.last_sync_datetime = "2022-10-01 00:00:00"
print(self.sde_db_sync.get_projects_info())
def test_create_gdb_files(self):
self.sde_db_sync.create_gdb_files()
self.assertTrue(os.path.exists(self.sde_db_sync.out_gdb_path))
self.assertTrue(os.path.exists(self.sde_db_sync.out_gdb_path + "\\" + self.sde_db_sync.out_gdb_files["Add"]))
self.assertTrue(os.path.exists(self.sde_db_sync.out_gdb_path + "\\" + self.sde_db_sync.out_gdb_files["Edit"]))
self.assertTrue(os.path.exists(self.sde_db_sync.out_gdb_path + "\\" + self.sde_db_sync.out_gdb_files["Delete"]))
arcpy.Delete_management(self.sde_db_sync.out_gdb_path + "\\" + self.sde_db_sync.out_gdb_files["Add"])
arcpy.Delete_management(self.sde_db_sync.out_gdb_path + "\\" + self.sde_db_sync.out_gdb_files["Edit"])
arcpy.Delete_management(self.sde_db_sync.out_gdb_path + "\\" + self.sde_db_sync.out_gdb_files["Delete"])
def test_get_max_object_id(self):
self.assertEqual(self.sde_db_sync.get_max_object_id("Building_A"), 1)
def test_set_last_max_object_id(self):
self.sde_db_sync.set_last_max_object_id("Building_A", 11)
def test_get_sys_time_condition(self):
ld = self.sde_db_sync.config.last_sync_datetime
cd = self.sde_db_sync.config.curr_sync_datetime
str_cond1 = "UpdateTime>=TO_DATE('" + ld + "','YYYY-MM-DD HH24:MI:SS') and UpdateTime<TO_DATE('" + cd + "','YYYY-MM-DD HH24:MI:SS')"
str_cond2 = "DeleteTime>=TO_DATE('" + ld + "','YYYY-MM-DD HH24:MI:SS') and DeleteTime<TO_DATE('" + cd + "','YYYY-MM-DD HH24:MI:SS')"
self.assertEqual(self.sde_db_sync.get_sys_time_condition(False), str_cond1)
self.assertEqual(self.sde_db_sync.get_sys_time_condition(True), str_cond2)
def test_get_feature_expression(self):
ld = self.sde_db_sync.config.last_sync_datetime
cd = self.sde_db_sync.config.curr_sync_datetime
ss = self.sde_db_sync.get_sys_time_condition(False)
cond = "{} and FeatureGuid {} (SELECT FeatureGuid FROM historyBuilding_A WHERE DeleteTime>=TO_DATE('{}','YYYY-MM-DD HH24:MI:SS') and DeleteTime<TO_DATE('{}','YYYY-MM-DD HH24:MI:SS') and (UpdateTime<TO_DATE('{}','YYYY-MM-DD HH24:MI:SS') or UpdateTime IS NULL))"
add_cond = cond.format(ss, "NOT IN", ld, cd, ld)
edit_cond = cond.format(ss, "IN", ld, cd, ld)
ss = self.sde_db_sync.get_sys_time_condition(True)
cond = "{} and (historyBuilding_A.UpdateTime<TO_DATE('{last_time}','YYYY-MM-DD HH24:MI:SS') or historyBuilding_A.UpdateTime IS NULL) and (FeatureGuid NOT IN (SELECT FeatureGuid FROM Building_A))"
del_cond = cond.format(ss, last_time=ld)
c1, c2, c3 = self.sde_db_sync.get_export_expression("Building_A")
self.assertEqual(c1, add_cond)
self.assertEqual(c2, edit_cond)
self.assertEqual(c3, del_cond)
def test_featureclass_to_featureclass(self):
self.sde_db_sync.create_gdb_files()
self.sde_db_sync.featureclass_to_featureclass("Building_A", self.sde_db_sync.out_gdb_path + "\\" + self.sde_db_sync.out_gdb_files["Add"], "Building_A", "ObjectID>0")
if __name__ == '__main__':
unittest.main()

52
test_sys_config.py Normal file
View File

@ -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()

350
translate2old.py Normal file
View File

@ -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)

Binary file not shown.