瀏覽代碼

20241219更新已有工具&代码

rmy 6 月之前
父節點
當前提交
e01010d9d3
共有 100 個文件被更改,包括 15578 次插入0 次删除
  1. 202
    0
      代码/20210827随机边长/RWexcel.py
  2. 37
    0
      代码/20221220林权/LQ/JZDcount1129.py
  3. 553
    0
      代码/20221220林权/LQ/JZDpoint20230110_1.py
  4. 2073
    0
      代码/20221220林权/LQ/LQreport_all1.py
  5. 196
    0
      代码/20221220林权/LQ/LZDsf1201.py
  6. 23
    0
      代码/20221220林权/LQ/PolygonZX.py
  7. 520
    0
      代码/20221220林权/LQ/SZdw1129_syb.py
  8. 527
    0
      代码/20221220林权/LQ/SZsf.py
  9. 70
    0
      代码/20221220林权/LQ/TFpolygon1129.py
  10. 553
    0
      代码/20221220林权/LQ/ZDT/JZDpoint1128.py
  11. 948
    0
      代码/20221220林权/LQ/ZDT/exportZDT_Batch.py
  12. 953
    0
      代码/20221220林权/LQ/ZDT/exportZDT_Single.py
  13. 28
    0
      代码/20221220林权/LQ/dlCMM_1203.py
  14. 136
    0
      代码/20231108黄河断面/DMljjs.py
  15. 104
    0
      代码/20231108黄河断面/DMzj.py
  16. 84
    0
      代码/20231108黄河断面/HBexcel.py
  17. 114
    0
      代码/20231108黄河断面/HBhhdmtable.py
  18. 292
    0
      代码/20231108黄河断面/HHdmExcel.py
  19. 156
    0
      代码/20231108黄河断面/HHdmTable.py
  20. 883
    0
      代码/20231108黄河断面/HHdm_tbx_3.py
  21. 二進制
      代码/20240112dwg右上角图框/.vs/20150313-T_cad_5000/v16/.suo
  22. 3
    0
      代码/20240112dwg右上角图框/.vs/ProjectSettings.json
  23. 二進制
      代码/20240112dwg右上角图框/.vs/T_cad/v16/.suo
  24. 9
    0
      代码/20240112dwg右上角图框/.vs/VSWorkspaceState.json
  25. 二進制
      代码/20240112dwg右上角图框/.vs/slnx.sqlite
  26. 20
    0
      代码/20240112dwg右上角图框/T_cad.sln
  27. 二進制
      代码/20240112dwg右上角图框/T_cad.suo
  28. 3
    0
      代码/20240112dwg右上角图框/T_cad/.vs/ProjectSettings.json
  29. 二進制
      代码/20240112dwg右上角图框/T_cad/.vs/slnx.sqlite
  30. 1543
    0
      代码/20240112dwg右上角图框/T_cad/Frame5000.cs
  31. 1951
    0
      代码/20240112dwg右上角图框/T_cad/LSTKAllCls.cs
  32. 192
    0
      代码/20240112dwg右上角图框/T_cad/LayerControl.cs
  33. 134
    0
      代码/20240112dwg右上角图框/T_cad/OldCls2.cs
  34. 36
    0
      代码/20240112dwg右上角图框/T_cad/Properties/AssemblyInfo.cs
  35. 111
    0
      代码/20240112dwg右上角图框/T_cad/T_cad.csproj
  36. 17
    0
      代码/20240112dwg右上角图框/T_cad/T_cad.csproj.user
  37. 3
    0
      代码/20240112dwg右上角图框/T_cad/app.config
  38. 二進制
      代码/20240112dwg右上角图框/T_cad/bin/Debug/T_cad.dll
  39. 3
    0
      代码/20240112dwg右上角图框/T_cad/bin/Debug/T_cad.dll.config
  40. 二進制
      代码/20240112dwg右上角图框/T_cad/bin/Debug/T_cad.pdb
  41. 30
    0
      代码/20240112dwg右上角图框/T_cad/bin/Debug/acad.err
  42. 66
    0
      代码/20240112dwg右上角图框/T_cad/mainCls.cs
  43. 二進制
      代码/20240112dwg右上角图框/T_cad/obj/Debug/DesignTimeResolveAssemblyReferences.cache
  44. 二進制
      代码/20240112dwg右上角图框/T_cad/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache
  45. 二進制
      代码/20240112dwg右上角图框/T_cad/obj/Debug/ResolveAssemblyReference.cache
  46. 二進制
      代码/20240112dwg右上角图框/T_cad/obj/Debug/T_cad.csproj.AssemblyReference.cache
  47. 29
    0
      代码/20240112dwg右上角图框/T_cad/obj/Debug/T_cad.csproj.FileListAbsolute.txt
  48. 二進制
      代码/20240112dwg右上角图框/T_cad/obj/Debug/T_cad.dll
  49. 二進制
      代码/20240112dwg右上角图框/T_cad/obj/Debug/T_cad.pdb
  50. 12
    0
      代码/20240112dwg右上角图框/UpgradeLog.XML
  51. 207
    0
      代码/20240112dwg右上角图框/_UpgradeReport_Files/UpgradeReport.css
  52. 232
    0
      代码/20240112dwg右上角图框/_UpgradeReport_Files/UpgradeReport.xslt
  53. 二進制
      代码/20240112dwg右上角图框/_UpgradeReport_Files/UpgradeReport_Minus.gif
  54. 二進制
      代码/20240112dwg右上角图框/_UpgradeReport_Files/UpgradeReport_Plus.gif
  55. 90
    0
      代码/20240226桐梓林/实际在用的数据和代码/BP2024_cgcs2000.txt
  56. 1
    0
      代码/20240226桐梓林/实际在用的数据和代码/CGCS2000_3_Degree_GK_Zone_34.prj
  57. 1
    0
      代码/20240226桐梓林/实际在用的数据和代码/GCS_WGS_1984.prj
  58. 11
    0
      代码/20240226桐梓林/实际在用的数据和代码/Memo.txt
  59. 678
    0
      代码/20240226桐梓林/实际在用的数据和代码/Newjson2023.py
  60. 91
    0
      代码/20240226桐梓林/实际在用的数据和代码/TZL2023.txt
  61. 218
    0
      代码/20241016断面自动生成/drawDMlineCOM1022_pan.py
  62. 231
    0
      代码/20241016断面自动生成/drawDMlineCOM1022_pan_1.py
  63. 144
    0
      代码/20241017都江堰断面/DMzl20241023.py
  64. 59
    0
      代码/20241017都江堰断面/ZDMDexcel.py
  65. 70
    0
      代码/20241017都江堰断面/ZDMDexcel_1108.py
  66. 55
    0
      代码/20241017都江堰断面/dmname.py
  67. 139
    0
      代码/20241017都江堰断面/dmname_onZH.py
  68. 108
    0
      代码/20241017都江堰断面/dmname_onZH_rename.py
  69. 614
    0
      代码/20241017都江堰断面/drawDMtable_20241202_QT.py
  70. 二進制
      加密后软件工具/exe/平面控制网稳定性已知系统分析软件(最最最终版).exe
  71. 二進制
      未加密软件工具/CAD插件工具/右上角图框方位/T_cad_2024.dll
  72. 2
    0
      未加密软件工具/CAD插件工具/右上角图框方位/更新命令部分.txt
  73. 二進制
      未加密软件工具/CAD插件工具/右上角图框方位/最老版本/GIS/UtilityManager02TK.tbx
  74. 二進制
      未加密软件工具/CAD插件工具/右上角图框方位/最老版本/GIS/UtilityManager02V1.tbx
  75. 二進制
      未加密软件工具/CAD插件工具/右上角图框方位/最老版本/cass/Debug2w/T_cad.dll
  76. 3
    0
      未加密软件工具/CAD插件工具/右上角图框方位/最老版本/cass/Debug2w/T_cad.dll.config
  77. 二進制
      未加密软件工具/CAD插件工具/右上角图框方位/最老版本/cass/Debug2w/T_cad.pdb
  78. 二進制
      未加密软件工具/CAD插件工具/右上角图框方位/最老版本/示例数据/原始模板1.dwg
  79. 二進制
      未加密软件工具/CAD插件工具/右上角图框方位/最老版本/示例数据/成图模板.bak
  80. 二進制
      未加密软件工具/CAD插件工具/右上角图框方位/最老版本/示例数据/成图模板.dwg
  81. 二進制
      未加密软件工具/CAD插件工具/右上角图框方位/最老版本/示例数据/需求模板.dwg
  82. 3
    0
      未加密软件工具/CAD插件工具/右上角图框方位/最老版本/示例数据/需求模板.dwl
  83. 7
    0
      未加密软件工具/CAD插件工具/右上角图框方位/最老版本/示例数据/需求模板.dwl2
  84. 二進制
      未加密软件工具/CAD插件工具/右上角图框方位/需求模板_1.dwg
  85. 二進制
      未加密软件工具/arcgis工具箱/DEM1.2.tbx
  86. 二進制
      未加密软件工具/arcgis工具箱/DLG检查1.5版.tbx
  87. 二進制
      未加密软件工具/arcgis工具箱/DM1.2.tbx
  88. 二進制
      未加密软件工具/arcgis工具箱/DOM1.2.tbx
  89. 二進制
      未加密软件工具/arcgis工具箱/dmgl(忘了这缩写是什么了)/dmgl0817new.tbx
  90. 二進制
      未加密软件工具/arcgis工具箱/dmgl(忘了这缩写是什么了)/dmgl0817使用说明.docx
  91. 二進制
      未加密软件工具/arcgis工具箱/倒流工具箱.tbx
  92. 二進制
      未加密软件工具/arcgis工具箱/公路断面工具.tbx
  93. 二進制
      未加密软件工具/arcgis工具箱/图斑操作/图斑操作0310.tbx
  94. 二進制
      未加密软件工具/arcgis工具箱/图斑操作/图斑操作0310使用说明.docx
  95. 二進制
      未加密软件工具/arcgis工具箱/批处理库容2_0.tbx
  96. 二進制
      未加密软件工具/arcgis工具箱/批量TIN转GRID.tbx
  97. 二進制
      未加密软件工具/arcgis工具箱/批量mdb转dwg.tbx
  98. 二進制
      未加密软件工具/arcgis工具箱/批量导入投影坐标系(最新版1.0).tbx
  99. 二進制
      未加密软件工具/arcgis工具箱/批量提取图斑new_3.tbx
  100. 0
    0
      未加密软件工具/arcgis工具箱/批量提取图斑注记2024_1_9.tbx

+ 202
- 0
代码/20210827随机边长/RWexcel.py 查看文件

@@ -0,0 +1,202 @@
1
+import os
2
+from typing import Counter
3
+import openpyxl
4
+from openpyxl.styles import PatternFill, Border, Side, Alignment, Protection, Font
5
+import datetime
6
+import random
7
+from tkinter import *  
8
+import tkinter as tk
9
+import tkinter.filedialog
10
+import tkinter.messagebox
11
+
12
+def start():
13
+    window = tk.Tk()  # 创建窗口对象的背景色
14
+    window.title('随机边长填表程序')   # 设置窗口的标题
15
+    window.geometry('400x275')      # 设置窗口的大小
16
+    title = tk.Label(window, text='随机边长填表程序', font=('微软雅黑', 12), width=40, height=3)
17
+    title.place(x=0,y=0,anchor='nw')
18
+
19
+    choosepath = tk.Label(window,text='选择成果表:',font=('微软雅黑',12),width=20,height=2)
20
+    choosepath.place(x=0,y=50,anchor='nw')
21
+    path_var1 = tk.StringVar() #输入路径
22
+    entry1 = tk.Entry(window, textvariable=path_var1)
23
+    entry1.place(x=170, y=65, anchor='nw')
24
+
25
+    exceltext = tk.Label(window,text='选择精度检测表:',font=('微软雅黑',12),width=20,height=2)
26
+    exceltext.place(x=0,y=100,anchor='nw')
27
+    path_var2 = tk.StringVar() #输入路径
28
+    entry2 = tk.Entry(window, textvariable=path_var2)
29
+    entry2.place(x=170, y=110, anchor='nw')
30
+
31
+    def choose1():
32
+        filename=tkinter.filedialog.askopenfilename(filetypes=[("xls,xlsx格式",".xlsx")])
33
+        path_var1.set(filename)
34
+
35
+    def choose2():
36
+        filename2=tkinter.filedialog.askopenfilename(filetypes=[("xls,xlsx格式",".xlsx")])
37
+        path_var2.set(filename2)
38
+
39
+    def tuichu():
40
+        window.destroy()
41
+
42
+    def unmergecell(path):
43
+        tdata3 = openpyxl.load_workbook(path)
44
+        sheetna3 = tdata3.sheetnames
45
+        sheet3 = tdata3[sheetna3[0]]
46
+        tabledd = 1
47
+        writemm = 8
48
+        while tabledd > 0 and tabledd < 4:
49
+            dataend1 = sheet3.cell(row=writemm, column=1).value
50
+            if dataend1 != None and tabledd < 3:
51
+                sheet3.unmerge_cells(start_row=writemm, start_column=1, end_row=writemm, end_column=6)
52
+                sheet3.unmerge_cells(start_row=writemm, start_column=7, end_row=writemm, end_column=8)
53
+                tdata3.save(path)
54
+                tabledd = tabledd + 1
55
+                writemm = writemm + 1
56
+            elif tabledd == 3:
57
+                sheet3.unmerge_cells(start_row=writemm, start_column=1, end_row=writemm, end_column=3)
58
+                sheet3.unmerge_cells(start_row=writemm, start_column=4, end_row=writemm, end_column=6)
59
+                sheet3.unmerge_cells(start_row=writemm, start_column=7, end_row=writemm, end_column=8)
60
+                tdata3.save(path)
61
+                tabledd = tabledd + 1
62
+                writemm = writemm + 1
63
+            else:
64
+                writemm = writemm + 1
65
+        tdata3.save(path)
66
+        tdata3.close()
67
+
68
+
69
+    def main():
70
+        starttime = datetime.datetime.now()
71
+        print (str(starttime))
72
+        path1 = entry1.get()
73
+        path2 = entry2.get()
74
+        #先读
75
+        #先读一遍就把那三行全部拆了
76
+        unmergecell(path2)
77
+        tdata = openpyxl.load_workbook(path1)
78
+        tdata2 = openpyxl.load_workbook(path2)
79
+        qzbhnum = "null"
80
+        writeii = 8
81
+        sheetna = tdata.sheetnames
82
+        sheetna2 = tdata2.sheetnames
83
+        sheet2 = tdata2[sheetna2[0]]
84
+        #这里需要读取每一个表,所以创建循环,当此张表是空表时tablecc变为-1,结束循环
85
+        tableii = 0
86
+        tablecc = 1
87
+        while tablecc == 1:
88
+            try:
89
+                sheet1 = tdata[sheetna[tableii]]
90
+            except:
91
+                break
92
+            #判断A10是否有数据
93
+            tableda = sheet1.cell(row=10, column=1).value
94
+            if tableda != 1:
95
+                tablecc = -1
96
+            else:
97
+                #寻找第二个1所在的单元格,确定点数,方便随机数
98
+                secondii = 12
99
+                secondcc = 1
100
+                while secondcc == 1:
101
+                    tableda2 = sheet1.cell(row=secondii, column=1).value
102
+                    if tableda2 == 1 or secondii == 80:
103
+                        if secondii == 80:
104
+                            secondcc = -1
105
+                            Count2 = 34
106
+                        else:
107
+                            #count1是最终点数,因为random从0开始,所以本来13的数就变成了12
108
+                            secondcc = -1
109
+                            Count0 = secondii - 12
110
+                            Count1 = Count0 / 2
111
+                            Count2 = int(Count1)
112
+                        #随机一个数
113
+                        ranok = -1
114
+                        while ranok == -1:
115
+                            ran0 = random.choice(range(Count2))
116
+                            #获取边长
117
+                            bcrow0 = ran0 * 2
118
+                            bcrow1 = bcrow0 + 11
119
+                            bclen = sheet1.cell(row=bcrow1, column=5).value
120
+                            if float(bclen) < 2:
121
+                                ranok = -1
122
+                            else:
123
+                                ranok = 1
124
+
125
+                        ran1 = ran0 + 1
126
+                        #做个判断,判断是否是最后一个数
127
+                        if ran1 == Count2 + 1 and ran1 != 35:
128
+                            ran2 = 1
129
+                        elif ran1 == 35:
130
+                            ran2 = ran1 + 1
131
+                        else:
132
+                            ran2 = ran1 + 1
133
+                        #第一个单元格需要填入的信息整合下
134
+                        str1 = 'J' + str(ran1) + '-J' + str(ran2)
135
+                        
136
+                        #判断下是否超出空白范围
137
+                        dataend = sheet2.cell(row=writeii,column=1).value
138
+                        cellborder = Border(left=Side(border_style='thin',color='FF000000'),right=Side(border_style='thin',color='FF000000'),
139
+                        top=Side(border_style='thin',color='FF000000'),bottom=Side(border_style='thin',color='FF000000'))
140
+                        alignmentcell=Alignment(horizontal='center',vertical='bottom')
141
+                        #前三行需要拆分单元格
142
+                        if dataend != None:
143
+                            sheet2.insert_rows(writeii,1)   
144
+                            sheet2.cell(row=writeii,column=1).border = cellborder
145
+                            sheet2.cell(row=writeii,column=2).border = cellborder
146
+                            sheet2.cell(row=writeii,column=3).border = cellborder
147
+                            sheet2.cell(row=writeii,column=4).border = cellborder
148
+                            sheet2.cell(row=writeii,column=5).border = cellborder
149
+                            sheet2.cell(row=writeii,column=6).border = cellborder
150
+                            sheet2.cell(row=writeii,column=7).border = cellborder
151
+                            sheet2.cell(row=writeii,column=8).border = cellborder
152
+                            sheet2.merge_cells(start_row=writeii, start_column=1, end_row=writeii, end_column=2)
153
+                            sheet2.merge_cells(start_row=writeii, start_column=3, end_row=writeii, end_column=4)
154
+                            sheet2.merge_cells(start_row=writeii, start_column=5, end_row=writeii, end_column=6)
155
+                        sheet2.cell(row=writeii,column=1).alignment = alignmentcell
156
+                        sheet2.cell(row=writeii,column=3).alignment = alignmentcell
157
+                        sheet2.cell(row=writeii,column=5).alignment = alignmentcell
158
+                        sheet2.cell(row=writeii,column=7).alignment = alignmentcell
159
+                        sheet2.cell(row=writeii,column=8).alignment = alignmentcell
160
+                        sheet2.cell(row=writeii,column=1).value=str1
161
+                        sheet2.cell(row=writeii,column=3).value=bclen
162
+                        #填写编号
163
+                        bhnum = sheet1.cell(row=3, column=1).value
164
+                        bhnum1 = bhnum.split('J',1)
165
+                        qzbhnum = bhnum1[0][-6:]
166
+                        bhnum2 = "J" + str(bhnum1[1])
167
+                        sheet2.cell(row=writeii,column=8).value=bhnum2
168
+                        tableii = tableii + 1
169
+                        writeii = writeii + 1
170
+                        tdata2.save(path2)
171
+                    else:
172
+                        secondii = secondii + 2
173
+        sheet2.cell(row=3,column=7).value=qzbhnum
174
+        sheet2.cell(row=writeii,column=1).value= "检测数量:"+ str(tableii) + " 个"
175
+        #再把最后三个合回去
176
+        sheet2.merge_cells(start_row=writeii, start_column=1, end_row=writeii, end_column=6)
177
+        sheet2.merge_cells(start_row=writeii, start_column=7, end_row=writeii, end_column=8)
178
+        sheet2.merge_cells(start_row=writeii+1, start_column=1, end_row=writeii+1, end_column=6)
179
+        sheet2.merge_cells(start_row=writeii+1, start_column=7, end_row=writeii+1, end_column=8)
180
+        sheet2.merge_cells(start_row=writeii+2, start_column=1, end_row=writeii+2, end_column=3)
181
+        sheet2.merge_cells(start_row=writeii+2, start_column=4, end_row=writeii+2, end_column=6)
182
+        sheet2.merge_cells(start_row=writeii+2, start_column=7, end_row=writeii+2, end_column=8)
183
+        tdata2.save(path2)
184
+        tdata2.close()
185
+        endtime = datetime.datetime.now()
186
+        print (str(endtime))
187
+        tkinter.messagebox.showinfo(title='结束',message='运行成功!')
188
+        window.destroy()
189
+
190
+    tk.Button(window, text='选择', command=choose1).place(x=350, y=50, anchor='nw')
191
+    tk.Button(window, text='选择', command=choose2).place(x=350, y=100, anchor='nw')
192
+    tk.Button(window,text='确认',command=main).place(x=120,y=150,anchor='nw')
193
+    tk.Button(window,text='取消',command=tuichu).place(x=230,y=150,anchor='nw')
194
+    noticemes = tk.Label(window,text='请务必删除中间已填写的内容,再运行!',fg="red",font=('微软雅黑',12),width=35,height=2)
195
+    noticemes.place(x=10,y=180,anchor='nw')
196
+    noticemes = tk.Label(window,text='请等待弹出 运行成功 窗口再关闭程序!',fg="red",font=('微软雅黑',12),width=35,height=2)
197
+    noticemes.place(x=10,y=220,anchor='nw')
198
+    window.mainloop()
199
+
200
+if __name__ == '__main__':
201
+    # main(r"D:\1work_now\20210819\新建文件夹\大坪子村大坪子组界址点成果表.xlsx",r"D:\1work_now\20210819\新建文件夹\2 相对位置精度检测表.xlsx")
202
+    start()

+ 37
- 0
代码/20221220林权/LQ/JZDcount1129.py 查看文件

@@ -0,0 +1,37 @@
1
+import arcpy
2
+import math
3
+
4
+def JZpoint(inpath, outfileshp):
5
+    txtpath = outfileshp + '\\JZpointCount.txt'
6
+    mm = 0
7
+    zdh = ''
8
+    with open(txtpath,'w') as line:
9
+        arcpy.MakeFeatureLayer_management(inpath, 'JZD')
10
+        with arcpy.da.SearchCursor('JZD', ['SHAPE@', 'JZDH', 'ZDBH']) as cursorA:
11
+            for curA in cursorA:
12
+                zddm = curA[2]
13
+                if zdh == '':
14
+                    zdh = zddm
15
+                    line.write(zddm +':')
16
+                    mm = 1
17
+                    point1 = curA[0].lastPoint
18
+                    #重心
19
+                    jzdh = curA[1]
20
+                elif zddm == zdh:
21
+                    mm = mm + 1
22
+                else:
23
+                    zdh = zddm
24
+                    line.write(str(mm)+ '\n')
25
+                    line.write(zddm +':')
26
+                    mm = 1
27
+        #把最后一个点加上
28
+        line.write(str(mm))
29
+
30
+                    
31
+
32
+if __name__ == '__main__':
33
+    try:
34
+        # 输入shp,输出界址点文本
35
+        JZpoint(arcpy.GetParameterAsText(0),arcpy.GetParameterAsText(1))
36
+    except arcpy.ExecuteError:
37
+        arcpy.AddMessage(arcpy.GetMessages())

+ 553
- 0
代码/20221220林权/LQ/JZDpoint20230110_1.py 查看文件

@@ -0,0 +1,553 @@
1
+import arcpy
2
+import math
3
+
4
+def JZpointmake(inpath, outfileshp):
5
+    # region [读取shp]
6
+    shpstr = 'JZD1.shp'
7
+    outpath = outfileshp + '\\' + 'JZD1.shp'
8
+    try:
9
+        arcpy.CreateFeatureclass_management(outfileshp, shpstr, 'POINT')
10
+    except:
11
+        arcpy.Delete_management(outpath)
12
+        arcpy.CreateFeatureclass_management(outfileshp, shpstr, 'POINT')
13
+    # 加载
14
+    arcpy.MakeFeatureLayer_management(inpath, 'LB')
15
+    arcpy.MakeFeatureLayer_management(outpath, 'JZD')
16
+    sr = arcpy.Describe('LB').spatialReference
17
+    # 添加一群字段
18
+    arcpy.AddField_management('JZD', '标识码', 'LONG')
19
+    arcpy.AddField_management('JZD', 'YSDM', 'TEXT')
20
+    arcpy.AddField_management('JZD', 'JZDH', 'TEXT')
21
+    arcpy.AddField_management('JZD', 'JBLX', 'TEXT')
22
+    arcpy.AddField_management('JZD', 'JZDLX', 'TEXT')
23
+    arcpy.AddField_management('JZD', 'ZDBH', 'TEXT')
24
+    arcpy.AddField_management('JZD', '顺序号', 'LONG')
25
+    arcpy.AddField_management('JZD', 'flag', 'LONG')
26
+    #float按理说应该符合的
27
+    bsm = 0
28
+    field1 = ['SHAPE@', '标识码', 'YSDM', 'JZDH', 'JBLX',
29
+              'JZDLX',  'ZDBH', '顺序号','flag']
30
+    # endregion
31
+    with arcpy.da.InsertCursor('JZD', field1) as cursorZ:
32
+        with arcpy.da.SearchCursor('LB', ['SHAPE@', '宗地编号']) as cursorA:
33
+            for curA in cursorA:
34
+                # region [读折点]
35
+                poly1 = curA[0]
36
+                zdbh = curA[1]
37
+                if zdbh == None or zdbh == '' or zdbh == ' ':
38
+                    pass
39
+                else:
40
+                    # 获取折点
41
+                    points = poly1.getPart()
42
+                    pt = points[0]
43
+                    mm = 0
44
+                    linelist = []  
45
+                    indexp = 0
46
+                    #存的都是点
47
+                    while mm < pt.count:
48
+                        jzd = pt[mm]
49
+                        try:
50
+                            xx = round(jzd.X,4)
51
+                            yy = round(jzd.Y,4)
52
+                            if mm == 0 or mm == indexp:
53
+                                xx0 = xx
54
+                                yy0 = yy
55
+                                slist = []
56
+                                slist.append(pt[mm]) 
57
+                            else:
58
+                                numdis0 = xx - xx0
59
+                                numdis1 = yy - yy0 
60
+                                numdis = math.sqrt((numdis0 * numdis0)+(numdis1*numdis1))
61
+                                if xx == xx0 and yy == yy0:
62
+                                    #一个的结束
63
+                                    indexp = mm + 1
64
+                                    linelist.append(slist)  
65
+                                if numdis < 0.1:
66
+                                    pass
67
+                                else:
68
+                                    slist.append(pt[mm]) 
69
+                            mm = mm + 1
70
+                        except:
71
+                            if mm == indexp:
72
+                                indexp = mm + 1
73
+                                mm = mm + 1 
74
+                    llen = len(linelist)
75
+                    #判断下如果多环,排个序
76
+                    linelist1 = pdlen(linelist)
77
+                    linelist = linelist1
78
+                    # endregion
79
+                    #甭管有没有环,都是第一个来处理
80
+                    ln1 = linelist[0]
81
+                    list1 = []
82
+                    nn1 = 0
83
+                    while nn1 < len(ln1):
84
+                        if nn1 == len(ln1) - 1:
85
+                            fpx = round(ln1[nn1].X,4)
86
+                            fpy = round(ln1[nn1].Y,4)
87
+                            lpx = round(ln1[0].X,4)
88
+                            lpy = round(ln1[0].Y,4)
89
+                            fpoint = arcpy.Point(fpx, fpy)
90
+                            lpoint = arcpy.Point(lpx, lpy)
91
+                        else:
92
+                            fpx = round(ln1[nn1].X,4)
93
+                            fpy = round(ln1[nn1].Y,4)
94
+                            lpx = round(ln1[nn1 + 1].X,4)
95
+                            lpy = round(ln1[nn1 + 1].Y,4)
96
+                            fpoint = arcpy.Point(fpx, fpy)
97
+                            lpoint = arcpy.Point(lpx, lpy)
98
+                        new_array = arcpy.Array()
99
+                        new_array.append(fpoint)
100
+                        new_array.append(lpoint)
101
+                        ln2 = arcpy.Polyline(new_array,sr)
102
+                        #先把起始点加进去
103
+                        bl1 = addpoint(list1,fpoint)
104
+                        if bl1 == 1:
105
+                            list1.append(fpoint)
106
+                        
107
+                            # list1.append(lpoint)
108
+                        #插入点
109
+                        arcpy.SelectLayerByLocation_management('LB','INTERSECT',ln2)
110
+                        count0 = int(arcpy.GetCount_management('LB').getOutput(0)) 
111
+                        if count0 < 2:
112
+                            bl4 = addpoint(list1,lpoint)
113
+                            if bl4 == 1:
114
+                                list1.append(lpoint)
115
+                            nn1 = nn1 + 1
116
+                        else:
117
+                            #对于同一个线段来说,把所有点的位置准确点
118
+                            listp1 = []
119
+                            with arcpy.da.SearchCursor('LB', ['SHAPE@', '宗地编号']) as cursorB:
120
+                                for curB in cursorB:
121
+                                    zdbh1 = curB[1]
122
+                                    #排除自己
123
+                                    if zdbh1 == zdbh:
124
+                                        pass
125
+                                    else:
126
+                                        try:
127
+                                            shpB = curB[0]
128
+                                            lineB = shpB.boundary ()
129
+                                            rln = lineB.intersect (ln2, 2)
130
+                                            fpoint1 = rln.firstPoint
131
+                                            lpoint1 = rln.lastPoint
132
+                                            fx = round(fpoint1.X,4)
133
+                                            fy = round(fpoint1.Y,4)
134
+                                            lx = round(lpoint1.X,4)
135
+                                            ly = round(lpoint1.Y,4)
136
+                                            #判断这两个点是否都在里面
137
+                                            fp = arcpy.Point(fx, fy)
138
+                                            lp = arcpy.Point(lx, ly)
139
+                                            list2 = []
140
+                                            bl1 = addpoint(list1,fp)
141
+                                            if bl1 == 1:
142
+                                                #判断与起点的距离
143
+                                                dis1 = math.sqrt(((fpx - fx)*(fpx - fx)) + ((fpy-fy)*(fpy-fy)))
144
+                                                slist2 = []
145
+                                                slist2.append(dis1)
146
+                                                slist2.append(fp)
147
+                                                list2.append(slist2)
148
+                                            bl1 = addpoint(list1,lp)
149
+                                            if bl1 == 1:
150
+                                                dis1 = math.sqrt(((fpx - lx)*(fpx - lx)) + ((fpy-ly)*(fpy-ly)))
151
+                                                slist2 = []
152
+                                                slist2.append(dis1)
153
+                                                slist2.append(lp)
154
+                                                list2.append(slist2)
155
+                                            if len(list2) == 1:
156
+                                                listp1.append(list2[0][1])
157
+                                            elif len(list2) == 2:
158
+                                                #对2排序
159
+                                                if list2[0][0] < list2[1][0]:
160
+                                                    listp1.append(list2[0][1])
161
+                                                    listp1.append(list2[1][1])
162
+                                                else:
163
+                                                    listp1.append(list2[1][1])
164
+                                                    listp1.append(list2[0][1])
165
+                                        except:
166
+                                            pass
167
+                            #得到所有的点,进行一个与起点的排序
168
+                            nn2 = 0
169
+                            listp2 =[]
170
+                            while nn2 < len(listp1):
171
+                                num0 = fpx - listp1[nn2].X
172
+                                num1 = fpy - listp1[nn2].Y
173
+                                dis2 = math.sqrt((num0*num0)+(num1*num1))
174
+                                slistp2 = []
175
+                                slistp2.append(dis2)
176
+                                slistp2.append(listp1[nn2])
177
+                                listp2.append(slistp2)
178
+                                nn2 = nn2 + 1
179
+                            listp2.sort()
180
+                            nn3 = 0
181
+                            bl3 = 0
182
+                            while nn3 < len(listp2):
183
+                                #这里要看下要不要除重
184
+                                bl3 = addpoint(list1,listp2[nn3][1])
185
+                                if bl3 == 1:
186
+                                    list1.append(listp2[nn3][1])
187
+                                nn3 = nn3 + 1  
188
+                            bl4 = addpoint(list1,lpoint)
189
+                            if bl4 == 1:
190
+                                list1.append(lpoint)
191
+                        nn1 = nn1 + 1
192
+                    
193
+                    if len(linelist) == 1:
194
+                        listF = linezd(list1,poly1)
195
+                        #直接写
196
+                        ii = 0
197
+                        zdh = 0
198
+                        while ii < len(listF):
199
+                            if ii == 0:
200
+                                zdh = zdh + 1
201
+                                bsm = bsm + 1
202
+                                # shape
203
+                                point1 = arcpy.Point(listF[ii][0], listF[ii][1])
204
+                                # 要素代码
205
+                                ysdm = '6002010300'
206
+                                # 顺序号
207
+                                sxh = ii + 1
208
+                                # 界址点号
209
+                                jzdh = 'J' + str(zdh)
210
+                                # 宗地代码
211
+                                zddm = curA[1]
212
+                                rlist = []
213
+                                rlist.append(point1)
214
+                                rlist.append(bsm)
215
+                                rlist.append(ysdm)
216
+                                rlist.append(jzdh)
217
+                                rlist.append('')
218
+                                rlist.append('')
219
+                                rlist.append(zddm)
220
+                                rlist.append(zdh)
221
+                                rlist.append(1)
222
+                                cursorZ.insertRow(rlist)
223
+                            else:
224
+                                numdis0 = listF[ii][0] - listF[ii - 1][0]
225
+                                numdis1 = listF[ii][1] - listF[ii - 1][1]
226
+                                numdis2 = math.sqrt((numdis0 * numdis0)+(numdis1*numdis1))
227
+                                if numdis2 < 0.1:
228
+                                    pass
229
+                                else:
230
+                                    zdh = zdh + 1
231
+                                    bsm = bsm + 1
232
+                                    # shape
233
+                                    point1 = arcpy.Point(listF[ii][0], listF[ii][1])
234
+                                    # 要素代码
235
+                                    ysdm = '6002010300'
236
+                                    # 顺序号
237
+                                    sxh = ii + 1
238
+                                    # 界址点号
239
+                                    jzdh = 'J' + str(zdh)
240
+                                    # 宗地代码
241
+                                    zddm = curA[1]
242
+                                    rlist = []
243
+                                    rlist.append(point1)
244
+                                    rlist.append(bsm)
245
+                                    rlist.append(ysdm)
246
+                                    rlist.append(jzdh)
247
+                                    rlist.append('')
248
+                                    rlist.append('')
249
+                                    rlist.append(zddm)
250
+                                    rlist.append(zdh)
251
+                                    rlist.append(1)
252
+                                    cursorZ.insertRow(rlist)
253
+                            ii = ii + 1
254
+                    else:
255
+                        mm0 = 0
256
+                        zdh = 0
257
+                        while mm0 < len(linelist):
258
+                            if mm0 == 0:
259
+                                listF = linezd(list1,poly1)
260
+                                ii = 0
261
+                                while ii < len(listF):
262
+                                    if ii == 0:
263
+                                        zdh = zdh + 1
264
+                                        bsm = bsm + 1
265
+                                        # shape
266
+                                        point1 = arcpy.Point(listF[ii][0], listF[ii][1])
267
+                                        # 要素代码
268
+                                        ysdm = '6002010300'
269
+                                        # 顺序号
270
+                                        sxh = ii + 1
271
+                                        # 界址点号
272
+                                        jzdh = 'J' + str(zdh)
273
+                                        # 宗地代码
274
+                                        zddm = curA[1]
275
+                                        rlist = []
276
+                                        rlist.append(point1)
277
+                                        rlist.append(bsm)
278
+                                        rlist.append(ysdm)
279
+                                        rlist.append(jzdh)
280
+                                        rlist.append('')
281
+                                        rlist.append('')
282
+                                        rlist.append(zddm)
283
+                                        rlist.append(zdh)
284
+                                        rlist.append(mm0+1)
285
+                                        cursorZ.insertRow(rlist)
286
+                                    else:
287
+                                        numdis0 = listF[ii][0] - listF[ii - 1][0]
288
+                                        numdis1 = listF[ii][1] - listF[ii - 1][1]
289
+                                        numdis2 = math.sqrt((numdis0 * numdis0)+(numdis1*numdis1))
290
+                                        if numdis2 < 0.1:
291
+                                            pass
292
+                                        else:
293
+                                            zdh = zdh + 1
294
+                                            bsm = bsm + 1
295
+                                            # shape
296
+                                            point1 = arcpy.Point(listF[ii][0], listF[ii][1])
297
+                                            # 要素代码
298
+                                            ysdm = '6002010300'
299
+                                            # 顺序号
300
+                                            sxh = ii + 1
301
+                                            # 界址点号
302
+                                            jzdh = 'J' + str(zdh)
303
+                                            # 宗地代码
304
+                                            zddm = curA[1]
305
+                                            rlist = []
306
+                                            rlist.append(point1)
307
+                                            rlist.append(bsm)
308
+                                            rlist.append(ysdm)
309
+                                            rlist.append(jzdh)
310
+                                            rlist.append('')
311
+                                            rlist.append('')
312
+                                            rlist.append(zddm)
313
+                                            rlist.append(zdh)
314
+                                            rlist.append(mm0+1)
315
+                                            cursorZ.insertRow(rlist)
316
+                                    ii = ii + 1
317
+                            else:
318
+                                listF = linezd(linelist[mm0],poly1)
319
+                                ii = len(listF) - 1
320
+                                while ii >= 0:
321
+                                    if ii == len(listF) - 1:
322
+                                        zdh = zdh + 1
323
+                                        bsm = bsm + 1
324
+                                        # shape
325
+                                        point1 = arcpy.Point(listF[ii][0], listF[ii][1])
326
+                                        # 要素代码
327
+                                        ysdm = '6002010300'
328
+                                        # 顺序号
329
+                                        sxh = ii + 1
330
+                                        # 界址点号
331
+                                        jzdh = 'J' + str(zdh)
332
+                                        # 宗地代码
333
+                                        zddm = curA[1]
334
+                                        rlist = []
335
+                                        rlist.append(point1)
336
+                                        rlist.append(bsm)
337
+                                        rlist.append(ysdm)
338
+                                        rlist.append(jzdh)
339
+                                        rlist.append('')
340
+                                        rlist.append('')
341
+                                        rlist.append(zddm)
342
+                                        rlist.append(zdh)
343
+                                        rlist.append(mm0+1)
344
+                                        cursorZ.insertRow(rlist)
345
+                                    else:
346
+                                        numdis0 = listF[ii][0] - listF[ii - 1][0]
347
+                                        numdis1 = listF[ii][1] - listF[ii - 1][1]
348
+                                        numdis2 = math.sqrt((numdis0 * numdis0)+(numdis1*numdis1))
349
+                                        if numdis2 < 0.1:
350
+                                            pass
351
+                                        else:
352
+                                            zdh = zdh + 1
353
+                                            bsm = bsm + 1
354
+                                            # shape
355
+                                            point1 = arcpy.Point(listF[ii][0], listF[ii][1])
356
+                                            # 要素代码
357
+                                            ysdm = '6002010300'
358
+                                            # 顺序号
359
+                                            sxh = ii + 1
360
+                                            # 界址点号
361
+                                            jzdh = 'J' + str(zdh)
362
+                                            # 宗地代码
363
+                                            zddm = curA[1]
364
+                                            rlist = []
365
+                                            rlist.append(point1)
366
+                                            rlist.append(bsm)
367
+                                            rlist.append(ysdm)
368
+                                            rlist.append(jzdh)
369
+                                            rlist.append('')
370
+                                            rlist.append('')
371
+                                            rlist.append(zddm)
372
+                                            rlist.append(zdh)
373
+                                            rlist.append(mm0+1)
374
+                                            cursorZ.insertRow(rlist)
375
+                                    ii = ii - 1
376
+                            mm0 = mm0 + 1
377
+                    arcpy.AddMessage(zdbh + ' FINISH')
378
+
379
+def pdlen(list1):
380
+    ii = 0
381
+    list2 = []
382
+    while ii < len(list1):
383
+        pts = list1[ii]
384
+        length1 = 0
385
+        mm = 0
386
+        while mm < len(pts):
387
+            if mm == len(pts) - 1:
388
+                pt1 = pts[mm]
389
+                pt2 = pts[0]
390
+                dis1 = math.sqrt(((pt1.X-pt2.X)*(pt1.X-pt2.X))+((pt1.Y-pt2.Y)*(pt1.Y-pt2.Y)))
391
+                length1 = length1 + dis1
392
+                mm = mm + 1
393
+            else:
394
+                pt1 = pts[mm]
395
+                pt2 = pts[mm + 1]
396
+                dis1 = math.sqrt(((pt1.X-pt2.X)*(pt1.X-pt2.X))+((pt1.Y-pt2.Y)*(pt1.Y-pt2.Y)))
397
+                length1 = length1 + dis1
398
+                mm = mm + 1
399
+        slist2 = []
400
+        slist2.append(length1)
401
+        slist2.append(pts)
402
+        list2.append(slist2)
403
+        ii = ii + 1
404
+    list2.sort(reverse=True)
405
+    nn = 0
406
+    list3 = []
407
+    while nn < len(list2):
408
+        list3.append(list2[nn][1])
409
+        nn = nn + 1
410
+    return list3
411
+
412
+
413
+
414
+
415
+def addpoint(list1,pt):
416
+    ptx = round(pt.X,4)
417
+    pty = round(pt.Y,4)
418
+    ii = 0
419
+    bl = 1
420
+    while ii < len(list1):
421
+        if ptx == round(list1[ii].X,4) and pty == round(list1[ii].Y,4):
422
+            bl = -1
423
+        ii = ii + 1
424
+    return bl
425
+
426
+def linezd(line1,poly):
427
+    # 获取折点
428
+    mm = 0
429
+    pp = 0
430
+    list1 = []
431
+    while mm < len(line1):
432
+        plist = []
433
+        jzd = line1[mm]
434
+        try:
435
+            xx = jzd.X
436
+            yy = jzd.Y
437
+            plist.append(xx)
438
+            plist.append(yy)
439
+            # 初始顺序
440
+            plist.append(pp)
441
+            list1.append(plist)
442
+            pp = pp + 1
443
+            mm = mm + 1
444
+        except:
445
+            mm = mm + 1 
446
+    # 对折点排序(算法)
447
+    if len(list1) < 3:
448
+        listF = []
449
+    else:
450
+        # listF = zdsort(list1, zx)
451
+        listF = jzdsort(list1,poly)
452
+    return listF
453
+
454
+def jzdsort(list0,poly):
455
+    m = 0
456
+    n = 0
457
+    northwest = []
458
+    northwest.append(poly.extent.XMin)
459
+    northwest.append(poly.extent.YMax)
460
+    minDis = (northwest[1] - list0[0][1])*(northwest[1] - list0[0][1]) + (northwest[0] - list0[0][0])*(northwest[0] - list0[0][0])
461
+    maxStdangle = cal_stdangle(northwest,list0[0])
462
+    while m < len(list0):        
463
+        Dis = (northwest[1] - list0[m][1])*(northwest[1] - list0[m][1]) + (northwest[0] - list0[m][0])*(northwest[0] - list0[m][0])
464
+        if Dis < minDis:
465
+            minDis = Dis
466
+            maxStdangle = cal_stdangle(northwest,list0[m])
467
+            n = m
468
+        if abs(Dis-minDis) < 0.000001:
469
+            stdangle = cal_stdangle(northwest,list0[m])
470
+            if stdangle > maxStdangle:
471
+                maxStdangle = stdangle
472
+                n = m 
473
+        m = m + 1
474
+    i = 0
475
+    while i < len(list0):    
476
+        if n == 0:
477
+            vectangleN = cal_stdangle(list0[0], list0[1])
478
+            vectangleNl = cal_stdangle(list0[len(list0)-1], list0[0]) 
479
+            if abs(vectangleN-vectangleNl) < 3:
480
+                n = len(list0)-1          
481
+        else:
482
+            if n == len(list0)-1:
483
+                vectangleN = cal_stdangle(list0[n], list0[0])
484
+            else:            
485
+                vectangleN = cal_stdangle(list0[n], list0[n+1]) 
486
+            vectangleNl = cal_stdangle(list0[n-1], list0[n])    
487
+            if abs(vectangleN-vectangleNl) < 3:
488
+                n = n-1
489
+        i = i + 1
490
+    list4 = []     
491
+    a = n     
492
+    num = 0
493
+    while a < len(list0):
494
+        slist4 = []
495
+        num = num + 1
496
+        slist4.append(list0[a][0])
497
+        slist4.append(list0[a][1])
498
+        slist4.append(num)
499
+        list4.append(slist4)   
500
+        a = a + 1    
501
+    a = 0
502
+    while a < n:
503
+        slist4 = []
504
+        num = num + 1
505
+        slist4.append(list0[a][0])
506
+        slist4.append(list0[a][1])
507
+        slist4.append(num)
508
+        list4.append(slist4)   
509
+        a = a + 1
510
+    return list4
511
+
512
+
513
+def cal_stdangle(lastp,p): 
514
+    stdangle=0
515
+    dy= p[1]-lastp[1]
516
+    dx= p[0]-lastp[0]
517
+    if dx==0 and dy>0:
518
+        stdangle = 0
519
+    if dx==0 and dy<0:
520
+        stdangle = 180
521
+    if dy==0 and dx>0:
522
+        stdangle = 90
523
+    if dy==0 and dx<0:
524
+        stdangle = 270
525
+    if dx>0 and dy>0:
526
+       stdangle = math.atan(dx/dy)*180/math.pi
527
+    elif dx<0 and dy>0:
528
+       stdangle = 360 + math.atan(dx/dy)*180/math.pi
529
+    elif dx<0 and dy<0:
530
+       stdangle = 180 + math.atan(dx/dy)*180/math.pi
531
+    elif dx>0 and dy<0:
532
+       stdangle = 180 + math.atan(dx/dy)*180/math.pi
533
+    return stdangle
534
+    
535
+def calcangle(lastp,p): 
536
+    angle=0
537
+    stdangle = cal_stdangle(lastp,p)
538
+    if (stdangle < 45 and stdangle >= 0) or (stdangle <= 360 and stdangle >= 315):
539
+        angle = 270
540
+    if (stdangle < 135 and stdangle >= 45):
541
+        angle = 0
542
+    if (stdangle < 225 and stdangle >= 135):
543
+        angle = 90
544
+    if (stdangle < 315 and stdangle >= 225):
545
+        angle = 180
546
+    return angle
547
+
548
+if __name__ == '__main__':
549
+    try:
550
+        # 输入shp,输出界址点文件夹
551
+        JZpointmake(arcpy.GetParameterAsText(0),arcpy.GetParameterAsText(1))
552
+    except arcpy.ExecuteError:
553
+        arcpy.AddMessage(arcpy.GetMessages())

+ 2073
- 0
代码/20221220林权/LQ/LQreport_all1.py
文件差異過大導致無法顯示
查看文件


+ 196
- 0
代码/20221220林权/LQ/LZDsf1201.py 查看文件

@@ -0,0 +1,196 @@
1
+import arcpy
2
+import math
3
+
4
+def LZDpoly(zdshp, jzdshp, outpath):
5
+    # 先把总点数搞出来,zdbh+总点数
6
+    txtpath1 = outpath + '\\LZD.txt'
7
+    arcpy.MakeFeatureLayer_management(jzdshp, 'JZD')
8
+    arcpy.MakeFeatureLayer_management(zdshp, 'ZD')
9
+    sr = arcpy.Describe('ZD').spatialReference
10
+    cc = 1
11
+    # 在外面写个字典
12
+    zd = {'公路用地': 'GLYD', '特殊用地': 'TSYD', '公用设施用地': 'GYSS', '交通服务场站用地': 'JTFW', '沟渠': 'GQ',
13
+          '灌木林地': 'GMLD', '其他林地': 'QTLD', '乔木林地': 'QMLD', '竹林地': 'ZLD', '果园': 'GY', '旱地': 'HD', 
14
+          '河流水面': 'HLSM', '坑塘水面': 'KTSM', '养殖坑塘': 'YZKT', '农村道路': 'NCDL', '农村宅基地': 'NCZJD', 
15
+          '其他草地': 'QTCD', '其他园地': 'QTYD', '设施农用地': 'SSNYD', '水田': 'ST'}
16
+    # with open(txtpath1.decode('utf-8'), 'w') as line:
17
+    with arcpy.da.SearchCursor('ZD', ['SHAPE@', '宗地编码']) as cursorA:
18
+        for curA in cursorA:
19
+            # 先找到对应宗地
20
+            shpA = curA[0]
21
+            # 所有点存个list,方便删(list0,listz0)
22
+            zdbh = curA[1]
23
+            if zdbh == '' or zdbh == ' ' or zdbh == None:
24
+                pass
25
+            else:
26
+                # if cc == 1:
27
+                #     cc = -1
28
+                # else:
29
+                #     line.write('\n')
30
+                # line.write(zdbh + ':')
31
+                list1 = []
32
+                ii = 0
33
+                with arcpy.da.SearchCursor('JZD', ['SHAPE@', 'JZDH','ZDBH']) as cursorB:
34
+                    for curB in cursorB:
35
+                        # 前一个和当前的相交
36
+                        if zdbh == curB[2]:
37
+                            if ii == 0:
38
+                                fp = curB[0].firstPoint
39
+                                fpx = fp.X
40
+                                fpy = fp.Y
41
+                                fpoint = arcpy.Point(fpx, fpy)
42
+                                firstpoint = arcpy.Point(fpx, fpy)
43
+                            else:
44
+                                lp = curB[0].firstPoint
45
+                                lpx = lp.X
46
+                                lpy = lp.Y
47
+                                lpoint = arcpy.Point(lpx, lpy)
48
+                                new_array = arcpy.Array()
49
+                                new_array.append(fpoint)
50
+                                new_array.append(lpoint)
51
+                                ln2 = arcpy.Polyline(new_array, sr)
52
+                                arcpy.SelectLayerByLocation_management(
53
+                                    'ZD', 'INTERSECT', ln2)
54
+                                with arcpy.da.SearchCursor('ZD', ['SHAPE@', '宗地编号', 'DLMC', '权利人']) as cursorC:
55
+                                    for curC in cursorC:
56
+                                        # 排除自己
57
+                                        str1 = curC[1]
58
+                                        shpC = curC[0]
59
+                                        if str1 == zdbh:
60
+                                            pass
61
+                                        else:
62
+                                            # 排除只交一个点的情况
63
+                                            bl1 = fpoint.disjoint(shpC)
64
+                                            bl2 = lpoint.disjoint(shpC)
65
+                                            if bl1 == False and bl2 == False:
66
+                                                if str1 == None or str1 == '' or str1 == ' ':
67
+                                                    str1 = curC[2]
68
+                                                    str2 = zd[str1]
69
+                                                    slist1 = []
70
+                                                    slist1.append(ii)
71
+                                                    slist1.append(ii+1)
72
+                                                    slist1.append(str2)
73
+                                                    list1.append(slist1)
74
+                                                else:
75
+                                                    str1 = curC[3] + \
76
+                                                        '(' + curC[1]+')'
77
+                                                    slist1 = []
78
+                                                    slist1.append(ii)
79
+                                                    slist1.append(ii+1)
80
+                                                    slist1.append(str1)
81
+                                                    list1.append(slist1)
82
+                                fp = curB[0].firstPoint
83
+                                fpx = fp.X
84
+                                fpy = fp.Y
85
+                                fpoint = arcpy.Point(fpx, fpy)
86
+                            ii = ii + 1
87
+                new_array = arcpy.Array()
88
+                new_array.append(fpoint)
89
+                new_array.append(firstpoint)
90
+                ln2 = arcpy.Polyline(new_array, sr)
91
+                arcpy.SelectLayerByLocation_management(
92
+                    'ZD', 'INTERSECT', ln2)
93
+                with arcpy.da.SearchCursor('ZD', ['SHAPE@', '宗地编号', 'DLMC', '权利人']) as cursorC:
94
+                    for curC in cursorC:
95
+                        # 排除自己
96
+                        str1 = curC[1]
97
+                        shpC = curC[0]
98
+                        if str1 == zdbh:
99
+                            pass
100
+                        else:
101
+                            # 排除只交一个点的情况
102
+                            bl1 = fpoint.disjoint(shpC)
103
+                            bl2 = lpoint.disjoint(shpC)
104
+                            if bl1 == False and bl2 == False:
105
+                                if str1 == None or str1 == '' or str1 == ' ':
106
+                                    str1 = curC[2]
107
+                                    slist1 = []
108
+                                    slist1.append(ii)
109
+                                    slist1.append(1)
110
+                                    slist1.append(str1)
111
+                                    list1.append(slist1)
112
+                                else:
113
+                                    str1 = curC[3] + '(' + curC[1]+')'
114
+                                    slist1 = []
115
+                                    slist1.append(ii)
116
+                                    slist1.append(1)
117
+                                    slist1.append(str1)
118
+                                    list1.append(slist1)
119
+                # 然后把相同的合在一起,书写在txt上
120
+                mm = 0
121
+                qsd = ''
122
+                zd = ''
123
+                nr = ''
124
+                while mm < len(list1):
125
+                    if mm == len(list1) - 1:
126
+                        if nr == list1[mm][2]:
127
+                            if 'JE' in nr:
128
+                                str1 = nr.split('(',-1)[-1]
129
+                                nr = str1.replace(')','')
130
+                            else:
131
+                                try:
132
+                                    nr = str1
133
+                                except:
134
+                                    nr = 'QT'
135
+                            zd = 'J1'
136
+                            # line.write(nr + ',')
137
+                            # line.write(qsd + ',')
138
+                            # line.write(zd + ';')
139
+                        else:
140
+                            if 'JE' in nr:
141
+                                str1 = nr.split('(',-1)[-1]
142
+                                nr = str1.replace(')','')
143
+                            else:
144
+                                try:
145
+                                    nr = str1
146
+                                except:
147
+                                    nr = 'QT'
148
+                            # line.write(nr + ',')
149
+                            # line.write(qsd + ',')
150
+                            # line.write(zd + ';')
151
+                            qsd = 'J' + str(list1[mm][0])
152
+                            nr = list1[mm][2]
153
+                            zd = 'J1'
154
+                            if 'JE' in nr:
155
+                                str1 = nr.split('(',-1)[-1]
156
+                                nr = str1.replace(')','')
157
+                            else:
158
+                                try:
159
+                                    nr = str1
160
+                                except:
161
+                                    nr = 'QT'
162
+                            # line.write(nr + ',')
163
+                            # line.write(qsd + ',')
164
+                            # line.write(zd + ';')
165
+                    elif mm == 0:
166
+                        nr = list1[mm][2]
167
+                        qsd = 'J1'
168
+                    else:
169
+                        if nr == list1[mm][2]:
170
+                            pass
171
+                        else:
172
+                            zd = 'J' + str(list1[mm][0])
173
+                            if 'JE' in nr:
174
+                                str1 = nr.split('(',-1)[-1]
175
+                                nr = str1.replace(')','')
176
+                            else:
177
+                                try:
178
+                                    nr = str1
179
+                                except:
180
+                                    nr = 'QT'
181
+                            # line.write(nr + ',')
182
+                            # line.write(qsd + ',')
183
+                            # line.write(zd + ';')
184
+                            qsd = 'J' + str(list1[mm][0])
185
+                            nr = list1[mm][2]
186
+                    mm = mm + 1
187
+                arcpy.AddMessage(zdbh + ' finish')
188
+
189
+
190
+if __name__ == '__main__':
191
+    try:
192
+        # 输入宗地shp,输入界址点,界址点总数,底图all,输出文件夹
193
+        LZDpoly(r'D:\2work_now\20221026\test\testLZD1.shp',
194
+                r'D:\2work_now\20221026\JZD\JZD.shp', r'D:\2work_now\20221026\test')
195
+    except arcpy.ExecuteError:
196
+        arcpy.AddMessage(arcpy.GetMessages())

+ 23
- 0
代码/20221220林权/LQ/PolygonZX.py 查看文件

@@ -0,0 +1,23 @@
1
+import arcpy
2
+import math
3
+
4
+def ZXpoint(shppath,outpath):
5
+    txtpath = outpath + '\\ZXpoint.txt'
6
+    arcpy.MakeFeatureLayer_management(shppath, 'SHP')
7
+    with open(txtpath,'w') as line:
8
+        with arcpy.da.SearchCursor('SHP', ['SHAPE@', '宗地编号']) as cursorA:
9
+            for curA in cursorA:
10
+                zdbh = curA[1]
11
+                shp1 = curA[0]
12
+                #中心点的计算
13
+                ceny = (shp1.extent.YMax + shp1.extent.YMin)/2
14
+                cenx = (shp1.extent.XMax + shp1.extent.XMin)/2
15
+                line.write(zdbh + ':' + str(round(cenx,4)) + ',' + str(round(ceny,4)))
16
+                line.write('\n')
17
+
18
+if __name__ == '__main__':
19
+    try:
20
+        # 输入shp,输出界址点文件夹
21
+        ZXpoint(arcpy.GetParameterAsText(0),arcpy.GetParameterAsText(1))
22
+    except arcpy.ExecuteError:
23
+        arcpy.AddMessage(arcpy.GetMessages())

+ 520
- 0
代码/20221220林权/LQ/SZdw1129_syb.py 查看文件

@@ -0,0 +1,520 @@
1
+import arcpy
2
+import math
3
+
4
+def SZpoly(zdpath1,zdpath2,tbpath1,tbpath2,tbpath3,outpath,):
5
+    tb1 = -1
6
+    arcpy.MakeFeatureLayer_management(zdpath1, 'ZD')
7
+    #获取坐标系
8
+    sr = arcpy.Describe('ZD').spatialReference
9
+    try:
10
+        arcpy.MakeFeatureLayer_management(tbpath1, 'TB')
11
+        tb1 = 1
12
+    except:
13
+        arcpy.AddMessage('无图斑1shp可加载')
14
+    zd2 = -1
15
+    try:
16
+        arcpy.MakeFeatureLayer_management(zdpath2, 'ZD2')
17
+        zd2 = 1
18
+    except:
19
+        arcpy.AddMessage('无宗地2shp可加载')
20
+    tb2 = -1
21
+    try:
22
+        arcpy.MakeFeatureLayer_management(tbpath2, 'TB2')
23
+        tb2 = 1
24
+    except:
25
+        arcpy.AddMessage('无图斑2shp可加载')
26
+    tb3 = -1
27
+    try:
28
+        arcpy.MakeFeatureLayer_management(tbpath3, 'TB3')
29
+        tb3 = 1
30
+    except:
31
+        arcpy.AddMessage('无图斑3shp可加载')
32
+    #添加字段
33
+    try:
34
+        arcpy.AddField_management('ZD', '四至北', 'TEXT')
35
+    except:
36
+        arcpy.AddMessage('四至北字段已存在')
37
+    try:
38
+        arcpy.AddField_management('ZD', '四至南', 'TEXT')
39
+    except:
40
+        arcpy.AddMessage('四至南字段已存在')
41
+    try:
42
+        arcpy.AddField_management('ZD', '四至西', 'TEXT')
43
+    except:
44
+        arcpy.AddMessage('四至西字段已存在')
45
+    try:
46
+        arcpy.AddField_management('ZD', '四至东', 'TEXT')
47
+    except:
48
+        arcpy.AddMessage('四至东字段已存在')
49
+    #先全部把包络矩形做出来
50
+    outshp = outpath + '\\minipolygon.shp'
51
+    #效果不理想的话可以用面积
52
+    try:
53
+        arcpy.MinimumBoundingGeometry_management(zdpath1,outshp,"RECTANGLE_BY_AREA", "NONE")
54
+    except:
55
+        arcpy.Delete_management(outshp)
56
+        arcpy.MinimumBoundingGeometry_management(zdpath1,outshp,"RECTANGLE_BY_AREA", "NONE")
57
+    #先读取方向存成list(shape,宗地编号,北的方向)
58
+    llist = []
59
+    arcpy.MakeFeatureLayer_management(outshp, 'out1')
60
+    with arcpy.da.UpdateCursor('out1', ['宗地编号','SHAPE@']) as cursorZ:
61
+        for curZ in cursorZ:
62
+            #把四至边的位置确定下来,并存下来
63
+            shp0 = curZ[1]
64
+            fxlist = []
65
+            fxlist = pdszx(shp0,sr)
66
+            sllist = []
67
+            sllist.append(curZ[0])
68
+            sllist.append(fxlist)
69
+            llist.append(sllist)
70
+    with arcpy.da.UpdateCursor('ZD', ['宗地编号','权利人','四至北','四至东','四至南','四至西','SHAPE@']) as cursorA:
71
+        for curA in cursorA:
72
+            zdbh = curA[0]
73
+            ii = 0
74
+            fxlist = []
75
+            while ii < len(llist):
76
+                if zdbh == llist[ii][0]:
77
+                    fxlist = llist[ii][1]
78
+                    break
79
+                else:
80
+                    ii = ii + 1
81
+            szlist = []
82
+            szlist.append(curA[2])
83
+            szlist.append(curA[3])
84
+            szlist.append(curA[4])
85
+            szlist.append(curA[5])
86
+            szlist1 = zdszsf('ZD',szlist,fxlist,zdbh)
87
+            szlist = szlist1
88
+            if zd2 == 1:
89
+                szlist1 = zdszsf('ZD2',szlist,fxlist,zdbh)
90
+                szlist = szlist1
91
+            if szlist1[0] !='' and szlist1[1] !='' and szlist1[2] !='' and szlist1[3] !='':
92
+                pass
93
+            else:
94
+                #图斑
95
+                if tb1 == 1:
96
+                    szlist1 = tbszsf('TB',szlist,fxlist,shp0)
97
+                    szlist = szlist1
98
+                if tb2 == 1:
99
+                    szlist1 = tbszsf('TB2',szlist,fxlist,shp0)
100
+                    szlist = szlist1
101
+                if tb3 == 1:
102
+                    szlist1 = tbszsf('TB3',szlist,fxlist,shp0)
103
+                    szlist = szlist1
104
+            curA[2] = szlist[0]
105
+            curA[3] = szlist[1]
106
+            curA[4] = szlist[2]
107
+            curA[5] = szlist[3]
108
+            cursorA.updateRow (curA)
109
+            arcpy.AddMessage(zdbh + ' finish')
110
+
111
+#约束下,至少占比5/1(这个可以调)
112
+def zdszsf(layer1,szlist,fxlist,zdbh):
113
+    #然后挨个做相交
114
+    arcpy.SelectLayerByLocation_management(layer1,'CONTAINS',fxlist[0])
115
+    count0 = int(arcpy.GetCount_management(layer1).getOutput(0)) 
116
+    with arcpy.da.SearchCursor(layer1, ['宗地编号','权利人']) as cursorB:
117
+        for curB in cursorB:
118
+            if count0 != 0 and curB[0] != zdbh:
119
+                str1 = curB[1] + '(' + curB[0] + ')'
120
+                if szlist[0] == '':
121
+                    szlist[0] = str1
122
+                    break
123
+                else:
124
+                    pass
125
+    arcpy.SelectLayerByLocation_management(layer1,'INTERSECT',fxlist[0])
126
+    count0 = int(arcpy.GetCount_management(layer1).getOutput(0)) 
127
+    with arcpy.da.SearchCursor(layer1, ['宗地编号','权利人','SHAPE@']) as cursorC:
128
+        for curC in cursorC:
129
+            if count0 != 0 and curC[0] != zdbh:
130
+                #先尝试相交
131
+                shp0 = fxlist[0].buffer(1)
132
+                shp1 = curC[2]
133
+                line1 = shp0.intersect(shp1, 4)
134
+                len1 = (shp0.area)/5
135
+                if line1.area < len1:
136
+                    pass
137
+                else:
138
+                    str1 = curC[1] + '(' + curC[0] + ')'
139
+                    if szlist[0] == '':
140
+                        szlist[0] = str1
141
+                        break
142
+                    else:
143
+                        pass
144
+    arcpy.SelectLayerByLocation_management(layer1,'CONTAINS',fxlist[1])
145
+    count0 = int(arcpy.GetCount_management(layer1).getOutput(0)) 
146
+    with arcpy.da.SearchCursor(layer1, ['宗地编号','权利人']) as cursorD:
147
+        for curD in cursorD:
148
+            if count0 != 0 and curD[0] != zdbh:
149
+                str1 = curD[1] + '(' + curD[0] + ')'
150
+                if szlist[1] == '':
151
+                    szlist[1] = str1
152
+                    break
153
+                else:
154
+                    pass
155
+    arcpy.SelectLayerByLocation_management(layer1,'INTERSECT',fxlist[1])
156
+    count0 = int(arcpy.GetCount_management(layer1).getOutput(0)) 
157
+    with arcpy.da.SearchCursor(layer1, ['宗地编号','权利人','SHAPE@']) as cursorE:
158
+        for curE in cursorE:
159
+            if count0 != 0 and curE[0] != zdbh:
160
+                shp0 = fxlist[1].buffer(1)
161
+                shp1 = curE[2]
162
+                line1 = shp0.intersect (shp1, 4)
163
+                len1 = (shp0.area)/5
164
+                if line1.area < len1:
165
+                    pass
166
+                else:
167
+                    str1 = curE[1] + '(' + curE[0] + ')'
168
+                    if szlist[1] == '':
169
+                        szlist[1] = str1
170
+                        break
171
+                    else:
172
+                        pass
173
+    arcpy.SelectLayerByLocation_management(layer1,'CONTAINS',fxlist[2])
174
+    count0 = int(arcpy.GetCount_management(layer1).getOutput(0)) 
175
+    with arcpy.da.SearchCursor(layer1, ['宗地编号','权利人']) as cursorF:
176
+        for curF in cursorF:
177
+            if count0 != 0 and curF[0] != zdbh:
178
+                str1 = curF[1] + '(' + curF[0] + ')'
179
+                if szlist[2] == '':
180
+                    szlist[2] = str1
181
+                    break
182
+                else:
183
+                    pass
184
+    arcpy.SelectLayerByLocation_management(layer1,'INTERSECT',fxlist[2])
185
+    count0 = int(arcpy.GetCount_management(layer1).getOutput(0)) 
186
+    with arcpy.da.SearchCursor(layer1, ['宗地编号','权利人','SHAPE@']) as cursorG:
187
+        for curG in cursorG:
188
+            if count0 != 0 and curG[0] != zdbh:
189
+                shp0 = fxlist[2].buffer(1)
190
+                shp1 = curG[2]
191
+                line1 = shp0.intersect (shp1, 4)
192
+                len1 = (shp0.area)/5
193
+                if line1.area < len1:
194
+                    pass
195
+                else:
196
+                    str1 = curG[1] + '(' + curG[0] + ')'
197
+                    if szlist[2] == '':
198
+                        szlist[2] = str1
199
+                        break
200
+                    else:
201
+                        pass
202
+    arcpy.SelectLayerByLocation_management(layer1,'CONTAINS',fxlist[3])
203
+    count0 = int(arcpy.GetCount_management(layer1).getOutput(0)) 
204
+    with arcpy.da.SearchCursor(layer1, ['宗地编号','权利人']) as cursorH:
205
+        for curH in cursorH:
206
+            if count0 != 0 and curH[0] != zdbh:
207
+                str1 = curH[1] + '(' + curH[0] + ')'
208
+                if szlist[3] == '':
209
+                    szlist[3] = str1
210
+                    break
211
+                else:
212
+                    pass
213
+    arcpy.SelectLayerByLocation_management(layer1,'INTERSECT',fxlist[3])
214
+    count0 = int(arcpy.GetCount_management(layer1).getOutput(0)) 
215
+    with arcpy.da.SearchCursor(layer1, ['宗地编号','权利人','SHAPE@']) as cursorI:
216
+        for curI in cursorI:
217
+            if count0 != 0 and curI[0] != zdbh:
218
+                shp0 = fxlist[3].buffer(1)
219
+                shp1 = curI[2]
220
+                line1 = shp0.intersect (shp1, 4)
221
+                len1 = (shp0.area)/5
222
+                if line1.area < len1:
223
+                    pass
224
+                else:
225
+                    str1 = curI[1] + '(' + curI[0] + ')'
226
+                    if szlist[3] == '':
227
+                        szlist[3] = str1
228
+                        break
229
+                    else:
230
+                        pass
231
+    return szlist
232
+
233
+def tbszsf(layer1,szlist,fxlist,shp0):
234
+    #然后挨个做相交
235
+    arcpy.SelectLayerByLocation_management(layer1,'CONTAINS',shp0)
236
+    count0 = int(arcpy.GetCount_management(layer1).getOutput(0)) 
237
+    with arcpy.da.SearchCursor(layer1, ['DLMC']) as cursorB:
238
+        for curB in cursorB:
239
+            if count0 != 0:
240
+                str1 = curB[0]
241
+                if szlist[0] == '':
242
+                    szlist[0] = str1
243
+                    break
244
+                else:
245
+                    pass
246
+    arcpy.SelectLayerByLocation_management(layer1,'INTERSECT',fxlist[0])
247
+    count0 = int(arcpy.GetCount_management(layer1).getOutput(0)) 
248
+    list1 = []
249
+    with arcpy.da.SearchCursor(layer1, ['DLMC','SHAPE@']) as cursorC:
250
+        for curC in cursorC:
251
+            if count0 != 0:
252
+                try:
253
+                    shp2 = fxlist[0].buffer(1)
254
+                    shp1 = curC[1]
255
+                    line1 = shp2.intersect(shp1, 4)
256
+                    len1 = (shp2.area)/5
257
+                    if line1.area < len1:
258
+                        pass
259
+                    else:
260
+                        str1 = curC[0]
261
+                        if szlist[0] == '':
262
+                            szlist[0] = str1
263
+                            break
264
+                        else:
265
+                            pass
266
+                except:
267
+                    pass
268
+    arcpy.SelectLayerByLocation_management(layer1,'CONTAINS',shp0)
269
+    count0 = int(arcpy.GetCount_management(layer1).getOutput(0)) 
270
+    with arcpy.da.SearchCursor(layer1, ['DLMC']) as cursorD:
271
+        for curD in cursorD:
272
+            if count0 != 0:
273
+                str1 = curD[0]
274
+                if szlist[1] == '':
275
+                    szlist[1] = str1
276
+                    break
277
+                else:
278
+                    pass
279
+    arcpy.SelectLayerByLocation_management(layer1,'INTERSECT',fxlist[1])
280
+    count0 = int(arcpy.GetCount_management(layer1).getOutput(0)) 
281
+    list1 = []
282
+    with arcpy.da.SearchCursor(layer1, ['DLMC','SHAPE@']) as cursorE:
283
+        for curE in cursorE:
284
+            if count0 != 0:
285
+                try:
286
+                    shp2 = fxlist[1].buffer(1)
287
+                    shp1 = curE[1]
288
+                    line1 = shp2.intersect(shp1, 4)
289
+                    len1 = (shp2.area)/5
290
+                    if line1.area < len1:
291
+                        pass
292
+                    else:
293
+                        str1 = curE[0]
294
+                        if szlist[1] == '':
295
+                            szlist[1] = str1
296
+                            break
297
+                        else:
298
+                            pass
299
+                except:
300
+                    pass
301
+    arcpy.SelectLayerByLocation_management(layer1,'CONTAINS',shp0)
302
+    count0 = int(arcpy.GetCount_management(layer1).getOutput(0)) 
303
+    with arcpy.da.SearchCursor(layer1, ['DLMC']) as cursorF:
304
+        for curF in cursorF:
305
+            if count0 != 0:
306
+                str1 =  curF[0]
307
+                if szlist[2] == '':
308
+                    szlist[2] = str1
309
+                    break
310
+                else:
311
+                    pass
312
+    arcpy.SelectLayerByLocation_management(layer1,'INTERSECT',fxlist[2])
313
+    count0 = int(arcpy.GetCount_management(layer1).getOutput(0)) 
314
+    list1 = []
315
+    with arcpy.da.SearchCursor(layer1, ['DLMC','SHAPE@']) as cursorG:
316
+        for curG in cursorG:
317
+            if count0 != 0:
318
+                try:
319
+                    shp2 = fxlist[2].buffer(1)
320
+                    shp1 = curG[1]
321
+                    line1 = shp2.intersect(shp1, 4)
322
+                    len1 = (shp2.area)/5
323
+                    if line1.area < len1:
324
+                        pass
325
+                    else:
326
+                        str1 = curG[0]
327
+                        if szlist[2] == '':
328
+                            szlist[2] = str1
329
+                            break
330
+                        else:
331
+                            pass
332
+                except:
333
+                    pass
334
+    arcpy.SelectLayerByLocation_management(layer1,'CONTAINS',shp0)
335
+    count0 = int(arcpy.GetCount_management(layer1).getOutput(0)) 
336
+    with arcpy.da.SearchCursor(layer1, ['DLMC']) as cursorH:
337
+        for curH in cursorH:
338
+            if count0 != 0:
339
+                str1 = curH[0]
340
+                if szlist[3] == '':
341
+                    szlist[3] = str1
342
+                    break
343
+                else:
344
+                    pass
345
+    arcpy.SelectLayerByLocation_management(layer1,'INTERSECT',fxlist[3])
346
+    count0 = int(arcpy.GetCount_management(layer1).getOutput(0)) 
347
+    list1 = []
348
+    with arcpy.da.SearchCursor(layer1, ['DLMC','SHAPE@']) as cursorI:
349
+        for curI in cursorI:
350
+            if count0 != 0:
351
+                try:
352
+                    shp2 = fxlist[3].buffer(1)
353
+                    shp1 = curI[1]
354
+                    line1 = shp2.intersect(shp1, 4)
355
+                    len1 = (shp2.area)/5
356
+                    if line1.area < len1:
357
+                        pass
358
+                    else:
359
+                        str1 = curI[0]
360
+                        if szlist[3] == '':
361
+                            szlist[3] = str1
362
+                            break
363
+                        else:
364
+                            pass
365
+                except:
366
+                    pass
367
+    return szlist
368
+            
369
+
370
+    
371
+def pdszx(shp1,sr):
372
+    zd1 = shp1.centroid
373
+    zdx = zd1.X
374
+    zdy = zd1.Y
375
+    points = shp1.getPart()
376
+    pt = points[0] 
377
+    ii = 0
378
+    bfx = []
379
+    dfx = []
380
+    nfx = []
381
+    xfx = []
382
+    while ii < 4:
383
+        pt0 = pt[ii]
384
+        pty = pt0.Y
385
+        if pty > zdy:
386
+            bfx.append(pt0)
387
+        else:
388
+            nfx.append(pt0)
389
+        ii = ii + 1
390
+    #暂时没想到会有三个点的可能性
391
+    if len(bfx) == 2:
392
+        # if bfx[0].X > bfx[1].X:
393
+        if bfx[0].X > zdx and bfx[1].X < zdx:
394
+            dfx.append(bfx[0])
395
+            xfx.append(bfx[1])
396
+        elif bfx[0].X < zdx and bfx[1].X > zdx:
397
+            dfx.append(bfx[1])
398
+            xfx.append(bfx[0])
399
+        elif bfx[0].X > bfx[1].X and bfx[1].X > zdx:
400
+            dfx.append(bfx[0])
401
+            dfx.append(bfx[1])
402
+            nfx.append(bfx[0])
403
+            bfx.remove(bfx[0])
404
+        elif bfx[0].X < bfx[1].X and bfx[0].X > zdx:
405
+            dfx.append(bfx[0])
406
+            dfx.append(bfx[1])
407
+            nfx.append(bfx[1])
408
+            bfx.remove(bfx[1])
409
+        elif bfx[0].X > bfx[1].X and bfx[0].X < zdx:
410
+            xfx.append(bfx[0])
411
+            xfx.append(bfx[1])
412
+            nfx.append(bfx[1])
413
+            bfx.remove(bfx[1])
414
+        elif bfx[0].X < bfx[1].X and bfx[1].X < zdx:
415
+            xfx.append(bfx[0])
416
+            xfx.append(bfx[1])
417
+            nfx.append(bfx[0])
418
+            bfx.remove(bfx[0])
419
+        if nfx[0].X > zdx and zdx > nfx[1].X:
420
+            dfx.append(nfx[0])
421
+            xfx.append(nfx[1])
422
+        elif nfx[0].X < zdx and zdx < nfx[1].X:
423
+            dfx.append(nfx[1])
424
+            xfx.append(nfx[0])
425
+        elif nfx[0].X > nfx[1].X and nfx[1].X > zdx:
426
+            dfx.append(nfx[0])
427
+            dfx.append(nfx[1])
428
+            bfx.append(nfx[0])
429
+            nfx.remove(nfx[0])
430
+        elif nfx[0].X < nfx[1].X and nfx[0].X > zdx:
431
+            dfx.append(nfx[0])
432
+            dfx.append(nfx[1])
433
+            bfx.append(nfx[1])
434
+            nfx.remove(nfx[1])
435
+        elif nfx[0].X > nfx[1].X and nfx[0].X < zdx:
436
+            xfx.append(nfx[0])
437
+            xfx.append(nfx[1])
438
+            bfx.append(nfx[1])
439
+            nfx.remove(nfx[1])
440
+        elif nfx[0].X < nfx[1].X and nfx[1].X < zdx:
441
+            xfx.append(nfx[0])
442
+            xfx.append(nfx[1])
443
+            bfx.append(nfx[0])
444
+            nfx.remove(nfx[0])
445
+    elif len(bfx) == 1:
446
+        #也就是必有两个相同y值
447
+        if round(nfx[0].Y,2) == round(nfx[1].Y,2):
448
+            if nfx[0].X > nfx[1].X:
449
+                bfx.append(nfx[0])
450
+                nfx.remove(nfx[0])
451
+                dfx.append(bfx[1])
452
+                dfx.append(nfx[1])
453
+                xfx.append(bfx[0])
454
+                xfx.append(nfx[0])
455
+            else:
456
+                bfx.append(nfx[1])
457
+                nfx.remove(nfx[1])
458
+                dfx.append(bfx[1])
459
+                dfx.append(nfx[1])
460
+                xfx.append(bfx[0])
461
+                xfx.append(nfx[0])
462
+        elif round(nfx[0].Y,2) == round(nfx[2].Y,2):
463
+            if nfx[0].X > nfx[2].X:
464
+                bfx.append(nfx[0])
465
+                nfx.remove(nfx[0])
466
+                dfx.append(bfx[1])
467
+                dfx.append(nfx[0])
468
+                xfx.append(bfx[0])
469
+                xfx.append(nfx[1])
470
+            else:
471
+                bfx.append(nfx[2])
472
+                nfx.remove(nfx[2])
473
+                dfx.append(bfx[1])
474
+                dfx.append(nfx[1])
475
+                xfx.append(bfx[0])
476
+                xfx.append(nfx[0])
477
+        elif round(nfx[1].Y,2) == round(nfx[2].Y,2):
478
+            if nfx[1].X > nfx[2].X:
479
+                bfx.append(nfx[1])
480
+                nfx.remove(nfx[1])
481
+                dfx.append(bfx[1])
482
+                dfx.append(nfx[0])
483
+                xfx.append(bfx[0])
484
+                xfx.append(nfx[1])
485
+            else:
486
+                bfx.append(nfx[2])
487
+                nfx.remove(nfx[2])
488
+                dfx.append(bfx[1])
489
+                dfx.append(nfx[0])
490
+                xfx.append(bfx[0])
491
+                xfx.append(nfx[1])
492
+    #把点变成线,然后根据BDNX的顺序存储
493
+    line1 = arcpy.Polyline(arcpy.Array(bfx),sr)
494
+    line2 = arcpy.Polyline(arcpy.Array(dfx),sr)
495
+    line3 = arcpy.Polyline(arcpy.Array(nfx),sr)
496
+    line4 = arcpy.Polyline(arcpy.Array(xfx),sr)
497
+    llist = []
498
+    llist.append(line1)
499
+    llist.append(line2)
500
+    llist.append(line3)
501
+    llist.append(line4)
502
+    return llist
503
+
504
+def takefir(elem):
505
+    return elem[0]
506
+
507
+if __name__ == '__main__':
508
+    try:
509
+        #根据需求设计4个选项,宗地1,宗地2,外业补充,731,待定
510
+        SZpoly(r'D:\2work_now\20221026\test\testSZ.shp','',r'D:\2work_now\20221026\test\BDDW.shp',r'D:\2work_now\20221026\test\BGTB.shp','',r'D:\2work_now\20221026\test')
511
+    except arcpy.ExecuteError:
512
+        arcpy.AddMessage(arcpy.GetMessages())
513
+
514
+
515
+
516
+
517
+
518
+
519
+
520
+

+ 527
- 0
代码/20221220林权/LQ/SZsf.py 查看文件

@@ -0,0 +1,527 @@
1
+import arcpy
2
+import math
3
+
4
+def SZpoly(zdpath1,zdpath2,tbpath1,tbpath2,tbpath3):
5
+    tb1 = -1
6
+    arcpy.MakeFeatureLayer_management(zdpath1, 'ZD')
7
+    try:
8
+        arcpy.MakeFeatureLayer_management(tbpath1, 'TB')
9
+        tb1 = 1
10
+    except:
11
+        arcpy.AddMessage('无图斑1shp可加载')
12
+    zd2 = -1
13
+    try:
14
+        arcpy.MakeFeatureLayer_management(zdpath2, 'ZD2')
15
+        zd2 = 1
16
+    except:
17
+        arcpy.AddMessage('无宗地2shp可加载')
18
+    tb2 = -1
19
+    try:
20
+        arcpy.MakeFeatureLayer_management(tbpath2, 'TB2')
21
+        tb2 = 1
22
+    except:
23
+        arcpy.AddMessage('无图斑2shp可加载')
24
+    tb3 = -1
25
+    try:
26
+        arcpy.MakeFeatureLayer_management(tbpath3, 'TB3')
27
+        tb3 = 1
28
+    except:
29
+        arcpy.AddMessage('无图斑3shp可加载')
30
+    #添加字段
31
+    try:
32
+        arcpy.AddField_management('ZD', '四至北', 'TEXT')
33
+    except:
34
+        arcpy.AddMessage('四至北字段已存在')
35
+        print('四至北字段已存在')
36
+    try:
37
+        arcpy.AddField_management('ZD', '四至南', 'TEXT')
38
+    except:
39
+        arcpy.AddMessage('四至南字段已存在')
40
+        print('四至南字段已存在')
41
+    try:
42
+        arcpy.AddField_management('ZD', '四至西', 'TEXT')
43
+    except:
44
+        arcpy.AddMessage('四至西字段已存在')
45
+        print('四至西字段已存在')
46
+    try:
47
+        arcpy.AddField_management('ZD', '四至东', 'TEXT')
48
+    except:
49
+        arcpy.AddMessage('四至东字段已存在')
50
+        print('四至东字段已存在')
51
+
52
+    #一个一个来,先把临宗地搞出来
53
+    with arcpy.da.UpdateCursor('ZD', ['SHAPE@', '四至北','四至东','四至南','四至西','宗地编号']) as cursorA:
54
+        for curA in cursorA:
55
+            #szlist1是邻宗的结果,szlist2是地物的结果
56
+            szlist1 = []
57
+            szlist2 = []
58
+            poly1 = curA[0]
59
+            #这个阈值可以调整
60
+            buf1 = poly1.buffer(1)
61
+            zddm0 = curA[5]
62
+            list1 = []
63
+            #首先是挑选出相交的几个图形(应该不会很巧的只是共线)
64
+            arcpy.SelectLayerByLocation_management('ZD','INTERSECT',buf1)
65
+            count0 = int(arcpy.GetCount_management('ZD').getOutput(0)) 
66
+            if count0 == 0:
67
+                #那就不关宗地什么事了
68
+                pass
69
+            else:
70
+                #shape,宗地编号,权利人
71
+                
72
+                with arcpy.da.SearchCursor('ZD', ['SHAPE@', '宗地编号','权利人']) as cursorB:
73
+                    for curB in cursorB:
74
+                        #排除自己
75
+                        zddm1 = curB[1]
76
+                        if zddm1 == zddm0:
77
+                            pass
78
+                        else:
79
+                            #先把信息都装入list,方便提取
80
+                            slist1 = []
81
+                            slist1.append(curB[0])
82
+                            slist1.append(curB[1])
83
+                            slist1.append(curB[2])
84
+                            list1.append(slist1)
85
+            #首先是挑选出相交的几个图形(应该不会很巧的只是共线)
86
+            if zd2 == 1:
87
+                arcpy.SelectLayerByLocation_management('ZD2','INTERSECT',buf1)
88
+                count0 = int(arcpy.GetCount_management('ZD2').getOutput(0)) 
89
+                if count0 == 0:
90
+                    pass
91
+                else:
92
+                    #shape,宗地编号,权利人
93
+                    with arcpy.da.SearchCursor('ZD2', ['SHAPE@', '宗地编号','权利人']) as cursorC:
94
+                        for curC in cursorC:
95
+                            #排除自己
96
+                            zddm1 = curC[1]
97
+                            if zddm1 == zddm0:
98
+                                pass
99
+                            else:
100
+                                #先把信息都装入list,方便提取
101
+                                slist1 = []
102
+                                slist1.append(curC[0])
103
+                                slist1.append(curC[1])
104
+                                slist1.append(curC[2])
105
+                                list1.append(slist1)
106
+            if list1 != []:
107
+                #分别过四至内容
108
+                szlist1 = szsf(list1,buf1,poly1)
109
+            list2 = []
110
+            if tb1 == 1:
111
+                #首先相交
112
+                arcpy.SelectLayerByLocation_management('TB','INTERSECT',buf1)
113
+                count1 = int(arcpy.GetCount_management('TB').getOutput(0)) 
114
+                if count1 == 0:
115
+                    #那就不关图斑什么事了
116
+                    pass
117
+                else:
118
+                    with arcpy.da.SearchCursor('TB', ['SHAPE@', 'DLMC']) as cursorD:
119
+                        for curD in cursorD:
120
+                            slist2 = []
121
+                            slist2.append(curD[0])
122
+                            slist2.append(curD[1])
123
+                            list2.append(slist2)
124
+                
125
+            if tb2 == 1:
126
+                #首先相交
127
+                arcpy.SelectLayerByLocation_management('TB2','INTERSECT',buf1)
128
+                count1 = int(arcpy.GetCount_management('TB2').getOutput(0)) 
129
+                if count1 == 0:
130
+                    #那就不关图斑什么事了
131
+                    pass
132
+                else:
133
+                    with arcpy.da.SearchCursor('TB2', ['SHAPE@', 'DLMC']) as cursorE:
134
+                        for curE in cursorE:
135
+                            slist2 = []
136
+                            slist2.append(curE[0])
137
+                            slist2.append(curE[1])
138
+                            list2.append(slist2) 
139
+            if tb3 == 1:
140
+                #首先相交
141
+                arcpy.SelectLayerByLocation_management('TB3','INTERSECT',buf1)
142
+                count1 = int(arcpy.GetCount_management('TB3').getOutput(0)) 
143
+                if count1 == 0:
144
+                    #那就不关图斑什么事了
145
+                    pass
146
+                else:
147
+                    with arcpy.da.SearchCursor('TB3', ['SHAPE@', 'DLMC']) as cursorF:
148
+                        for curF in cursorF:
149
+                            #角度和地物名称
150
+                            slist2 = []
151
+                            slist2.append(curF[0])
152
+                            slist2.append(curF[1])
153
+                            list2.append(slist2)
154
+            if list2 != [] and szlist1 !=[]:
155
+                #分别过四至内容(图斑只需要补没有的)
156
+                szlist2 = szsf1(list2,poly1,szlist1,poly1)
157
+            else:
158
+                szlist2 = szlist1 
159
+            try:
160
+            #再四舍五入下,防止有空
161
+                if szlist2[0] != '':
162
+                    curA[1] = szlist2[0]
163
+                else:
164
+                    if szlist2[1] !='':
165
+                        curA[1] = szlist2[1]
166
+                    else:
167
+                        if szlist2[3] !='':
168
+                            curA[1] = szlist2[3]
169
+                if szlist2[1] != '':
170
+                    curA[2] = szlist2[1]
171
+                else:
172
+                    if szlist2[0] !='':
173
+                        curA[2] = szlist2[0]
174
+                    else:
175
+                        if szlist2[2] !='':
176
+                            curA[2] = szlist2[2]
177
+                if szlist2[2] != '':
178
+                    curA[3] = szlist2[2]
179
+                else:
180
+                    if szlist2[1] !='':
181
+                        curA[3] = szlist2[1]
182
+                    else:
183
+                        if szlist2[3] !='':
184
+                            curA[3] = szlist2[3]
185
+                if szlist2[3] != '':
186
+                    curA[4] = szlist2[3]
187
+                else:
188
+                    if szlist2[0] !='':
189
+                        curA[4] = szlist2[0]
190
+                    else:
191
+                        if szlist2[2] !='':
192
+                            curA[4] = szlist2[2]
193
+                cursorA.updateRow(curA) 
194
+            except:
195
+                pass
196
+            arcpy.AddMessage(zddm0 + ' OK')
197
+            
198
+
199
+def szsf(list1,poly1,opoly1):
200
+    szb = []
201
+    szd = []
202
+    szn = []
203
+    szx = []
204
+    listsz = []
205
+    ii = 0
206
+    ceny = (opoly1.extent.YMax + opoly1.extent.YMin)/2
207
+    cenx = (opoly1.extent.XMax + opoly1.extent.XMin)/2
208
+    while ii < len(list1):
209
+        shp1 = list1[ii][0]
210
+        #获取焦点做垂线计算角度
211
+        try:
212
+            pts = poly1.intersect(shp1, 1)
213
+            #不管有多少个点,直接求平均值
214
+            sumx = 0
215
+            sumy = 0
216
+            kk = 0
217
+            for pt in pts:
218
+                ptx = pt.X
219
+                pty = pt.Y
220
+                sumx = sumx + ptx
221
+                sumy = sumy + pty
222
+                kk = kk + 1
223
+            pjx = sumx / kk
224
+            pjy = sumy / kk
225
+            #计算角度
226
+            ang1 = math.atan2((pjy-ceny), (pjx-cenx))
227
+            angle1 = ang1/math.pi*180
228
+            if angle1 >45 and angle1 < 135:
229
+                slist = []
230
+                #存角度、宗地代码
231
+                slist.append(angle1)
232
+                slist.append(list1[ii][1])
233
+                slist.append(list1[ii][2])
234
+                szb.append(slist)
235
+            if angle1 < 45 and angle1 > -45:
236
+                slist = []
237
+                #存角度、宗地代码
238
+                slist.append(angle1)
239
+                slist.append(list1[ii][1])
240
+                slist.append(list1[ii][2])
241
+                szd.append(slist)
242
+            if angle1 > -135 and angle1 < -45:
243
+                slist = []
244
+                #存角度、宗地代码
245
+                slist.append(angle1)
246
+                slist.append(list1[ii][1])
247
+                slist.append(list1[ii][2])
248
+                szn.append(slist)
249
+            if angle1 < -135 or angle1 > 135:
250
+                slist = []
251
+                #存角度、宗地代码
252
+                slist.append(angle1)
253
+                slist.append(list1[ii][1])
254
+                slist.append(list1[ii][2])
255
+                szx.append(slist)
256
+        except:
257
+            pass
258
+        ii = ii + 1
259
+    #角度,宗地代码,权利人
260
+    if len(szb) == 0:
261
+        listsz.append('')
262
+    elif len(szb) == 1:
263
+        jestr = szb[0][2] + '(' + szb[0][1] + ')'
264
+        listsz.append(jestr)
265
+    else:
266
+        #排序,找出最正的那个
267
+        ii1 = 0
268
+        list2 = []
269
+        while ii1 < len(szb):
270
+            ang2 = abs(szb[ii1][0])
271
+            #宗地编号
272
+            zdstr = szb[ii1][1]
273
+            cz = abs(ang2 - 90)
274
+            slist2 = []
275
+            slist2.append(cz)
276
+            slist2.append(zdstr)
277
+            #权利人
278
+            slist2.append(szb[ii1][2])
279
+            list2.append(slist2)
280
+            ii1 = ii1 + 1
281
+        list2.sort(key=takefir,reverse=True)
282
+        jestr = list2[0][2] + '(' + list2[0][1] + ')'
283
+        listsz.append(jestr)
284
+    if len(szd) == 0:
285
+        listsz.append('')
286
+    elif len(szd) == 1:
287
+        jestr = szd[0][2] + '(' + szd[0][1] + ')'
288
+        listsz.append(jestr)
289
+    else:
290
+        #排序,找出最正的那个
291
+        ii1 = 0
292
+        list2 = []
293
+        while ii1 < len(szd):
294
+            ang2 = abs(szd[ii1][0])
295
+            #宗地编号
296
+            zdstr = szd[ii1][1]
297
+            cz = abs(ang2)
298
+            slist2 = []
299
+            slist2.append(cz)
300
+            slist2.append(zdstr)
301
+            #权利人
302
+            slist2.append(szd[ii1][2])
303
+            list2.append(slist2)
304
+            ii1 = ii1 + 1
305
+        list2.sort(key=takefir,reverse=True)
306
+        jestr = list2[0][2] + '(' + list2[0][1] + ')'
307
+        listsz.append(jestr)
308
+    if len(szn) == 0:
309
+        listsz.append('')
310
+    elif len(szn) == 1:
311
+        jestr = szn[0][2] + '(' + szn[0][1] + ')'
312
+        listsz.append(jestr)
313
+    else:
314
+        #排序,找出最正的那个
315
+        ii1 = 0
316
+        list2 = []
317
+        while ii1 < len(szn):
318
+            ang2 = abs(szn[ii1][0])
319
+            #宗地编号
320
+            zdstr = szn[ii1][1]
321
+            cz = abs(ang2 + 90)
322
+            slist2 = []
323
+            slist2.append(cz)
324
+            slist2.append(zdstr)
325
+            #权利人
326
+            slist2.append(szn[ii1][2])
327
+            list2.append(slist2)
328
+            ii1 = ii1 + 1
329
+        list2.sort(key=takefir,reverse=True)
330
+        jestr = list2[0][2] + '(' + list2[0][1] + ')'
331
+        listsz.append(jestr)
332
+    if len(szx) == 0:
333
+        listsz.append('')
334
+    elif len(szx) == 1:
335
+        jestr = szx[0][2] + '(' + szx[0][1] + ')'
336
+        listsz.append(jestr)
337
+    else:
338
+        #排序,找出最正的那个
339
+        ii1 = 0
340
+        list2 = []
341
+        while ii1 < len(szx):
342
+            ang2 = abs(szx[ii1][0])
343
+            #宗地编号
344
+            zdstr = szx[ii1][1]
345
+            cz = 180 - abs(ang2)
346
+            slist2 = []
347
+            slist2.append(cz)
348
+            slist2.append(zdstr)
349
+            #权利人
350
+            slist2.append(szx[ii1][2])
351
+            list2.append(slist2)
352
+            ii1 = ii1 + 1
353
+        list2.sort(key=takefir,reverse=True)
354
+        jestr = list2[0][2] + '(' + list2[0][1] + ')'
355
+        listsz.append(jestr)
356
+    return listsz
357
+
358
+def szsf1(list1,poly1,list0,opoly1):
359
+    szb = []
360
+    szd = []
361
+    szn = []
362
+    szx = []
363
+    listsz = []
364
+    ii = 0
365
+    ceny = (opoly1.extent.YMax + opoly1.extent.YMin)/2
366
+    cenx = (opoly1.extent.XMax + opoly1.extent.XMin)/2
367
+    while ii < len(list1):
368
+        shp1 = list1[ii][0]
369
+        #获取焦点做垂线计算角度
370
+        try:
371
+            pts = poly1.intersect(shp1, 1)
372
+            #不管有多少个点,直接求平均值
373
+            sumx = 0
374
+            sumy = 0
375
+            kk = 0
376
+            for pt in pts:
377
+                ptx = pt.X
378
+                pty = pt.Y
379
+                sumx = sumx + ptx
380
+                sumy = sumy + pty
381
+                kk = kk + 1
382
+            pjx = sumx / kk
383
+            pjy = sumy / kk
384
+            #计算角度
385
+            ang1 = math.atan2((pjy-ceny), (pjx-cenx))
386
+            angle1 = ang1/math.pi*180
387
+            if angle1 >30 and angle1 < 150:
388
+                slist = []
389
+                #存角度、类型
390
+                slist.append(angle1)
391
+                slist.append(list1[ii][1])
392
+                szb.append(slist)
393
+            if angle1 < 60 and angle1 > -60:
394
+                slist = []
395
+                #存角度、宗地代码
396
+                slist.append(angle1)
397
+                slist.append(list1[ii][1])
398
+                szd.append(slist)
399
+            if angle1 > -150 and angle1 < -30:
400
+                slist = []
401
+                #存角度、宗地代码
402
+                slist.append(angle1)
403
+                slist.append(list1[ii][1])
404
+                szn.append(slist)
405
+            if angle1 < -120 or angle1 > 120:
406
+                slist = []
407
+                #存角度、宗地代码
408
+                slist.append(angle1)
409
+                slist.append(list1[ii][1])
410
+                szx.append(slist)
411
+        except:
412
+            pass
413
+        ii = ii + 1
414
+    #角度,地物类型
415
+    if list0[0] == '':
416
+        if len(szb) == 0:
417
+            listsz.append('')
418
+        elif len(szb) == 1:
419
+            jestr = szb[0][1]
420
+            listsz.append(jestr)
421
+        else:
422
+            #排序,找出最正的那个
423
+            ii1 = 0
424
+            list2 = []
425
+            while ii1 < len(szb):
426
+                ang2 = abs(szb[ii1][0])
427
+                #地物类型
428
+                zdstr = szb[ii1][1]
429
+                cz = abs(ang2 - 90)
430
+                slist2 = []
431
+                slist2.append(cz)
432
+                slist2.append(zdstr)
433
+                list2.append(slist2)
434
+                ii1 = ii1 + 1
435
+            list2.sort(key=takefir,reverse=True)
436
+            jestr = list2[0][1]
437
+            listsz.append(jestr)
438
+    else:
439
+        listsz.append(list0[0])
440
+    if list0[1] == '':
441
+        if len(szd) == 0:
442
+            listsz.append('')
443
+        elif len(szd) == 1:
444
+            jestr = szd[0][1]
445
+            listsz.append(jestr)
446
+        else:
447
+            #排序,找出最正的那个
448
+            ii1 = 0
449
+            list2 = []
450
+            while ii1 < len(szd):
451
+                ang2 = abs(szd[ii1][0])
452
+                #地物类型
453
+                zdstr = szd[ii1][1]
454
+                cz = abs(ang2)
455
+                slist2 = []
456
+                slist2.append(cz)
457
+                slist2.append(zdstr)
458
+                list2.append(slist2)
459
+                ii1 = ii1 + 1
460
+            list2.sort(key=takefir,reverse=True)
461
+            jestr = list2[0][1]
462
+            listsz.append(jestr)
463
+    else:
464
+        listsz.append(list0[1])
465
+    if list0[2] == '':
466
+        if len(szn) == 0:
467
+            listsz.append('')
468
+        elif len(szn) == 1:
469
+            jestr = szn[0][1]
470
+            listsz.append(jestr)
471
+        else:
472
+            #排序,找出最正的那个
473
+            ii1 = 0
474
+            list2 = []
475
+            while ii1 < len(szn):
476
+                ang2 = abs(szn[ii1][0])
477
+                #地物类型
478
+                zdstr = szn[ii1][1]
479
+                cz = abs(ang2 + 90)
480
+                slist2 = []
481
+                slist2.append(cz)
482
+                slist2.append(zdstr)
483
+                list2.append(slist2)
484
+                ii1 = ii1 + 1
485
+            list2.sort(key=takefir,reverse=True)
486
+            jestr = list2[0][1]
487
+            listsz.append(jestr)
488
+    else:
489
+        listsz.append(list0[2])
490
+    if list0[3] == '':
491
+        if len(szx) == 0:
492
+            listsz.append('')
493
+        elif len(szx) == 1:
494
+            jestr = szx[0][1]
495
+            listsz.append(jestr)
496
+        else:
497
+            #排序,找出最正的那个
498
+            ii1 = 0
499
+            list2 = []
500
+            while ii1 < len(szx):
501
+                ang2 = abs(szx[ii1][0])
502
+                #地物类型
503
+                zdstr = szx[ii1][1]
504
+                cz = 180 - abs(ang2)
505
+                slist2 = []
506
+                slist2.append(cz)
507
+                slist2.append(zdstr)
508
+                list2.append(slist2)
509
+                ii1 = ii1 + 1
510
+            list2.sort(key=takefir,reverse=True)
511
+            jestr = list2[0][1]
512
+            listsz.append(jestr)
513
+    else:
514
+        listsz.append(list0[3])
515
+    return listsz
516
+
517
+
518
+def takefir(elem):
519
+    return elem[0]
520
+
521
+if __name__ == '__main__':
522
+    try:
523
+        #根据需求设计4个选项,宗地1,宗地2,图斑,路,房(这个待定)
524
+        # 输入宗地shp(记得复制),图斑shp(没有就不管)
525
+        SZpoly(arcpy.GetParameterAsText(0),arcpy.GetParameterAsText(1),arcpy.GetParameterAsText(2),arcpy.GetParameterAsText(3),arcpy.GetParameterAsText(4))
526
+    except arcpy.ExecuteError:
527
+        arcpy.AddMessage(arcpy.GetMessages())

+ 70
- 0
代码/20221220林权/LQ/TFpolygon1129.py 查看文件

@@ -0,0 +1,70 @@
1
+from asyncore import write
2
+import arcpy
3
+
4
+def TFtoTB(tbshp,tfshp,outfilepath):
5
+    outpath = outfilepath + '\\TF.txt'
6
+    #加载
7
+    arcpy.MakeFeatureLayer_management(tbshp, 'TB')
8
+    arcpy.MakeFeatureLayer_management(tfshp, 'TF')
9
+    with open(outpath,'w') as f:
10
+        with arcpy.da.SearchCursor('TB',['SHAPE@','宗地编码']) as cursorA:
11
+            for curA in cursorA:
12
+                list1 = []
13
+                shape1 = curA[0]
14
+                zdh = curA[1]
15
+                #相交,包含,被包含
16
+                arcpy.SelectLayerByLocation_management('TF',"INTERSECT",shape1)
17
+                ma1 = int(arcpy.GetCount_management('TF').getOutput(0)) 
18
+                if ma1 != 0:
19
+                    with arcpy.da.SearchCursor('TF',['TFH']) as cursorB:
20
+                        for curB in cursorB:
21
+                            tfh1 = str(curB[0])
22
+                            list1.append(tfh1)
23
+                arcpy.SelectLayerByLocation_management('TF',"WITHIN",shape1)
24
+                ma2 = int(arcpy.GetCount_management('TF').getOutput(0)) 
25
+                if ma2 != 0:
26
+                    with arcpy.da.SearchCursor('TF',['TFH']) as cursorC:
27
+                        for curC in cursorC:
28
+                            tfh2 = str(curC[0])
29
+                            list1.append(tfh2)
30
+                arcpy.SelectLayerByLocation_management('TF',"COMPLETELY_CONTAINS",shape1)
31
+                ma3 = int(arcpy.GetCount_management('TF').getOutput(0)) 
32
+                if ma3 != 0:
33
+                    with arcpy.da.SearchCursor('TF',['TFH']) as cursorD:
34
+                        for curD in cursorD:
35
+                            tfh3 = str(curD[0])
36
+                            list1.append(tfh3)
37
+                if list1 == []:
38
+                    pass
39
+                else:
40
+                    f.write(zdh)
41
+                    f.write(':')
42
+                    ii = 0
43
+                    list2 = []
44
+                    while ii < len(list1):
45
+                        if list1[ii] in list2:
46
+                            pass
47
+                        else:
48
+                            if ii == 0:
49
+                                f.write(list1[ii])
50
+                                list2.append(list1[ii])
51
+                            else:
52
+                                f.write(',')
53
+                                f.write(list1[ii])
54
+                                list2.append(list1[ii])  
55
+                        ii = ii + 1
56
+                    f.write('\n')
57
+                    f.flush()
58
+                print('ok')
59
+                arcpy.AddMessage ('ok')
60
+
61
+
62
+
63
+if __name__ == '__main__':
64
+    try:
65
+        #输入shp,图幅shp,输出文件夹
66
+        TFtoTB(arcpy.GetParameterAsText(0),arcpy.GetParameterAsText(1),arcpy.GetParameterAsText(2))
67
+    except arcpy.ExecuteError:
68
+        arcpy.AddMessage (arcpy.GetMessages())
69
+
70
+

+ 553
- 0
代码/20221220林权/LQ/ZDT/JZDpoint1128.py 查看文件

@@ -0,0 +1,553 @@
1
+import arcpy
2
+import math
3
+
4
+def JZpointmake(inpath, outfileshp):
5
+    # region [读取shp]
6
+    shpstr = 'JZD1.shp'
7
+    outpath = outfileshp + '\\' + 'JZD1.shp'
8
+    try:
9
+        arcpy.CreateFeatureclass_management(outfileshp, shpstr, 'POINT')
10
+    except:
11
+        arcpy.Delete_management(outpath)
12
+        arcpy.CreateFeatureclass_management(outfileshp, shpstr, 'POINT')
13
+    # 加载
14
+    arcpy.MakeFeatureLayer_management(inpath, 'LB')
15
+    arcpy.MakeFeatureLayer_management(outpath, 'JZD')
16
+    sr = arcpy.Describe('LB').spatialReference
17
+    # 添加一群字段
18
+    arcpy.AddField_management('JZD', '标识码', 'LONG')
19
+    arcpy.AddField_management('JZD', 'YSDM', 'TEXT')
20
+    arcpy.AddField_management('JZD', 'JZDH', 'TEXT')
21
+    arcpy.AddField_management('JZD', 'JBLX', 'TEXT')
22
+    arcpy.AddField_management('JZD', 'JZDLX', 'TEXT')
23
+    arcpy.AddField_management('JZD', 'ZDBH', 'TEXT')
24
+    arcpy.AddField_management('JZD', '顺序号', 'LONG')
25
+    arcpy.AddField_management('JZD', 'flag', 'LONG')
26
+    #float按理说应该符合的
27
+    bsm = 0
28
+    field1 = ['SHAPE@', '标识码', 'YSDM', 'JZDH', 'JBLX',
29
+              'JZDLX',  'ZDBH', '顺序号','flag']
30
+    # endregion
31
+    with arcpy.da.InsertCursor('JZD', field1) as cursorZ:
32
+        with arcpy.da.SearchCursor('LB', ['SHAPE@', '宗地编号']) as cursorA:
33
+            for curA in cursorA:
34
+                # region [读折点]
35
+                poly1 = curA[0]
36
+                zdbh = curA[1]
37
+                if zdbh == None or zdbh == '' or zdbh == ' ':
38
+                    pass
39
+                else:
40
+                    # 获取折点
41
+                    points = poly1.getPart()
42
+                    pt = points[0]
43
+                    mm = 0
44
+                    linelist = []  
45
+                    indexp = 0
46
+                    #存的都是点
47
+                    while mm < pt.count:
48
+                        jzd = pt[mm]
49
+                        try:
50
+                            xx = round(jzd.X,4)
51
+                            yy = round(jzd.Y,4)
52
+                            if mm == 0 or mm == indexp:
53
+                                xx0 = xx
54
+                                yy0 = yy
55
+                                slist = []
56
+                                slist.append(pt[mm]) 
57
+                            else:
58
+                                numdis0 = xx - xx0
59
+                                numdis1 = yy - yy0 
60
+                                numdis = math.sqrt((numdis0 * numdis0)+(numdis1*numdis1))
61
+                                if xx == xx0 and yy == yy0:
62
+                                    #一个的结束
63
+                                    indexp = mm + 1
64
+                                    linelist.append(slist)  
65
+                                if numdis < 0.1:
66
+                                    pass
67
+                                else:
68
+                                    slist.append(pt[mm]) 
69
+                            mm = mm + 1
70
+                        except:
71
+                            if mm == indexp:
72
+                                indexp = mm + 1
73
+                                mm = mm + 1 
74
+                    llen = len(linelist)
75
+                    #判断下如果多环,排个序
76
+                    linelist1 = pdlen(linelist)
77
+                    linelist = linelist1
78
+                    # endregion
79
+                    #甭管有没有环,都是第一个来处理
80
+                    ln1 = linelist[0]
81
+                    list1 = []
82
+                    nn1 = 0
83
+                    while nn1 < len(ln1):
84
+                        if nn1 == len(ln1) - 1:
85
+                            fpx = round(ln1[nn1].X,4)
86
+                            fpy = round(ln1[nn1].Y,4)
87
+                            lpx = round(ln1[0].X,4)
88
+                            lpy = round(ln1[0].Y,4)
89
+                            fpoint = arcpy.Point(fpx, fpy)
90
+                            lpoint = arcpy.Point(lpx, lpy)
91
+                        else:
92
+                            fpx = round(ln1[nn1].X,4)
93
+                            fpy = round(ln1[nn1].Y,4)
94
+                            lpx = round(ln1[nn1 + 1].X,4)
95
+                            lpy = round(ln1[nn1 + 1].Y,4)
96
+                            fpoint = arcpy.Point(fpx, fpy)
97
+                            lpoint = arcpy.Point(lpx, lpy)
98
+                        new_array = arcpy.Array()
99
+                        new_array.append(fpoint)
100
+                        new_array.append(lpoint)
101
+                        ln2 = arcpy.Polyline(new_array,sr)
102
+                        #先把起始点加进去
103
+                        bl1 = addpoint(list1,fpoint)
104
+                        if bl1 == 1:
105
+                            list1.append(fpoint)
106
+                        
107
+                            # list1.append(lpoint)
108
+                        #插入点
109
+                        arcpy.SelectLayerByLocation_management('LB','INTERSECT',ln2)
110
+                        count0 = int(arcpy.GetCount_management('LB').getOutput(0)) 
111
+                        if count0 < 2:
112
+                            bl4 = addpoint(list1,lpoint)
113
+                            if bl4 == 1:
114
+                                list1.append(lpoint)
115
+                            nn1 = nn1 + 1
116
+                        else:
117
+                            #对于同一个线段来说,把所有点的位置准确点
118
+                            listp1 = []
119
+                            with arcpy.da.SearchCursor('LB', ['SHAPE@', '宗地编号']) as cursorB:
120
+                                for curB in cursorB:
121
+                                    zdbh1 = curB[1]
122
+                                    #排除自己
123
+                                    if zdbh1 == zdbh:
124
+                                        pass
125
+                                    else:
126
+                                        try:
127
+                                            shpB = curB[0]
128
+                                            lineB = shpB.boundary ()
129
+                                            rln = lineB.intersect (ln2, 2)
130
+                                            fpoint1 = rln.firstPoint
131
+                                            lpoint1 = rln.lastPoint
132
+                                            fx = round(fpoint1.X,4)
133
+                                            fy = round(fpoint1.Y,4)
134
+                                            lx = round(lpoint1.X,4)
135
+                                            ly = round(lpoint1.Y,4)
136
+                                            #判断这两个点是否都在里面
137
+                                            fp = arcpy.Point(fx, fy)
138
+                                            lp = arcpy.Point(lx, ly)
139
+                                            list2 = []
140
+                                            bl1 = addpoint(list1,fp)
141
+                                            if bl1 == 1:
142
+                                                #判断与起点的距离
143
+                                                dis1 = math.sqrt(((fpx - fx)*(fpx - fx)) + ((fpy-fy)*(fpy-fy)))
144
+                                                slist2 = []
145
+                                                slist2.append(dis1)
146
+                                                slist2.append(fp)
147
+                                                list2.append(slist2)
148
+                                            bl1 = addpoint(list1,lp)
149
+                                            if bl1 == 1:
150
+                                                dis1 = math.sqrt(((fpx - lx)*(fpx - lx)) + ((fpy-ly)*(fpy-ly)))
151
+                                                slist2 = []
152
+                                                slist2.append(dis1)
153
+                                                slist2.append(lp)
154
+                                                list2.append(slist2)
155
+                                            if len(list2) == 1:
156
+                                                listp1.append(list2[0][1])
157
+                                            elif len(list2) == 2:
158
+                                                #对2排序
159
+                                                if list2[0][0] < list2[1][0]:
160
+                                                    listp1.append(list2[0][1])
161
+                                                    listp1.append(list2[1][1])
162
+                                                else:
163
+                                                    listp1.append(list2[1][1])
164
+                                                    listp1.append(list2[0][1])
165
+                                        except:
166
+                                            pass
167
+                            #得到所有的点,进行一个与起点的排序
168
+                            nn2 = 0
169
+                            listp2 =[]
170
+                            while nn2 < len(listp1):
171
+                                num0 = fpx - listp1[nn2].X
172
+                                num1 = fpy - listp1[nn2].Y
173
+                                dis2 = math.sqrt((num0*num0)+(num1*num1))
174
+                                slistp2 = []
175
+                                slistp2.append(dis2)
176
+                                slistp2.append(listp1[nn2])
177
+                                listp2.append(slistp2)
178
+                                nn2 = nn2 + 1
179
+                            listp2.sort()
180
+                            nn3 = 0
181
+                            bl3 = 0
182
+                            while nn3 < len(listp2):
183
+                                #这里要看下要不要除重
184
+                                bl3 = addpoint(list1,listp2[nn3][1])
185
+                                if bl3 == 1:
186
+                                    list1.append(listp2[nn3][1])
187
+                                nn3 = nn3 + 1  
188
+                            bl4 = addpoint(list1,lpoint)
189
+                            if bl4 == 1:
190
+                                list1.append(lpoint)
191
+                        nn1 = nn1 + 1
192
+                    
193
+                    if len(linelist) == 1:
194
+                        listF = linezd(list1,poly1)
195
+                        #直接写
196
+                        ii = 0
197
+                        zdh = 0
198
+                        while ii < len(listF):
199
+                            if ii == 0:
200
+                                zdh = zdh + 1
201
+                                bsm = bsm + 1
202
+                                # shape
203
+                                point1 = arcpy.Point(listF[ii][0], listF[ii][1])
204
+                                # 要素代码
205
+                                ysdm = '6002010300'
206
+                                # 顺序号
207
+                                sxh = ii + 1
208
+                                # 界址点号
209
+                                jzdh = 'J' + str(zdh)
210
+                                # 宗地代码
211
+                                zddm = curA[1]
212
+                                rlist = []
213
+                                rlist.append(point1)
214
+                                rlist.append(bsm)
215
+                                rlist.append(ysdm)
216
+                                rlist.append(jzdh)
217
+                                rlist.append('')
218
+                                rlist.append('')
219
+                                rlist.append(zddm)
220
+                                rlist.append(zdh)
221
+                                rlist.append(1)
222
+                                cursorZ.insertRow(rlist)
223
+                            else:
224
+                                numdis0 = listF[ii][0] - listF[ii - 1][0]
225
+                                numdis1 = listF[ii][1] - listF[ii - 1][1]
226
+                                numdis2 = math.sqrt((numdis0 * numdis0)+(numdis1*numdis1))
227
+                                if numdis2 < 0.1:
228
+                                    pass
229
+                                else:
230
+                                    zdh = zdh + 1
231
+                                    bsm = bsm + 1
232
+                                    # shape
233
+                                    point1 = arcpy.Point(listF[ii][0], listF[ii][1])
234
+                                    # 要素代码
235
+                                    ysdm = '6002010300'
236
+                                    # 顺序号
237
+                                    sxh = ii + 1
238
+                                    # 界址点号
239
+                                    jzdh = 'J' + str(zdh)
240
+                                    # 宗地代码
241
+                                    zddm = curA[1]
242
+                                    rlist = []
243
+                                    rlist.append(point1)
244
+                                    rlist.append(bsm)
245
+                                    rlist.append(ysdm)
246
+                                    rlist.append(jzdh)
247
+                                    rlist.append('')
248
+                                    rlist.append('')
249
+                                    rlist.append(zddm)
250
+                                    rlist.append(zdh)
251
+                                    rlist.append(1)
252
+                                    cursorZ.insertRow(rlist)
253
+                            ii = ii + 1
254
+                    else:
255
+                        mm0 = 0
256
+                        zdh = 0
257
+                        while mm0 < len(linelist):
258
+                            if mm0 == 0:
259
+                                listF = linezd(list1,poly1)
260
+                                ii = 0
261
+                                while ii < len(listF):
262
+                                    if ii == 0:
263
+                                        zdh = zdh + 1
264
+                                        bsm = bsm + 1
265
+                                        # shape
266
+                                        point1 = arcpy.Point(listF[ii][0], listF[ii][1])
267
+                                        # 要素代码
268
+                                        ysdm = '6002010300'
269
+                                        # 顺序号
270
+                                        sxh = ii + 1
271
+                                        # 界址点号
272
+                                        jzdh = 'J' + str(zdh)
273
+                                        # 宗地代码
274
+                                        zddm = curA[1]
275
+                                        rlist = []
276
+                                        rlist.append(point1)
277
+                                        rlist.append(bsm)
278
+                                        rlist.append(ysdm)
279
+                                        rlist.append(jzdh)
280
+                                        rlist.append('')
281
+                                        rlist.append('')
282
+                                        rlist.append(zddm)
283
+                                        rlist.append(zdh)
284
+                                        rlist.append(mm0+1)
285
+                                        cursorZ.insertRow(rlist)
286
+                                    else:
287
+                                        numdis0 = listF[ii][0] - listF[ii - 1][0]
288
+                                        numdis1 = listF[ii][1] - listF[ii - 1][1]
289
+                                        numdis2 = math.sqrt((numdis0 * numdis0)+(numdis1*numdis1))
290
+                                        if numdis2 < 0.1:
291
+                                            pass
292
+                                        else:
293
+                                            zdh = zdh + 1
294
+                                            bsm = bsm + 1
295
+                                            # shape
296
+                                            point1 = arcpy.Point(listF[ii][0], listF[ii][1])
297
+                                            # 要素代码
298
+                                            ysdm = '6002010300'
299
+                                            # 顺序号
300
+                                            sxh = ii + 1
301
+                                            # 界址点号
302
+                                            jzdh = 'J' + str(zdh)
303
+                                            # 宗地代码
304
+                                            zddm = curA[1]
305
+                                            rlist = []
306
+                                            rlist.append(point1)
307
+                                            rlist.append(bsm)
308
+                                            rlist.append(ysdm)
309
+                                            rlist.append(jzdh)
310
+                                            rlist.append('')
311
+                                            rlist.append('')
312
+                                            rlist.append(zddm)
313
+                                            rlist.append(zdh)
314
+                                            rlist.append(mm0+1)
315
+                                            cursorZ.insertRow(rlist)
316
+                                    ii = ii + 1
317
+                            else:
318
+                                listF = linezd(linelist[mm0],poly1)
319
+                                ii = len(listF) - 1
320
+                                while ii >= 0:
321
+                                    if ii == len(listF) - 1:
322
+                                        zdh = zdh + 1
323
+                                        bsm = bsm + 1
324
+                                        # shape
325
+                                        point1 = arcpy.Point(listF[ii][0], listF[ii][1])
326
+                                        # 要素代码
327
+                                        ysdm = '6002010300'
328
+                                        # 顺序号
329
+                                        sxh = ii + 1
330
+                                        # 界址点号
331
+                                        jzdh = 'J' + str(zdh)
332
+                                        # 宗地代码
333
+                                        zddm = curA[1]
334
+                                        rlist = []
335
+                                        rlist.append(point1)
336
+                                        rlist.append(bsm)
337
+                                        rlist.append(ysdm)
338
+                                        rlist.append(jzdh)
339
+                                        rlist.append('')
340
+                                        rlist.append('')
341
+                                        rlist.append(zddm)
342
+                                        rlist.append(zdh)
343
+                                        rlist.append(mm0+1)
344
+                                        cursorZ.insertRow(rlist)
345
+                                    else:
346
+                                        numdis0 = listF[ii][0] - listF[ii - 1][0]
347
+                                        numdis1 = listF[ii][1] - listF[ii - 1][1]
348
+                                        numdis2 = math.sqrt((numdis0 * numdis0)+(numdis1*numdis1))
349
+                                        if numdis2 < 0.1:
350
+                                            pass
351
+                                        else:
352
+                                            zdh = zdh + 1
353
+                                            bsm = bsm + 1
354
+                                            # shape
355
+                                            point1 = arcpy.Point(listF[ii][0], listF[ii][1])
356
+                                            # 要素代码
357
+                                            ysdm = '6002010300'
358
+                                            # 顺序号
359
+                                            sxh = ii + 1
360
+                                            # 界址点号
361
+                                            jzdh = 'J' + str(zdh)
362
+                                            # 宗地代码
363
+                                            zddm = curA[1]
364
+                                            rlist = []
365
+                                            rlist.append(point1)
366
+                                            rlist.append(bsm)
367
+                                            rlist.append(ysdm)
368
+                                            rlist.append(jzdh)
369
+                                            rlist.append('')
370
+                                            rlist.append('')
371
+                                            rlist.append(zddm)
372
+                                            rlist.append(zdh)
373
+                                            rlist.append(mm0+1)
374
+                                            cursorZ.insertRow(rlist)
375
+                                    ii = ii - 1
376
+                            mm0 = mm0 + 1
377
+                    arcpy.AddMessage(zdbh + ' FINISH')
378
+
379
+def pdlen(list1):
380
+    ii = 0
381
+    list2 = []
382
+    while ii < len(list1):
383
+        pts = list1[ii]
384
+        length1 = 0
385
+        mm = 0
386
+        while mm < len(pts):
387
+            if mm == len(pts) - 1:
388
+                pt1 = pts[mm]
389
+                pt2 = pts[0]
390
+                dis1 = math.sqrt(((pt1.X-pt2.X)*(pt1.X-pt2.X))+((pt1.Y-pt2.Y)*(pt1.Y-pt2.Y)))
391
+                length1 = length1 + dis1
392
+                mm = mm + 1
393
+            else:
394
+                pt1 = pts[mm]
395
+                pt2 = pts[mm + 1]
396
+                dis1 = math.sqrt(((pt1.X-pt2.X)*(pt1.X-pt2.X))+((pt1.Y-pt2.Y)*(pt1.Y-pt2.Y)))
397
+                length1 = length1 + dis1
398
+                mm = mm + 1
399
+        slist2 = []
400
+        slist2.append(length1)
401
+        slist2.append(pts)
402
+        list2.append(slist2)
403
+        ii = ii + 1
404
+    list2.sort(reverse=True)
405
+    nn = 0
406
+    list3 = []
407
+    while nn < len(list2):
408
+        list3.append(list2[nn][1])
409
+        nn = nn + 1
410
+    return list3
411
+
412
+
413
+
414
+
415
+def addpoint(list1,pt):
416
+    ptx = round(pt.X,4)
417
+    pty = round(pt.Y,4)
418
+    ii = 0
419
+    bl = 1
420
+    while ii < len(list1):
421
+        if ptx == round(list1[ii].X,4) and pty == round(list1[ii].Y,4):
422
+            bl = -1
423
+        ii = ii + 1
424
+    return bl
425
+
426
+def linezd(line1,poly):
427
+    # 获取折点
428
+    mm = 0
429
+    pp = 0
430
+    list1 = []
431
+    while mm < len(line1):
432
+        plist = []
433
+        jzd = line1[mm]
434
+        try:
435
+            xx = jzd.X
436
+            yy = jzd.Y
437
+            plist.append(xx)
438
+            plist.append(yy)
439
+            # 初始顺序
440
+            plist.append(pp)
441
+            list1.append(plist)
442
+            pp = pp + 1
443
+            mm = mm + 1
444
+        except:
445
+            mm = mm + 1 
446
+    # 对折点排序(算法)
447
+    if len(list1) < 3:
448
+        listF = []
449
+    else:
450
+        # listF = zdsort(list1, zx)
451
+        listF = jzdsort(list1,poly)
452
+    return listF
453
+
454
+def jzdsort(list0,poly):
455
+    m = 0
456
+    n = 0
457
+    northwest = []
458
+    northwest.append(poly.extent.XMin)
459
+    northwest.append(poly.extent.YMax)
460
+    minDis = (northwest[1] - list0[0][1])*(northwest[1] - list0[0][1]) + (northwest[0] - list0[0][0])*(northwest[0] - list0[0][0])
461
+    maxStdangle = cal_stdangle(northwest,list0[0])
462
+    while m < len(list0):        
463
+        Dis = (northwest[1] - list0[m][1])*(northwest[1] - list0[m][1]) + (northwest[0] - list0[m][0])*(northwest[0] - list0[m][0])
464
+        if Dis < minDis:
465
+            minDis = Dis
466
+            maxStdangle = cal_stdangle(northwest,list0[m])
467
+            n = m
468
+        if abs(Dis-minDis) < 0.000001:
469
+            stdangle = cal_stdangle(northwest,list0[m])
470
+            if stdangle > maxStdangle:
471
+                maxStdangle = stdangle
472
+                n = m 
473
+        m = m + 1
474
+    i = 0
475
+    while i < len(list0):    
476
+        if n == 0:
477
+            vectangleN = cal_stdangle(list0[0], list0[1])
478
+            vectangleNl = cal_stdangle(list0[len(list0)-1], list0[0]) 
479
+            if abs(vectangleN-vectangleNl) < 3:
480
+                n = len(list0)-1          
481
+        else:
482
+            if n == len(list0)-1:
483
+                vectangleN = cal_stdangle(list0[n], list0[0])
484
+            else:            
485
+                vectangleN = cal_stdangle(list0[n], list0[n+1]) 
486
+            vectangleNl = cal_stdangle(list0[n-1], list0[n])    
487
+            if abs(vectangleN-vectangleNl) < 3:
488
+                n = n-1
489
+        i = i + 1
490
+    list4 = []     
491
+    a = n     
492
+    num = 0
493
+    while a < len(list0):
494
+        slist4 = []
495
+        num = num + 1
496
+        slist4.append(list0[a][0])
497
+        slist4.append(list0[a][1])
498
+        slist4.append(num)
499
+        list4.append(slist4)   
500
+        a = a + 1    
501
+    a = 0
502
+    while a < n:
503
+        slist4 = []
504
+        num = num + 1
505
+        slist4.append(list0[a][0])
506
+        slist4.append(list0[a][1])
507
+        slist4.append(num)
508
+        list4.append(slist4)   
509
+        a = a + 1
510
+    return list4
511
+
512
+
513
+def cal_stdangle(lastp,p): 
514
+    stdangle=0
515
+    dy= p[1]-lastp[1]
516
+    dx= p[0]-lastp[0]
517
+    if dx==0 and dy>0:
518
+        stdangle = 0
519
+    if dx==0 and dy<0:
520
+        stdangle = 180
521
+    if dy==0 and dx>0:
522
+        stdangle = 90
523
+    if dy==0 and dx<0:
524
+        stdangle = 270
525
+    if dx>0 and dy>0:
526
+       stdangle = math.atan(dx/dy)*180/math.pi
527
+    elif dx<0 and dy>0:
528
+       stdangle = 360 + math.atan(dx/dy)*180/math.pi
529
+    elif dx<0 and dy<0:
530
+       stdangle = 180 + math.atan(dx/dy)*180/math.pi
531
+    elif dx>0 and dy<0:
532
+       stdangle = 180 + math.atan(dx/dy)*180/math.pi
533
+    return stdangle
534
+    
535
+def calcangle(lastp,p): 
536
+    angle=0
537
+    stdangle = cal_stdangle(lastp,p)
538
+    if (stdangle < 45 and stdangle >= 0) or (stdangle <= 360 and stdangle >= 315):
539
+        angle = 270
540
+    if (stdangle < 135 and stdangle >= 45):
541
+        angle = 0
542
+    if (stdangle < 225 and stdangle >= 135):
543
+        angle = 90
544
+    if (stdangle < 315 and stdangle >= 225):
545
+        angle = 180
546
+    return angle
547
+
548
+if __name__ == '__main__':
549
+    try:
550
+        # 输入shp,输出界址点文件夹
551
+        JZpointmake(r'D:\2work_now\20221026LQ\1231\Export_Output.shp',r'D:\2work_now\20221026LQ\1231\JZD')
552
+    except arcpy.ExecuteError:
553
+        arcpy.AddMessage(arcpy.GetMessages())

+ 948
- 0
代码/20221220林权/LQ/ZDT/exportZDT_Batch.py 查看文件

@@ -0,0 +1,948 @@
1
+# -*- coding: utf-8 -*-
2
+from cmath import e
3
+import os
4
+from re import L
5
+import arcpy
6
+import pythonaddins
7
+import math
8
+from multiprocessing import Process
9
+import random
10
+import fnmatch
11
+import time
12
+
13
+def TFtoTB(shape, elem):
14
+    list1 = []
15
+    # 相交,包含,被包含            
16
+    arcpy.SelectLayerByLocation_management('TF', "INTERSECT", shape)
17
+    ma1 = int(arcpy.GetCount_management('TF').getOutput(0))
18
+    if ma1 != 0:
19
+        with arcpy.da.SearchCursor('TF', ['TFH1']) as cursorB:
20
+            for curB in cursorB:
21
+                tfh1 = str(curB[0])
22
+                if list1.__contains__(tfh1):
23
+                    pass
24
+                else:
25
+                    list1.append(tfh1)
26
+    arcpy.SelectLayerByLocation_management('TF', "WITHIN", shape)
27
+    ma2 = int(arcpy.GetCount_management('TF').getOutput(0))
28
+    if ma2 != 0:
29
+        with arcpy.da.SearchCursor('TF', ['TFH1']) as cursorC:
30
+            for curC in cursorC:
31
+                tfh2 = str(curC[0])
32
+                if list1.__contains__(tfh2):
33
+                    pass
34
+                else:
35
+                    list1.append(tfh2)
36
+    arcpy.SelectLayerByLocation_management('TF', "COMPLETELY_CONTAINS", shape)
37
+    ma3 = int(arcpy.GetCount_management('TF').getOutput(0))
38
+    if ma3 != 0:
39
+        with arcpy.da.SearchCursor('TF', ['TFH1']) as cursorD:
40
+            for curD in cursorD:
41
+                tfh3 = str(curD[0])
42
+                if list1.__contains__(tfh3):
43
+                    pass
44
+                else:
45
+                    list1.append(tfh3)
46
+    if list1 == []:
47
+        pass
48
+    else:
49
+        ii = 0
50
+        while ii < len(list1):
51
+            # tfh.append(list1[ii])
52
+            elem.text = elem.text + list1[ii]
53
+            if ii == (len(list1) - 1):
54
+                pass
55
+            elif ( ii + 1 ) % 2 == 0:
56
+                elem.text = elem.text + '\n'+ ' '
57
+            else:
58
+                elem.text = elem.text + ','
59
+            ii = ii + 1
60
+
61
+def JZGenerate(outfileshp, zdbh):
62
+# def JZGenerate(outfileshp):
63
+    shpstr = 'JZD.shp'
64
+    shpstr1 = 'JZX.shp'
65
+    outpath = outfileshp + '\\' + shpstr
66
+    outpath1 = outfileshp + '\\' + shpstr1
67
+    try:
68
+        arcpy.CreateFeatureclass_management(outfileshp, shpstr, 'POINT', spatial_reference=4523) #"4507"
69
+    except:
70
+        arcpy.Delete_management(outpath)
71
+        arcpy.CreateFeatureclass_management(outfileshp, shpstr, 'POINT', spatial_reference=4523)
72
+    try:
73
+        arcpy.CreateFeatureclass_management(outfileshp, shpstr1, 'POLYLINE', spatial_reference=4523)
74
+    except:
75
+        arcpy.Delete_management(outpath1)
76
+        arcpy.CreateFeatureclass_management(outfileshp, shpstr1, 'POLYLINE', spatial_reference=4523)
77
+    sr = arcpy.Describe(LayerObject.currentLayer).spatialReference
78
+    #  加载   
79
+    lyrjzd = arcpy.mapping.Layer(outpath)
80
+    arcpy.mapping.AddLayer(df, lyrjzd)  
81
+    lyrjzx = arcpy.mapping.Layer(outpath1)
82
+    arcpy.mapping.AddLayer(df, lyrjzx)
83
+    # 添加一群字段
84
+    arcpy.AddField_management('JZD', '标识码', 'LONG')
85
+    arcpy.AddField_management('JZD', 'YSDM', 'TEXT')
86
+    arcpy.AddField_management('JZD', 'JZDH', 'TEXT')
87
+    arcpy.AddField_management('JZD', 'JBLX', 'TEXT')
88
+    arcpy.AddField_management('JZD', 'JZDLX', 'TEXT')
89
+    arcpy.AddField_management('JZD', 'ZDBH', 'TEXT')
90
+    arcpy.AddField_management('JZD', '顺序号', 'LONG')
91
+    arcpy.AddField_management('JZD', 'flag', 'LONG')
92
+    arcpy.AddField_management('JZD', 'ANGLE', 'LONG')
93
+    #float按理说应该符合的
94
+    bsm = 0
95
+    field1 = ['SHAPE@', '标识码', 'YSDM', 'JZDH', 'JBLX',
96
+              'JZDLX',  'ZDBH', '顺序号','flag','ANGLE']
97
+    # endregion
98
+    with arcpy.da.InsertCursor('JZD', field1) as cursorZ:
99
+        with arcpy.da.SearchCursor(LayerObject.currentLayer, ['SHAPE@', '宗地编号']) as cursorA:
100
+            for curA in cursorA:
101
+                # region [读折点]
102
+                poly1 = curA[0]
103
+                zdbh = curA[1]
104
+                if zdbh == None or zdbh == '' or zdbh == ' ':
105
+                    pass
106
+                else:
107
+                    # 获取折点
108
+                    points = poly1.getPart()
109
+                    pt = points[0]
110
+                    mm = 0
111
+                    linelist = []  
112
+                    indexp = 0
113
+                    #存的都是点
114
+                    while mm < pt.count:
115
+                        jzd = pt[mm]
116
+                        try:
117
+                            xx = round(jzd.X,4)
118
+                            yy = round(jzd.Y,4)
119
+                            if mm == 0 or mm == indexp:
120
+                                xx0 = xx
121
+                                yy0 = yy
122
+                                slist = []
123
+                                slist.append(pt[mm]) 
124
+                            else:
125
+                                numdis0 = xx - xx0
126
+                                numdis1 = yy - yy0 
127
+                                numdis = math.sqrt((numdis0 * numdis0)+(numdis1*numdis1))
128
+                                if xx == xx0 and yy == yy0:
129
+                                    #一个的结束
130
+                                    indexp = mm + 1
131
+                                    linelist.append(slist)  
132
+                                if numdis < 0.1:
133
+                                    pass
134
+                                else:
135
+                                    slist.append(pt[mm]) 
136
+                            mm = mm + 1
137
+                        except:
138
+                            if mm == indexp:
139
+                                indexp = mm + 1
140
+                                mm = mm + 1 
141
+                    llen = len(linelist)
142
+                    #判断下如果多环,排个序
143
+                    linelist1 = pdlen(linelist)
144
+                    linelist = linelist1
145
+                    # endregion
146
+                    #甭管有没有环,都是第一个来处理
147
+                    ln1 = linelist[0]
148
+                    list1 = []
149
+                    nn1 = 0
150
+                    while nn1 < len(ln1):
151
+                        if nn1 == len(ln1) - 1:
152
+                            fpx = round(ln1[nn1].X,4)
153
+                            fpy = round(ln1[nn1].Y,4)
154
+                            lpx = round(ln1[0].X,4)
155
+                            lpy = round(ln1[0].Y,4)
156
+                            fpoint = arcpy.Point(fpx, fpy)
157
+                            lpoint = arcpy.Point(lpx, lpy)
158
+                        else:
159
+                            fpx = round(ln1[nn1].X,4)
160
+                            fpy = round(ln1[nn1].Y,4)
161
+                            lpx = round(ln1[nn1 + 1].X,4)
162
+                            lpy = round(ln1[nn1 + 1].Y,4)
163
+                            fpoint = arcpy.Point(fpx, fpy)
164
+                            lpoint = arcpy.Point(lpx, lpy)
165
+                        new_array = arcpy.Array()
166
+                        new_array.append(fpoint)
167
+                        new_array.append(lpoint)
168
+                        ln2 = arcpy.Polyline(new_array,sr)
169
+                        #先把起始点加进去
170
+                        bl1 = addpoint(list1,fpoint)
171
+                        if bl1 == 1:
172
+                            list1.append(fpoint)
173
+                            # list1.append(lpoint)
174
+                        #插入点
175
+                        arcpy.SelectLayerByLocation_management(LayerObject.currentLayer,'INTERSECT',ln2)
176
+                        count0 = int(arcpy.GetCount_management(LayerObject.currentLayer).getOutput(0)) 
177
+                        if count0 < 2:
178
+                            bl4 = addpoint(list1,lpoint)
179
+                            if bl4 == 1:
180
+                                list1.append(lpoint)
181
+                            nn1 = nn1 + 1
182
+                        else:
183
+                            #对于同一个线段来说,把所有点的位置准确点
184
+                            listp1 = []
185
+                            with arcpy.da.SearchCursor(LayerObject.currentLayer, ['SHAPE@', '宗地编号']) as cursorB:
186
+                                for curB in cursorB:
187
+                                    zdbh1 = curB[1]
188
+                                    #排除自己
189
+                                    if zdbh1 == zdbh:
190
+                                        pass
191
+                                    else:
192
+                                        try:
193
+                                            shpB = curB[0]
194
+                                            lineB = shpB.boundary ()
195
+                                            rln = lineB.intersect (ln2, 2)
196
+                                            fpoint1 = rln.firstPoint
197
+                                            lpoint1 = rln.lastPoint
198
+                                            fx = round(fpoint1.X,4)
199
+                                            fy = round(fpoint1.Y,4)
200
+                                            lx = round(lpoint1.X,4)
201
+                                            ly = round(lpoint1.Y,4)
202
+                                            #判断这两个点是否都在里面
203
+                                            fp = arcpy.Point(fx, fy)
204
+                                            lp = arcpy.Point(lx, ly)
205
+                                            list2 = []
206
+                                            bl1 = addpoint(list1,fp)
207
+                                            if bl1 == 1:
208
+                                                #判断与起点的距离
209
+                                                dis1 = math.sqrt(((fpx - fx)*(fpx - fx)) + ((fpy-fy)*(fpy-fy)))
210
+                                                slist2 = []
211
+                                                slist2.append(dis1)
212
+                                                slist2.append(fp)
213
+                                                list2.append(slist2)
214
+                                            bl1 = addpoint(list1,lp)
215
+                                            if bl1 == 1:
216
+                                                dis1 = math.sqrt(((fpx - lx)*(fpx - lx)) + ((fpy-ly)*(fpy-ly)))
217
+                                                slist2 = []
218
+                                                slist2.append(dis1)
219
+                                                slist2.append(lp)
220
+                                                list2.append(slist2)
221
+                                            if len(list2) == 1:
222
+                                                listp1.append(list2[0][1])
223
+                                            elif len(list2) == 2:
224
+                                                #对2排序
225
+                                                if list2[0][0] < list2[1][0]:
226
+                                                    listp1.append(list2[0][1])
227
+                                                    listp1.append(list2[1][1])
228
+                                                else:
229
+                                                    listp1.append(list2[1][1])
230
+                                                    listp1.append(list2[0][1])
231
+                                        except:
232
+                                            pass
233
+                            #得到所有的点,进行一个与起点的排序
234
+                            nn2 = 0
235
+                            listp2 =[]
236
+                            while nn2 < len(listp1):
237
+                                num0 = fpx - listp1[nn2].X
238
+                                num1 = fpy - listp1[nn2].Y
239
+                                dis2 = math.sqrt((num0*num0)+(num1*num1))
240
+                                slistp2 = []
241
+                                slistp2.append(dis2)
242
+                                slistp2.append(listp1[nn2])
243
+                                listp2.append(slistp2)
244
+                                nn2 = nn2 + 1
245
+                            listp2.sort()
246
+                            nn3 = 0
247
+                            bl3 = 0
248
+                            while nn3 < len(listp2):
249
+                                #这里要看下要不要除重
250
+                                bl3 = addpoint(list1,listp2[nn3][1])
251
+                                if bl3 == 1:
252
+                                    list1.append(listp2[nn3][1])
253
+                                nn3 = nn3 + 1  
254
+                            bl4 = addpoint(list1,lpoint)
255
+                            if bl4 == 1:
256
+                                list1.append(lpoint)
257
+                        nn1 = nn1 + 1
258
+                    
259
+                    with arcpy.da.InsertCursor('JZX',  ['SHAPE@']) as cursorY:
260
+                        if len(linelist) == 1:
261
+                            listF = linezd(list1,poly1)
262
+                            #直接写
263
+                            ii = 0
264
+                            zdh = 0
265
+                            while ii < len(listF):
266
+                                if ii == 0:
267
+                                    zdh = zdh + 1
268
+                                    bsm = bsm + 1
269
+                                    # shape
270
+                                    point1 = arcpy.Point(listF[ii][0], listF[ii][1])
271
+                                    # 要素代码
272
+                                    ysdm = '6002010300'
273
+                                    # 界址点号
274
+                                    jzdh = 'J' + str(zdh)
275
+                                    # 宗地代码
276
+                                    zddm = curA[1]
277
+                                    ag = calcangle(listF[ii-1],listF[ii])
278
+                                    rlist = []
279
+                                    rlist.append(point1)
280
+                                    rlist.append(bsm)
281
+                                    rlist.append(ysdm)
282
+                                    rlist.append(jzdh)
283
+                                    rlist.append('')
284
+                                    rlist.append('')
285
+                                    rlist.append(zddm)
286
+                                    rlist.append(zdh)
287
+                                    rlist.append(1)
288
+                                    rlist.append(ag)
289
+                                    cursorZ.insertRow(rlist)
290
+                                    point = arcpy.Point(listF[ii][0], listF[ii][1])                        
291
+                                    if ii == len(listF) - 1:
292
+                                        point0 = arcpy.Point(listF[0][0], listF[0][1])
293
+                                    else:
294
+                                        point0 = arcpy.Point(listF[ii+1][0], listF[ii+1][1])
295
+                                    array=arcpy.Array()
296
+                                    array.add(point)
297
+                                    array.add(point0)
298
+                                    pl=arcpy.Polyline(array)
299
+                                    cursorY.insertRow([pl])
300
+                                else:
301
+                                    numdis0 = listF[ii][0] - listF[ii - 1][0]
302
+                                    numdis1 = listF[ii][1] - listF[ii - 1][1]
303
+                                    numdis2 = math.sqrt((numdis0 * numdis0)+(numdis1*numdis1))
304
+                                    if numdis2 < 0.1:
305
+                                        pass
306
+                                    else:
307
+                                        zdh = zdh + 1
308
+                                        bsm = bsm + 1
309
+                                        # shape
310
+                                        point1 = arcpy.Point(listF[ii][0], listF[ii][1])
311
+                                        # 要素代码
312
+                                        ysdm = '6002010300'
313
+                                        # 界址点号
314
+                                        jzdh = 'J' + str(zdh)
315
+                                        # 宗地代码
316
+                                        zddm = curA[1]
317
+                                        ag = calcangle(listF[ii-1],listF[ii])
318
+                                        rlist = []
319
+                                        rlist.append(point1)
320
+                                        rlist.append(bsm)
321
+                                        rlist.append(ysdm)
322
+                                        rlist.append(jzdh)
323
+                                        rlist.append('')
324
+                                        rlist.append('')
325
+                                        rlist.append(zddm)
326
+                                        rlist.append(zdh)
327
+                                        rlist.append(1)
328
+                                        rlist.append(ag)
329
+                                        cursorZ.insertRow(rlist)
330
+                                        point = arcpy.Point(listF[ii][0], listF[ii][1])                        
331
+                                        if ii == len(listF) - 1:
332
+                                            point0 = arcpy.Point(listF[0][0], listF[0][1])
333
+                                        else:
334
+                                            point0 = arcpy.Point(listF[ii+1][0], listF[ii+1][1])
335
+                                        array=arcpy.Array()
336
+                                        array.add(point)
337
+                                        array.add(point0)
338
+                                        pl=arcpy.Polyline(array)
339
+                                        cursorY.insertRow([pl])
340
+                                ii = ii + 1
341
+                        else:
342
+                            mm0 = 0
343
+                            zdh = 0
344
+                            while mm0 < len(linelist):
345
+                                if mm0 == 0:
346
+                                    listF = linezd(list1,poly1)
347
+                                    ii = 0
348
+                                    while ii < len(listF):
349
+                                        if ii == 0:
350
+                                            zdh = zdh + 1
351
+                                            bsm = bsm + 1
352
+                                            # shape
353
+                                            point1 = arcpy.Point(listF[ii][0], listF[ii][1])
354
+                                            # 要素代码
355
+                                            ysdm = '6002010300'
356
+                                            # 界址点号
357
+                                            jzdh = 'J' + str(zdh)
358
+                                            # 宗地代码
359
+                                            zddm = curA[1]
360
+                                            ag = calcangle(listF[ii-1],listF[ii])
361
+                                            rlist = []
362
+                                            rlist.append(point1)
363
+                                            rlist.append(bsm)
364
+                                            rlist.append(ysdm)
365
+                                            rlist.append(jzdh)
366
+                                            rlist.append('')
367
+                                            rlist.append('')
368
+                                            rlist.append(zddm)
369
+                                            rlist.append(zdh)
370
+                                            rlist.append(mm0+1)
371
+                                            rlist.append(ag)
372
+                                            cursorZ.insertRow(rlist)
373
+                                            point = arcpy.Point(listF[ii][0], listF[ii][1])                        
374
+                                            if ii == len(listF) - 1:
375
+                                                point0 = arcpy.Point(listF[0][0], listF[0][1])
376
+                                            else:
377
+                                                point0 = arcpy.Point(listF[ii+1][0], listF[ii+1][1])
378
+                                            array=arcpy.Array()
379
+                                            array.add(point)
380
+                                            array.add(point0)
381
+                                            pl=arcpy.Polyline(array)
382
+                                            cursorY.insertRow([pl])
383
+                                        else:
384
+                                            numdis0 = listF[ii][0] - listF[ii - 1][0]
385
+                                            numdis1 = listF[ii][1] - listF[ii - 1][1]
386
+                                            numdis2 = math.sqrt((numdis0 * numdis0)+(numdis1*numdis1))
387
+                                            if numdis2 < 0.1:
388
+                                                pass
389
+                                            else:
390
+                                                zdh = zdh + 1
391
+                                                bsm = bsm + 1
392
+                                                # shape
393
+                                                point1 = arcpy.Point(listF[ii][0], listF[ii][1])
394
+                                                # 要素代码
395
+                                                ysdm = '6002010300'
396
+                                                # 界址点号
397
+                                                jzdh = 'J' + str(zdh)
398
+                                                # 宗地代码
399
+                                                zddm = curA[1]
400
+                                                ag = calcangle(listF[ii-1],listF[ii])
401
+                                                rlist = []
402
+                                                rlist.append(point1)
403
+                                                rlist.append(bsm)
404
+                                                rlist.append(ysdm)
405
+                                                rlist.append(jzdh)
406
+                                                rlist.append('')
407
+                                                rlist.append('')
408
+                                                rlist.append(zddm)
409
+                                                rlist.append(zdh)
410
+                                                rlist.append(mm0+1)
411
+                                                rlist.append(ag)
412
+                                                cursorZ.insertRow(rlist)
413
+                                                point = arcpy.Point(listF[ii][0], listF[ii][1])                        
414
+                                                if ii == len(listF) - 1:
415
+                                                    point0 = arcpy.Point(listF[0][0], listF[0][1])
416
+                                                else:
417
+                                                    point0 = arcpy.Point(listF[ii+1][0], listF[ii+1][1])
418
+                                                array=arcpy.Array()
419
+                                                array.add(point)
420
+                                                array.add(point0)
421
+                                                pl=arcpy.Polyline(array)
422
+                                                cursorY.insertRow([pl])
423
+                                        ii = ii + 1
424
+                                else:
425
+                                    listF = linezd(linelist[mm0],poly1)
426
+                                    ii = len(listF) - 1
427
+                                    while ii >= 0:
428
+                                        if ii == len(listF) - 1:
429
+                                            zdh = zdh + 1
430
+                                            bsm = bsm + 1
431
+                                            # shape
432
+                                            point1 = arcpy.Point(listF[ii][0], listF[ii][1])
433
+                                            # 要素代码
434
+                                            ysdm = '6002010300'
435
+                                            # 界址点号
436
+                                            jzdh = 'J' + str(zdh)
437
+                                            # 宗地代码
438
+                                            zddm = curA[1]
439
+                                            ag = calcangle(listF[ii-1],listF[ii])
440
+                                            rlist = []
441
+                                            rlist.append(point1)
442
+                                            rlist.append(bsm)
443
+                                            rlist.append(ysdm)
444
+                                            rlist.append(jzdh)
445
+                                            rlist.append('')
446
+                                            rlist.append('')
447
+                                            rlist.append(zddm)
448
+                                            rlist.append(zdh)
449
+                                            rlist.append(mm0+1)
450
+                                            rlist.append(ag)
451
+                                            cursorZ.insertRow(rlist)
452
+                                            point = arcpy.Point(listF[ii][0], listF[ii][1])                        
453
+                                            if ii == len(listF) - 1:
454
+                                                point0 = arcpy.Point(listF[0][0], listF[0][1])
455
+                                            else:
456
+                                                point0 = arcpy.Point(listF[ii+1][0], listF[ii+1][1])
457
+                                            array=arcpy.Array()
458
+                                            array.add(point)
459
+                                            array.add(point0)
460
+                                            pl=arcpy.Polyline(array)
461
+                                            cursorY.insertRow([pl])
462
+                                        else:
463
+                                            numdis0 = listF[ii][0] - listF[ii - 1][0]
464
+                                            numdis1 = listF[ii][1] - listF[ii - 1][1]
465
+                                            numdis2 = math.sqrt((numdis0 * numdis0)+(numdis1*numdis1))
466
+                                            if numdis2 < 0.1:
467
+                                                pass
468
+                                            else:
469
+                                                zdh = zdh + 1
470
+                                                bsm = bsm + 1
471
+                                                # shape
472
+                                                point1 = arcpy.Point(listF[ii][0], listF[ii][1])
473
+                                                # 要素代码
474
+                                                ysdm = '6002010300'
475
+                                                # 界址点号
476
+                                                jzdh = 'J' + str(zdh)
477
+                                                # 宗地代码
478
+                                                zddm = curA[1]
479
+                                                ag = calcangle(listF[ii-1],listF[ii])
480
+                                                rlist = []
481
+                                                rlist.append(point1)
482
+                                                rlist.append(bsm)
483
+                                                rlist.append(ysdm)
484
+                                                rlist.append(jzdh)
485
+                                                rlist.append('')
486
+                                                rlist.append('')
487
+                                                rlist.append(zddm)
488
+                                                rlist.append(zdh)
489
+                                                rlist.append(mm0+1)
490
+                                                rlist.append(ag)
491
+                                                cursorZ.insertRow(rlist)
492
+                                                point = arcpy.Point(listF[ii][0], listF[ii][1])                        
493
+                                                if ii == len(listF) - 1:
494
+                                                    point0 = arcpy.Point(listF[0][0], listF[0][1])
495
+                                                else:
496
+                                                    point0 = arcpy.Point(listF[ii+1][0], listF[ii+1][1])
497
+                                                array=arcpy.Array()
498
+                                                array.add(point)
499
+                                                array.add(point0)
500
+                                                pl=arcpy.Polyline(array)
501
+                                                cursorY.insertRow([pl])
502
+                                        ii = ii - 1
503
+                                mm0 = mm0 + 1
504
+
505
+def pdlen(list1):
506
+    ii = 0
507
+    list2 = []
508
+    while ii < len(list1):
509
+        pts = list1[ii]
510
+        length1 = 0
511
+        mm = 0
512
+        while mm < len(pts):
513
+            if mm == len(pts) - 1:
514
+                pt1 = pts[mm]
515
+                pt2 = pts[0]
516
+                dis1 = math.sqrt(((pt1.X-pt2.X)*(pt1.X-pt2.X))+((pt1.Y-pt2.Y)*(pt1.Y-pt2.Y)))
517
+                length1 = length1 + dis1
518
+                mm = mm + 1
519
+            else:
520
+                pt1 = pts[mm]
521
+                pt2 = pts[mm + 1]
522
+                dis1 = math.sqrt(((pt1.X-pt2.X)*(pt1.X-pt2.X))+((pt1.Y-pt2.Y)*(pt1.Y-pt2.Y)))
523
+                length1 = length1 + dis1
524
+                mm = mm + 1
525
+        slist2 = []
526
+        slist2.append(length1)
527
+        slist2.append(pts)
528
+        list2.append(slist2)
529
+        ii = ii + 1
530
+    list2.sort(reverse=True)
531
+    nn = 0
532
+    list3 = []
533
+    while nn < len(list2):
534
+        list3.append(list2[nn][1])
535
+        nn = nn + 1
536
+    return list3
537
+                
538
+def calc_angle(lastp,p):
539
+    angle = 0
540
+    if p[0]-lastp[0]>0 and p[1]-lastp[1]>0:#↗
541
+        angle = 0
542
+    if p[0]-lastp[0]>0 and p[1]-lastp[1]<0:#↘
543
+        angle = 90
544
+    if p[0]-lastp[0]<0 and p[1]-lastp[1]<0:#↙
545
+        angle = 180
546
+    if p[0]-lastp[0]<0 and p[1]-lastp[1]>0:#↖
547
+        angle = 270
548
+    return angle
549
+
550
+def cal_stdangle(lastp,p): 
551
+    stdangle=0
552
+    dy= p[1]-lastp[1]
553
+    dx= p[0]-lastp[0]
554
+    if dx==0 and dy>0:
555
+        stdangle = 0
556
+    if dx==0 and dy<0:
557
+        stdangle = 180
558
+    if dy==0 and dx>0:
559
+        stdangle = 90
560
+    if dy==0 and dx<0:
561
+        stdangle = 270
562
+    if dx>0 and dy>0:
563
+       stdangle = math.atan(dx/dy)*180/math.pi
564
+    elif dx<0 and dy>0:
565
+       stdangle = 360 + math.atan(dx/dy)*180/math.pi
566
+    elif dx<0 and dy<0:
567
+       stdangle = 180 + math.atan(dx/dy)*180/math.pi
568
+    elif dx>0 and dy<0:
569
+       stdangle = 180 + math.atan(dx/dy)*180/math.pi
570
+    return stdangle
571
+    
572
+def calcangle(lastp,p): 
573
+    angle=0
574
+    stdangle = cal_stdangle(lastp,p)
575
+    if (stdangle < 45 and stdangle >= 0) or (stdangle <= 360 and stdangle >= 315):
576
+        angle = 270
577
+    if (stdangle < 135 and stdangle >= 45):
578
+        angle = 0
579
+    if (stdangle < 225 and stdangle >= 135):
580
+        angle = 90
581
+    if (stdangle < 315 and stdangle >= 225):
582
+        angle = 180
583
+    return angle
584
+    
585
+def addpoint(list1,pt):
586
+    ptx = round(pt.X,4)
587
+    pty = round(pt.Y,4)
588
+    ii = 0
589
+    bl = 1
590
+    while ii < len(list1):
591
+        if ptx == round(list1[ii].X,4) and pty == round(list1[ii].Y,4):
592
+            bl = -1
593
+        ii = ii + 1
594
+    return bl
595
+
596
+def linezd(line1,poly):
597
+    # 获取折点
598
+    mm = 0
599
+    pp = 0
600
+    list1 = []
601
+    while mm < len(line1):
602
+        plist = []
603
+        jzd = line1[mm]
604
+        try:
605
+            xx = jzd.X
606
+            yy = jzd.Y
607
+            plist.append(xx)
608
+            plist.append(yy)
609
+            # 初始顺序
610
+            plist.append(pp)
611
+            list1.append(plist)
612
+            pp = pp + 1
613
+            mm = mm + 1
614
+        except:
615
+            mm = mm + 1 
616
+    # 对折点排序(算法)
617
+    if len(list1) < 3:
618
+        listF = []
619
+    else:
620
+        # listF = zdsort(list1, zx)
621
+        listF = jzdsort(list1,poly)
622
+    return listF
623
+
624
+def jzdsort(list0,poly):
625
+    m = 0
626
+    n = 0
627
+    northwest = []
628
+    northwest.append(poly.extent.XMin)
629
+    northwest.append(poly.extent.YMax)
630
+    minDis = (northwest[1] - list0[0][1])*(northwest[1] - list0[0][1]) + (northwest[0] - list0[0][0])*(northwest[0] - list0[0][0])
631
+    maxStdangle = cal_stdangle(northwest,list0[0])
632
+    while m < len(list0):        
633
+        Dis = (northwest[1] - list0[m][1])*(northwest[1] - list0[m][1]) + (northwest[0] - list0[m][0])*(northwest[0] - list0[m][0])
634
+        if Dis < minDis:
635
+            minDis = Dis
636
+            maxStdangle = cal_stdangle(northwest,list0[m])
637
+            n = m
638
+        if abs(Dis-minDis) < 0.000001:
639
+            stdangle = cal_stdangle(northwest,list0[m])
640
+            if stdangle > maxStdangle:
641
+                maxStdangle = stdangle
642
+                n = m 
643
+        m = m + 1
644
+    i = 0
645
+    while i < len(list0):    
646
+        if n == 0:
647
+            vectangleN = cal_stdangle(list0[0], list0[1])
648
+            vectangleNl = cal_stdangle(list0[len(list0)-1], list0[0]) 
649
+            if abs(vectangleN-vectangleNl) < 3:
650
+                n = len(list0)-1          
651
+        else:
652
+            if n == len(list0)-1:
653
+                vectangleN = cal_stdangle(list0[n], list0[0])
654
+            else:            
655
+                vectangleN = cal_stdangle(list0[n], list0[n+1]) 
656
+            vectangleNl = cal_stdangle(list0[n-1], list0[n])    
657
+            if abs(vectangleN-vectangleNl) < 3:
658
+                n = n-1
659
+        i = i + 1
660
+    list4 = []     
661
+    a = n     
662
+    num = 0
663
+    while a < len(list0):
664
+        slist4 = []
665
+        num = num + 1
666
+        slist4.append(list0[a][0])
667
+        slist4.append(list0[a][1])
668
+        slist4.append(num)
669
+        list4.append(slist4)   
670
+        a = a + 1    
671
+    a = 0
672
+    while a < n:
673
+        slist4 = []
674
+        num = num + 1
675
+        slist4.append(list0[a][0])
676
+        slist4.append(list0[a][1])
677
+        slist4.append(num)
678
+        list4.append(slist4)   
679
+        a = a + 1
680
+    return list4
681
+    
682
+def mkdir(path):
683
+	folder = os.path.exists(path)
684
+	if not folder:                   #判断是否存在文件夹如果不存在则创建为文件夹
685
+		os.makedirs(path)            #makedirs 创建文件时如果路径不存在会创建这个路径
686
+
687
+def getScale(scale):
688
+	yushu = float(str(scale).split(".", 1)[0]) % 50
689
+	lastTWO = 0
690
+	if yushu < 25:
691
+		lastTWO = float(str(scale).split(".", 1)[0]) // 50 * 50
692
+	if yushu < 75 and yushu >= 25:
693
+		lastTWO = float(str(scale).split(".", 1)[0]) // 50 * 50 + 50
694
+	if yushu < 100 and yushu >= 75:
695
+		lastTWO = float(str(scale).split(".", 1)[0]) // 50 * 50 + 100
696
+	scale = "1:" + str(lastTWO).split(".",1)[0]
697
+	return scale
698
+
699
+class LayerObject:
700
+    currentLayer = ""
701
+
702
+mxd = arcpy.mapping.MapDocument('current')
703
+df = arcpy.mapping.ListDataFrames(mxd)[0]
704
+
705
+LayerObject.currentLayer = arcpy.GetParameterAsText(0)
706
+
707
+#设置保存路径
708
+savePath1 = arcpy.GetParameterAsText(1)
709
+#当前数据源               
710
+arcpy.env.workspace = arcpy.GetParameterAsText(2)
711
+#宗地添加面积字段并计算    
712
+arcpy.AddField_management(LayerObject.currentLayer, "Area", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
713
+arcpy.CalculateField_management(LayerObject.currentLayer, "Area", "round(!shape.area!,2)", "PYTHON_9.3")
714
+#面转线 
715
+line = arcpy.PolygonToLine_management("Copy", savePath1 +"\line.shp")
716
+
717
+#遍历宗地
718
+rows = arcpy.SearchCursor(LayerObject.currentLayer)
719
+for row in rows:
720
+        for lyr in arcpy.mapping.ListLayers(mxd, "", df):
721
+            if lyr.name == "dlclip":
722
+                arcpy.mapping.RemoveLayer(df, lyr)
723
+            if lyr.name == "JZD":
724
+                arcpy.mapping.RemoveLayer(df, lyr)
725
+            if lyr.name == "JZX":
726
+                arcpy.mapping.RemoveLayer(df, lyr)
727
+            if lyr.name == "lineclip":
728
+                arcpy.mapping.RemoveLayer(df, lyr)
729
+        filename = row.getValue(u"宗地编号")  
730
+        savePath = os.path.join(savePath1, filename)
731
+        mkdir(savePath)
732
+        arcpy.SelectLayerByAttribute_management(LayerObject.currentLayer, "CLEAR_SELECTION")
733
+        arcpy.SelectLayerByAttribute_management("Copy", "CLEAR_SELECTION")
734
+        OBJECTID_1 = row.getValue(u"OBJECTID_1")
735
+        query = "OBJECTID_1={0}".format(OBJECTID_1)
736
+        #
737
+        arcpy.SelectLayerByAttribute_management(LayerObject.currentLayer, "NEW_SELECTION", query)
738
+        #
739
+        df.zoomToSelectedFeatures()
740
+        df.scale *= 1.3
741
+        shape = row.shape
742
+        #编辑文本元素
743
+              
744
+        qlr = row.getValue(u"权利人")
745
+        title = filename + qlr + u"宗地图"
746
+        tfh = " "
747
+        zdmj = "{}".format(row.getValue(u"Area"))
748
+        
749
+            
750
+        # east = row.getValue(u"四至东")
751
+        # east =east.replace(")","/0301)")
752
+        # south = row.getValue(u"四至南")
753
+        # south =south.replace(")","/0301)")
754
+        # west = row.getValue(u"四至西")
755
+        # west =west.replace(")","/0301)")
756
+        # north = row.getValue(u"四至北")
757
+        # north =north.replace(")","/0301)")
758
+
759
+        time_tuple = time.localtime(time.time())
760
+        rq = "{}年{}月{}日".format(time_tuple[0],time_tuple[1],time_tuple[2]) 
761
+        ny = "{}年{}月".format(time_tuple[0],time_tuple[1])       
762
+        elemlist = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT")
763
+        for elem in elemlist:
764
+            if elem.name == "zddm":
765
+                elem.text = filename
766
+            if elem.name == "qlr":
767
+                elem.text = qlr
768
+            if elem.name == "tfh":
769
+                elem.text = tfh
770
+                #预先添加标准TF图层,计算得到图幅号    
771
+                TFtoTB(row.shape, elem)
772
+            if elem.name == "zdmj":
773
+                elem.text = zdmj
774
+            # if elem.name == "east":
775
+            #     elem.text = east           
776
+            # if elem.name == "south":
777
+            #     elem.text = south          
778
+            # if elem.name == "west":
779
+            #     elem.text = west
780
+            # if elem.name == "north":
781
+            #     elem.text = north
782
+            if elem.name == "scale":
783
+                elem.text = getScale(df.scale)
784
+            if elem.name == "ztz":
785
+                elem.text = random.choice(['王荣华','余思翰','阮梦妍','杨玉婧','赵芩','屈亚星'])
786
+            if elem.name == "shz":
787
+                elem.text = random.choice(['何杰','张学仪'])
788
+            if elem.name == "ztrq":
789
+                elem.text = rq
790
+            if elem.name == "shrq":
791
+                elem.text = rq
792
+            if elem.name == "jzdtjf":
793
+                elem.text = ny + "图解法测绘界址点"
794
+            if elem.name == "zlz":
795
+                title = filename + qlr + u"宗地草图"
796
+                elem.text = random.choice(['王荣华','余思翰','阮梦妍','杨玉婧','赵芩','屈亚星'])
797
+            if elem.name == "jcz":
798
+                elem.text = random.choice(['何杰','张学仪'])
799
+            if elem.name == "zlrq":
800
+                elem.text = rq
801
+            if elem.name == "jcrq":
802
+                elem.text = rq
803
+        
804
+
805
+        arcpy.SelectLayerByAttribute_management("TF", "CLEAR_SELECTION")
806
+        #生成当前宗地界址点线   
807
+        JZGenerate(savePath, filename)
808
+        arcpy.SelectLayerByAttribute_management(LayerObject.currentLayer, "NEW_SELECTION", query)
809
+        #界址线添加长度字段
810
+        arcpy.AddField_management("JZX", "LENGTH", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
811
+        arcpy.CalculateField_management("JZX", "LENGTH", "round(!shape.length!,2)", "PYTHON_9.3")
812
+
813
+        #建立缓冲区            
814
+        if df.scale > 1000:
815
+            shapebuffer = arcpy.Polygon.buffer(shape, 10)
816
+        elif df.scale > 900:
817
+            shapebuffer = arcpy.Polygon.buffer(shape, 9)
818
+        elif df.scale > 800:
819
+            shapebuffer = arcpy.Polygon.buffer(shape, 8)
820
+        elif df.scale > 700:
821
+            shapebuffer = arcpy.Polygon.buffer(shape, 7)            
822
+        elif df.scale > 600:
823
+            shapebuffer = arcpy.Polygon.buffer(shape, 6)
824
+        elif df.scale > 500:
825
+            shapebuffer = arcpy.Polygon.buffer(shape, 5)
826
+        elif df.scale > 400:
827
+            shapebuffer = arcpy.Polygon.buffer(shape, 4)
828
+        elif df.scale > 300:
829
+            shapebuffer = arcpy.Polygon.buffer(shape, 3)
830
+        elif df.scale > 200:
831
+            shapebuffer = arcpy.Polygon.buffer(shape, 2)
832
+        elif df.scale > 100:
833
+            shapebuffer = arcpy.Polygon.buffer(shape, 1)
834
+        else:
835
+            shapebuffer = arcpy.Polygon.buffer(shape, 0.5)
836
+        #裁剪线图层  
837
+        arcpy.Clip_analysis(line, shapebuffer, savePath + "\lineclip.shp")
838
+        lyrline = arcpy.mapping.Layer(savePath + "\lineclip.shp")
839
+        arcpy.mapping.AddLayer(df, lyrline)
840
+        
841
+        arcpy.SelectLayerByLocation_management(lyrline, "BOUNDARY_TOUCHES", shape)
842
+        arcpy.SelectLayerByAttribute_management(lyrline, "SWITCH_SELECTION")
843
+        arcpy.DeleteFeatures_management(lyrline)
844
+        
845
+        arcpy.SelectLayerByLocation_management("BCDW", "BOUNDARY_TOUCHES", shape)
846
+        arcpy.CopyFeatures_management("BCDW", savePath + "\BCDW.shp")
847
+        
848
+        arcpy.SelectLayerByLocation_management("ZJD", "BOUNDARY_TOUCHES", shape)
849
+        arcpy.CopyFeatures_management("ZJD", savePath + "\ZJD.shp")
850
+        
851
+        arcpy.SelectLayerByLocation_management("Copy", "SHARE_A_LINE_SEGMENT_WITH", shape)
852
+        neighlist = []
853
+        m = int(arcpy.GetCount_management("Copy").getOutput(0))
854
+        if m != 0:
855
+            with arcpy.da.SearchCursor("Copy", ['宗地编号']) as cursor:
856
+                for cur in cursor:
857
+                    f = cur[0]
858
+                    if f == filename:
859
+                        pass
860
+                    else:
861
+                        if neighlist.__contains__(f):
862
+                            pass
863
+                        else:
864
+                            neighlist.append(f)
865
+        txtfile = open(os.path.join(savePath1, "neighbourList.txt"),'a')
866
+        txtfile.write(filename + ':' + str(len(neighlist)) + str(tuple(neighlist)).replace("u","").replace("510811100205JE00","") + '\n')
867
+        
868
+        
869
+        arcpy.Clip_analysis("DLTB", shapebuffer, savePath + "\dlbfclip.shp")
870
+        shape1 = arcpy.Polygon.buffer(shape, 0.1)
871
+        #     
872
+        arcpy.Erase_analysis(savePath + "\dlbfclip.shp", shape1, savePath + "\dlclip.shp")
873
+
874
+        fcs = arcpy.ListFeatureClasses() 
875
+        for fc in fcs:            
876
+            if fc.__contains__("dlclip"):
877
+                arcpy.Delete_management(os.path.join(arcpy.env.workspace,fc))
878
+        arcpy.FeatureClassToGeodatabase_conversion([savePath + '\dlclip.shp'], arcpy.env.workspace)  
879
+        
880
+        target_lyr = arcpy.env.workspace + "\dlclip"
881
+        #     
882
+        arcpy.AddRepresentation_cartography(target_lyr,
883
+                                "DL_Rep",                                    
884
+                                import_rule_layer = "DLTB")
885
+        arcpy.CalculateField_management(target_lyr, "RuleID_1", '!RuleID!', "PYTHON_9.3")
886
+
887
+        lyrdl = arcpy.mapping.Layer(target_lyr)
888
+        refLayer = arcpy.mapping.ListLayers(mxd, "", df)
889
+        arcpy.mapping.InsertLayer(df, refLayer[len(refLayer) - 1], lyrdl, "AFTER")
890
+
891
+        arcpy.SetLayerRepresentation_cartography("dlclip", "DL_Rep")
892
+
893
+        for lyr in arcpy.mapping.ListLayers(mxd, "", df):
894
+            if lyr.name == "Point":
895
+                lyr.replaceDataSource(savePath, "SHAPEFILE_WORKSPACE", "JZD")
896
+                lyr.showLabels = True
897
+                lyr.labelClasses[0].SQLQuery  = "ANGLE = 0"
898
+                lyr.labelClasses[0].expression  = "[JZDH]"
899
+                lyr.labelClasses[1].SQLQuery  = "ANGLE = 90"
900
+                lyr.labelClasses[1].expression  = "[JZDH]"
901
+                lyr.labelClasses[2].SQLQuery  = "ANGLE = 180"
902
+                lyr.labelClasses[2].expression  = "[JZDH]"
903
+                lyr.labelClasses[3].SQLQuery  = "ANGLE = 270"
904
+                lyr.labelClasses[3].expression  = "[JZDH]"
905
+                lyr.visible = True                    
906
+            elif lyr.name == "Polyline":
907
+                lyr.replaceDataSource(savePath, "SHAPEFILE_WORKSPACE", "JZX")
908
+                lyr.showLabels = True
909
+                lyr.labelClasses[0].expression  = "[LENGTH]"                
910
+                lyr.visible = True
911
+            elif lyr.name == LayerObject.currentLayer:
912
+                lyr.showLabels = True
913
+                lyr.labelClasses[0].SQLQuery = '"OBJECTID_1" = ' + str(OBJECTID_1)
914
+                lyr.visible = True
915
+            elif lyr.name == "Copy":
916
+                lyr.showLabels = True
917
+                sqlquery = str(tuple(neighlist))
918
+                if sqlquery.endswith(",)"):
919
+                    query = sqlquery.replace(",)", ")")
920
+                else:
921
+                    query = sqlquery
922
+                lyr.labelClasses[0].SQLQuery = '"宗地编号" IN ' + query.replace("u","")   
923
+                lyr.visible = True
924
+            elif lyr.name == "line":
925
+                lyr.replaceDataSource(savePath, "SHAPEFILE_WORKSPACE", "lineclip")
926
+                lyr.visible = True                  
927
+            elif lyr.name == "dlclip":
928
+                lyr.visible = True
929
+            elif lyr.name == "BCDW":
930
+                lyr.replaceDataSource(savePath, "SHAPEFILE_WORKSPACE", "BCDW")
931
+                lyr.visible = True        
932
+            elif lyr.name == "ZJD":
933
+                lyr.replaceDataSource(savePath, "SHAPEFILE_WORKSPACE", "ZJD")
934
+                lyr.visible = True                                
935
+            else:
936
+                lyr.visible = False    
937
+        #saveMxdPath = savePath + "\\" + title + ".mxd"
938
+        #mxd.saveACopy(saveMxdPath)
939
+        arcpy.mapping.ExportToJPEG( mxd, savePath  + "\\" + title + ".jpg", resolution = 300)
940
+        arcpy.Delete_management(savePath +"\dlbfclip.shp")
941
+        arcpy.Delete_management(savePath +"\dlclip.shp") 
942
+        #arcpy.Delete_management(savePath +"\lineclip.shp")
943
+        #arcpy.Delete_management(savePath +"\JZD.shp")
944
+        #arcpy.Delete_management(savePath +"\JZX.shp")
945
+        arcpy.AddMessage (filename + ' Finish!')
946
+        txtfile.close() 
947
+arcpy.Delete_management(savePath1 +"\line.shp")
948
+     

+ 953
- 0
代码/20221220林权/LQ/ZDT/exportZDT_Single.py 查看文件

@@ -0,0 +1,953 @@
1
+# -*- coding: utf-8 -*-
2
+from cmath import e
3
+import os
4
+from re import L
5
+import arcpy
6
+import pythonaddins
7
+import math
8
+from multiprocessing import Process
9
+import random
10
+import fnmatch
11
+import time
12
+
13
+def TFtoTB(shape, elem):
14
+    list1 = []
15
+    # 相交,包含,被包含            
16
+    arcpy.SelectLayerByLocation_management('TF', "INTERSECT", shape)
17
+    ma1 = int(arcpy.GetCount_management('TF').getOutput(0))
18
+    if ma1 != 0:
19
+        with arcpy.da.SearchCursor('TF', ['TFH1']) as cursorB:
20
+            for curB in cursorB:
21
+                tfh1 = str(curB[0])
22
+                if list1.__contains__(tfh1):
23
+                    pass
24
+                else:
25
+                    list1.append(tfh1)
26
+    arcpy.SelectLayerByLocation_management('TF', "WITHIN", shape)
27
+    ma2 = int(arcpy.GetCount_management('TF').getOutput(0))
28
+    if ma2 != 0:
29
+        with arcpy.da.SearchCursor('TF', ['TFH1']) as cursorC:
30
+            for curC in cursorC:
31
+                tfh2 = str(curC[0])
32
+                if list1.__contains__(tfh2):
33
+                    pass
34
+                else:
35
+                    list1.append(tfh2)
36
+    arcpy.SelectLayerByLocation_management('TF', "COMPLETELY_CONTAINS", shape)
37
+    ma3 = int(arcpy.GetCount_management('TF').getOutput(0))
38
+    if ma3 != 0:
39
+        with arcpy.da.SearchCursor('TF', ['TFH1']) as cursorD:
40
+            for curD in cursorD:
41
+                tfh3 = str(curD[0])
42
+                if list1.__contains__(tfh3):
43
+                    pass
44
+                else:
45
+                    list1.append(tfh3)
46
+    if list1 == []:
47
+        pass
48
+    else:
49
+        ii = 0
50
+        while ii < len(list1):
51
+            # tfh.append(list1[ii])
52
+            elem.text = elem.text + list1[ii]
53
+            if ii == (len(list1) - 1):
54
+                pass
55
+            elif ( ii + 1 ) % 2 == 0:
56
+                elem.text = elem.text + '\n'+ ' '
57
+            else:
58
+                elem.text = elem.text + ','
59
+            ii = ii + 1
60
+
61
+def JZGenerate(outfileshp, zdbh):
62
+# def JZGenerate(outfileshp):
63
+    shpstr = 'JZD.shp'
64
+    shpstr1 = 'JZX.shp'
65
+    outpath = outfileshp + '\\' + shpstr
66
+    outpath1 = outfileshp + '\\' + shpstr1
67
+    try:
68
+        arcpy.CreateFeatureclass_management(outfileshp, shpstr, 'POINT', spatial_reference=4523) #"4507"
69
+    except:
70
+        arcpy.Delete_management(outpath)
71
+        arcpy.CreateFeatureclass_management(outfileshp, shpstr, 'POINT', spatial_reference=4523)
72
+    try:
73
+        arcpy.CreateFeatureclass_management(outfileshp, shpstr1, 'POLYLINE', spatial_reference=4523)
74
+    except:
75
+        arcpy.Delete_management(outpath1)
76
+        arcpy.CreateFeatureclass_management(outfileshp, shpstr1, 'POLYLINE', spatial_reference=4523)
77
+    sr = arcpy.Describe(LayerObject.currentLayer).spatialReference
78
+    #  加载   
79
+    lyrjzd = arcpy.mapping.Layer(outpath)
80
+    arcpy.mapping.AddLayer(df, lyrjzd)  
81
+    lyrjzx = arcpy.mapping.Layer(outpath1)
82
+    arcpy.mapping.AddLayer(df, lyrjzx)
83
+    # 添加一群字段
84
+    arcpy.AddField_management('JZD', '标识码', 'LONG')
85
+    arcpy.AddField_management('JZD', 'YSDM', 'TEXT')
86
+    arcpy.AddField_management('JZD', 'JZDH', 'TEXT')
87
+    arcpy.AddField_management('JZD', 'JBLX', 'TEXT')
88
+    arcpy.AddField_management('JZD', 'JZDLX', 'TEXT')
89
+    arcpy.AddField_management('JZD', 'ZDBH', 'TEXT')
90
+    arcpy.AddField_management('JZD', '顺序号', 'LONG')
91
+    arcpy.AddField_management('JZD', 'flag', 'LONG')
92
+    arcpy.AddField_management('JZD', 'ANGLE', 'LONG')
93
+    #float按理说应该符合的
94
+    bsm = 0
95
+    field1 = ['SHAPE@', '标识码', 'YSDM', 'JZDH', 'JBLX',
96
+              'JZDLX',  'ZDBH', '顺序号','flag','ANGLE']
97
+    # endregion
98
+    with arcpy.da.InsertCursor('JZD', field1) as cursorZ:
99
+        with arcpy.da.SearchCursor(LayerObject.currentLayer, ['SHAPE@', '宗地编号']) as cursorA:
100
+            for curA in cursorA:
101
+                # region [读折点]
102
+                poly1 = curA[0]
103
+                zdbh = curA[1]
104
+                if zdbh == None or zdbh == '' or zdbh == ' ':
105
+                    pass
106
+                else:
107
+                    # 获取折点
108
+                    points = poly1.getPart()
109
+                    pt = points[0]
110
+                    mm = 0
111
+                    linelist = []  
112
+                    indexp = 0
113
+                    #存的都是点
114
+                    while mm < pt.count:
115
+                        jzd = pt[mm]
116
+                        try:
117
+                            xx = round(jzd.X,4)
118
+                            yy = round(jzd.Y,4)
119
+                            if mm == 0 or mm == indexp:
120
+                                xx0 = xx
121
+                                yy0 = yy
122
+                                slist = []
123
+                                slist.append(pt[mm]) 
124
+                            else:
125
+                                numdis0 = xx - xx0
126
+                                numdis1 = yy - yy0 
127
+                                numdis = math.sqrt((numdis0 * numdis0)+(numdis1*numdis1))
128
+                                if xx == xx0 and yy == yy0:
129
+                                    #一个的结束
130
+                                    indexp = mm + 1
131
+                                    linelist.append(slist)  
132
+                                if numdis < 0.1:
133
+                                    pass
134
+                                else:
135
+                                    slist.append(pt[mm]) 
136
+                            mm = mm + 1
137
+                        except:
138
+                            if mm == indexp:
139
+                                indexp = mm + 1
140
+                                mm = mm + 1 
141
+                    llen = len(linelist)
142
+                    #判断下如果多环,排个序
143
+                    linelist1 = pdlen(linelist)
144
+                    linelist = linelist1
145
+                    # endregion
146
+                    #甭管有没有环,都是第一个来处理
147
+                    ln1 = linelist[0]
148
+                    list1 = []
149
+                    nn1 = 0
150
+                    while nn1 < len(ln1):
151
+                        if nn1 == len(ln1) - 1:
152
+                            fpx = round(ln1[nn1].X,4)
153
+                            fpy = round(ln1[nn1].Y,4)
154
+                            lpx = round(ln1[0].X,4)
155
+                            lpy = round(ln1[0].Y,4)
156
+                            fpoint = arcpy.Point(fpx, fpy)
157
+                            lpoint = arcpy.Point(lpx, lpy)
158
+                        else:
159
+                            fpx = round(ln1[nn1].X,4)
160
+                            fpy = round(ln1[nn1].Y,4)
161
+                            lpx = round(ln1[nn1 + 1].X,4)
162
+                            lpy = round(ln1[nn1 + 1].Y,4)
163
+                            fpoint = arcpy.Point(fpx, fpy)
164
+                            lpoint = arcpy.Point(lpx, lpy)
165
+                        new_array = arcpy.Array()
166
+                        new_array.append(fpoint)
167
+                        new_array.append(lpoint)
168
+                        ln2 = arcpy.Polyline(new_array,sr)
169
+                        #先把起始点加进去
170
+                        bl1 = addpoint(list1,fpoint)
171
+                        if bl1 == 1:
172
+                            list1.append(fpoint)
173
+                            # list1.append(lpoint)
174
+                        #插入点
175
+                        arcpy.SelectLayerByLocation_management(LayerObject.currentLayer,'INTERSECT',ln2)
176
+                        count0 = int(arcpy.GetCount_management(LayerObject.currentLayer).getOutput(0)) 
177
+                        if count0 < 2:
178
+                            bl4 = addpoint(list1,lpoint)
179
+                            if bl4 == 1:
180
+                                list1.append(lpoint)
181
+                            nn1 = nn1 + 1
182
+                        else:
183
+                            #对于同一个线段来说,把所有点的位置准确点
184
+                            listp1 = []
185
+                            with arcpy.da.SearchCursor(LayerObject.currentLayer, ['SHAPE@', '宗地编号']) as cursorB:
186
+                                for curB in cursorB:
187
+                                    zdbh1 = curB[1]
188
+                                    #排除自己
189
+                                    if zdbh1 == zdbh:
190
+                                        pass
191
+                                    else:
192
+                                        try:
193
+                                            shpB = curB[0]
194
+                                            lineB = shpB.boundary ()
195
+                                            rln = lineB.intersect (ln2, 2)
196
+                                            fpoint1 = rln.firstPoint
197
+                                            lpoint1 = rln.lastPoint
198
+                                            fx = round(fpoint1.X,4)
199
+                                            fy = round(fpoint1.Y,4)
200
+                                            lx = round(lpoint1.X,4)
201
+                                            ly = round(lpoint1.Y,4)
202
+                                            #判断这两个点是否都在里面
203
+                                            fp = arcpy.Point(fx, fy)
204
+                                            lp = arcpy.Point(lx, ly)
205
+                                            list2 = []
206
+                                            bl1 = addpoint(list1,fp)
207
+                                            if bl1 == 1:
208
+                                                #判断与起点的距离
209
+                                                dis1 = math.sqrt(((fpx - fx)*(fpx - fx)) + ((fpy-fy)*(fpy-fy)))
210
+                                                slist2 = []
211
+                                                slist2.append(dis1)
212
+                                                slist2.append(fp)
213
+                                                list2.append(slist2)
214
+                                            bl1 = addpoint(list1,lp)
215
+                                            if bl1 == 1:
216
+                                                dis1 = math.sqrt(((fpx - lx)*(fpx - lx)) + ((fpy-ly)*(fpy-ly)))
217
+                                                slist2 = []
218
+                                                slist2.append(dis1)
219
+                                                slist2.append(lp)
220
+                                                list2.append(slist2)
221
+                                            if len(list2) == 1:
222
+                                                listp1.append(list2[0][1])
223
+                                            elif len(list2) == 2:
224
+                                                #对2排序
225
+                                                if list2[0][0] < list2[1][0]:
226
+                                                    listp1.append(list2[0][1])
227
+                                                    listp1.append(list2[1][1])
228
+                                                else:
229
+                                                    listp1.append(list2[1][1])
230
+                                                    listp1.append(list2[0][1])
231
+                                        except:
232
+                                            pass
233
+                            #得到所有的点,进行一个与起点的排序
234
+                            nn2 = 0
235
+                            listp2 =[]
236
+                            while nn2 < len(listp1):
237
+                                num0 = fpx - listp1[nn2].X
238
+                                num1 = fpy - listp1[nn2].Y
239
+                                dis2 = math.sqrt((num0*num0)+(num1*num1))
240
+                                slistp2 = []
241
+                                slistp2.append(dis2)
242
+                                slistp2.append(listp1[nn2])
243
+                                listp2.append(slistp2)
244
+                                nn2 = nn2 + 1
245
+                            listp2.sort()
246
+                            nn3 = 0
247
+                            bl3 = 0
248
+                            while nn3 < len(listp2):
249
+                                #这里要看下要不要除重
250
+                                bl3 = addpoint(list1,listp2[nn3][1])
251
+                                if bl3 == 1:
252
+                                    list1.append(listp2[nn3][1])
253
+                                nn3 = nn3 + 1  
254
+                            bl4 = addpoint(list1,lpoint)
255
+                            if bl4 == 1:
256
+                                list1.append(lpoint)
257
+                        nn1 = nn1 + 1
258
+                    
259
+                    with arcpy.da.InsertCursor('JZX',  ['SHAPE@']) as cursorY:
260
+                        if len(linelist) == 1:
261
+                            listF = linezd(list1,poly1)
262
+                            #直接写
263
+                            ii = 0
264
+                            zdh = 0
265
+                            while ii < len(listF):
266
+                                if ii == 0:
267
+                                    zdh = zdh + 1
268
+                                    bsm = bsm + 1
269
+                                    # shape
270
+                                    point1 = arcpy.Point(listF[ii][0], listF[ii][1])
271
+                                    # 要素代码
272
+                                    ysdm = '6002010300'
273
+                                    # 界址点号
274
+                                    jzdh = 'J' + str(zdh)
275
+                                    # 宗地代码
276
+                                    zddm = curA[1]
277
+                                    ag = calcangle(listF[ii-1],listF[ii])
278
+                                    rlist = []
279
+                                    rlist.append(point1)
280
+                                    rlist.append(bsm)
281
+                                    rlist.append(ysdm)
282
+                                    rlist.append(jzdh)
283
+                                    rlist.append('')
284
+                                    rlist.append('')
285
+                                    rlist.append(zddm)
286
+                                    rlist.append(zdh)
287
+                                    rlist.append(1)
288
+                                    rlist.append(ag)
289
+                                    cursorZ.insertRow(rlist)
290
+                                    point = arcpy.Point(listF[ii][0], listF[ii][1])                        
291
+                                    if ii == len(listF) - 1:
292
+                                        point0 = arcpy.Point(listF[0][0], listF[0][1])
293
+                                    else:
294
+                                        point0 = arcpy.Point(listF[ii+1][0], listF[ii+1][1])
295
+                                    array=arcpy.Array()
296
+                                    array.add(point)
297
+                                    array.add(point0)
298
+                                    pl=arcpy.Polyline(array)
299
+                                    cursorY.insertRow([pl])
300
+                                else:
301
+                                    numdis0 = listF[ii][0] - listF[ii - 1][0]
302
+                                    numdis1 = listF[ii][1] - listF[ii - 1][1]
303
+                                    numdis2 = math.sqrt((numdis0 * numdis0)+(numdis1*numdis1))
304
+                                    if numdis2 < 0.1:
305
+                                        pass
306
+                                    else:
307
+                                        zdh = zdh + 1
308
+                                        bsm = bsm + 1
309
+                                        # shape
310
+                                        point1 = arcpy.Point(listF[ii][0], listF[ii][1])
311
+                                        # 要素代码
312
+                                        ysdm = '6002010300'
313
+                                        # 界址点号
314
+                                        jzdh = 'J' + str(zdh)
315
+                                        # 宗地代码
316
+                                        zddm = curA[1]
317
+                                        ag = calcangle(listF[ii-1],listF[ii])
318
+                                        rlist = []
319
+                                        rlist.append(point1)
320
+                                        rlist.append(bsm)
321
+                                        rlist.append(ysdm)
322
+                                        rlist.append(jzdh)
323
+                                        rlist.append('')
324
+                                        rlist.append('')
325
+                                        rlist.append(zddm)
326
+                                        rlist.append(zdh)
327
+                                        rlist.append(1)
328
+                                        rlist.append(ag)
329
+                                        cursorZ.insertRow(rlist)
330
+                                        point = arcpy.Point(listF[ii][0], listF[ii][1])                        
331
+                                        if ii == len(listF) - 1:
332
+                                            point0 = arcpy.Point(listF[0][0], listF[0][1])
333
+                                        else:
334
+                                            point0 = arcpy.Point(listF[ii+1][0], listF[ii+1][1])
335
+                                        array=arcpy.Array()
336
+                                        array.add(point)
337
+                                        array.add(point0)
338
+                                        pl=arcpy.Polyline(array)
339
+                                        cursorY.insertRow([pl])
340
+                                ii = ii + 1
341
+                        else:
342
+                            mm0 = 0
343
+                            zdh = 0
344
+                            while mm0 < len(linelist):
345
+                                if mm0 == 0:
346
+                                    listF = linezd(list1,poly1)
347
+                                    ii = 0
348
+                                    while ii < len(listF):
349
+                                        if ii == 0:
350
+                                            zdh = zdh + 1
351
+                                            bsm = bsm + 1
352
+                                            # shape
353
+                                            point1 = arcpy.Point(listF[ii][0], listF[ii][1])
354
+                                            # 要素代码
355
+                                            ysdm = '6002010300'
356
+                                            # 界址点号
357
+                                            jzdh = 'J' + str(zdh)
358
+                                            # 宗地代码
359
+                                            zddm = curA[1]
360
+                                            ag = calcangle(listF[ii-1],listF[ii])
361
+                                            rlist = []
362
+                                            rlist.append(point1)
363
+                                            rlist.append(bsm)
364
+                                            rlist.append(ysdm)
365
+                                            rlist.append(jzdh)
366
+                                            rlist.append('')
367
+                                            rlist.append('')
368
+                                            rlist.append(zddm)
369
+                                            rlist.append(zdh)
370
+                                            rlist.append(mm0+1)
371
+                                            rlist.append(ag)
372
+                                            cursorZ.insertRow(rlist)
373
+                                            point = arcpy.Point(listF[ii][0], listF[ii][1])                        
374
+                                            if ii == len(listF) - 1:
375
+                                                point0 = arcpy.Point(listF[0][0], listF[0][1])
376
+                                            else:
377
+                                                point0 = arcpy.Point(listF[ii+1][0], listF[ii+1][1])
378
+                                            array=arcpy.Array()
379
+                                            array.add(point)
380
+                                            array.add(point0)
381
+                                            pl=arcpy.Polyline(array)
382
+                                            cursorY.insertRow([pl])
383
+                                        else:
384
+                                            numdis0 = listF[ii][0] - listF[ii - 1][0]
385
+                                            numdis1 = listF[ii][1] - listF[ii - 1][1]
386
+                                            numdis2 = math.sqrt((numdis0 * numdis0)+(numdis1*numdis1))
387
+                                            if numdis2 < 0.1:
388
+                                                pass
389
+                                            else:
390
+                                                zdh = zdh + 1
391
+                                                bsm = bsm + 1
392
+                                                # shape
393
+                                                point1 = arcpy.Point(listF[ii][0], listF[ii][1])
394
+                                                # 要素代码
395
+                                                ysdm = '6002010300'
396
+                                                # 界址点号
397
+                                                jzdh = 'J' + str(zdh)
398
+                                                # 宗地代码
399
+                                                zddm = curA[1]
400
+                                                ag = calcangle(listF[ii-1],listF[ii])
401
+                                                rlist = []
402
+                                                rlist.append(point1)
403
+                                                rlist.append(bsm)
404
+                                                rlist.append(ysdm)
405
+                                                rlist.append(jzdh)
406
+                                                rlist.append('')
407
+                                                rlist.append('')
408
+                                                rlist.append(zddm)
409
+                                                rlist.append(zdh)
410
+                                                rlist.append(mm0+1)
411
+                                                rlist.append(ag)
412
+                                                cursorZ.insertRow(rlist)
413
+                                                point = arcpy.Point(listF[ii][0], listF[ii][1])                        
414
+                                                if ii == len(listF) - 1:
415
+                                                    point0 = arcpy.Point(listF[0][0], listF[0][1])
416
+                                                else:
417
+                                                    point0 = arcpy.Point(listF[ii+1][0], listF[ii+1][1])
418
+                                                array=arcpy.Array()
419
+                                                array.add(point)
420
+                                                array.add(point0)
421
+                                                pl=arcpy.Polyline(array)
422
+                                                cursorY.insertRow([pl])
423
+                                        ii = ii + 1
424
+                                else:
425
+                                    listF = linezd(linelist[mm0],poly1)
426
+                                    ii = len(listF) - 1
427
+                                    while ii >= 0:
428
+                                        if ii == len(listF) - 1:
429
+                                            zdh = zdh + 1
430
+                                            bsm = bsm + 1
431
+                                            # shape
432
+                                            point1 = arcpy.Point(listF[ii][0], listF[ii][1])
433
+                                            # 要素代码
434
+                                            ysdm = '6002010300'
435
+                                            # 界址点号
436
+                                            jzdh = 'J' + str(zdh)
437
+                                            # 宗地代码
438
+                                            zddm = curA[1]
439
+                                            ag = calcangle(listF[ii-1],listF[ii])
440
+                                            rlist = []
441
+                                            rlist.append(point1)
442
+                                            rlist.append(bsm)
443
+                                            rlist.append(ysdm)
444
+                                            rlist.append(jzdh)
445
+                                            rlist.append('')
446
+                                            rlist.append('')
447
+                                            rlist.append(zddm)
448
+                                            rlist.append(zdh)
449
+                                            rlist.append(mm0+1)
450
+                                            rlist.append(ag)
451
+                                            cursorZ.insertRow(rlist)
452
+                                            point = arcpy.Point(listF[ii][0], listF[ii][1])                        
453
+                                            if ii == len(listF) - 1:
454
+                                                point0 = arcpy.Point(listF[0][0], listF[0][1])
455
+                                            else:
456
+                                                point0 = arcpy.Point(listF[ii+1][0], listF[ii+1][1])
457
+                                            array=arcpy.Array()
458
+                                            array.add(point)
459
+                                            array.add(point0)
460
+                                            pl=arcpy.Polyline(array)
461
+                                            cursorY.insertRow([pl])
462
+                                        else:
463
+                                            numdis0 = listF[ii][0] - listF[ii - 1][0]
464
+                                            numdis1 = listF[ii][1] - listF[ii - 1][1]
465
+                                            numdis2 = math.sqrt((numdis0 * numdis0)+(numdis1*numdis1))
466
+                                            if numdis2 < 0.1:
467
+                                                pass
468
+                                            else:
469
+                                                zdh = zdh + 1
470
+                                                bsm = bsm + 1
471
+                                                # shape
472
+                                                point1 = arcpy.Point(listF[ii][0], listF[ii][1])
473
+                                                # 要素代码
474
+                                                ysdm = '6002010300'
475
+                                                # 界址点号
476
+                                                jzdh = 'J' + str(zdh)
477
+                                                # 宗地代码
478
+                                                zddm = curA[1]
479
+                                                ag = calcangle(listF[ii-1],listF[ii])
480
+                                                rlist = []
481
+                                                rlist.append(point1)
482
+                                                rlist.append(bsm)
483
+                                                rlist.append(ysdm)
484
+                                                rlist.append(jzdh)
485
+                                                rlist.append('')
486
+                                                rlist.append('')
487
+                                                rlist.append(zddm)
488
+                                                rlist.append(zdh)
489
+                                                rlist.append(mm0+1)
490
+                                                rlist.append(ag)
491
+                                                cursorZ.insertRow(rlist)
492
+                                                point = arcpy.Point(listF[ii][0], listF[ii][1])                        
493
+                                                if ii == len(listF) - 1:
494
+                                                    point0 = arcpy.Point(listF[0][0], listF[0][1])
495
+                                                else:
496
+                                                    point0 = arcpy.Point(listF[ii+1][0], listF[ii+1][1])
497
+                                                array=arcpy.Array()
498
+                                                array.add(point)
499
+                                                array.add(point0)
500
+                                                pl=arcpy.Polyline(array)
501
+                                                cursorY.insertRow([pl])
502
+                                        ii = ii - 1
503
+                                mm0 = mm0 + 1
504
+
505
+def pdlen(list1):
506
+    ii = 0
507
+    list2 = []
508
+    while ii < len(list1):
509
+        pts = list1[ii]
510
+        length1 = 0
511
+        mm = 0
512
+        while mm < len(pts):
513
+            if mm == len(pts) - 1:
514
+                pt1 = pts[mm]
515
+                pt2 = pts[0]
516
+                dis1 = math.sqrt(((pt1.X-pt2.X)*(pt1.X-pt2.X))+((pt1.Y-pt2.Y)*(pt1.Y-pt2.Y)))
517
+                length1 = length1 + dis1
518
+                mm = mm + 1
519
+            else:
520
+                pt1 = pts[mm]
521
+                pt2 = pts[mm + 1]
522
+                dis1 = math.sqrt(((pt1.X-pt2.X)*(pt1.X-pt2.X))+((pt1.Y-pt2.Y)*(pt1.Y-pt2.Y)))
523
+                length1 = length1 + dis1
524
+                mm = mm + 1
525
+        slist2 = []
526
+        slist2.append(length1)
527
+        slist2.append(pts)
528
+        list2.append(slist2)
529
+        ii = ii + 1
530
+    list2.sort(reverse=True)
531
+    nn = 0
532
+    list3 = []
533
+    while nn < len(list2):
534
+        list3.append(list2[nn][1])
535
+        nn = nn + 1
536
+    return list3
537
+                
538
+def calc_angle(lastp,p):
539
+    angle = 0
540
+    if p[0]-lastp[0]>0 and p[1]-lastp[1]>0:#↗
541
+        angle = 0
542
+    if p[0]-lastp[0]>0 and p[1]-lastp[1]<0:#↘
543
+        angle = 90
544
+    if p[0]-lastp[0]<0 and p[1]-lastp[1]<0:#↙
545
+        angle = 180
546
+    if p[0]-lastp[0]<0 and p[1]-lastp[1]>0:#↖
547
+        angle = 270
548
+    return angle
549
+
550
+def cal_stdangle(lastp,p): 
551
+    stdangle=0
552
+    dy= p[1]-lastp[1]
553
+    dx= p[0]-lastp[0]
554
+    if dx==0 and dy>0:
555
+        stdangle = 0
556
+    if dx==0 and dy<0:
557
+        stdangle = 180
558
+    if dy==0 and dx>0:
559
+        stdangle = 90
560
+    if dy==0 and dx<0:
561
+        stdangle = 270
562
+    if dx>0 and dy>0:
563
+       stdangle = math.atan(dx/dy)*180/math.pi
564
+    elif dx<0 and dy>0:
565
+       stdangle = 360 + math.atan(dx/dy)*180/math.pi
566
+    elif dx<0 and dy<0:
567
+       stdangle = 180 + math.atan(dx/dy)*180/math.pi
568
+    elif dx>0 and dy<0:
569
+       stdangle = 180 + math.atan(dx/dy)*180/math.pi
570
+    return stdangle
571
+    
572
+def calcangle(lastp,p): 
573
+    angle=0
574
+    stdangle = cal_stdangle(lastp,p)
575
+    if (stdangle < 45 and stdangle >= 0) or (stdangle <= 360 and stdangle >= 315):
576
+        angle = 270
577
+    if (stdangle < 135 and stdangle >= 45):
578
+        angle = 0
579
+    if (stdangle < 225 and stdangle >= 135):
580
+        angle = 90
581
+    if (stdangle < 315 and stdangle >= 225):
582
+        angle = 180
583
+    return angle
584
+    
585
+def addpoint(list1,pt):
586
+    ptx = round(pt.X,4)
587
+    pty = round(pt.Y,4)
588
+    ii = 0
589
+    bl = 1
590
+    while ii < len(list1):
591
+        if ptx == round(list1[ii].X,4) and pty == round(list1[ii].Y,4):
592
+            bl = -1
593
+        ii = ii + 1
594
+    return bl
595
+
596
+def linezd(line1,poly):
597
+    # 获取折点
598
+    mm = 0
599
+    pp = 0
600
+    list1 = []
601
+    while mm < len(line1):
602
+        plist = []
603
+        jzd = line1[mm]
604
+        try:
605
+            xx = jzd.X
606
+            yy = jzd.Y
607
+            plist.append(xx)
608
+            plist.append(yy)
609
+            # 初始顺序
610
+            plist.append(pp)
611
+            list1.append(plist)
612
+            pp = pp + 1
613
+            mm = mm + 1
614
+        except:
615
+            mm = mm + 1 
616
+    # 对折点排序(算法)
617
+    if len(list1) < 3:
618
+        listF = []
619
+    else:
620
+        # listF = zdsort(list1, zx)
621
+        listF = jzdsort(list1,poly)
622
+    return listF
623
+
624
+def jzdsort(list0,poly):
625
+    m = 0
626
+    n = 0
627
+    northwest = []
628
+    northwest.append(poly.extent.XMin)
629
+    northwest.append(poly.extent.YMax)
630
+    minDis = (northwest[1] - list0[0][1])*(northwest[1] - list0[0][1]) + (northwest[0] - list0[0][0])*(northwest[0] - list0[0][0])
631
+    maxStdangle = cal_stdangle(northwest,list0[0])
632
+    while m < len(list0):        
633
+        Dis = (northwest[1] - list0[m][1])*(northwest[1] - list0[m][1]) + (northwest[0] - list0[m][0])*(northwest[0] - list0[m][0])
634
+        if Dis < minDis:
635
+            minDis = Dis
636
+            maxStdangle = cal_stdangle(northwest,list0[m])
637
+            n = m
638
+        if abs(Dis-minDis) < 0.000001:
639
+            stdangle = cal_stdangle(northwest,list0[m])
640
+            if stdangle > maxStdangle:
641
+                maxStdangle = stdangle
642
+                n = m 
643
+        m = m + 1
644
+    i = 0
645
+    while i < len(list0):    
646
+        if n == 0:
647
+            vectangleN = cal_stdangle(list0[0], list0[1])
648
+            vectangleNl = cal_stdangle(list0[len(list0)-1], list0[0]) 
649
+            if abs(vectangleN-vectangleNl) < 3:
650
+                n = len(list0)-1          
651
+        else:
652
+            if n == len(list0)-1:
653
+                vectangleN = cal_stdangle(list0[n], list0[0])
654
+            else:            
655
+                vectangleN = cal_stdangle(list0[n], list0[n+1]) 
656
+            vectangleNl = cal_stdangle(list0[n-1], list0[n])    
657
+            if abs(vectangleN-vectangleNl) < 3:
658
+                n = n-1
659
+        i = i + 1
660
+    list4 = []     
661
+    a = n     
662
+    num = 0
663
+    while a < len(list0):
664
+        slist4 = []
665
+        num = num + 1
666
+        slist4.append(list0[a][0])
667
+        slist4.append(list0[a][1])
668
+        slist4.append(num)
669
+        list4.append(slist4)   
670
+        a = a + 1    
671
+    a = 0
672
+    while a < n:
673
+        slist4 = []
674
+        num = num + 1
675
+        slist4.append(list0[a][0])
676
+        slist4.append(list0[a][1])
677
+        slist4.append(num)
678
+        list4.append(slist4)   
679
+        a = a + 1
680
+    return list4
681
+    
682
+def mkdir(path):
683
+	folder = os.path.exists(path)
684
+	if not folder:                   #判断是否存在文件夹如果不存在则创建为文件夹
685
+		os.makedirs(path)            #makedirs 创建文件时如果路径不存在会创建这个路径
686
+
687
+def getScale(scale):
688
+	yushu = float(str(scale).split(".", 1)[0]) % 50
689
+	lastTWO = 0
690
+	if yushu < 25:
691
+		lastTWO = float(str(scale).split(".", 1)[0]) // 50 * 50
692
+	if yushu < 75 and yushu >= 25:
693
+		lastTWO = float(str(scale).split(".", 1)[0]) // 50 * 50 + 50
694
+	if yushu < 100 and yushu >= 75:
695
+		lastTWO = float(str(scale).split(".", 1)[0]) // 50 * 50 + 100
696
+	scale = "1:" + str(lastTWO).split(".",1)[0]
697
+	return scale
698
+
699
+class LayerObject:
700
+    currentLayer = ""
701
+
702
+mxd = arcpy.mapping.MapDocument('current')
703
+df = arcpy.mapping.ListDataFrames(mxd)[0]
704
+
705
+LayerObject.currentLayer = arcpy.GetParameterAsText(0)
706
+arcpy.SelectLayerByAttribute_management(LayerObject.currentLayer, "CLEAR_SELECTION")
707
+arcpy.SelectLayerByAttribute_management("Copy", "CLEAR_SELECTION")
708
+#设置保存路径
709
+savePath1 = arcpy.GetParameterAsText(1)
710
+singlelist = arcpy.GetParameterAsText(2).split(",")
711
+arcpy.env.workspace = arcpy.GetParameterAsText(3)
712
+times = 1
713
+if len(arcpy.GetParameterAsText(4)) > 0:
714
+    times = float(arcpy.GetParameterAsText(4))
715
+#宗地添加面积字段并计算    
716
+arcpy.AddField_management(LayerObject.currentLayer, "Area", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
717
+arcpy.CalculateField_management(LayerObject.currentLayer, "Area", "round(!shape.area!,2)", "PYTHON_9.3")
718
+#面转线 
719
+line = arcpy.PolygonToLine_management("Copy", savePath1 +"\line.shp")
720
+
721
+#遍历宗地
722
+rows = arcpy.SearchCursor(LayerObject.currentLayer)    
723
+for row in rows:
724
+    if row.getValue(u"宗地编号")[-3:] in singlelist:
725
+        for lyr in arcpy.mapping.ListLayers(mxd, "", df):
726
+            if lyr.name == "dlclip":
727
+                arcpy.mapping.RemoveLayer(df, lyr)
728
+            if lyr.name == "JZD":
729
+                arcpy.mapping.RemoveLayer(df, lyr)
730
+            if lyr.name == "JZX":
731
+                arcpy.mapping.RemoveLayer(df, lyr)
732
+            if lyr.name == "lineclip":
733
+                arcpy.mapping.RemoveLayer(df, lyr)
734
+        filename = row.getValue(u"宗地编号")  
735
+        savePath = os.path.join(savePath1, filename)
736
+        mkdir(savePath)
737
+        arcpy.SelectLayerByAttribute_management(LayerObject.currentLayer, "CLEAR_SELECTION")
738
+        arcpy.SelectLayerByAttribute_management("Copy", "CLEAR_SELECTION")
739
+        OBJECTID_1 = row.getValue(u"OBJECTID_1")
740
+        query = "OBJECTID_1={0}".format(OBJECTID_1)
741
+        #
742
+        arcpy.SelectLayerByAttribute_management(LayerObject.currentLayer, "NEW_SELECTION", query)
743
+        #
744
+        df.zoomToSelectedFeatures()
745
+        df.scale *= 1.1
746
+        shape = row.shape
747
+        #编辑文本元素
748
+              
749
+        qlr = row.getValue(u"权利人")
750
+        title = filename + qlr + u"宗地图"
751
+        tfh = " "
752
+        zdmj = "{}".format(row.getValue(u"Area"))
753
+        
754
+            
755
+        # east = row.getValue(u"四至东")
756
+        # east =east.replace(")","/0301)")
757
+        # south = row.getValue(u"四至南")
758
+        # south =south.replace(")","/0301)")
759
+        # west = row.getValue(u"四至西")
760
+        # west =west.replace(")","/0301)")
761
+        # north = row.getValue(u"四至北")
762
+        # north =north.replace(")","/0301)")
763
+        time_tuple = time.localtime(time.time())
764
+        rq = "{}年{}月{}日".format(time_tuple[0],time_tuple[1],time_tuple[2])
765
+        ny = "{}年{}月".format(time_tuple[0],time_tuple[1])
766
+        elemlist = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT")
767
+        for elem in elemlist:
768
+            if elem.name == "zddm":
769
+                elem.text = filename
770
+            if elem.name == "qlr":
771
+                elem.text = qlr
772
+            if elem.name == "tfh":
773
+                elem.text = tfh
774
+                #预先添加标准TF图层,计算得到图幅号    
775
+                TFtoTB(row.shape, elem)
776
+            if elem.name == "zdmj":
777
+                elem.text = zdmj
778
+            # if elem.name == "east":
779
+            #     elem.text = east           
780
+            # if elem.name == "south":
781
+            #     elem.text = south          
782
+            # if elem.name == "west":
783
+            #     elem.text = west
784
+            # if elem.name == "north":
785
+            #     elem.text = north
786
+            if elem.name == "scale":
787
+                elem.text = getScale(df.scale)
788
+            if elem.name == "ztz":
789
+                elem.text = random.choice(['王荣华','余思翰','阮梦妍','杨玉婧','赵芩','屈亚星'])
790
+            if elem.name == "shz":
791
+                elem.text = random.choice(['何杰','张学仪'])
792
+            if elem.name == "ztrq":
793
+                elem.text = rq
794
+            if elem.name == "shrq":
795
+                elem.text = rq
796
+            if elem.name == "jzdtjf":
797
+                elem.text = ny + "图解法测绘界址点"
798
+            if elem.name == "zlz":
799
+                title = filename + qlr + u"宗地草图"
800
+                elem.text = random.choice(['王荣华','余思翰','阮梦妍','杨玉婧','赵芩','屈亚星'])
801
+            if elem.name == "jcz":
802
+                elem.text = random.choice(['何杰','张学仪'])
803
+            if elem.name == "zlrq":
804
+                elem.text = rq
805
+            if elem.name == "jcrq":
806
+                elem.text = rq
807
+
808
+        arcpy.SelectLayerByAttribute_management("TF", "CLEAR_SELECTION")
809
+
810
+        #生成当前宗地界址点线   
811
+        JZGenerate(savePath, filename)
812
+        arcpy.SelectLayerByAttribute_management(LayerObject.currentLayer, "NEW_SELECTION", query)
813
+        #界址线添加长度字段
814
+        arcpy.AddField_management("JZX", "LENGTH", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
815
+        arcpy.CalculateField_management("JZX", "LENGTH", "round(!shape.length!,2)", "PYTHON_9.3")
816
+
817
+        
818
+        #建立缓冲区
819
+        if df.scale > 1000:
820
+            shapebuffer = arcpy.Polygon.buffer(shape, 10 * times)
821
+        elif df.scale > 900:
822
+            shapebuffer = arcpy.Polygon.buffer(shape, 9 * times)
823
+        elif df.scale > 800:
824
+            shapebuffer = arcpy.Polygon.buffer(shape, 8 * times)
825
+        elif df.scale > 700:
826
+            shapebuffer = arcpy.Polygon.buffer(shape, 7 * times)            
827
+        elif df.scale > 600:
828
+            shapebuffer = arcpy.Polygon.buffer(shape, 6 * times)
829
+        elif df.scale > 500:
830
+            shapebuffer = arcpy.Polygon.buffer(shape, 5 * times)
831
+        elif df.scale > 400:
832
+            shapebuffer = arcpy.Polygon.buffer(shape, 4 * times)
833
+        elif df.scale > 300:
834
+            shapebuffer = arcpy.Polygon.buffer(shape, 3 * times)
835
+        elif df.scale > 200:
836
+            shapebuffer = arcpy.Polygon.buffer(shape, 2 * times)
837
+        elif df.scale > 100:
838
+            shapebuffer = arcpy.Polygon.buffer(shape, 1 * times)
839
+        else:
840
+            shapebuffer = arcpy.Polygon.buffer(shape, 0.5 * times)
841
+        #裁剪线图层  
842
+        arcpy.Clip_analysis(line, shapebuffer, savePath + "\lineclip.shp")
843
+        lyrline = arcpy.mapping.Layer(savePath + "\lineclip.shp")
844
+        arcpy.mapping.AddLayer(df, lyrline)  
845
+        arcpy.SelectLayerByLocation_management(lyrline, "BOUNDARY_TOUCHES", shape)
846
+        arcpy.SelectLayerByAttribute_management(lyrline, "SWITCH_SELECTION")
847
+        arcpy.DeleteFeatures_management(lyrline)
848
+        
849
+        arcpy.SelectLayerByLocation_management("BCDW", "BOUNDARY_TOUCHES", shape)
850
+        arcpy.CopyFeatures_management("BCDW", savePath + "\BCDW.shp")
851
+        
852
+        arcpy.SelectLayerByLocation_management("ZJD", "BOUNDARY_TOUCHES", shape)
853
+        arcpy.CopyFeatures_management("ZJD", savePath + "\ZJD.shp")
854
+        
855
+        arcpy.SelectLayerByLocation_management("Copy", "SHARE_A_LINE_SEGMENT_WITH", shape)
856
+        neighlist = []
857
+        m = int(arcpy.GetCount_management("Copy").getOutput(0))
858
+        if m != 0:
859
+            with arcpy.da.SearchCursor("Copy", ['宗地编号']) as cursor:
860
+                for cur in cursor:
861
+                    f = cur[0]
862
+                    if f == filename:
863
+                        pass
864
+                    else:
865
+                        if neighlist.__contains__(f):
866
+                            pass
867
+                        else:
868
+                            neighlist.append(f)
869
+        txtfile = open(os.path.join(savePath1, "neighbourList.txt"),'a')
870
+        txtfile.write(filename + ':' + str(len(neighlist)) + str(tuple(neighlist)).replace("u","").replace("510811100205JE00","") + '\n')
871
+        
872
+        arcpy.Clip_analysis("DLTB", shapebuffer, savePath + "\dlbfclip.shp")
873
+        shape1 = arcpy.Polygon.buffer(shape, 0.1)
874
+        #     
875
+        arcpy.Erase_analysis(savePath + "\dlbfclip.shp", shape1, savePath + "\dlclip.shp")
876
+        #                
877
+
878
+        fcs = arcpy.ListFeatureClasses() 
879
+        for fc in fcs:            
880
+            if fc.__contains__("dlclip"):
881
+                arcpy.Delete_management(os.path.join(arcpy.env.workspace,fc))
882
+        #arcpy.env.workspace = savePath
883
+        arcpy.FeatureClassToGeodatabase_conversion([savePath + '\dlclip.shp'], arcpy.env.workspace)  
884
+        
885
+        target_lyr = arcpy.env.workspace + "\dlclip"
886
+        #     
887
+        arcpy.AddRepresentation_cartography(target_lyr,
888
+                                "DL_Rep",                                    
889
+                                import_rule_layer = "DLTB")
890
+        arcpy.CalculateField_management(target_lyr, "RuleID_1", '!RuleID!', "PYTHON_9.3")
891
+
892
+        lyrdl = arcpy.mapping.Layer(target_lyr)
893
+        refLayer = arcpy.mapping.ListLayers(mxd, "", df)
894
+        arcpy.mapping.InsertLayer(df, refLayer[len(refLayer) - 1], lyrdl, "AFTER")
895
+
896
+        arcpy.SetLayerRepresentation_cartography("dlclip", "DL_Rep")
897
+
898
+        for lyr in arcpy.mapping.ListLayers(mxd, "", df):
899
+            if lyr.name == "Point":
900
+                lyr.replaceDataSource(savePath, "SHAPEFILE_WORKSPACE", "JZD")
901
+                lyr.showLabels = True
902
+                lyr.labelClasses[0].SQLQuery  = "ANGLE = 0"
903
+                lyr.labelClasses[0].expression  = "[JZDH]"
904
+                lyr.labelClasses[1].SQLQuery  = "ANGLE = 90"
905
+                lyr.labelClasses[1].expression  = "[JZDH]"
906
+                lyr.labelClasses[2].SQLQuery  = "ANGLE = 180"
907
+                lyr.labelClasses[2].expression  = "[JZDH]"
908
+                lyr.labelClasses[3].SQLQuery  = "ANGLE = 270"
909
+                lyr.labelClasses[3].expression  = "[JZDH]"
910
+                lyr.visible = True                    
911
+            elif lyr.name == "Polyline":
912
+                lyr.replaceDataSource(savePath, "SHAPEFILE_WORKSPACE", "JZX")
913
+                lyr.showLabels = True
914
+                lyr.labelClasses[0].expression  = "[LENGTH]"                
915
+                lyr.visible = True
916
+            elif lyr.name == LayerObject.currentLayer:
917
+                lyr.showLabels = True
918
+                lyr.labelClasses[0].SQLQuery = '"OBJECTID_1" = ' + str(OBJECTID_1)
919
+                lyr.visible = True
920
+            elif lyr.name == "Copy":
921
+                lyr.showLabels = True
922
+                sqlquery = str(tuple(neighlist))
923
+                if sqlquery.endswith(",)"):
924
+                    query = sqlquery.replace(",)", ")")
925
+                else:
926
+                    query = sqlquery
927
+                lyr.labelClasses[0].SQLQuery = '"宗地编号" IN ' + query.replace("u","")   
928
+                lyr.visible = True
929
+            elif lyr.name == "line":
930
+                lyr.replaceDataSource(savePath, "SHAPEFILE_WORKSPACE", "lineclip")
931
+                lyr.visible = True                
932
+            elif lyr.name == "dlclip":
933
+                lyr.visible = True 
934
+            elif lyr.name == "BCDW":
935
+                lyr.replaceDataSource(savePath, "SHAPEFILE_WORKSPACE", "BCDW")
936
+                lyr.visible = True        
937
+            elif lyr.name == "ZJD":
938
+                lyr.replaceDataSource(savePath, "SHAPEFILE_WORKSPACE", "ZJD")
939
+                lyr.visible = True                  
940
+            else:
941
+                lyr.visible = False    
942
+        #saveMxdPath = savePath + "\\" + title + ".mxd"
943
+        #mxd.saveACopy(saveMxdPath)
944
+        arcpy.mapping.ExportToJPEG( mxd, savePath  + "\\" + title + ".jpg", resolution = 300)
945
+        arcpy.Delete_management(savePath +"\dlbfclip.shp")
946
+        arcpy.Delete_management(savePath +"\dlclip.shp")
947
+        #arcpy.Delete_management(savePath +"\lineclip.shp")
948
+        #arcpy.Delete_management(savePath +"\JZD.shp")
949
+        #arcpy.Delete_management(savePath +"\JZX.shp")
950
+        arcpy.AddMessage (filename + ' Finish!')
951
+        txtfile.close() 
952
+arcpy.Delete_management(savePath1 +"\line.shp")
953
+     

+ 28
- 0
代码/20221220林权/LQ/dlCMM_1203.py 查看文件

@@ -0,0 +1,28 @@
1
+import arcpy
2
+import math
3
+
4
+def LZDpoly(zdshp):
5
+    arcpy.MakeFeatureLayer_management(zdshp, 'ZD')
6
+    # 在外面写个字典
7
+    zd = {'公路用地': 'GLYD', '特殊用地': 'TSYD', '公用设施用地': 'GYSS', '交通服务场站用地': 'JTFW', '沟渠': 'GQ',
8
+          '灌木林地': 'GMLD', '其他林地': 'QTLD', '乔木林地': 'QMLD', '竹林地': 'ZLD', '果园': 'GY', '旱地': 'HD', 
9
+          '河流水面': 'HLSM', '坑塘水面': 'KTSM', '养殖坑塘': 'YZKT', '农村道路': 'NCDL', '农村宅基地': 'NCZJD', 
10
+          '其他草地': 'QTCD', '其他园地': 'QTYD', '设施农用地': 'SSNYD', '水田': 'ST'}
11
+    arcpy.AddField_management('ZD', 'dl', 'TEXT')
12
+    with arcpy.da.UpdateCursor('ZD', ['SHAPE@', '宗地编码','DLMC','dl']) as cursorA:
13
+        for curA in cursorA:
14
+            zdbh = curA[1]
15
+            dlmc = curA[2]
16
+            if dlmc == '' or dlmc == ' ' or dlmc == None:
17
+                curA[3] = zdbh
18
+            else:
19
+                str1 = zd[dlmc]
20
+                curA[3] = str1
21
+            cursorA.updateRow (curA)
22
+
23
+if __name__ == '__main__':
24
+    try:
25
+        # 输入宗地shp
26
+        LZDpoly(r'D:\2work_now\20221026\test\testLZD1.shp')
27
+    except arcpy.ExecuteError:
28
+        arcpy.AddMessage(arcpy.GetMessages())

+ 136
- 0
代码/20231108黄河断面/DMljjs.py 查看文件

@@ -0,0 +1,136 @@
1
+import os
2
+from posixpath import dirname
3
+import xlrd
4
+import xlwt
5
+import math
6
+import tkinter as tk
7
+import numpy as np
8
+from tkinter import filedialog as tkFileDialog
9
+from tkinter import messagebox
10
+
11
+def start():
12
+    window = tk.Tk() # 创建窗口对象的背景色
13
+    window.title('断面累距计算程序')  # 设置窗口的标题
14
+    window.geometry('400x200')     # 设置窗口的大小
15
+    title = tk.Label(window, text='断面累距计算程序',
16
+                     font=('微软雅黑', 12), width=40, height=3)
17
+    title.place(x=0, y=0, anchor='nw')
18
+    choosepath = tk.Label(window, text='断面表格文件夹:',
19
+                          font=('微软雅黑', 12), width=20, height=2)
20
+    choosepath.place(x=0, y=50, anchor='nw')
21
+    path_var1 = tk.StringVar() # 输入路径
22
+    entry1 = tk.Entry(window, textvariable=path_var1)
23
+    entry1.place(x=170, y=65, anchor='nw')
24
+
25
+    def choose1():
26
+        file_dir = tkFileDialog.askdirectory()
27
+        path_var1.set(file_dir)
28
+
29
+    def tuichu():
30
+        window.destroy()
31
+
32
+    def main():
33
+        inpath = entry1.get()
34
+        #遍历文件夹
35
+        for parent,dirname,filenames in os.walk(inpath):
36
+            for filename in filenames:
37
+                #排除其他文件的干扰
38
+                if '.xls' in filename:
39
+                    if '_100' in filename:
40
+                        pass
41
+                    else:
42
+                        #完整路径
43
+                        filepath = parent + '/' +filename
44
+                        #拆分出断面名字dmm
45
+                        dmm = filename.split('.',-1)[0]
46
+                        xls = xlrd.open_workbook(filepath)
47
+                        sheet1 = xls.sheets()[0]
48
+                        #存个list存放距离
49
+                        dislist = []
50
+                        rows = sheet1.nrows
51
+                        ii = 1
52
+                        fpx = 0
53
+                        fpy = 0
54
+                        while ii < rows:
55
+                            if sheet1.cell_value(ii,1) != '':
56
+                                if ii == 1:
57
+                                    #起点
58
+                                    fpx = sheet1.cell_value(ii,1)
59
+                                    fpy = sheet1.cell_value(ii,2)
60
+                                    list1 = []
61
+                                    list1.append(fpx)
62
+                                    list1.append(fpy)
63
+                                    list1.append(sheet1.cell_value(ii,3))
64
+                                    list1.append(sheet1.cell_value(ii,4))
65
+                                    list1.append(0)
66
+                                    dislist.append(list1)
67
+                                    ii = ii + 1
68
+                                else:
69
+                                    xx = sheet1.cell_value(ii,1)
70
+                                    yy = sheet1.cell_value(ii,2)
71
+                                    #距离公式
72
+                                    num1 = xx - fpx
73
+                                    num2 = yy - fpy
74
+                                    num3 = num1 * num1
75
+                                    num4 = num2 * num2
76
+                                    num5 = num3 + num4
77
+                                    dis1 = math.sqrt(num5)
78
+                                    list1 = []
79
+                                    list1.append(xx)
80
+                                    list1.append(yy)
81
+                                    list1.append(sheet1.cell_value(ii,3))
82
+                                    list1.append(sheet1.cell_value(ii,4))
83
+                                    list1.append(dis1)
84
+                                    dislist.append(list1)
85
+                                    ii = ii + 1
86
+                            else:
87
+                                break
88
+                        #写到xls上
89
+                        #重创一个地址,然后全部重命名
90
+                        filepath1 = parent + '/' + dmm + '_100.xls'
91
+                        workbook = xlwt.Workbook(filepath1)
92
+                        sheet = workbook.add_sheet("sheet1")
93
+                        #抬头
94
+                        sheet.write(0,0,'点号')
95
+                        sheet.write(0,1,'X')
96
+                        sheet.write(0,2,'Y')
97
+                        sheet.write(0,3,'Z')
98
+                        sheet.write(0,4,'备注')
99
+                        sheet.write(0,5,'累距')
100
+                        mm = 0
101
+                        while mm < len(dislist):
102
+                            sheet.write((mm + 1), 0, (mm + 1))
103
+                            sheet.write((mm + 1), 1, dislist[mm][0])
104
+                            sheet.write((mm + 1), 2, dislist[mm][1])
105
+                            sheet.write((mm + 1), 3, round(dislist[mm][2],3))
106
+                            sheet.write((mm + 1), 4, dislist[mm][3])
107
+                            sheet.write((mm + 1), 5, round(dislist[mm][4],3))
108
+                            mm = mm + 1
109
+                        #删除以前的
110
+                        os.remove(filepath)
111
+                        workbook.save(filepath1)
112
+                        print(filename + ' FINISH')
113
+        #全部重命名
114
+        for parent,dirname,filenames in os.walk(inpath):
115
+            for filename in filenames:
116
+                #排除其他文件的干扰
117
+                if '.xls' in filename:
118
+                    ori = parent + '/' +filename
119
+                    newfile = filename.replace('_100','')
120
+                    new = parent + '/' + newfile
121
+                    os.rename(ori,new)
122
+                    print(filename + ' RENAME')
123
+        messagebox.showinfo("消息","运行成功")
124
+        window.destroy()
125
+
126
+                                
127
+
128
+
129
+
130
+    tk.Button(window, text='选择', command=choose1).place(x=320, y=60, anchor='nw')
131
+    tk.Button(window,text='确认',command=main).place(x=120,y=110,anchor='nw')
132
+    tk.Button(window,text='取消',command=tuichu).place(x=220,y=110,anchor='nw')
133
+    window.mainloop()
134
+
135
+if __name__ == '__main__':
136
+    start()

+ 104
- 0
代码/20231108黄河断面/DMzj.py 查看文件

@@ -0,0 +1,104 @@
1
+from pyautocad import Autocad, APoint, aDouble
2
+import os
3
+from posixpath import dirname
4
+import xlrd
5
+import tkinter as tk
6
+from tkinter import filedialog as tkFileDialog
7
+from tkinter import messagebox
8
+import shutil
9
+
10
+def start():
11
+    window = tk.Tk() # 创建窗口对象的背景色
12
+    window.title('断面名注记程序')  # 设置窗口的标题
13
+    window.geometry('400x250')     # 设置窗口的大小
14
+    title = tk.Label(window, text='断面名注记程序',
15
+                     font=('微软雅黑', 12), width=40, height=3)
16
+    title.place(x=0, y=0, anchor='nw')
17
+    choosepath = tk.Label(window, text='选择表格文件夹:',
18
+                          font=('微软雅黑', 12), width=20, height=2)
19
+    choosepath.place(x=0, y=50, anchor='nw')
20
+    path_var1 = tk.StringVar() # 输入路径
21
+    entry1 = tk.Entry(window, textvariable=path_var1)
22
+    entry1.place(x=170, y=65, anchor='nw')
23
+    resultpath = tk.Label(window, text='选择dwg:',
24
+                          font=('微软雅黑', 12), width=20, height=2)
25
+    resultpath.place(x=10, y=100, anchor='nw')
26
+    path_var2 = tk.StringVar() # 输出路径
27
+    entry2 = tk.Entry(window, textvariable=path_var2)
28
+    entry2.place(x=170, y=115, anchor='nw')
29
+    lebel1 = tk.Label(window, text='请确保CAD已经打开。',
30
+                          font=('微软雅黑', 10), width=40, height=2)
31
+    lebel1.place(x=0, y=150, anchor='nw')
32
+
33
+    def choose1():
34
+            file_dir1 = tkFileDialog.askdirectory()
35
+            path_var1.set(file_dir1)
36
+
37
+    def choose2():
38
+            file_dir2 = tkFileDialog.askopenfilename(filetypes=[('DWG', '*.dwg'), ('DWG', '*.DWG'),('All Files', '*')])
39
+            path_var2.set(file_dir2)
40
+
41
+    def tuichu():
42
+        window.destroy()
43
+    
44
+    def main():
45
+        excelpath = entry1.get()
46
+        dwgpath = entry2.get()
47
+        #遍历文件,得到点的坐标和注记内容
48
+        list1 = []
49
+        for parent,dirname,filenames in os.walk(excelpath):
50
+            for filename in filenames:
51
+                #排一下其他文件
52
+                if '.xls' in filename:
53
+                    #得到表格的完整路径
54
+                    filepath = parent + '/' +filename
55
+                    #拆分出断面名字dmm
56
+                    dmm = filename.split('.',-1)[0]
57
+                    #只取excel的第一个端点
58
+                    xlr = xlrd.open_workbook(filepath)
59
+                    table = xlr.sheets()[0]
60
+                    list2 = []
61
+                    list2.append(dmm)
62
+                    list2.append(table.cell(1, 1).value)
63
+                    list2.append(table.cell(1, 2).value)
64
+                    list1.append(list2)
65
+        #打开cad
66
+        #首先链接cad
67
+        acad = Autocad(create_if_not_exists=True)
68
+        acad.Application.Documents.Open(dwgpath)
69
+        # 当前文件模型空间中所包含的图层总数
70
+        layernums = acad.ActiveDocument.Layers.count 
71
+        # 获取指定图层索引号
72
+        layernames = [acad.ActiveDocument.Layers.Item(i).Name for i in range(layernums)]
73
+        index = layernames.index("DMX") 
74
+        # 将指定图层设定当前
75
+        acad.ActiveDocument.ActiveLayer = acad.ActiveDocument.Layers.Item(index)
76
+        # 获取当前文档
77
+        doc = acad.doc
78
+        # 获取模型空间
79
+        msp = doc.ModelSpace
80
+        #先写上去,再看细节怎么调
81
+        # 定义文本的插入点坐标
82
+        ii = 0
83
+        while ii < len(list1):
84
+            # 定义文本的插入点坐标
85
+            insertion_point = APoint(list1[ii][1] - 1, list1[ii][2] + 1)
86
+            # 定义文本的高度和样式
87
+            text_height = 2.0
88
+            # 插入单行文本
89
+            text = msp.AddText(list1[ii][0], insertion_point, text_height)
90
+            ii = ii + 1
91
+        #关闭当前
92
+        acad.doc.Close()
93
+        messagebox.showinfo("消息","运行成功")
94
+        window.destroy()
95
+
96
+    tk.Button(window, text='选择', command=choose1).place(x=320, y=60, anchor='nw')
97
+    tk.Button(window, text='选择', command=choose2).place(x=320, y=110, anchor='nw')
98
+    tk.Button(window,text='确认',command=main).place(x=120,y=200,anchor='nw')
99
+    tk.Button(window,text='取消',command=tuichu).place(x=220,y=200,anchor='nw')
100
+
101
+    window.mainloop()
102
+
103
+if __name__ == '__main__':
104
+    start()

+ 84
- 0
代码/20231108黄河断面/HBexcel.py 查看文件

@@ -0,0 +1,84 @@
1
+import os
2
+import xlrd
3
+import tkinter as tk
4
+from tkinter import filedialog as tkFileDialog
5
+from tkinter import messagebox
6
+from openpyxl import load_workbook,workbook
7
+
8
+def start():
9
+    window = tk.Tk() # 创建窗口对象的背景色
10
+    window.title('excel合并程序')  # 设置窗口的标题
11
+    window.geometry('400x250')     # 设置窗口的大小
12
+    title = tk.Label(window, text='excel合并程序',
13
+                     font=('微软雅黑', 12), width=40, height=3)
14
+    title.place(x=0, y=0, anchor='nw')
15
+    choosepath = tk.Label(window, text='选择表格文件夹:',
16
+                          font=('微软雅黑', 12), width=20, height=2)
17
+    choosepath.place(x=0, y=50, anchor='nw')
18
+    path_var1 = tk.StringVar() # 输入路径
19
+    entry1 = tk.Entry(window, textvariable=path_var1)
20
+    entry1.place(x=170, y=65, anchor='nw')
21
+    resultpath = tk.Label(window, text='选择输出文件夹:',
22
+                          font=('微软雅黑', 12), width=20, height=2)
23
+    resultpath.place(x=8, y=100, anchor='nw')
24
+    path_var2 = tk.StringVar() # 输出路径
25
+    entry2 = tk.Entry(window, textvariable=path_var2)
26
+    entry2.place(x=170, y=115, anchor='nw')
27
+
28
+    def choose1():
29
+        file_dir = tkFileDialog.askdirectory()
30
+        path_var1.set(file_dir)
31
+
32
+    def choose2():
33
+        file_dir2 = tkFileDialog.askdirectory()
34
+        path_var2.set(file_dir2)
35
+
36
+    def tuichu():
37
+        window.destroy()
38
+
39
+    def main():
40
+        inpath = entry1.get()
41
+        outpath = entry2.get()
42
+        #输出路径
43
+        outfpath = outpath + '/UnionResult.xlsx'
44
+        new_wb = workbook()
45
+        ws2 = new_wb['Sheet']
46
+        new_wb.remove(ws2)
47
+        #遍历文件夹
48
+        for parent,dirname,filenames in os.walk(inpath):
49
+            for filename in filenames:
50
+                #排除其他文件的干扰
51
+                if '.xls' in filename:
52
+                    #完整路径
53
+                    filepath = parent + '/' +filename
54
+                    #记下名字
55
+                    fname = str(filename)
56
+                    dmm = fname.replace('.xls','')
57
+                    #读取
58
+                    xls = xlrd.open_workbook(filepath)
59
+                    sheet1 = xls.sheets()[0]
60
+                    rows = sheet1.nrows
61
+                    ii = 0
62
+                    while ii < rows:
63
+                        data = sheet1.row(ii)
64
+                if '.xlsx' in filename:
65
+                    #完整路径
66
+                    filepath = parent + '/' +filename
67
+                    #记下名字
68
+                    fname = str(filename)
69
+                    dmm = fname.replace('.xlsx','')
70
+                    old_wb = load_workbook(filepath)
71
+                    new_wb = load_workbook(outfpath)
72
+                    
73
+
74
+        messagebox.showinfo("消息","运行成功")
75
+        window.destroy()
76
+
77
+    tk.Button(window, text='选择', command=choose1).place(x=320, y=60, anchor='nw')
78
+    tk.Button(window, text='选择', command=choose2).place(x=320, y=110, anchor='nw')
79
+    tk.Button(window,text='确认',command=main).place(x=120,y=210,anchor='nw')
80
+    tk.Button(window,text='取消',command=tuichu).place(x=220,y=210,anchor='nw')
81
+    window.mainloop()
82
+
83
+if __name__ == '__main__':
84
+    start()

+ 114
- 0
代码/20231108黄河断面/HBhhdmtable.py 查看文件

@@ -0,0 +1,114 @@
1
+from pyautocad import Autocad, APoint, aDouble
2
+import os
3
+from posixpath import dirname
4
+import xlrd
5
+import tkinter as tk
6
+from tkinter import filedialog as tkFileDialog
7
+from tkinter import messagebox
8
+import shutil
9
+
10
+def start():
11
+    window = tk.Tk() # 创建窗口对象的背景色
12
+    window.title('断面线图表合并程序')  # 设置窗口的标题
13
+    window.geometry('400x250')     # 设置窗口的大小
14
+    title = tk.Label(window, text='断面线图表合并程序',
15
+                     font=('微软雅黑', 12), width=40, height=3)
16
+    title.place(x=0, y=0, anchor='nw')
17
+    choosepath = tk.Label(window, text='选择dwg文件夹:',
18
+                          font=('微软雅黑', 12), width=20, height=2)
19
+    choosepath.place(x=0, y=50, anchor='nw')
20
+    path_var1 = tk.StringVar() # 输入路径
21
+    entry1 = tk.Entry(window, textvariable=path_var1)
22
+    entry1.place(x=170, y=65, anchor='nw')
23
+    resultpath = tk.Label(window, text='选择输出文件夹:',
24
+                          font=('微软雅黑', 12), width=20, height=2)
25
+    resultpath.place(x=0, y=100, anchor='nw')
26
+    path_var2 = tk.StringVar() # 输出路径
27
+    entry2 = tk.Entry(window, textvariable=path_var2)
28
+    entry2.place(x=170, y=115, anchor='nw')
29
+    lebel1 = tk.Label(window, text='请确保CAD已经打开。',
30
+                          font=('微软雅黑', 10), width=40, height=2)
31
+    lebel1.place(x=0, y=145, anchor='nw')
32
+
33
+    def choose1():
34
+            file_dir1 = tkFileDialog.askdirectory()
35
+            path_var1.set(file_dir1)
36
+
37
+    def choose2():
38
+            file_dir2 = tkFileDialog.askdirectory()
39
+            path_var2.set(file_dir2)
40
+
41
+    def tuichu():
42
+        window.destroy()
43
+
44
+    def main():
45
+        excelpath = entry1.get()
46
+        outpath = entry2.get()
47
+        #首先链接cad
48
+        acad = Autocad(create_if_not_exists=True)
49
+        mm = 0
50
+        #遍历文件夹每个表格
51
+        for parent,dirname,filenames in os.walk(excelpath):
52
+            for filename in filenames:
53
+                #排一下其他文件
54
+                if '.dwg' in filename:
55
+                    #得到表格的完整路径
56
+                    filepath = parent + '/' +filename
57
+                    #拆分出断面名字dmm
58
+                    dmm = filename.split('.',-1)[0]
59
+                    #先复制,再打开,再另存覆盖?
60
+                    #判断下存在就删除
61
+                    #第一个点只需要z值,那么把断面名之类的信息也放在这里
62
+                    if mm == 0:
63
+                        outfpath = outpath + '\\合并断面.dwg'
64
+                        if os.path.exists(outfpath):
65
+                            os.remove(outfpath)
66
+                        shutil.copy(filepath, outfpath)
67
+                        acad.Application.Documents.Open(outfpath)
68
+                        target_doc = acad.ActiveDocument
69
+                    else:
70
+                        acad.Application.Documents.Open(filepath)
71
+                        doc = acad.ActiveDocument
72
+                        #把所有文字全部踢出来
73
+                        handle_string = 'select'
74
+                        text1 = list(acad.iter_objects(["Text", "Line","Circle"]))
75
+                        for t1 in text1:
76
+                            handle_string += ' (handent "'+t1.Handle+'")'
77
+                        #命令
78
+                        handle_string += '\n\n'
79
+                        doc.SendCommand(handle_string)
80
+                        #移动的距离做算法
81
+                        num1 = (1960 * mm) - 170
82
+                        str1 = 'move\n-170,-180,0\n' + str(num1) + ',-180,0\n'
83
+                        #移动
84
+                        # doc.SendCommand('move\n-80,-140,0\n760,-140,0\n')
85
+                        doc.SendCommand(str1)
86
+                        #再次选择
87
+                        doc.SendCommand(handle_string)
88
+                        #复制
89
+                        doc.SendCommand('copybase\n-170,-180,0\n')
90
+                        # target_doc.SendCommand('PASTEORIG\n')
91
+                        target_doc.SendCommand('PASTEORIG\n')
92
+                        #但不保存
93
+                        doc.Close(False)
94
+                    # #另存为
95
+                    # acad.doc.SaveAs(outfpath)
96
+                    #关闭当前
97
+                    print(dmm + ' FINISH')
98
+                    mm = mm + 1
99
+        #最后保存
100
+        target_doc.Close()
101
+
102
+
103
+        messagebox.showinfo("消息","运行成功")
104
+        window.destroy()
105
+    
106
+    tk.Button(window, text='选择', command=choose1).place(x=320, y=60, anchor='nw')
107
+    tk.Button(window, text='选择', command=choose2).place(x=320, y=110, anchor='nw')
108
+    tk.Button(window,text='确认',command=main).place(x=120,y=185,anchor='nw')
109
+    tk.Button(window,text='取消',command=tuichu).place(x=220,y=185,anchor='nw')
110
+    
111
+    window.mainloop()
112
+
113
+if __name__ == '__main__':
114
+    start()

+ 292
- 0
代码/20231108黄河断面/HHdmExcel.py 查看文件

@@ -0,0 +1,292 @@
1
+import os
2
+from posixpath import dirname
3
+import xlrd
4
+import math
5
+import tkinter as tk
6
+import numpy as np
7
+from tkinter import filedialog as tkFileDialog
8
+from tkinter import messagebox
9
+from xlrd.book import Name
10
+from openpyxl import Workbook
11
+from openpyxl.styles import Alignment
12
+from openpyxl.styles import Font
13
+from openpyxl.styles import Border, Side
14
+from datetime import datetime
15
+
16
+def start():
17
+    window = tk.Tk() # 创建窗口对象的背景色
18
+    window.title('断面填表程序')  # 设置窗口的标题
19
+    window.geometry('400x250')     # 设置窗口的大小
20
+    title = tk.Label(window, text='断面填表程序',
21
+                     font=('微软雅黑', 12), width=40, height=3)
22
+    title.place(x=0, y=0, anchor='nw')
23
+    choosepath = tk.Label(window, text='选择断面表格文件夹:',
24
+                          font=('微软雅黑', 12), width=20, height=2)
25
+    choosepath.place(x=0, y=50, anchor='nw')
26
+    path_var1 = tk.StringVar() # 输入路径
27
+    entry1 = tk.Entry(window, textvariable=path_var1)
28
+    entry1.place(x=170, y=65, anchor='nw')
29
+    resultpath = tk.Label(window, text='选择输出文件夹:',
30
+                          font=('微软雅黑', 12), width=20, height=2)
31
+    resultpath.place(x=8, y=100, anchor='nw')
32
+    path_var2 = tk.StringVar() # 输出路径
33
+    entry2 = tk.Entry(window, textvariable=path_var2)
34
+    entry2.place(x=170, y=115, anchor='nw')
35
+
36
+    def choose1():
37
+        file_dir = tkFileDialog.askdirectory()
38
+        path_var1.set(file_dir)
39
+
40
+    def choose2():
41
+        file_dir2 = tkFileDialog.askdirectory()
42
+        path_var2.set(file_dir2)
43
+
44
+    def tuichu():
45
+        window.destroy()
46
+
47
+    def main():
48
+        inpath = entry1.get()
49
+        outpath = entry2.get()
50
+        #遍历文件夹
51
+        for parent,dirname,filenames in os.walk(inpath):
52
+            for filename in filenames:
53
+                #排除其他文件的干扰
54
+                if '.xls' in filename:
55
+                    #完整路径
56
+                    filepath = parent + '/' +filename
57
+                    #记下断面名
58
+                    fname = str(filename)
59
+                    dmm = fname.replace('.xls','')
60
+                    #确定输出路径
61
+                    excelpath = outpath + '/' + dmm + '.xlsx'
62
+                    #判断下如果存在,则删除
63
+                    if os.path.exists(excelpath):
64
+                        os.remove(excelpath)
65
+                    #写一个方法来倒写(原本的表格,需写入的表格,断面名)
66
+                    excelwrite(filepath,excelpath,dmm)
67
+                    print(dmm + ' FINISH' )
68
+
69
+        messagebox.showinfo("消息","运行成功")
70
+        window.destroy()
71
+
72
+    def excelwrite(filepath,excelpath,dmm):
73
+        #先把抬头写好
74
+        wb = Workbook() # 新建工作簿
75
+        ws2 = wb['Sheet']
76
+        wb.remove(ws2)
77
+        sheet = wb.create_sheet("成果表")  # 获取工作表
78
+        #设置列宽(算了下大概有0.84的倍率换算)
79
+        sheet.column_dimensions['A'].width = 5.87
80
+        sheet.column_dimensions['B'].width = 11.82
81
+        sheet.column_dimensions['C'].width = 11.82
82
+        sheet.column_dimensions['D'].width = 14.93
83
+        sheet.column_dimensions['E'].width = 5.87
84
+        sheet.column_dimensions['F'].width = 11.82
85
+        sheet.column_dimensions['G'].width = 11.82
86
+        sheet.column_dimensions['H'].width = 18.8
87
+        #设置行高
88
+        sheet.row_dimensions[2].height = 20.1
89
+        sheet.row_dimensions[3].height = 20.1
90
+        sheet.row_dimensions[4].height = 20.1
91
+        sheet.row_dimensions[5].height = 20.1
92
+        #指定单元格居中显示
93
+        alignment_center = Alignment(horizontal='center', vertical='center')# 指定区域单元格居中
94
+        #右对齐
95
+        alignment_right = Alignment(horizontal='right', vertical='center')
96
+        #左对齐
97
+        alignment_left = Alignment(horizontal='left', vertical='center')
98
+        #自动换行
99
+        # ws1.cell(2, 13).alignment = Alignment(wrap_text=True)
100
+        #修改字体宋体,18,加粗
101
+        sheet['A1'].font = Font(u'宋体',size = 18,bold=True)
102
+        #修改字体,宋体,12
103
+        font1 = Font(u'宋体',size = 12)
104
+        #修改字体,宋体,12,下划线
105
+        sheet['G5'].font = Font(u'宋体',size = 12,underline='single')
106
+        #设置边框
107
+        # 设置该单元格边框和颜色
108
+        border1 = Border(
109
+            left=Side(style='thin', color='00000000'),
110
+            bottom=Side(style='thin', color='00000000'),
111
+            right=Side(style='thin', color='00000000'),
112
+            top=Side(style='thin', color='00000000'))
113
+        #标题
114
+        sheet.merge_cells(start_row=1, start_column=1, end_row=1, end_column=8)
115
+        sheet.cell(row=1, column=1, value='黄河四川段综合治理可行性研究项目测绘横断面(CGCS2000)')
116
+        sheet['A1'].alignment = alignment_center
117
+        #第2行
118
+        sheet.merge_cells(start_row=2, start_column=1, end_row=2, end_column=6)
119
+        str1 = '断面名称:' + dmm + '号断面'
120
+        sheet.cell(row=2, column=1, value=str1)
121
+        sheet['A2'].font = font1
122
+        sheet['A2'].alignment = alignment_left
123
+        sheet.cell(row=2, column=7, value='日期:')
124
+        sheet['G2'].font = font1
125
+        sheet['G2'].alignment = alignment_right
126
+        # 获取当前日期和时间
127
+        now = datetime.now()
128
+        yy = now.year
129
+        mm = now.month
130
+        dd = now.day
131
+        str2 = str(yy) + '年' + str(mm) + '月' + str(dd) + '日'
132
+        sheet['H2'] = str2
133
+        sheet['H2'].alignment = alignment_center
134
+        sheet['H2'].font = font1
135
+        #第3行
136
+        sheet.merge_cells(start_row=3, start_column=1, end_row=3, end_column=2)
137
+        sheet.merge_cells(start_row=3, start_column=4, end_row=3, end_column=8)
138
+        sheet.cell(row=3, column=1, value='断面端点编号:')
139
+        sheet['A3'].alignment = alignment_left
140
+        sheet['A3'].font = font1
141
+        sheet['C3'].font = font1
142
+        sheet['D3'].font = font1
143
+        sheet.cell(row=3, column=4, value='断面基点坐标: X=  Y= H=')
144
+        sheet['D3'].alignment = alignment_center
145
+        #第4行
146
+        sheet.merge_cells(start_row=4, start_column=4, end_row=4, end_column=8)
147
+        #第5行
148
+        sheet.merge_cells(start_row=5, start_column=1, end_row=5, end_column=2)
149
+        sheet.merge_cells(start_row=5, start_column=3, end_row=5, end_column=4)
150
+        sheet.merge_cells(start_row=5, start_column=5, end_row=5, end_column=6)
151
+        sheet.cell(row=5, column=1, value='断面方位角:')
152
+        sheet['A5'].font = font1
153
+        sheet['A5'].alignment = alignment_left
154
+        sheet['C5'].font = Font(u'宋体',size = 12,underline='single')
155
+        sheet.cell(row=5, column=5, value='测量比例尺:')
156
+        sheet['E5'].alignment = alignment_right
157
+        sheet['E5'].font = font1
158
+        sheet.cell(row=5, column=7, value='1:100')
159
+        sheet['G5'].alignment = alignment_center
160
+
161
+        #然后边读边写
162
+        #打开表格,从第二行开始读
163
+        xlr = xlrd.open_workbook(filepath)
164
+        table = xlr.sheets()[0]
165
+        rows = table.nrows
166
+        #为了排除最后的空行,先存list,再计算点数
167
+        list1 = []
168
+        ii = 1
169
+        while ii < rows:
170
+            if table.cell(ii, 4).value != '' and table.cell(ii, 0).value != '':
171
+                list2 = []
172
+                dh = table.cell(ii, 0).value
173
+                lj = table.cell(ii, 5).value
174
+                zz = table.cell(ii, 3).value
175
+                bz = table.cell(ii, 4).value
176
+                list2.append(dh)
177
+                list2.append(lj)
178
+                list2.append(zz)
179
+                list2.append(bz)
180
+                list1.append(list2)
181
+                ii = ii + 1
182
+            else:
183
+                ii = ii + 1
184
+        counts = len(list1)
185
+        #再看有多少组
186
+        num2 = counts // 27
187
+        num1 = counts % 27
188
+        if num1 != 0:
189
+            num2 = num2 + 1
190
+        #按页数展完
191
+        num3 = counts // 54
192
+        num4 = counts % 54
193
+        if num4 != 0:
194
+            num3 = num3 + 1
195
+        #按页数把格式全附上
196
+        mm1 = 6
197
+        while mm1 < num3 * 28 + 6:
198
+            #设置行高
199
+            sheet.row_dimensions[mm1].height = 20.1
200
+            sheet.cell(row=mm1, column=1).alignment = alignment_center
201
+            sheet.cell(row=mm1, column=2).alignment = alignment_center
202
+            sheet.cell(row=mm1, column=3).alignment = alignment_center
203
+            sheet.cell(row=mm1, column=4).alignment = alignment_center
204
+            sheet.cell(row=mm1, column=5).alignment = alignment_center
205
+            sheet.cell(row=mm1, column=6).alignment = alignment_center
206
+            sheet.cell(row=mm1, column=7).alignment = alignment_center
207
+            sheet.cell(row=mm1, column=8).alignment = alignment_center
208
+            sheet.cell(row=mm1, column=1).font = font1
209
+            sheet.cell(row=mm1, column=2).font = font1
210
+            sheet.cell(row=mm1, column=3).font = font1
211
+            sheet.cell(row=mm1, column=4).font = font1
212
+            sheet.cell(row=mm1, column=5).font = font1
213
+            sheet.cell(row=mm1, column=6).font = font1
214
+            sheet.cell(row=mm1, column=7).font = font1
215
+            sheet.cell(row=mm1, column=8).font = font1
216
+            #加边线框
217
+            sheet.cell(row=mm1, column=1).border = border1
218
+            sheet.cell(row=mm1, column=2).border = border1
219
+            sheet.cell(row=mm1, column=3).border = border1
220
+            sheet.cell(row=mm1, column=4).border = border1
221
+            sheet.cell(row=mm1, column=5).border = border1
222
+            sheet.cell(row=mm1, column=6).border = border1
223
+            sheet.cell(row=mm1, column=7).border = border1
224
+            sheet.cell(row=mm1, column=8).border = border1
225
+            mm1 = mm1 + 1
226
+        mm = 0
227
+        #每28行一增
228
+        row1 = 0
229
+        while mm < num2:
230
+            #分单双数
231
+            if mm == 0 or mm % 2 == 0:
232
+                #双数都在左边
233
+                #先写抬头
234
+                sheet.cell(row=(row1 * 28) + 6, column=1, value='点号')
235
+                sheet.cell(row=(row1 * 28) + 6, column=2, value='累距(m)')
236
+                sheet.cell(row=(row1 * 28) + 6, column=3, value='高程(m)')
237
+                sheet.cell(row=(row1 * 28) + 6, column=4, value='备注')
238
+                #能写入点的范围
239
+                start1 = mm * 27
240
+                end1 = start1 + 27
241
+                nn1 = start1
242
+                oo1 = 7
243
+                while nn1 < end1:
244
+                    #只写有的
245
+                    if nn1 < len(list1):
246
+                        #写入
247
+                        sheet.cell(row=(row1 * 28) + oo1, column=1, value=int(list1[nn1][0]))
248
+                        sheet.cell(row=(row1 * 28) + oo1, column=2, value=format(float(list1[nn1][1]), '.3f'))
249
+                        sheet.cell(row=(row1 * 28) + oo1, column=3, value=format(float(list1[nn1][2]), '.3f'))
250
+                        sheet.cell(row=(row1 * 28) + oo1, column=4, value=list1[nn1][3])
251
+                        nn1 = nn1 + 1
252
+                        oo1 = oo1 + 1
253
+                    else:
254
+                        break
255
+                mm = mm + 1
256
+            else:
257
+                #单数都在右边
258
+                #先写抬头
259
+                sheet.cell(row=(row1 * 28) + 6, column=5, value='点号')
260
+                sheet.cell(row=(row1 * 28) + 6, column=6, value='累距(m)')
261
+                sheet.cell(row=(row1 * 28) + 6, column=7, value='高程(m)')
262
+                sheet.cell(row=(row1 * 28) + 6, column=8, value='备注')
263
+                #能写入点的范围
264
+                start1 = mm * 27
265
+                end1 = start1 + 27
266
+                nn1 = start1
267
+                oo1 = 7
268
+                while nn1 < end1:
269
+                    #只写有的
270
+                    if nn1 < len(list1):
271
+                        #写入
272
+                        sheet.cell(row=(row1 * 28) + oo1, column=5, value=int(list1[nn1][0]))
273
+                        sheet.cell(row=(row1 * 28) + oo1, column=6, value=format(float(list1[nn1][1]), '.3f'))
274
+                        sheet.cell(row=(row1 * 28) + oo1, column=7, value=format(float(list1[nn1][2]), '.3f'))
275
+                        sheet.cell(row=(row1 * 28) + oo1, column=8, value=list1[nn1][3])
276
+                        nn1 = nn1 + 1
277
+                        oo1 = oo1 + 1
278
+                    else:
279
+                        break
280
+                mm = mm + 1
281
+                row1 = row1 + 1
282
+
283
+        wb.save(excelpath)
284
+        
285
+    tk.Button(window, text='选择', command=choose1).place(x=320, y=60, anchor='nw')
286
+    tk.Button(window, text='选择', command=choose2).place(x=320, y=110, anchor='nw')
287
+    tk.Button(window,text='确认',command=main).place(x=120,y=210,anchor='nw')
288
+    tk.Button(window,text='取消',command=tuichu).place(x=220,y=210,anchor='nw')
289
+    window.mainloop()
290
+
291
+if __name__ == '__main__':
292
+    start()

+ 156
- 0
代码/20231108黄河断面/HHdmTable.py 查看文件

@@ -0,0 +1,156 @@
1
+from pyautocad import Autocad, APoint, aDouble
2
+import os
3
+from posixpath import dirname
4
+import xlrd
5
+import tkinter as tk
6
+from tkinter import filedialog as tkFileDialog
7
+from tkinter import messagebox
8
+import shutil
9
+
10
+def start():
11
+    window = tk.Tk() # 创建窗口对象的背景色
12
+    window.title('断面线图表绘制程序')  # 设置窗口的标题
13
+    window.geometry('400x300')     # 设置窗口的大小
14
+    title = tk.Label(window, text='断面线图表绘制程序',
15
+                     font=('微软雅黑', 12), width=40, height=3)
16
+    title.place(x=0, y=0, anchor='nw')
17
+    choosepath = tk.Label(window, text='选择表格文件夹:',
18
+                          font=('微软雅黑', 12), width=20, height=2)
19
+    choosepath.place(x=0, y=50, anchor='nw')
20
+    path_var1 = tk.StringVar() # 输入路径
21
+    entry1 = tk.Entry(window, textvariable=path_var1)
22
+    entry1.place(x=170, y=65, anchor='nw')
23
+    resultpath = tk.Label(window, text='选择输出文件夹:',
24
+                          font=('微软雅黑', 12), width=20, height=2)
25
+    resultpath.place(x=0, y=100, anchor='nw')
26
+    path_var2 = tk.StringVar() # 输出路径
27
+    entry2 = tk.Entry(window, textvariable=path_var2)
28
+    entry2.place(x=170, y=115, anchor='nw')
29
+    oripath = tk.Label(window, text='选择原始模板:',
30
+                          font=('微软雅黑', 12), width=20, height=2)
31
+    oripath.place(x=0, y=150, anchor='nw')
32
+    path_var3 = tk.StringVar() # 输出路径
33
+    entry3 = tk.Entry(window, textvariable=path_var3)
34
+    entry3.place(x=170, y=165, anchor='nw')
35
+    lebel1 = tk.Label(window, text='请确保CAD已经打开。',
36
+                          font=('微软雅黑', 10), width=40, height=2)
37
+    lebel1.place(x=0, y=190, anchor='nw')
38
+
39
+    def choose1():
40
+            file_dir1 = tkFileDialog.askdirectory()
41
+            path_var1.set(file_dir1)
42
+
43
+    def choose2():
44
+            file_dir2 = tkFileDialog.askdirectory()
45
+            path_var2.set(file_dir2)
46
+
47
+    def choose3():
48
+            file_dir3 = tkFileDialog.askopenfilename(filetypes=[('DWG', '*.dwg'), ('DWG', '*.DWG'),('All Files', '*')])
49
+            path_var3.set(file_dir3)
50
+
51
+    def tuichu():
52
+        window.destroy()
53
+
54
+    def main():
55
+        excelpath = entry1.get()
56
+        outpath = entry2.get()
57
+        ori = entry3.get()
58
+        #首先链接cad
59
+        acad = Autocad(create_if_not_exists=True)
60
+        #遍历文件夹每个表格
61
+        for parent,dirname,filenames in os.walk(excelpath):
62
+            for filename in filenames:
63
+                #排一下其他文件
64
+                if '.xls' in filename:
65
+                    #得到表格的完整路径
66
+                    filepath = parent + '/' +filename
67
+                    #拆分出断面名字dmm
68
+                    dmm = filename.split('.',-1)[0]
69
+                    #先复制,再打开,再另存覆盖?
70
+                    #判断下存在就删除
71
+                    outfpath = outpath + '\\' + dmm + '号断面.dwg'
72
+                    if os.path.exists(outfpath):
73
+                        os.remove(outfpath)
74
+                    shutil.copy(ori, outfpath)
75
+                    acad.Application.Documents.Open(outfpath)
76
+                    #打开表格,从第二行开始读
77
+                    xlr = xlrd.open_workbook(filepath)
78
+                    table = xlr.sheets()[0]
79
+                    row = table.nrows
80
+                    #设置一条二位多段线line
81
+                    line1 = []
82
+                    ii = 1
83
+                    while ii < row:
84
+                        #第一个点只需要z值,那么把断面名之类的信息也放在这里
85
+                        if ii == 1:
86
+                            #两个标题的修改
87
+                            text1 = list(acad.iter_objects("Text"))
88
+                            for t1 in text1:
89
+                                if '号断面图' in t1.TextString:
90
+                                    t1.TextString = dmm + '号断面图'
91
+                                if '断面名称' in t1.TextString:
92
+                                    t1.TextString = '断面名称:' + dmm
93
+                                if t1.TextString == '左端点':
94
+                                    t2 = t1
95
+                            #Z值
96
+                            z1 = float(table.cell(ii, 3).value)
97
+                            #计算方式,(z-3400)*5
98
+                            num1 = z1 - 3400
99
+                            num2 = num1 * 10
100
+                            #设置dmlist[x,y,z]
101
+                            pt1 = [0,num2,0]
102
+                            line1 = line1 + pt1
103
+                            ii = ii + 1
104
+                        else:
105
+                            #判定下是否有值,没有就跳过
106
+                            try:
107
+                                #首先是文字
108
+                                str1 = table.cell(ii, 4).value
109
+                                dis1 = float(table.cell(ii, 5).value)
110
+                                #计算公式2 * dis1
111
+                                num3 = dis1 * 10                               
112
+                                #复制
113
+                                copy = t2.Copy()
114
+                                #移动
115
+                                center = APoint(0,-19.9995,0)
116
+                                pt = APoint(num3,-19.9995,0)
117
+                                copy.move(center,pt)
118
+                                #重新赋值
119
+                                copy.TextString = str1
120
+                                #然后是线
121
+                                #Z值
122
+                                z2 = float(table.cell(ii, 3).value)
123
+                                #计算方式,(z-3400)*5
124
+                                num4 = z2 - 3400
125
+                                num5 = num4 * 10
126
+                                #设置dmlist[x,y,z]
127
+                                pt2 = [num3,num5,0]
128
+                                line1 = line1 + pt2
129
+                                ii = ii + 1
130
+                            except:
131
+                                ii = ii + 1
132
+                    #把线绘制出来
133
+                    pnts = aDouble(line1)
134
+                    plineObj = acad.model.AddPolyLine(pnts)
135
+                    #指定图层
136
+                    plineObj.Layer = "DMX"
137
+                    # #另存为
138
+                    # acad.doc.SaveAs(outfpath)
139
+                    #关闭当前
140
+                    acad.doc.Close()
141
+                    print(dmm + ' FINISH')
142
+
143
+
144
+        messagebox.showinfo("消息","运行成功")
145
+        window.destroy()
146
+    
147
+    tk.Button(window, text='选择', command=choose1).place(x=320, y=60, anchor='nw')
148
+    tk.Button(window, text='选择', command=choose2).place(x=320, y=110, anchor='nw')
149
+    tk.Button(window, text='选择', command=choose3).place(x=320, y=160, anchor='nw')
150
+    tk.Button(window,text='确认',command=main).place(x=120,y=230,anchor='nw')
151
+    tk.Button(window,text='取消',command=tuichu).place(x=220,y=230,anchor='nw')
152
+    
153
+    window.mainloop()
154
+
155
+if __name__ == '__main__':
156
+    start()

+ 883
- 0
代码/20231108黄河断面/HHdm_tbx_3.py 查看文件

@@ -0,0 +1,883 @@
1
+import arcpy
2
+import xlwt
3
+import os
4
+import random
5
+
6
+def dmorder(dmxname,zxx,list1):
7
+    #循环一遍list1,找到交点和交点离起点的距离
8
+    ii = 0
9
+    #创建一个list,存放线形、距离,交点(point)
10
+    list2 = []
11
+    while ii < len(list1):
12
+        xjpg = zxx.intersect (list1[ii], 1)
13
+        xjp = xjpg.firstPoint
14
+        disxj = zxx.measureOnLine (xjp)
15
+        list3 = []
16
+        list3.append(list1[ii])
17
+        list3.append(disxj)
18
+        list3.append(xjp)
19
+        list2.append(list3)
20
+        ii = ii + 1
21
+    #排序(用第二个参数排序,排升序)
22
+    list2.sort(key=lambda x: x[1], reverse=False)
23
+    #再创建一个list,放线形、线名
24
+    list4 = []
25
+    mm = 0
26
+    while mm < len(list2):
27
+        list3 = []
28
+        list3.append(list2[mm][0])
29
+        num = mm + 1
30
+        #不足两位的用0填补
31
+        if mm < 9:
32
+            lname = dmxname + '#0' + str(num)
33
+        else:
34
+            lname = dmxname + '#' + str(num)
35
+        list3.append(lname)
36
+        list3.append(list2[mm][2])
37
+        list4.append(list3)
38
+        mm = mm + 1
39
+    return list4
40
+
41
+def diszd(zxx,zds):
42
+    ii = 0
43
+    #存放折点,距离
44
+    list1 = []
45
+    while ii < zds.count:
46
+        dis1 = zxx.measureOnLine (zds[ii])
47
+        list2 = []
48
+        list2.append(zds[ii])
49
+        list2.append(dis1)
50
+        list1.append(list2)
51
+        ii = ii + 1
52
+    return list1
53
+
54
+def jdpd(line,listzd,disxjp):
55
+    fp = line.firstPoint
56
+    #挨个和交点比对,得到距离刚好大于当前点,且小于下一个点的
57
+    ii = 0
58
+    #以防出现空的
59
+    strResult = ''
60
+    while ii < listzd.count:
61
+        disf = listzd[ii][1]
62
+        disl = listzd[ii + 1][1]
63
+        #有可能正好在某个点上,所以要细分情况
64
+        if disxjp > disf and disxjp < disl:
65
+            #获得A和B两个点,然后就是套用算法
66
+            lnfpx = listzd[ii][0].X
67
+            lnfpy = listzd[ii][0].Y
68
+            lnlpx = listzd[ii + 1][0].X
69
+            lnlpy = listzd[ii + 1][0].Y
70
+            ax = lnlpx - lnfpx
71
+            ay = lnlpy - lnfpy
72
+            bx = fp.X - lnfpx
73
+            by = fp.Y - lnfpy
74
+            judge = ax * by - ay * bx
75
+            if judge > 0 :
76
+                strResult= "LEFT"
77
+            else:
78
+                strResult = "RIGHT"
79
+            break
80
+        elif disxjp == disf and disxjp < disl:
81
+            #获得A和B两个点,然后就是套用算法
82
+            lnfpx = listzd[ii][0].X
83
+            lnfpy = listzd[ii][0].Y
84
+            lnlpx = listzd[ii + 1][0].X
85
+            lnlpy = listzd[ii + 1][0].Y
86
+            ax = lnlpx - lnfpx
87
+            ay = lnlpy - lnfpy
88
+            bx = fp.X - lnfpx
89
+            by = fp.Y - lnfpy
90
+            judge = ax * by - ay * bx
91
+            if judge > 0 :
92
+                strResult= "LEFT"
93
+            else:
94
+                strResult = "RIGHT"
95
+            break
96
+        elif disxjp > disf and disxjp == disl:
97
+            #获得A和B两个点,然后就是套用算法
98
+            lnfpx = listzd[ii][0].X
99
+            lnfpy = listzd[ii][0].Y
100
+            lnlpx = listzd[ii + 1][0].X
101
+            lnlpy = listzd[ii + 1][0].Y
102
+            ax = lnlpx - lnfpx
103
+            ay = lnlpy - lnfpy
104
+            bx = fp.X - lnfpx
105
+            by = fp.Y - lnfpy
106
+            judge = ax * by - ay * bx
107
+            if judge > 0 :
108
+                strResult= "LEFT"
109
+            else:
110
+                strResult = "RIGHT"
111
+            break
112
+        else:
113
+            ii = ii + 1
114
+    return strResult
115
+
116
+def tbclip(dxtgpath,dxtapath,outpath):
117
+    #创建一个shp文件
118
+    gcpath = outpath + '\\GCtb.shp'
119
+    try:
120
+        arcpy.CreateFeatureclass_management(outpath, 'GCtb.shp', 'POLYGON')
121
+    except:
122
+        arcpy.Delete_management(gcpath)
123
+        arcpy.CreateFeatureclass_management(outpath, 'GCtb.shp', 'POLYGON')
124
+    #读取
125
+    arcpy.MakeFeatureLayer_management(dxtgpath, 'dxtg')
126
+    arcpy.MakeFeatureLayer_management(dxtapath, 'dxta')
127
+    arcpy.MakeFeatureLayer_management(gcpath, 'gc')
128
+    #加图斑类型字段(英文)
129
+    arcpy.AddField_management('gc','LX','TEXT')
130
+    #先存图形,再更新图形,再赋值 
131
+    with arcpy.da.InsertCursor('gc', ['SHAPE@']) as cursorH:
132
+        with arcpy.da.SearchCursor('dxtg',['SHAPE@','Layer']) as cursorI:
133
+            for curI in cursorI:
134
+                if curI[1] == '9611':
135
+                    list1 = []
136
+                    list1.append(curI[0])
137
+                    cursorH.insertRow(list1)
138
+    with arcpy.da.UpdateCursor('gc',['SHAPE@','FID','LX']) as cursorJ:
139
+        for curJ in cursorJ:
140
+            pg4 = curJ[0]
141
+            id1 = curJ[1]
142
+            #判断是否有没有相交的
143
+            arcpy.SelectLayerByLocation_management('gc',"INTERSECT",pg4)
144
+            count1 = int(arcpy.GetCount_management('gc')[0])
145
+            if count1 != 0:
146
+                #其中小的裁大的
147
+                with arcpy.da.SearchCursor('gc',['SHAPE@','FID']) as cursorK:
148
+                    for curK in cursorK:
149
+                        pg5 = curK[0]
150
+                        id2 = curK[1]
151
+                        if id1 == id2:
152
+                            pass
153
+                        else:
154
+                            if pg4.area >= pg5.area:
155
+                                #再看下是否相交
156
+                                pg7 = pg4.intersect (pg5, 4)
157
+                                if pg7.area != 0:
158
+                                    #直接裁剪,再赋值
159
+                                    #如果差异没办法用的话,换成交集取反
160
+                                    pg6 = pg4.difference (pg5)
161
+                                    if pg6.area == 0:
162
+                                        pg8 = pg4.symmetricDifference (pg7)
163
+                                        if pg8.area != 0:
164
+                                            curJ[0] = pg8
165
+                                            pg4 = pg8
166
+                                            cursorJ.updateRow(curJ)
167
+                                    else:
168
+                                        curJ[0] = pg6
169
+                                        pg4 = pg6
170
+                                        cursorJ.updateRow(curJ)
171
+            #判断是否有包含的
172
+            arcpy.SelectLayerByLocation_management('gc',"WITHIN",pg4)   
173
+            count2 = int(arcpy.GetCount_management('gc')[0])
174
+            if count2 != 0:
175
+                with arcpy.da.SearchCursor('gc',['SHAPE@','FID']) as cursorL:
176
+                    for curL in cursorL:  
177
+                        pg7 = curL[0]
178
+                        id3 = curL[1]
179
+                        if id3 == id1:
180
+                            pass
181
+                        else:
182
+                            pg8 = pg4.symmetricDifference (pg7)   
183
+                            curJ[0] = pg8
184
+                            pg4 = pg8
185
+                            cursorJ.updateRow(curJ)
186
+            #在这里找赋值
187
+            arcpy.SelectLayerByLocation_management('dxta',"WITHIN",pg4)
188
+            count2 = int(arcpy.GetCount_management('dxta')[0])
189
+            if count2 != 0:
190
+                with arcpy.da.SearchCursor('dxta',['Layer','RefName']) as cursorG:
191
+                    for curG in cursorG:
192
+                        if curG[0] == '9611':
193
+                            if curG[1] == '0101' or curG[1] == '0102' or curG[1] == '0103':
194
+                                #耕地
195
+                                curJ[2] = 'GD'
196
+                                cursorJ.updateRow(curJ)
197
+                                break
198
+                            elif curG[1] == '0301' or curG[1] == '0302' or curG[1] == '0307':
199
+                                #林地
200
+                                curJ[2] = 'LD'
201
+                                cursorJ.updateRow(curJ)
202
+                                break
203
+                            elif curG[1] == '0401' or curG[1] == '0402' or curG[1] == '0403' or curG[1] == '0404':
204
+                                #都是草地
205
+                                curJ[2] = 'CD'
206
+                                cursorJ.updateRow(curJ)
207
+                                break
208
+                            elif curG[1] == '1101':
209
+                                #河流
210
+                                curJ[2] = 'HL'
211
+                                cursorJ.updateRow(curJ)
212
+                                break
213
+                            elif curG[1] == '1003':
214
+                                #公路
215
+                                curJ[2] = 'GL'
216
+                                cursorJ.updateRow(curJ)
217
+                                break
218
+                            elif curG[1] == '1004' or curG[1] == '1006':
219
+                                #道路
220
+                                curJ[2] = 'DL'
221
+                                cursorJ.updateRow(curJ)
222
+                                break
223
+                            elif curG[1] == '1107':
224
+                                #沟渠
225
+                                curJ[2] = 'GQ'
226
+                                cursorJ.updateRow(curJ)
227
+                                break
228
+                            elif curG[1] == '1106':
229
+                                #滩涂
230
+                                curJ[2] = 'TT'
231
+                                cursorJ.updateRow(curJ)
232
+                                break
233
+                            elif curG[1] == '1104':
234
+                                #坑塘
235
+                                curJ[2] = 'KT'
236
+                                cursorJ.updateRow(curJ)
237
+                                break
238
+                            elif curG[1] == '0701' or curG[1] == '0702':
239
+                                #房屋
240
+                                curJ[2] = 'FW'
241
+                                cursorJ.updateRow(curJ)      
242
+                                break      
243
+                            elif curG[1] == '1204':
244
+                                #盐碱地
245
+                                curJ[2] = 'YJD'
246
+                                cursorJ.updateRow(curJ)      
247
+                                break  
248
+                            elif curG[1] == '1205':
249
+                                #沙地
250
+                                curJ[2] = 'SD'
251
+                                cursorJ.updateRow(curJ)      
252
+                                break    
253
+                            elif curG[1] == '1206':
254
+                                #裸土地
255
+                                curJ[2] = 'LTD'
256
+                                cursorJ.updateRow(curJ)      
257
+                                break  
258
+                            elif curG[1] == '1207':
259
+                                #石砾地
260
+                                curJ[2] = 'SLD'
261
+                                cursorJ.updateRow(curJ)      
262
+                                break 
263
+                            elif curG[1] == '0305':
264
+                                #灌木
265
+                                curJ[2] = 'GM'
266
+                                cursorJ.updateRow(curJ)      
267
+                                break 
268
+    return gcpath             
269
+               
270
+def dwpd(lx):
271
+    dw = ''
272
+    if lx == 'GD':
273
+        dw = '耕地'
274
+    elif lx == 'LD':
275
+        dw = '林地'
276
+    elif lx == 'CD':
277
+        dw = '草地'  
278
+    elif lx == 'TT':
279
+        dw = '滩涂'
280
+    elif lx == 'KT':
281
+        dw = '坑塘'
282
+    elif lx == 'YJD':
283
+        dw = '盐碱地'
284
+    elif lx == 'SD':
285
+        dw = '沙地'
286
+    elif lx == 'LTD':
287
+        dw = '裸土地'
288
+    elif lx == 'SLD':
289
+        dw = '石砾地'
290
+    elif lx == 'GM':
291
+        dw = '灌木'
292
+    elif lx == '':
293
+        dw = 'XX'
294
+    return dw
295
+
296
+def randomjj(jjs,jjz):
297
+    #随机一个数
298
+    rand_num = round(random.uniform(jjs, jjz),3)
299
+    return rand_num
300
+
301
+
302
+def DM(dmxpath,dxtpath,dempath,jjs0,jjz0,outpath):
303
+    #间距
304
+    jjs = float(jjs0)
305
+    jjz = float(jjz0)
306
+    #把图名的开头提出来
307
+    dmxfile = dmxpath.split('\\',-1)[-1]
308
+    dmxname = dmxfile.split('.',-1)[0]
309
+    #读取断面线
310
+    dmxlpath = dmxpath + '\\Polyline'
311
+    arcpy.MakeFeatureLayer_management(dmxlpath,'dmx')
312
+    #读取水下点
313
+    sxdpath = dmxpath + '\\Point'
314
+    arcpy.MakeFeatureLayer_management(sxdpath,'sxd')
315
+    #读取地形图的线、面、注记
316
+    dxtlpath = dxtpath + '\\Polyline'
317
+    arcpy.MakeFeatureLayer_management(dxtlpath,'dxtl')
318
+    dxtgpath = dxtpath + '\\Polygon'
319
+    dxtapath = dxtpath + '\\Annotation'
320
+    #需要一个过程文件,把图斑裁出来
321
+    gcpath = tbclip(dxtgpath,dxtapath,outpath)
322
+    arcpy.MakeFeatureLayer_management(gcpath,'gcshp')
323
+    #找寻所有的断面线,生成一个包含断面线形状的list
324
+    #找到zzx
325
+    list1 = []
326
+    with arcpy.da.SearchCursor('dmx',['SHAPE@','Layer']) as cursorA:
327
+        for curA in cursorA:
328
+            layer = curA[1]
329
+            if layer == 'DMX':
330
+                list1.append(curA[0])
331
+            elif layer == 'zxx':
332
+                zxx = curA[0]
333
+    #通过中心线找到断面名(断面前缀、zxx、断面线list)
334
+    #list2包括线形和线名,交点
335
+    list2 = dmorder(dmxname,zxx,list1)
336
+    #对每根线做操作
337
+    ii = 0
338
+    #先得到zxx的所有折点
339
+    zds = zxx.getPart(0)
340
+    #把折点距起点的距离全部算出来,再存放为listzd(折点,距离)
341
+    listzd = diszd(zxx,zds)
342
+    while ii < len(list2):
343
+        line = list2[ii][0]
344
+        xjp = list2[ii][2]
345
+        disxjp = zxx.measureOnLine (xjp)
346
+        #首先判定线的起点是左基点还是右基点
347
+        bl = jdpd(line,listzd,disxjp)
348
+        #对应线的水下点,其距起点的距离,高程,地物类型搞出来
349
+        list4 = []
350
+        #这个是最终的不管左右的list
351
+        list40 = []
352
+        linebuf = line.buffer(0.1)
353
+        arcpy.SelectLayerByLocation_management('sxd',"WITHIN",linebuf)
354
+        with arcpy.da.SearchCursor('sxd',['SHAPE@','Layer','Elevation']) as cursorB:
355
+            for curB in cursorB:
356
+                layer1 = curB[1]
357
+                if layer1 == 'sxd':
358
+                    list3 = []
359
+                    #先把点挪到线上
360
+                    disp = line.distanceTo (curB[0])
361
+                    if disp == 0:
362
+                        #那就直接用
363
+                        list3.append(curB[0])
364
+                        dissxd = line.measureOnLine (curB[0])
365
+                        list3.append(dissxd)
366
+                        list3.append(curB[2])
367
+                        list3.append('水下')
368
+                        list4.append(list3)
369
+                    else:
370
+                        sxd1 = line.queryPointAndDistance(curB[0])
371
+                        sxd = sxd1[0].firstPoint
372
+                        list3.append(sxd)
373
+                        list3.append(sxd1[1])
374
+                        list3.append(curB[2])
375
+                        list3.append('水下')
376
+                        list4.append(list3)
377
+        #把河流图斑踢出来
378
+        #坎子、房子、沟渠、道路需要岔线上的先添加
379
+        #线地形图涉及到坎子
380
+        arcpy.SelectLayerByLocation_management('dxtl',"INTERSECT",line)
381
+        count1 = int(arcpy.GetCount_management('dxtl')[0])
382
+        if count1 != 0:
383
+            with arcpy.da.SearchCursor('dxtl',['SHAPE@','Layer','Linetype']) as cursorC:
384
+                for curC in cursorC:
385
+                    layer2 = curC[1]
386
+                    lt = curC[2]
387
+                    if layer2 == 'DMTZ' and lt == '10421':
388
+                        line1 = curC[0]
389
+                        kjdg = line.intersect (line1, 1)
390
+                        kjd = kjdg.firstPoint
391
+                        kjdx = kjd.X
392
+                        kjdy = kjd.Y
393
+                        kjdstr = str(kjdx) + ' ' + str(kjdy)
394
+                        list5 = []
395
+                        list5.append(kjd)
396
+                        #距起点的距离
397
+                        disk = line.measureOnLine (kjd)
398
+                        list5.append(disk)
399
+                        #z值
400
+                        kjz = arcpy.GetCellValue_management(dempath, kjdstr)
401
+                        try:
402
+                            list5.append(float(kjz.getOutput(0)))
403
+                        except:
404
+                            list5.append(0)
405
+                        # list5.append(-100)
406
+                        #地物类型
407
+                        list5.append('坎上')
408
+                        list4.append(list5)
409
+        #找出所有相交的图斑
410
+        arcpy.SelectLayerByLocation_management('gcshp',"INTERSECT",line)
411
+        with arcpy.da.SearchCursor('gcshp',['SHAPE@','LX']) as cursorD:
412
+            for curD in cursorD:
413
+                layer3 = curD[1]
414
+                if layer3 == 'FW':
415
+                    pg1 = curD[0]
416
+                    pgb = pg1.boundary ()
417
+                    pjdg = pgb.intersect (line, 1)
418
+                    pjdgc = pjdg.pointCount
419
+                    mm = 0
420
+                    while mm < pjdgc:
421
+                        list6 = []
422
+                        pjd = pjdg[mm]
423
+                        pjdx = pjd.X
424
+                        pjdy = pjd.Y
425
+                        pjdstr = str(pjdx) + ' ' + str(pjdy)
426
+                        list6.append(pjd)
427
+                        #距离
428
+                        dispj = line.measureOnLine (pjd)
429
+                        list6.append(dispj)
430
+                        #z值
431
+                        pjz = arcpy.GetCellValue_management(dempath, pjdstr)
432
+                        try:
433
+                            list6.append(float(pjz.getOutput(0)))
434
+                        except:
435
+                            list6.append(0)
436
+                        # list6.append(-100)
437
+                        #备注
438
+                        list6.append('房屋')
439
+                        list4.append(list6)
440
+                        mm = mm + 1
441
+                elif layer3 == 'GL':
442
+                    pg1 = curD[0]
443
+                    pgb = pg1.boundary ()
444
+                    pjdg = pgb.intersect (line, 1)
445
+                    pjdgc = pjdg.pointCount
446
+                    mm = 0
447
+                    while mm < pjdgc:
448
+                        list6 = []
449
+                        pjd = pjdg[mm]
450
+                        pjdx = pjd.X
451
+                        pjdy = pjd.Y
452
+                        pjdstr = str(pjdx) + ' ' + str(pjdy)
453
+                        list6.append(pjd)
454
+                        #距离
455
+                        dispj = line.measureOnLine (pjd)
456
+                        list6.append(dispj)
457
+                        #z值
458
+                        pjz = arcpy.GetCellValue_management(dempath, pjdstr)
459
+                        try:
460
+                            list6.append(float(pjz.getOutput(0)))
461
+                        except:
462
+                            list6.append(0)
463
+                        # list6.append(-100)
464
+                        #备注
465
+                        list6.append('公路')
466
+                        list4.append(list6)
467
+                        mm = mm + 1
468
+                elif layer3 == 'DL':
469
+                    pg1 = curD[0]
470
+                    pgb = pg1.boundary ()
471
+                    pjdg = pgb.intersect (line, 1)
472
+                    pjdgc = pjdg.pointCount
473
+                    mm = 0
474
+                    while mm < pjdgc:
475
+                        list6 = []
476
+                        pjd = pjdg[mm]
477
+                        pjdx = pjd.X
478
+                        pjdy = pjd.Y
479
+                        pjdstr = str(pjdx) + ' ' + str(pjdy)
480
+                        list6.append(pjd)
481
+                        #距离
482
+                        dispj = line.measureOnLine (pjd)
483
+                        list6.append(dispj)
484
+                        #z值
485
+                        pjz = arcpy.GetCellValue_management(dempath, pjdstr)
486
+                        try:
487
+                            list6.append(float(pjz.getOutput(0)))
488
+                        except:
489
+                            list6.append(0)
490
+                        # list6.append(-100)
491
+                        #备注
492
+                        list6.append('道路')
493
+                        list4.append(list6)
494
+                        mm = mm + 1
495
+                elif layer3 == 'GQ':
496
+                    pg1 = curD[0]
497
+                    pgb = pg1.boundary ()
498
+                    pjdg = pgb.intersect (line, 1)
499
+                    pjdgc = pjdg.pointCount
500
+                    mm = 0
501
+                    while mm < pjdgc:
502
+                        list6 = []
503
+                        pjd = pjdg[mm]
504
+                        pjdx = pjd.X
505
+                        pjdy = pjd.Y
506
+                        pjdstr = str(pjdx) + ' ' + str(pjdy)
507
+                        list6.append(pjd)
508
+                        #距离
509
+                        dispj = line.measureOnLine (pjd)
510
+                        list6.append(dispj)
511
+                        #z值
512
+                        pjz = arcpy.GetCellValue_management(dempath, pjdstr)
513
+                        try:
514
+                            list6.append(float(pjz.getOutput(0)))
515
+                        except:
516
+                            list6.append(0)
517
+                        # list6.append(-100)
518
+                        #备注
519
+                        list6.append('沟渠')
520
+                        list4.append(list6)
521
+                        mm = mm + 1
522
+        #一个布尔值,用于判断端点是否需要挪
523
+        bl1 = 0
524
+        #从左基点开始,每2.8m取一个点,避开上面已经剃过点的地方                
525
+        if bl == "LEFT":
526
+            #那么前面的距离顺序都是对的,直接找就成了
527
+            #先存放左基点
528
+            #判定是否在水里
529
+            fp = line.firstPoint
530
+            fpp = arcpy.PointGeometry(fp)
531
+            #首先看点落在哪个图斑里
532
+            arcpy.SelectLayerByLocation_management('gcshp',"CONTAINS",fpp)
533
+            with arcpy.da.SearchCursor('gcshp',['SHAPE@','LX']) as cursorF:
534
+                for curF in cursorF:
535
+                    lx = curF[1]
536
+                    dw = dwpd(lx)
537
+                    if dw != '':
538
+                        list6 = []
539
+                        pjdx = fp.X
540
+                        pjdy = fp.Y
541
+                        pjdstr = str(pjdx) + ' ' + str(pjdy)
542
+                        list6.append(fp)
543
+                        #距离
544
+                        list6.append(0)
545
+                        #z值
546
+                        pjz = arcpy.GetCellValue_management(dempath, pjdstr)
547
+                        try:
548
+                            list6.append(float(pjz.getOutput(0)))
549
+                        except:
550
+                            list6.append(0)
551
+                        # list6.append(-100)
552
+                        #备注
553
+                        list6.append(dw)
554
+                        list4.append(list6) 
555
+                    else:
556
+                        #如果不是就记录下它的坐标,到时候套第一个水下点的高程
557
+                        list6 = []
558
+                        pjdx = fp.X
559
+                        pjdy = fp.Y
560
+                        list6.append(fp)
561
+                        #距离
562
+                        list6.append(0)
563
+                        #z值
564
+                        pjz = -9999
565
+                        list6.append(float(pjz))
566
+                        #备注
567
+                        list6.append(dw)
568
+                        list4.append(list6) 
569
+                        bl1 = 1
570
+            #隔一定距离存一个点
571
+            length = line.length
572
+            #总长
573
+            zlen = 0
574
+            while length - zlen > jjz:
575
+                #如果比最大值小的话就直接取
576
+                jj1 = randomjj(jjs,jjz)
577
+                zlen = zlen + jj1
578
+                ptg2 = line.positionAlongLine(zlen)
579
+                pt2 = ptg2.firstPoint
580
+                list6 = []
581
+                arcpy.SelectLayerByLocation_management('gcshp',"CONTAINS",ptg2)
582
+                count2 = int(arcpy.GetCount_management('gcshp')[0])
583
+                with arcpy.da.SearchCursor('gcshp',['SHAPE@','LX']) as cursorG:
584
+                    for curG in cursorG:
585
+                        lx = curG[1]
586
+                        dw = dwpd(lx)
587
+                        if dw != '':
588
+                            list6 = []
589
+                            pjdx = pt2.X
590
+                            pjdy = pt2.Y
591
+                            pjdstr = str(pjdx) + ' ' + str(pjdy)
592
+                            list6.append(pt2)
593
+                            #距离
594
+                            list6.append(zlen)
595
+                            #z值
596
+                            pjz = arcpy.GetCellValue_management(dempath, pjdstr)
597
+                            try:
598
+                                list6.append(float(pjz.getOutput(0)))
599
+                            except:
600
+                                list6.append(0)
601
+                            # list6.append(-100)
602
+                            #备注
603
+                            list6.append(dw)
604
+                            list4.append(list6) 
605
+                
606
+            #右基点
607
+            fp = line.lastPoint
608
+            fpp = arcpy.PointGeometry(fp)
609
+            #首先看点落在哪个图斑里
610
+            arcpy.SelectLayerByLocation_management('gcshp',"CONTAINS",fpp)
611
+            with arcpy.da.SearchCursor('gcshp',['SHAPE@','LX']) as cursorF:
612
+                for curF in cursorF:
613
+                    lx = curF[1]
614
+                    dw = dwpd(lx)
615
+                    if dw != '':
616
+                        list6 = []
617
+                        pjdx = fp.X
618
+                        pjdy = fp.Y
619
+                        pjdstr = str(pjdx) + ' ' + str(pjdy)
620
+                        list6.append(fp)
621
+                        #距离
622
+                        list6.append(length)
623
+                        #z值
624
+                        pjz = arcpy.GetCellValue_management(dempath, pjdstr)
625
+                        try:
626
+                            list6.append(float(pjz.getOutput(0)))
627
+                        except:
628
+                            list6.append(0)
629
+                        # list6.append(-100)
630
+                        #备注
631
+                        list6.append(dw)
632
+                        list4.append(list6) 
633
+                    else:
634
+                        list6 = []
635
+                        list6.append(fp)
636
+                        #距离
637
+                        list6.append(length)
638
+                        #z值
639
+                        pjz = -9999
640
+                        list6.append(float(pjz))
641
+                        #备注
642
+                        list6.append(dw)
643
+                        list4.append(list6) 
644
+                        bl1 = -1
645
+            list40 = list4    
646
+        else:
647
+            fp = line.lastPoint
648
+            fpp = arcpy.PointGeometry(fp)
649
+            #首先看点落在哪个图斑里
650
+            arcpy.SelectLayerByLocation_management('gcshp',"CONTAINS",fpp)
651
+            with arcpy.da.SearchCursor('gcshp',['SHAPE@','LX']) as cursorF:
652
+                for curF in cursorF:
653
+                    lx = curF[1]
654
+                    dw = dwpd(lx)
655
+                    if dw != '':
656
+                        list6 = []
657
+                        pjdx = fp.X
658
+                        pjdy = fp.Y
659
+                        pjdstr = str(pjdx) + ' ' + str(pjdy)
660
+                        list6.append(fp)
661
+                        #距离
662
+                        list6.append(0)
663
+                        #z值
664
+                        pjz = arcpy.GetCellValue_management(dempath, pjdstr)
665
+                        try:
666
+                            list6.append(float(pjz.getOutput(0)))
667
+                        except:
668
+                            list6.append(0)
669
+                        # list6.append(-100)
670
+                        #备注
671
+                        list6.append(dw)
672
+                        list40.append(list6) 
673
+                    else:
674
+                        list6 = []
675
+                        list6.append(fp)
676
+                        #距离
677
+                        list6.append(0)
678
+                        #z值
679
+                        pjz = -9999
680
+                        list6.append(float(pjz))
681
+                        #备注
682
+                        list6.append(dw)
683
+                        list40.append(list6) 
684
+                        bl1 = 1
685
+            #隔一定距离存一个点
686
+            length = line.length
687
+            zlen = 0
688
+            while length - zlen > jjz:
689
+                jj1 = randomjj(jjs,jjz)
690
+                zlen = zlen + jj1
691
+                jj2 = length - zlen
692
+                ptg2 = line.positionAlongLine(jj2)
693
+                pt2 = ptg2.firstPoint
694
+                list6 = []
695
+                arcpy.SelectLayerByLocation_management('gcshp',"CONTAINS",ptg2)
696
+                with arcpy.da.SearchCursor('gcshp',['SHAPE@','LX']) as cursorG:
697
+                    for curG in cursorG:
698
+                        lx = curG[1]
699
+                        dw = dwpd(lx)
700
+                        if dw != '':
701
+                            list6 = []
702
+                            pjdx = pt2.X
703
+                            pjdy = pt2.Y
704
+                            pjdstr = str(pjdx) + ' ' + str(pjdy)
705
+                            list6.append(pt2)
706
+                            #距离
707
+                            list6.append(zlen)
708
+                            #z值
709
+                            pjz = arcpy.GetCellValue_management(dempath, pjdstr)
710
+                            try:
711
+                                list6.append(float(pjz.getOutput(0)))
712
+                            except:
713
+                                list6.append(0)
714
+                            # list6.append(-100)
715
+                            #备注
716
+                            list6.append(dw)
717
+                            list40.append(list6) 
718
+                
719
+            #右基点
720
+            fp = line.firstPoint
721
+            fpp = arcpy.PointGeometry(fp)
722
+            #首先看点落在哪个图斑里
723
+            arcpy.SelectLayerByLocation_management('gcshp',"CONTAINS",fpp)
724
+            with arcpy.da.SearchCursor('gcshp',['SHAPE@','LX']) as cursorF:
725
+                for curF in cursorF:
726
+                    lx = curF[1]
727
+                    dw = dwpd(lx)
728
+                    if dw != '':
729
+                        list6 = []
730
+                        pjdx = fp.X
731
+                        pjdy = fp.Y
732
+                        pjdstr = str(pjdx) + ' ' + str(pjdy)
733
+                        list6.append(fp)
734
+                        #距离
735
+                        list6.append(length)
736
+                        #z值
737
+                        pjz = arcpy.GetCellValue_management(dempath, pjdstr)
738
+                        try:
739
+                            list6.append(float(pjz.getOutput(0)))
740
+                        except:
741
+                            list6.append(0)
742
+                        # list6.append(-100)
743
+                        #备注
744
+                        list6.append(dw)
745
+                        list40.append(list6)  
746
+                    else:
747
+                        list6 = []
748
+                        list6.append(fp)
749
+                        #距离
750
+                        list6.append(length)
751
+                        #z值
752
+                        pjz = -9999
753
+                        list6.append(float(pjz))
754
+                        #备注
755
+                        list6.append(dw)
756
+                        list40.append(list6) 
757
+                        bl1 = -1
758
+            #把list4里的距离重新计算后放入40
759
+            oo = 0
760
+            while oo < len(list4):
761
+                list9 = []
762
+                list9.append(list4[oo][0])
763
+                dis1 = length - list4[oo][1]
764
+                list9.append(dis1)
765
+                list9.append(list4[oo][2])
766
+                list9.append(list4[oo][3])
767
+                list40.append(list9)  
768
+                oo = oo + 1 
769
+        #排序
770
+        list40.sort(key=lambda x: x[1], reverse=False)
771
+        #把起点或者终点的水下点挪到第一个
772
+        if bl1 == 1:
773
+            #左端点
774
+            if list40[0][1] == 0 and list40[0][2] == -9999:
775
+                fp1 = list40[0][0]
776
+                list40[1][0] = fp1
777
+                list40[1][1] = 0
778
+                del list40[0]
779
+            else:
780
+                fp1 = list40[1][0]
781
+                list40[0][0] = fp1
782
+                list40[0][1] = 0
783
+                del list40[1]
784
+        if bl1 == -1:
785
+            #右端点
786
+            len1 = len(list40)-1
787
+            if list40[len1][1] == length and list40[len1][2] == -9999:
788
+                fp1 = list40[len(list40)-1][0]
789
+                list40[len(list40)-2][0] = fp1
790
+                list40[len(list40)-2][1] = length
791
+                del list40[len(list40)-1]
792
+            else:
793
+                fp1 = list40[len(list40)-2][0]
794
+                list40[len(list40)-1][0] = fp1
795
+                list40[len(list40)-1][1] = length
796
+                del list40[len(list40)-2]
797
+        #排除距离相同的尾巴
798
+        if round(list40[len(list40)-1][1],3) == round(list40[len(list40)-2][1],3):
799
+            del list40[len(list40)-1]
800
+        if round(list40[0][1],3) == round(list40[1][1],3):
801
+            del list40[1]
802
+        #这里把地形变换的第一个水下,和最后一个水下写成水边线
803
+        qq = 0
804
+        while qq < (len(list40) - 1):
805
+            if list40[qq][3] == '水下':
806
+                #判断它的前后是否不是水下
807
+                if list40[qq-1][3] != '水下' and list40[qq-1][3] != '左端点' and list40[qq-1][3] != '水边线':
808
+                    list40[qq][3] = '水边线'
809
+                elif list40[qq+1][3] != '水下' and list40[qq+1][3] != '右端点' and list40[qq+1][3] != '水边线':
810
+                    list40[qq][3] = '水边线'
811
+                qq = qq + 1
812
+            else:
813
+                qq = qq + 1
814
+        #新建一个excel
815
+        expath = outpath + '\\' + list2[ii][1] + '.xls'
816
+        #判断下存不存在,存在则删除
817
+        if os.path.exists(expath):  
818
+            # 删除文件  
819
+            os.remove(expath)        
820
+        #写个抬头
821
+        workBook = xlwt.Workbook(encoding='utf-8')
822
+        sheet = workBook.add_sheet("sheet1")
823
+        sheet.write(0,0,'点号')
824
+        sheet.write(0,1,'X')
825
+        sheet.write(0,2,'Y')
826
+        sheet.write(0,3,'Z')
827
+        sheet.write(0,4,'备注')
828
+        sheet.write(0,5,'累距')
829
+        pp = 0
830
+        while pp < len(list40):
831
+            if pp == 0:
832
+                pp1 = pp + 1
833
+                sheet.write(pp1,0,(pp+1))
834
+                try:
835
+                    sheet.write(pp1,1,round(list40[pp][0].X,4))
836
+                    sheet.write(pp1,2,round(list40[pp][0].Y,4))
837
+                except:
838
+                    pt3 = list40[pp][0].firstPoint
839
+                    sheet.write(pp1,1,round(pt3.X,4))
840
+                    sheet.write(pp1,2,round(pt3.Y,4))
841
+                sheet.write(pp1,3,round(list40[pp][2],3))
842
+                sheet.write(pp1,4,'左端点')
843
+                sheet.write(pp1,5,round(list40[pp][1],3))
844
+                pp = pp + 1
845
+            elif pp == len(list40) - 1:
846
+                pp1 = pp + 1
847
+                sheet.write(pp1,0,(pp+1))
848
+                try:
849
+                    sheet.write(pp1,1,round(list40[pp][0].X,4))
850
+                    sheet.write(pp1,2,round(list40[pp][0].Y,4))
851
+                except:
852
+                    pt3 = list40[pp][0].firstPoint
853
+                    sheet.write(pp1,1,round(pt3.X,4))
854
+                    sheet.write(pp1,2,round(pt3.Y,4))
855
+                sheet.write(pp1,3,round(list40[pp][2],3))
856
+                sheet.write(pp1,4,'右端点')
857
+                sheet.write(pp1,5,round(list40[pp][1],3))
858
+                pp = pp + 1
859
+            else:
860
+                pp1 = pp + 1
861
+                sheet.write(pp1,0,(pp+1))
862
+                try:
863
+                    sheet.write(pp1,1,round(list40[pp][0].X,4))
864
+                    sheet.write(pp1,2,round(list40[pp][0].Y,4))
865
+                except:
866
+                    pt3 = list40[pp][0].firstPoint
867
+                    sheet.write(pp1,1,round(pt3.X,4))
868
+                    sheet.write(pp1,2,round(pt3.Y,4))
869
+                sheet.write(pp1,3,round(list40[pp][2],3))
870
+                sheet.write(pp1,4,list40[pp][3])
871
+                sheet.write(pp1,5,round(list40[pp][1],3))
872
+                pp = pp + 1
873
+        workBook.save(expath)
874
+        arcpy.AddMessage (list2[ii][1] + ' finish')
875
+        ii = ii + 1                  
876
+                                        
877
+if __name__ == '__main__':
878
+    try:
879
+        #断面线所在的dwg,地形图,dem,上间距,下间距,输出文件夹
880
+        DM(arcpy.GetParameterAsText(0),arcpy.GetParameterAsText(1),arcpy.GetParameterAsText(2),arcpy.GetParameterAsText(3),arcpy.GetParameterAsText(4),arcpy.GetParameterAsText(5))
881
+        # DM(r"D:\3work_now\20231108HHdm\1121\QJM2.dwg",r'D:\3work_now\20231108HHdm\1121\21求吉玛村2#护岸工程.dwg',r'D:\3work_now\20231108HHdm\1121\21.tif',2,3,r'D:\3work_now\20231108HHdm\1121\19')
882
+    except arcpy.ExecuteError:
883
+        arcpy.AddMessage (arcpy.GetMessages())

二進制
代码/20240112dwg右上角图框/.vs/20150313-T_cad_5000/v16/.suo 查看文件


+ 3
- 0
代码/20240112dwg右上角图框/.vs/ProjectSettings.json 查看文件

@@ -0,0 +1,3 @@
1
+{
2
+  "CurrentProjectSetting": null
3
+}

二進制
代码/20240112dwg右上角图框/.vs/T_cad/v16/.suo 查看文件


+ 9
- 0
代码/20240112dwg右上角图框/.vs/VSWorkspaceState.json 查看文件

@@ -0,0 +1,9 @@
1
+{
2
+  "ExpandedNodes": [
3
+    "",
4
+    "\\T_cad",
5
+    "\\_UpgradeReport_Files"
6
+  ],
7
+  "SelectedNode": "\\T_cad\\Frame5000.cs",
8
+  "PreviewInSolutionExplorer": false
9
+}

二進制
代码/20240112dwg右上角图框/.vs/slnx.sqlite 查看文件


+ 20
- 0
代码/20240112dwg右上角图框/T_cad.sln 查看文件

@@ -0,0 +1,20 @@
1
+
2
+Microsoft Visual Studio Solution File, Format Version 11.00
3
+# Visual Studio 2010
4
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "T_cad", "T_cad\T_cad.csproj", "{1110A1A3-576A-42FC-B84E-70A14C464BF7}"
5
+EndProject
6
+Global
7
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
8
+		Debug|Any CPU = Debug|Any CPU
9
+		Release|Any CPU = Release|Any CPU
10
+	EndGlobalSection
11
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
12
+		{1110A1A3-576A-42FC-B84E-70A14C464BF7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
13
+		{1110A1A3-576A-42FC-B84E-70A14C464BF7}.Debug|Any CPU.Build.0 = Debug|Any CPU
14
+		{1110A1A3-576A-42FC-B84E-70A14C464BF7}.Release|Any CPU.ActiveCfg = Release|Any CPU
15
+		{1110A1A3-576A-42FC-B84E-70A14C464BF7}.Release|Any CPU.Build.0 = Release|Any CPU
16
+	EndGlobalSection
17
+	GlobalSection(SolutionProperties) = preSolution
18
+		HideSolutionNode = FALSE
19
+	EndGlobalSection
20
+EndGlobal

二進制
代码/20240112dwg右上角图框/T_cad.suo 查看文件


+ 3
- 0
代码/20240112dwg右上角图框/T_cad/.vs/ProjectSettings.json 查看文件

@@ -0,0 +1,3 @@
1
+{
2
+  "CurrentProjectSetting": null
3
+}

二進制
代码/20240112dwg右上角图框/T_cad/.vs/slnx.sqlite 查看文件


+ 1543
- 0
代码/20240112dwg右上角图框/T_cad/Frame5000.cs
文件差異過大導致無法顯示
查看文件


+ 1951
- 0
代码/20240112dwg右上角图框/T_cad/LSTKAllCls.cs
文件差異過大導致無法顯示
查看文件


+ 192
- 0
代码/20240112dwg右上角图框/T_cad/LayerControl.cs 查看文件

@@ -0,0 +1,192 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Linq;
4
+using System.Text;
5
+
6
+using Autodesk.AutoCAD.Runtime;
7
+using Autodesk.AutoCAD.ApplicationServices;
8
+using Autodesk.AutoCAD.EditorInput;
9
+using Autodesk.AutoCAD.Colors;
10
+using Autodesk.AutoCAD.Windows;
11
+using Autodesk.AutoCAD.Geometry;
12
+using Autodesk.AutoCAD.DatabaseServices;
13
+
14
+namespace T_cad
15
+{
16
+
17
+
18
+
19
+    /// <summary>
20
+    /// RGB三原色
21
+    /// </summary>
22
+    public struct colorgb
23
+    {
24
+        public byte red;
25
+        public byte green;
26
+        public byte blue;
27
+
28
+        public colorgb(byte r, byte g, byte b)
29
+        {
30
+            this.red = r;
31
+            this.green = g;
32
+            this.blue = b;
33
+        }
34
+    }
35
+
36
+
37
+
38
+    /// <summary>
39
+    /// 对图层的操作处理,包括新建图层、
40
+    /// 把指定图层设置为当前图层和检查是否包含某个图层名
41
+    /// </summary>
42
+    class LayerControl
43
+    {
44
+        /// <summary>
45
+        /// 创建高程点错误标记层
46
+        /// </summary>
47
+        /// <param name="layername">要创建的图层的名字</param>
48
+        /// <param name="colo">RGB三原色</param>
49
+        public void creatlayer(string layername, colorgb colo)
50
+        {
51
+            Database database = Autodesk.AutoCAD.DatabaseServices.HostApplicationServices.WorkingDatabase;
52
+            DocumentLock doclock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
53
+            Transaction traction = database.TransactionManager.StartTransaction();
54
+            LayerTable lt = traction.GetObject(database.LayerTableId, OpenMode.ForWrite) as LayerTable;
55
+            try
56
+            {
57
+                LayerTableRecord layertablerecord = new LayerTableRecord();
58
+                layertablerecord.Name = layername;//设置层表记录的名字
59
+                layertablerecord.Color = Autodesk.AutoCAD.Colors.Color.FromRgb(colo.red, colo.green, colo.blue);//为层表记录赋颜色紫色
60
+                //layertablerecord.Color = Autodesk.AutoCAD.Colors.Color.FromColor(System.Drawing.Color.Magenta);
61
+
62
+
63
+                lt.Add(layertablerecord);
64
+                traction.AddNewlyCreatedDBObject(layertablerecord, true);
65
+                traction.Commit();
66
+            }
67
+            catch (Autodesk.AutoCAD.Runtime.Exception)
68
+            {
69
+                traction.Abort();
70
+            }
71
+            finally
72
+            {
73
+                traction.Dispose();
74
+                doclock.Dispose();
75
+            }
76
+        }
77
+
78
+
79
+        /// <summary>
80
+        /// 将指定图层设置为当前图层
81
+        /// </summary>
82
+        /// <param name="layername">要设置为当前图层的图层名字</param>
83
+        //public void movelayertofront(string layername)
84
+        //{
85
+        //    Database database = Autodesk.AutoCAD.DatabaseServices.HostApplicationServices.WorkingDatabase;
86
+        //    DocumentLock doclock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
87
+        //    Transaction traction = database.TransactionManager.StartTransaction();
88
+        //    try
89
+        //    {
90
+        //        LayerTable layertable = traction.GetObject(database.LayerTableId, OpenMode.ForRead) as LayerTable;
91
+        //        database.Clayer = layertable[layername];//把图层选为当前图层
92
+        //        traction.Commit();
93
+        //    }
94
+        //    catch (Autodesk.AutoCAD.Runtime.Exception)
95
+        //    {
96
+        //        traction.Abort();
97
+        //    }
98
+        //    finally
99
+        //    {
100
+        //        traction.Dispose();
101
+        //        doclock.Dispose();
102
+        //    }
103
+        //}
104
+
105
+
106
+
107
+        /// <summary>
108
+        /// 判断所命图层名是否已经存在
109
+        /// </summary>
110
+        /// <param name="layername">要判断的图层名字</param>
111
+        /// <returns>返回true表示在层表中存在要判断的图层名,
112
+        /// 返回false表示层表中不存在判断的图层名</returns>
113
+        public bool haslayername(string layername)
114
+        {
115
+            Database database = Autodesk.AutoCAD.DatabaseServices.HostApplicationServices.WorkingDatabase;
116
+            using (Transaction traction = database.TransactionManager.StartTransaction())
117
+            {
118
+                LayerTable lt = traction.GetObject(database.LayerTableId, OpenMode.ForRead) as LayerTable;
119
+
120
+                if (lt.Has(layername))
121
+                {
122
+                    traction.Commit();
123
+                    return true;
124
+                }
125
+                else
126
+                {
127
+                    traction.Commit();
128
+                    return false;
129
+                }
130
+            }
131
+
132
+
133
+
134
+        }
135
+
136
+
137
+
138
+
139
+        public void clear(string layername)
140
+        {
141
+           
142
+            Document document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
143
+            Database database = HostApplicationServices.WorkingDatabase;
144
+
145
+           
146
+            
147
+
148
+            DocumentLock documentlock = null;
149
+            Transaction traction = null;
150
+            try
151
+            {
152
+                traction = database.TransactionManager.StartTransaction();
153
+                documentlock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
154
+
155
+                BlockTable blocktable = traction.GetObject(database.BlockTableId,
156
+                                          OpenMode.ForWrite) as BlockTable;
157
+
158
+                BlockTableRecord blocktablerecord = traction.GetObject(blocktable[BlockTableRecord.ModelSpace],
159
+                                                OpenMode.ForWrite) as BlockTableRecord;
160
+
161
+
162
+                Editor editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
163
+                TypedValue[] typedvalue = new TypedValue[2];
164
+
165
+                typedvalue.SetValue(new TypedValue((int)DxfCode.Start, "Circle"), 0);
166
+                typedvalue.SetValue(new TypedValue((int)DxfCode.LayerName, "Cir"), 1);
167
+
168
+                SelectionFilter selectionfilter = new SelectionFilter(typedvalue);
169
+                PromptSelectionResult select = editor.SelectAll(selectionfilter);
170
+
171
+                if (select.Status == PromptStatus.OK)
172
+                {
173
+                    SelectionSet set = select.Value;
174
+
175
+                    ObjectId[] obj = new ObjectId[set.Count];
176
+                    obj = set.GetObjectIds();
177
+                    for (int i = 0; i < obj.Length; i++)
178
+                    {
179
+                        ObjectId objid = obj[i];
180
+                        Entity entity = (Entity)traction.GetObject(objid, OpenMode.ForWrite);
181
+                        entity.Erase();
182
+                    }
183
+                }
184
+                traction.Commit();
185
+            }
186
+            catch (Autodesk.AutoCAD.Runtime.Exception)
187
+            {
188
+               
189
+            }
190
+        }
191
+    }
192
+}

+ 134
- 0
代码/20240112dwg右上角图框/T_cad/OldCls2.cs 查看文件

@@ -0,0 +1,134 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Text;
4
+
5
+using Autodesk.AutoCAD.Runtime;
6
+using Autodesk.AutoCAD.EditorInput;
7
+using Autodesk.AutoCAD.Geometry;
8
+using Autodesk.AutoCAD.DatabaseServices;
9
+using Autodesk.AutoCAD.ApplicationServices;
10
+
11
+
12
+
13
+namespace T_cad
14
+{
15
+    class OldCls2
16
+    {
17
+
18
+        [CommandMethod("CTK")]
19
+        public void ctk()
20
+        {
21
+
22
+            Document document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
23
+            Database database = HostApplicationServices.WorkingDatabase;
24
+
25
+
26
+
27
+            using (Transaction traction = database.TransactionManager.StartTransaction())
28
+            {
29
+
30
+                DocumentLock documentlock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
31
+
32
+
33
+                BlockTable blocktable = traction.GetObject(database.BlockTableId,
34
+                                          OpenMode.ForWrite) as BlockTable;
35
+
36
+                BlockTableRecord blocktablerecord = traction.GetObject(blocktable[BlockTableRecord.ModelSpace],
37
+                                               OpenMode.ForWrite) as BlockTableRecord;
38
+
39
+
40
+                // 获得当前文档的编辑器  
41
+                Editor editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
42
+                // 创建一个 TypedValue 数组,用于定义过滤条件
43
+                TypedValue[] typedvalue = new TypedValue[1];
44
+                typedvalue.SetValue(new TypedValue((int)DxfCode.LayerName, "VC"), 0);
45
+                // 赋值过滤条件给 SelectionFilter 对象
46
+                SelectionFilter selectionfilter = new SelectionFilter(typedvalue);
47
+                // 要求在图形区域中手动选择对象
48
+                PromptSelectionResult psr = editor.GetSelection(selectionfilter);
49
+
50
+
51
+                if (psr.Status == PromptStatus.OK)
52
+                {
53
+                    SelectionSet selectionset = psr.Value;
54
+
55
+                    ObjectId[] obj = new ObjectId[selectionset.Count];
56
+                    obj = selectionset.GetObjectIds();
57
+
58
+
59
+                    for (int i = 0; i < obj.Length; i++)
60
+                    {
61
+                        ObjectId objid = obj[i];
62
+                        Entity entity = (Entity)traction.GetObject(objid, OpenMode.ForRead);
63
+                        Polyline line = entity as Polyline;
64
+
65
+                        Point3dCollection coll = new Point3dCollection();
66
+                        line.GetStretchPoints(coll);
67
+
68
+                        double max_x = coll[0].X;
69
+                        double max_y = coll[0].Y;
70
+                        double min_x = coll[0].X;
71
+                        double min_y = coll[0].Y;
72
+
73
+
74
+                        for (int j = 1; j < coll.Count; j++)
75
+                        {
76
+                            if (coll[j].X > max_x)
77
+                            {
78
+                                max_x = coll[j].X;
79
+                            }
80
+
81
+                            if (coll[j].Y > max_y)
82
+                            {
83
+                                max_y = coll[j].Y;
84
+                            }
85
+
86
+                            if (coll[j].X < min_x)
87
+                            {
88
+                                min_x = coll[j].X;
89
+                            }
90
+
91
+                            if (coll[j].Y < min_y)
92
+                            {
93
+                                min_y = coll[j].Y;
94
+                            }
95
+
96
+                        }
97
+
98
+
99
+                        Point3dCollection coll2 = new Point3dCollection();
100
+
101
+                        Point3d p1 = new Point3d(min_x, min_y, 0);
102
+                        Point3d p2 = new Point3d(min_x, max_y, 0);
103
+
104
+                        Point3d p3 = new Point3d(max_x, max_y, 0);
105
+                        Point3d p4 = new Point3d(max_x, min_y, 0);
106
+
107
+                        coll2.Add(p1);
108
+                        coll2.Add(p2);
109
+                        coll2.Add(p3);
110
+                        coll2.Add(p4);
111
+
112
+                        Polyline2d pline = new Polyline2d(Poly2dType.SimplePoly, coll2, 0, true, 0, 0, null);
113
+                        pline.Layer = "qtk";
114
+
115
+                        pline.SetDatabaseDefaults();
116
+                        blocktablerecord.AppendEntity(pline);
117
+                        traction.AddNewlyCreatedDBObject(pline, true);
118
+                    }
119
+
120
+                }
121
+
122
+
123
+
124
+                traction.Commit();
125
+                documentlock.Dispose();
126
+                traction.Dispose();
127
+            }
128
+
129
+
130
+
131
+        }
132
+
133
+    }
134
+}

+ 36
- 0
代码/20240112dwg右上角图框/T_cad/Properties/AssemblyInfo.cs 查看文件

@@ -0,0 +1,36 @@
1
+using System.Reflection;
2
+using System.Runtime.CompilerServices;
3
+using System.Runtime.InteropServices;
4
+
5
+// 有关程序集的常规信息通过下列属性集
6
+// 控制。更改这些属性值可修改
7
+// 与程序集关联的信息。
8
+[assembly: AssemblyTitle("T_cad")]
9
+[assembly: AssemblyDescription("")]
10
+[assembly: AssemblyConfiguration("")]
11
+[assembly: AssemblyCompany("微软中国")]
12
+[assembly: AssemblyProduct("T_cad")]
13
+[assembly: AssemblyCopyright("Copyright © 微软中国 2013")]
14
+[assembly: AssemblyTrademark("")]
15
+[assembly: AssemblyCulture("")]
16
+
17
+// 将 ComVisible 设置为 false 使此程序集中的类型
18
+// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型,
19
+// 则将该类型上的 ComVisible 属性设置为 true。
20
+[assembly: ComVisible(false)]
21
+
22
+// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
23
+[assembly: Guid("33a2fd36-6d93-4535-9e58-ebc333e1da3d")]
24
+
25
+// 程序集的版本信息由下面四个值组成:
26
+//
27
+//      主版本
28
+//      次版本 
29
+//      内部版本号
30
+//      修订号
31
+//
32
+// 可以指定所有这些值,也可以使用“内部版本号”和“修订号”的默认值,
33
+// 方法是按如下所示使用“*”:
34
+// [assembly: AssemblyVersion("1.0.*")]
35
+[assembly: AssemblyVersion("1.0.0.0")]
36
+[assembly: AssemblyFileVersion("1.0.0.0")]

+ 111
- 0
代码/20240112dwg右上角图框/T_cad/T_cad.csproj 查看文件

@@ -0,0 +1,111 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3
+  <PropertyGroup>
4
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6
+    <ProductVersion>9.0.21022</ProductVersion>
7
+    <SchemaVersion>2.0</SchemaVersion>
8
+    <ProjectGuid>{1110A1A3-576A-42FC-B84E-70A14C464BF7}</ProjectGuid>
9
+    <OutputType>Library</OutputType>
10
+    <AppDesignerFolder>Properties</AppDesignerFolder>
11
+    <RootNamespace>T_cad</RootNamespace>
12
+    <AssemblyName>T_cad</AssemblyName>
13
+    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
14
+    <FileAlignment>512</FileAlignment>
15
+    <FileUpgradeFlags>
16
+    </FileUpgradeFlags>
17
+    <OldToolsVersion>3.5</OldToolsVersion>
18
+    <UpgradeBackupLocation />
19
+    <PublishUrl>publish\</PublishUrl>
20
+    <Install>true</Install>
21
+    <InstallFrom>Disk</InstallFrom>
22
+    <UpdateEnabled>false</UpdateEnabled>
23
+    <UpdateMode>Foreground</UpdateMode>
24
+    <UpdateInterval>7</UpdateInterval>
25
+    <UpdateIntervalUnits>Days</UpdateIntervalUnits>
26
+    <UpdatePeriodically>false</UpdatePeriodically>
27
+    <UpdateRequired>false</UpdateRequired>
28
+    <MapFileExtensions>true</MapFileExtensions>
29
+    <ApplicationRevision>0</ApplicationRevision>
30
+    <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
31
+    <IsWebBootstrapper>false</IsWebBootstrapper>
32
+    <UseApplicationTrust>false</UseApplicationTrust>
33
+    <BootstrapperEnabled>true</BootstrapperEnabled>
34
+  </PropertyGroup>
35
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
36
+    <DebugSymbols>true</DebugSymbols>
37
+    <DebugType>full</DebugType>
38
+    <Optimize>false</Optimize>
39
+    <OutputPath>bin\Debug\</OutputPath>
40
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
41
+    <ErrorReport>prompt</ErrorReport>
42
+    <WarningLevel>4</WarningLevel>
43
+  </PropertyGroup>
44
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
45
+    <DebugType>pdbonly</DebugType>
46
+    <Optimize>true</Optimize>
47
+    <OutputPath>bin\Release\</OutputPath>
48
+    <DefineConstants>TRACE</DefineConstants>
49
+    <ErrorReport>prompt</ErrorReport>
50
+    <WarningLevel>4</WarningLevel>
51
+  </PropertyGroup>
52
+  <ItemGroup>
53
+    <Reference Include="acdbmgd">
54
+      <HintPath>D:\Program Files (x86)\AutoCAD 2007\acdbmgd.dll</HintPath>
55
+      <Private>False</Private>
56
+    </Reference>
57
+    <Reference Include="acmgd">
58
+      <HintPath>D:\Program Files (x86)\AutoCAD 2007\acmgd.dll</HintPath>
59
+      <Private>False</Private>
60
+    </Reference>
61
+    <Reference Include="System" />
62
+    <Reference Include="System.Core">
63
+      <RequiredTargetFramework>3.5</RequiredTargetFramework>
64
+    </Reference>
65
+    <Reference Include="System.Windows.Forms" />
66
+    <Reference Include="System.Xml.Linq">
67
+      <RequiredTargetFramework>3.5</RequiredTargetFramework>
68
+    </Reference>
69
+    <Reference Include="System.Data.DataSetExtensions">
70
+      <RequiredTargetFramework>3.5</RequiredTargetFramework>
71
+    </Reference>
72
+    <Reference Include="System.Data" />
73
+    <Reference Include="System.Xml" />
74
+  </ItemGroup>
75
+  <ItemGroup>
76
+    <Compile Include="mainCls.cs" />
77
+    <Compile Include="OldCls2.cs" />
78
+    <Compile Include="Frame5000.cs" />
79
+    <Compile Include="LayerControl.cs" />
80
+    <Compile Include="LSTKAllCls.cs" />
81
+    <Compile Include="Properties\AssemblyInfo.cs" />
82
+  </ItemGroup>
83
+  <ItemGroup>
84
+    <None Include="app.config" />
85
+  </ItemGroup>
86
+  <ItemGroup>
87
+    <BootstrapperPackage Include="Microsoft.Net.Client.3.5">
88
+      <Visible>False</Visible>
89
+      <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
90
+      <Install>false</Install>
91
+    </BootstrapperPackage>
92
+    <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
93
+      <Visible>False</Visible>
94
+      <ProductName>.NET Framework 3.5 SP1</ProductName>
95
+      <Install>true</Install>
96
+    </BootstrapperPackage>
97
+    <BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
98
+      <Visible>False</Visible>
99
+      <ProductName>Windows Installer 3.1</ProductName>
100
+      <Install>true</Install>
101
+    </BootstrapperPackage>
102
+  </ItemGroup>
103
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
104
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
105
+       Other similar extension points exist, see Microsoft.Common.targets.
106
+  <Target Name="BeforeBuild">
107
+  </Target>
108
+  <Target Name="AfterBuild">
109
+  </Target>
110
+  -->
111
+</Project>

+ 17
- 0
代码/20240112dwg右上角图框/T_cad/T_cad.csproj.user 查看文件

@@ -0,0 +1,17 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
3
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
4
+    <StartAction>Program</StartAction>
5
+    <StartProgram>C:\Program Files\AutoCAD 2007\acad.exe</StartProgram>
6
+  </PropertyGroup>
7
+  <PropertyGroup>
8
+    <PublishUrlHistory />
9
+    <InstallUrlHistory />
10
+    <SupportUrlHistory />
11
+    <UpdateUrlHistory />
12
+    <BootstrapperUrlHistory />
13
+    <ErrorReportUrlHistory />
14
+    <FallbackCulture>zh-CN</FallbackCulture>
15
+    <VerifyUploadedFiles>false</VerifyUploadedFiles>
16
+  </PropertyGroup>
17
+</Project>

+ 3
- 0
代码/20240112dwg右上角图框/T_cad/app.config 查看文件

@@ -0,0 +1,3 @@
1
+<?xml version="1.0"?>
2
+<configuration>
3
+	<startup/></configuration>

二進制
代码/20240112dwg右上角图框/T_cad/bin/Debug/T_cad.dll 查看文件


+ 3
- 0
代码/20240112dwg右上角图框/T_cad/bin/Debug/T_cad.dll.config 查看文件

@@ -0,0 +1,3 @@
1
+<?xml version="1.0"?>
2
+<configuration>
3
+	<startup/></configuration>

二進制
代码/20240112dwg右上角图框/T_cad/bin/Debug/T_cad.pdb 查看文件


+ 30
- 0
代码/20240112dwg右上角图框/T_cad/bin/Debug/acad.err 查看文件

@@ -0,0 +1,30 @@
1
+
2
+
3
+ÖÂÃü´íÎó:  Unhandled Access Violation Writing 0x68100208 Exception at 74df6994h
4
+
5
+08/14/2020 at 13:44:14.921  ͼÐÎ: Drawing1.dwg
6
+-------------
7
+
8
+
9
+ÖÂÃü´íÎó:  Unhandled e0434f4dh Exception at 762b33d2h
10
+
11
+09/14/2020 at 15:11:26.568  ͼÐÎ: Drawing1.dwg
12
+-------------
13
+
14
+
15
+ÖÂÃü´íÎó:  Unhandled e0434f4dh Exception at 762b33d2h
16
+
17
+09/14/2020 at 15:21:54.017  ͼÐÎ: Drawing1.dwg
18
+-------------
19
+
20
+
21
+ÖÂÃü´íÎó:  Unhandled Access Violation Writing 0x1a03110 Exception at 74e16994h
22
+
23
+09/14/2020 at 15:42:03.406  ͼÐÎ: E:\2020\20200914TKLYY\gcjs01\384.dwg
24
+-------------
25
+
26
+
27
+ÖÂÃü´íÎó:  Unhandled e0434f4dh Exception at 752b33d2h
28
+
29
+09/22/2020 at 10:49:45.584  ͼÐÎ: Drawing1.dwg
30
+-------------

+ 66
- 0
代码/20240112dwg右上角图框/T_cad/mainCls.cs 查看文件

@@ -0,0 +1,66 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Text;
4
+
5
+using System.Windows.Forms;
6
+
7
+using Autodesk.AutoCAD.Runtime;
8
+using Autodesk.AutoCAD.EditorInput;
9
+using Autodesk.AutoCAD.Geometry;
10
+using Autodesk.AutoCAD.DatabaseServices;
11
+using Autodesk.AutoCAD.ApplicationServices;
12
+
13
+
14
+
15
+namespace T_cad
16
+{
17
+    public class mainCls
18
+    {
19
+
20
+        [CommandMethod("tk")]
21
+        public void creat()
22
+        {
23
+            Frame5000 frame = new Frame5000();
24
+            frame.Produce();
25
+        }
26
+
27
+
28
+        [CommandMethod("ls")]
29
+        public void LSTKxiugai()
30
+        {
31
+
32
+            LSTKAllCls lstkallCls = new LSTKAllCls();
33
+            //lstkallCls.Function();
34
+            lstkallCls.mianfunction();
35
+        }
36
+
37
+        [CommandMethod("xgls")]
38
+        public void LSTK1_1000()
39
+        {
40
+
41
+            LSTKAllCls lstkallCls = new LSTKAllCls();
42
+            //lstkallCls.Function();
43
+            lstkallCls.DWGXiugai();
44
+        }
45
+
46
+
47
+        [CommandMethod("tt")]
48
+        public void tt()
49
+        {
50
+            LSTKAllCls lstkallCls = new LSTKAllCls();
51
+            //MessageBox.Show("hha");
52
+            //lstkallCls.DGWTKfunctionnew();
53
+            lstkallCls.DGWTKfunction2020();
54
+            MessageBox.Show("OK!");
55
+        }
56
+        [CommandMethod("dd")]
57
+        public void dd()
58
+        {
59
+            LSTKAllCls lstkallCls = new LSTKAllCls();
60
+            //MessageBox.Show("hha");
61
+            //lstkallCls.DGWTKfunctionnew();
62
+            lstkallCls.InserDOMbatch2021();
63
+            MessageBox.Show("OK!");
64
+        }
65
+    }
66
+}

二進制
代码/20240112dwg右上角图框/T_cad/obj/Debug/DesignTimeResolveAssemblyReferences.cache 查看文件


二進制
代码/20240112dwg右上角图框/T_cad/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache 查看文件


二進制
代码/20240112dwg右上角图框/T_cad/obj/Debug/ResolveAssemblyReference.cache 查看文件


二進制
代码/20240112dwg右上角图框/T_cad/obj/Debug/T_cad.csproj.AssemblyReference.cache 查看文件


+ 29
- 0
代码/20240112dwg右上角图框/T_cad/obj/Debug/T_cad.csproj.FileListAbsolute.txt 查看文件

@@ -0,0 +1,29 @@
1
+C:\Documents and Settings\Administrator\桌面\T_cad\T_cad\bin\Debug\T_cad.dll
2
+C:\Documents and Settings\Administrator\桌面\T_cad\T_cad\bin\Debug\T_cad.pdb
3
+C:\Documents and Settings\Administrator\桌面\T_cad\T_cad\obj\Debug\ResolveAssemblyReference.cache
4
+C:\Documents and Settings\Administrator\桌面\T_cad\T_cad\obj\Debug\T_cad.dll
5
+C:\Documents and Settings\Administrator\桌面\T_cad\T_cad\obj\Debug\T_cad.pdb
6
+C:\Documents and Settings\Administrator\桌面\T_cad\T_cad\bin\Debug\T_cad.dll.config
7
+C:\Documents and Settings\Administrator\桌面\T_cad_5000\T_cad\bin\Debug\T_cad.dll.config
8
+C:\Documents and Settings\Administrator\桌面\T_cad_5000\T_cad\bin\Debug\T_cad.dll
9
+C:\Documents and Settings\Administrator\桌面\T_cad_5000\T_cad\bin\Debug\T_cad.pdb
10
+C:\Documents and Settings\Administrator\桌面\T_cad_5000\T_cad\obj\Debug\ResolveAssemblyReference.cache
11
+C:\Documents and Settings\Administrator\桌面\T_cad_5000\T_cad\obj\Debug\T_cad.dll
12
+C:\Documents and Settings\Administrator\桌面\T_cad_5000\T_cad\obj\Debug\T_cad.pdb
13
+E:\CODE\20150313-T_cad_5000\T_cad\obj\Debug\ResolveAssemblyReference.cache
14
+E:\CODE\20150313-T_cad_5000\T_cad\obj\Debug\T_cad.dll
15
+E:\CODE\20150313-T_cad_5000\T_cad\bin\Debug\T_cad.dll.config
16
+E:\CODE\20150313-T_cad_5000\T_cad\bin\Debug\T_cad.dll
17
+E:\CODE\20150313-T_cad_5000\T_cad\bin\Debug\T_cad.pdb
18
+E:\CODE\20150313-T_cad_5000\T_cad\obj\Debug\T_cad.pdb
19
+H:\CODE\20150313-T_cad_5000\T_cad\bin\Debug\T_cad.dll.config
20
+H:\CODE\20150313-T_cad_5000\T_cad\bin\Debug\T_cad.dll
21
+H:\CODE\20150313-T_cad_5000\T_cad\bin\Debug\T_cad.pdb
22
+H:\CODE\20150313-T_cad_5000\T_cad\obj\Debug\ResolveAssemblyReference.cache
23
+H:\CODE\20150313-T_cad_5000\T_cad\obj\Debug\T_cad.dll
24
+H:\CODE\20150313-T_cad_5000\T_cad\obj\Debug\T_cad.pdb
25
+E:\code2\20150313-T_cad_5000\T_cad\bin\Debug\T_cad.dll.config
26
+E:\code2\20150313-T_cad_5000\T_cad\bin\Debug\T_cad.dll
27
+E:\code2\20150313-T_cad_5000\T_cad\bin\Debug\T_cad.pdb
28
+E:\code2\20150313-T_cad_5000\T_cad\obj\Debug\T_cad.dll
29
+E:\code2\20150313-T_cad_5000\T_cad\obj\Debug\T_cad.pdb

二進制
代码/20240112dwg右上角图框/T_cad/obj/Debug/T_cad.dll 查看文件


二進制
代码/20240112dwg右上角图框/T_cad/obj/Debug/T_cad.pdb 查看文件


+ 12
- 0
代码/20240112dwg右上角图框/UpgradeLog.XML 查看文件

@@ -0,0 +1,12 @@
1
+<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type='text/xsl' href='_UpgradeReport_Files/UpgradeReport.xslt'?><UpgradeLog>
2
+<Properties><Property Name="Solution" Value="T_cad">
3
+</Property><Property Name="解决方案文件" Value="E:\code2\20150313-T_cad_5000\T_cad.sln">
4
+</Property><Property Name="Date" Value="2020年8月7日">
5
+</Property><Property Name="Time" Value="9:16">
6
+</Property></Properties><Event ErrorLevel="0" Project="T_cad" Source="T_cad\T_cad.csproj" Description="项目已成功转换">
7
+</Event><Event ErrorLevel="3" Project="T_cad" Source="T_cad\T_cad.csproj" Description="Converted">
8
+</Event><Event ErrorLevel="0" Project="" Source="T_cad.sln" Description="成功转换解决方案">
9
+</Event><Event ErrorLevel="3" Project="" Source="T_cad.sln" Description="Converted">
10
+</Event><Event ErrorLevel="0" Project="T_cad" Source="T_cad\app.config" Description="文件已成功转换。所有的 &lt;supportedRuntime&gt; 和 &lt;requiredRuntime&gt; 标记都已移除,以使项目能够用 Visual Studio 2005 生成并运行。">
11
+</Event><Event ErrorLevel="3" Project="T_cad" Source="T_cad\app.config" Description="Converted">
12
+</Event></UpgradeLog>

+ 207
- 0
代码/20240112dwg右上角图框/_UpgradeReport_Files/UpgradeReport.css 查看文件

@@ -0,0 +1,207 @@
1
+BODY
2
+{
3
+	BACKGROUND-COLOR: white;
4
+	FONT-FAMILY: "Verdana", sans-serif;
5
+	FONT-SIZE: 100%;
6
+	MARGIN-LEFT: 0px;
7
+	MARGIN-TOP: 0px
8
+}
9
+P
10
+{
11
+	FONT-FAMILY: "Verdana", sans-serif;
12
+	FONT-SIZE: 70%;
13
+	LINE-HEIGHT: 12pt;
14
+	MARGIN-BOTTOM: 0px;
15
+	MARGIN-LEFT: 10px;
16
+	MARGIN-TOP: 10px
17
+}
18
+.note
19
+{
20
+	BACKGROUND-COLOR:  #ffffff;
21
+	COLOR: #336699;
22
+	FONT-FAMILY: "Verdana", sans-serif;
23
+	FONT-SIZE: 100%;
24
+	MARGIN-BOTTOM: 0px;
25
+	MARGIN-LEFT: 0px;
26
+	MARGIN-TOP: 0px;
27
+	PADDING-RIGHT: 10px
28
+}
29
+.infotable
30
+{
31
+	BACKGROUND-COLOR: #f0f0e0;
32
+	BORDER-BOTTOM: #ffffff 0px solid;
33
+	BORDER-COLLAPSE: collapse;
34
+	BORDER-LEFT: #ffffff 0px solid;
35
+	BORDER-RIGHT: #ffffff 0px solid;
36
+	BORDER-TOP: #ffffff 0px solid;
37
+	FONT-SIZE: 70%;
38
+	MARGIN-LEFT: 10px
39
+}
40
+.issuetable
41
+{
42
+	BACKGROUND-COLOR: #ffffe8;
43
+	BORDER-COLLAPSE: collapse;
44
+	COLOR: #000000;
45
+	FONT-SIZE: 100%;
46
+	MARGIN-BOTTOM: 10px;
47
+	MARGIN-LEFT: 13px;
48
+	MARGIN-TOP: 0px
49
+}
50
+.issuetitle
51
+{
52
+	BACKGROUND-COLOR: #ffffff;
53
+	BORDER-BOTTOM: #dcdcdc 1px solid;
54
+	BORDER-TOP: #dcdcdc 1px;
55
+	COLOR: #003366;
56
+	FONT-WEIGHT: normal
57
+}
58
+.header
59
+{
60
+	BACKGROUND-COLOR: #cecf9c;
61
+	BORDER-BOTTOM: #ffffff 1px solid;
62
+	BORDER-LEFT: #ffffff 1px solid;
63
+	BORDER-RIGHT: #ffffff 1px solid;
64
+	BORDER-TOP: #ffffff 1px solid;
65
+	COLOR: #000000;
66
+	FONT-WEIGHT: bold
67
+}
68
+.issuehdr
69
+{
70
+	BACKGROUND-COLOR: #E0EBF5;
71
+	BORDER-BOTTOM: #dcdcdc 1px solid;
72
+	BORDER-TOP: #dcdcdc 1px solid;
73
+	COLOR: #000000;
74
+	FONT-WEIGHT: normal
75
+}
76
+.issuenone
77
+{
78
+	BACKGROUND-COLOR: #ffffff;
79
+	BORDER-BOTTOM: 0px;
80
+	BORDER-LEFT: 0px;
81
+	BORDER-RIGHT: 0px;
82
+	BORDER-TOP: 0px;
83
+	COLOR: #000000;
84
+	FONT-WEIGHT: normal
85
+}
86
+.content
87
+{
88
+	BACKGROUND-COLOR: #e7e7ce;
89
+	BORDER-BOTTOM: #ffffff 1px solid;
90
+	BORDER-LEFT: #ffffff 1px solid;
91
+	BORDER-RIGHT: #ffffff 1px solid;
92
+	BORDER-TOP: #ffffff 1px solid;
93
+	PADDING-LEFT: 3px
94
+}
95
+.issuecontent
96
+{
97
+	BACKGROUND-COLOR: #ffffff;
98
+	BORDER-BOTTOM: #dcdcdc 1px solid;
99
+	BORDER-TOP: #dcdcdc 1px solid;
100
+	PADDING-LEFT: 3px
101
+}
102
+A:link
103
+{
104
+	COLOR: #cc6633;
105
+	TEXT-DECORATION: underline
106
+}
107
+A:visited
108
+{
109
+	COLOR: #cc6633;
110
+}
111
+A:active
112
+{
113
+	COLOR: #cc6633;
114
+}
115
+A:hover
116
+{
117
+	COLOR: #cc3300;
118
+	TEXT-DECORATION: underline
119
+}
120
+H1
121
+{
122
+	BACKGROUND-COLOR: #003366;
123
+	BORDER-BOTTOM: #336699 6px solid;
124
+	COLOR: #ffffff;
125
+	FONT-SIZE: 130%;
126
+	FONT-WEIGHT: normal;
127
+	MARGIN: 0em 0em 0em -20px;
128
+	PADDING-BOTTOM: 8px;
129
+	PADDING-LEFT: 30px;
130
+	PADDING-TOP: 16px
131
+}
132
+H2
133
+{
134
+	COLOR: #000000;
135
+	FONT-SIZE: 80%;
136
+	FONT-WEIGHT: bold;
137
+	MARGIN-BOTTOM: 3px;
138
+	MARGIN-LEFT: 10px;
139
+	MARGIN-TOP: 20px;
140
+	PADDING-LEFT: 0px
141
+}
142
+H3
143
+{
144
+	COLOR: #000000;
145
+	FONT-SIZE: 80%;
146
+	FONT-WEIGHT: bold;
147
+	MARGIN-BOTTOM: -5px;
148
+	MARGIN-LEFT: 10px;
149
+	MARGIN-TOP: 20px
150
+}
151
+H4
152
+{
153
+	COLOR: #000000;
154
+	FONT-SIZE: 70%;
155
+	FONT-WEIGHT: bold;
156
+	MARGIN-BOTTOM: 0px;
157
+	MARGIN-TOP: 15px;
158
+	PADDING-BOTTOM: 0px
159
+}
160
+UL
161
+{
162
+	COLOR: #000000;
163
+	FONT-SIZE: 70%;
164
+	LIST-STYLE: square;
165
+	MARGIN-BOTTOM: 0pt;
166
+	MARGIN-TOP: 0pt
167
+}
168
+OL
169
+{
170
+	COLOR: #000000;
171
+	FONT-SIZE: 70%;
172
+	LIST-STYLE: square;
173
+	MARGIN-BOTTOM: 0pt;
174
+	MARGIN-TOP: 0pt
175
+}
176
+LI
177
+{
178
+	LIST-STYLE: square;
179
+	MARGIN-LEFT: 0px
180
+}
181
+.expandable
182
+{
183
+	CURSOR: hand
184
+}
185
+.expanded
186
+{
187
+	color: black
188
+}
189
+.collapsed
190
+{
191
+	DISPLAY: none
192
+}
193
+.foot
194
+{
195
+BACKGROUND-COLOR: #ffffff;
196
+BORDER-BOTTOM: #cecf9c 1px solid;
197
+BORDER-TOP: #cecf9c 2px solid
198
+}
199
+.settings
200
+{
201
+MARGIN-LEFT: 25PX;
202
+}
203
+.help
204
+{
205
+TEXT-ALIGN: right;
206
+margin-right: 10px;
207
+}

+ 232
- 0
代码/20240112dwg右上角图框/_UpgradeReport_Files/UpgradeReport.xslt 查看文件

@@ -0,0 +1,232 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
3
+
4
+    <xsl:key name="ProjectKey" match="Event" use="@Project"/>
5
+
6
+    <xsl:template match="Events" mode="createProjects">
7
+        <projects>
8
+            <xsl:for-each select="Event">
9
+                <!--xsl:sort select="@Project" order="descending"/-->
10
+                <xsl:if test="(1=position()) or (preceding-sibling::*[1]/@Project != @Project)">
11
+
12
+                    <xsl:variable name="ProjectName" select="@Project"/>
13
+
14
+                    <project>
15
+                        <xsl:attribute name="name">
16
+                            <xsl:value-of select="@Project"/>
17
+                        </xsl:attribute> 
18
+
19
+                        <xsl:if test="@Project=''">
20
+                        <xsl:attribute name="solution">
21
+                            <xsl:value-of select="@Solution"/>
22
+                        </xsl:attribute> 
23
+                        </xsl:if>
24
+
25
+                        <xsl:for-each select="key('ProjectKey', $ProjectName)">
26
+                            <!--xsl:sort select="@Source" /-->
27
+                            <xsl:if test="(1=position()) or (preceding-sibling::*[1]/@Source != @Source)">
28
+
29
+                                <source>
30
+                                    <xsl:attribute name="name">
31
+                                        <xsl:value-of select="@Source"/>
32
+                                    </xsl:attribute>
33
+
34
+                                    <xsl:variable name="Source">
35
+                                        <xsl:value-of select="@Source"/>
36
+                                    </xsl:variable>
37
+
38
+                                    <xsl:for-each select="key('ProjectKey', $ProjectName)[ @Source = $Source ]">
39
+
40
+                                        <event>
41
+                                            <xsl:attribute name="error-level">
42
+                                                <xsl:value-of select="@ErrorLevel"/>
43
+                                            </xsl:attribute> 
44
+                                            <xsl:attribute name="description">
45
+                                                <xsl:value-of select="@Description"/>
46
+                                            </xsl:attribute> 
47
+                                        </event>
48
+                                    </xsl:for-each>
49
+                                </source>
50
+                            </xsl:if>
51
+                        </xsl:for-each>
52
+
53
+                    </project>
54
+                </xsl:if>
55
+            </xsl:for-each>
56
+        </projects>
57
+    </xsl:template>
58
+
59
+    <xsl:template match="projects">
60
+    <xsl:for-each select="project">
61
+    <xsl:sort select="@Name" order="ascending"/>
62
+        <h2>
63
+        <xsl:if test="@solution"><a _locID="Solution">解决方案</a>: <xsl:value-of select="@solution"/></xsl:if>
64
+        <xsl:if test="not(@solution)"><a _locID="Project">项目</a>: <xsl:value-of select="@name"/>
65
+            <xsl:for-each select="source">
66
+                <xsl:variable name="Hyperlink" select="@name"/>
67
+            <xsl:for-each select="event[@error-level='4']">
68
+             <A class="note"><xsl:attribute name="HREF"><xsl:value-of select="$Hyperlink"/></xsl:attribute><xsl:value-of select="@description"/></A>
69
+                </xsl:for-each>
70
+            </xsl:for-each>
71
+        </xsl:if>
72
+        </h2>
73
+
74
+        <table cellpadding="2" cellspacing="0" width="98%" border="1" bordercolor="white" class="infotable">
75
+            <tr>
76
+                <td nowrap="1" class="header" _locID="Filename">文件名</td>
77
+                <td nowrap="1" class="header" _locID="Status">状态</td>
78
+                <td nowrap="1" class="header" _locID="Errors">错误</td>
79
+                <td nowrap="1" class="header" _locID="Warnings">警告</td>
80
+            </tr>
81
+
82
+            <xsl:for-each select="source">
83
+                <xsl:sort select="@name" order="ascending"/>
84
+                <xsl:variable name="source-id" select="generate-id(.)"/>
85
+
86
+                <xsl:if test="count(event)!=count(event[@error-level='4'])">
87
+
88
+                <tr class="row">
89
+                    <td class="content">
90
+                        <A HREF="javascript:"><xsl:attribute name="onClick">javascript:document.images['<xsl:value-of select="$source-id"/>'].click()</xsl:attribute><IMG border="0" _locID="IMG.alt" _locAttrData="alt" alt="展开/折叠节" class="expandable" height="11" onclick="changepic()" src="_UpgradeReport_Files/UpgradeReport_Plus.gif" width="9"><xsl:attribute name="name"><xsl:value-of select="$source-id"/></xsl:attribute><xsl:attribute name="child">src<xsl:value-of select="$source-id"/></xsl:attribute></IMG></A> <xsl:value-of select="@name"/> 
91
+                    </td>
92
+                    <td class="content">
93
+                        <xsl:if test="count(event[@error-level='3'])=1">
94
+                            <xsl:for-each select="event[@error-level='3']">
95
+                            <xsl:if test="@description='Converted'"><a _locID="Converted1">已转换</a></xsl:if>
96
+                            <xsl:if test="@description!='Converted'"><xsl:value-of select="@description"/></xsl:if>
97
+                            </xsl:for-each>
98
+                        </xsl:if>
99
+                        <xsl:if test="count(event[@error-level='3'])!=1 and count(event[@error-level='3' and @description='Converted'])!=0"><a _locID="Converted2">已转换</a>
100
+                        </xsl:if>
101
+                    </td>
102
+                    <td class="content"><xsl:value-of select="count(event[@error-level='2'])"/></td>
103
+                    <td class="content"><xsl:value-of select="count(event[@error-level='1'])"/></td>
104
+                </tr>
105
+
106
+                <tr class="collapsed" bgcolor="#ffffff">
107
+                    <xsl:attribute name="id">src<xsl:value-of select="$source-id"/></xsl:attribute>
108
+
109
+                    <td colspan="7">
110
+                        <table width="97%" border="1" bordercolor="#dcdcdc" rules="cols" class="issuetable">
111
+                            <tr>
112
+                                <td colspan="7" class="issuetitle" _locID="ConversionIssues">转换报告 - <xsl:value-of select="@name"/>:</td>
113
+                            </tr>
114
+
115
+                            <xsl:for-each select="event[@error-level!='3']">
116
+                                <xsl:if test="@error-level!='4'">
117
+                                <tr>
118
+                                    <td class="issuenone" style="border-bottom:solid 1 lightgray">
119
+                                        <xsl:value-of select="@description"/>
120
+                                    </td>
121
+                                </tr>
122
+                                </xsl:if>
123
+                            </xsl:for-each>
124
+                        </table>
125
+                    </td>
126
+                </tr>
127
+                </xsl:if>
128
+            </xsl:for-each>
129
+
130
+            <tr valign="top">
131
+                <td class="foot">
132
+                    <xsl:if test="count(source)!=1">
133
+                        <xsl:value-of select="count(source)"/><a _locID="file1"> 个文件</a>
134
+                    </xsl:if>
135
+                    <xsl:if test="count(source)=1">
136
+                        <a _locID="file2">1 个文件</a>
137
+                    </xsl:if>
138
+                </td>
139
+                <td class="foot">
140
+					<a _locID="Converted3">已转换</a>: <xsl:value-of select="count(source/event[@error-level='3' and @description='Converted'])"/><BR/>
141
+					<a _locID="NotConverted">未转换</a>: <xsl:value-of select="count(source) - count(source/event[@error-level='3' and @description='Converted'])"/>
142
+                </td>
143
+                <td class="foot"><xsl:value-of select="count(source/event[@error-level='2'])"/></td>
144
+                <td class="foot"><xsl:value-of select="count(source/event[@error-level='1'])"/></td>
145
+            </tr>
146
+        </table>
147
+    </xsl:for-each>
148
+    </xsl:template>
149
+
150
+    <xsl:template match="Property">
151
+        <xsl:if test="@Name!='Date' and @Name!='Time' and @Name!='LogNumber' and @Name!='Solution'">
152
+        <tr><td nowrap="1"><b><xsl:value-of select="@Name"/>: </b><xsl:value-of select="@Value"/></td></tr>
153
+        </xsl:if>
154
+    </xsl:template>
155
+
156
+    <xsl:template match="UpgradeLog">
157
+        <html>
158
+            <head>
159
+                <META HTTP-EQUIV="Content-Type" content="text/html; charset=utf-8"/>
160
+                <link rel="stylesheet" href="_UpgradeReport_Files\UpgradeReport.css"/>
161
+                <title _locID="ConversionReport0">转换报告 
162
+                    <xsl:if test="Properties/Property[@Name='LogNumber']">
163
+                        <xsl:value-of select="Properties/Property[@Name='LogNumber']/@Value"/>
164
+                    </xsl:if>
165
+                </title>
166
+                <script language="javascript">
167
+                    function outliner () {
168
+                        oMe = window.event.srcElement
169
+                        //get child element
170
+                        var child = document.all[event.srcElement.getAttribute("child",false)];
171
+                        //if child element exists, expand or collapse it.
172
+                        if (null != child)
173
+                            child.className = child.className == "collapsed" ? "expanded" : "collapsed";
174
+                    }
175
+
176
+                    function changepic() {
177
+                        uMe = window.event.srcElement;
178
+                        var check = uMe.src.toLowerCase();
179
+                        if (check.lastIndexOf("upgradereport_plus.gif") != -1)
180
+                        {
181
+                            uMe.src = "_UpgradeReport_Files/UpgradeReport_Minus.gif"
182
+                        }
183
+                        else
184
+                        {
185
+                            uMe.src = "_UpgradeReport_Files/UpgradeReport_Plus.gif"
186
+                        }
187
+                    }
188
+                </script>
189
+            </head>
190
+            <body topmargin="0" leftmargin="0" rightmargin="0" onclick="outliner();">
191
+                <h1 _locID="ConversionReport">转换报告 - <xsl:value-of select="Properties/Property[@Name='Solution']/@Value"/></h1>
192
+
193
+                <p><span class="note">
194
+                <b _locID="TimeOfConversion">转换时间:</b>  <xsl:value-of select="Properties/Property[@Name='Date']/@Value"/>  <xsl:value-of select="Properties/Property[@Name='Time']/@Value"/><br/>
195
+                </span></p>
196
+
197
+                <xsl:variable name="SortedEvents">
198
+                    <Events>
199
+                        <xsl:for-each select="Event">
200
+                            <xsl:sort select="@Project" order="ascending"/>
201
+                            <xsl:sort select="@Source" order="ascending"/>
202
+                            <xsl:sort select="@ErrorLevel" order="ascending"/>
203
+                            <Event>
204
+                                <xsl:attribute name="Project"><xsl:value-of select="@Project"/> </xsl:attribute> 
205
+                                <xsl:attribute name="Solution"><xsl:value-of select="/UpgradeLog/Properties/Property[@Name='Solution']/@Value"/> </xsl:attribute> 
206
+                                <xsl:attribute name="Source"><xsl:value-of select="@Source"/> </xsl:attribute> 
207
+                                <xsl:attribute name="ErrorLevel"><xsl:value-of select="@ErrorLevel"/> </xsl:attribute> 
208
+                                <xsl:attribute name="Description"><xsl:value-of select="@Description"/> </xsl:attribute> 
209
+                            </Event>
210
+                        </xsl:for-each>     
211
+                    </Events>
212
+                </xsl:variable>
213
+                
214
+                <xsl:variable name="Projects">
215
+                    <xsl:apply-templates select="msxsl:node-set($SortedEvents)/*" mode="createProjects"/>
216
+                </xsl:variable>
217
+
218
+                <xsl:apply-templates select="msxsl:node-set($Projects)/*"/>
219
+
220
+                <p></p><p>
221
+                <table class="note">
222
+                    <tr>
223
+                        <td nowrap="1">
224
+                            <b _locID="ConversionSettings">转换设置</b>
225
+                        </td>
226
+                    </tr>
227
+                    <xsl:apply-templates select="Properties"/>
228
+                </table></p>
229
+            </body>
230
+        </html>
231
+    </xsl:template>
232
+</xsl:stylesheet>

二進制
代码/20240112dwg右上角图框/_UpgradeReport_Files/UpgradeReport_Minus.gif 查看文件


二進制
代码/20240112dwg右上角图框/_UpgradeReport_Files/UpgradeReport_Plus.gif 查看文件


+ 90
- 0
代码/20240226桐梓林/实际在用的数据和代码/BP2024_cgcs2000.txt 查看文件

@@ -0,0 +1,90 @@
1
+0,TP01-BD,34485301.081299997866154,2955223.545739999972284,1021.168159039999978
2
+1,TP02-BD,34485280.408200003206730,2955227.433960000053048,1021.085816099999988
3
+2,TP03-BD,34485258.683799996972084,2955231.585460000205785,1020.945290460000024
4
+3,TP04-BD,34485228.449000000953674,2955237.383080000057817,1020.945290460000024
5
+4,TP05-BD,34485199.474500000476837,2955242.808610000181943,1020.843441529999950
6
+5,TP06-BD,34485160.987300001084805,2955250.180900000035763,1020.970975169999974
7
+6,TP07-BD,34485122.458099998533726,2955257.520130000077188,1021.027699600000005
8
+7,TP08-BDZ,34485103.223399996757507,2955261.080229999963194,1020.962322960000051
9
+8,TP08-BDY,34485101.420000001788139,2955261.434580000117421,1021.040842440000006
10
+9,TP09-BD,34485079.014499999582767,2955265.498999999836087,1021.149470289999954
11
+10,TP10-BD,34485057.348999999463558,2955269.549509999807924,1021.128597460000037
12
+11,TP11-BD,34485036.384900003671646,2955273.562739999964833,1021.174869680000029
13
+12,TP12-BD,34485015.152500003576279,2955277.563860000111163,1021.134774790000051
14
+13,TP13-BD,34484929.877899996936321,2955293.708070000167936,1021.116641350000009
15
+14,TP14-BD,34484905.705700002610683,2955298.273039999883622,1021.142815749999954
16
+15,TP17-DQ,34484997.566500000655651,2954958.725519999861717,1004.983846240000048
17
+16,TP16-DQ,34484993.909599997103214,2954972.919369999784976,1005.191704220000020
18
+17,TP15-DQ,34484989.431699998676777,2954996.698530000168830,1005.118719090000013
19
+18,TP14-DQ,34484986.957500003278255,2955013.513269999995828,1005.129815740000026
20
+19,TP13-DQ,34484984.925300002098083,2955028.117169999983162,1005.088060530000007
21
+20,TP12-DQ,34484983.693000003695488,2955042.180860000196844,1005.034417709999957
22
+21,TP11-DQ,34484983.050599999725819,2955065.601170000154525,1004.683698209999989
23
+22,TP10-DQ,34484982.802699998021126,2955080.173849999904633,1004.683698209999989
24
+23,TP09-DQ,34484982.997900001704693,2955082.809549999888986,1004.683698209999989
25
+24,TP08-DQ,34484983.549099996685982,2955097.463669999968261,1004.833438770000043
26
+25,TP07-DQ,34484983.756499998271465,2955100.134730000048876,1004.787344159999975
27
+26,TP05-DQ,34484985.029600001871586,2955116.861149999778718,1004.735926279999944
28
+27,TP06-DQ,34484984.778800003230572,2955114.197769999969751,1004.859666139999945
29
+28,TP04-DQ,34484986.461699999868870,2955129.372729999944568,1004.242376110000009
30
+29,TP03-DQ,34484986.872699998319149,2955131.520060000009835,1004.242376110000009
31
+30,TP02-DQ,34484988.465700000524521,2955143.127830000128597,1004.231713639999953
32
+31,TP01-DQ,34484988.858400002121925,2955144.975459999870509,1004.231713639999953
33
+32,TP03-BPL,34485309.611900001764297,2955103.861200000159442,1039.687181360000068
34
+33,TP04-BPL,34485255.218699999153614,2955046.873339999932796,1034.675172239999938
35
+34,TP05-BPL,34485350.722199998795986,2955140.997700000181794,1062.301825849999886
36
+35,TP06-BPL,34485301.662500001490116,2955061.256260000169277,1059.548219459999927
37
+36,TP07-BPL,34485310.107400000095367,2955010.978550000116229,1098.883136960000002
38
+37,TP08-BPL,34485303.271899998188019,2955003.883899999782443,1098.887125949999927
39
+38,TP01-BPR,34484878.979199998080730,2955515.872349999845028,1089.566210339999998
40
+39,TP02-BPR,34484908.911899998784065,2955508.822929999791086,1065.499816849999888
41
+40,TP03-BPR,34484937.228500001132488,2955511.503579999785870,1035.584973819999959
42
+41,TP04-BPR,34484891.426399998366833,2955435.492860000114888,1065.406448149999960
43
+42,TP05-BPR,34484918.160599999129772,2955430.765209999866784,1035.304991559999962
44
+43,TP06-BPR,34484811.512199997901917,2955327.934599999804050,1097.654248450000068
45
+44,TP07-BPR,34484845.826499998569489,2955323.419830000028014,1065.372569950000070
46
+45,TP08-BPR,34484871.616599999368191,2955315.338090000208467,1035.354820349999954
47
+46,TP17-BPR,34484867.932099997997284,2955193.051059999968857,1035.265467429999944
48
+47,TP18-BPR,34484894.338600002229214,2955195.105529999826103,1020.911775000000034
49
+48,TP10-BPR,34484865.658299997448921,2955239.147369999904186,1035.324701049999931
50
+49,TP13-BPR,34484862.319799996912479,2955130.764640000183135,1035.324313750000101
51
+50,TP12-BPR,34484836.256899997591972,2955137.299959999974817,1065.273195120000082
52
+51,TP09-BPR,34484827.226099997758865,2955235.384730000048876,1076.977462210000112
53
+52,TP11-BPR,34484804.341700002551079,2955143.528450000099838,1096.841172579999920
54
+53,TP24-BPR,34484860.839599996805191,2954970.418949999846518,1035.278223199999957
55
+54,TP16-BPR,34484858.369000002741814,2954999.503260000143200,1035.091854009999906
56
+55,TP21-BPR,34484855.532200001180172,2955024.885749999899417,1035.800327169999946
57
+56,TP23-BPR,34484838.610600002110004,2954967.626720000058413,1065.251993189999894
58
+57,TP15-BPR,34484835.259000003337860,2955003.261340000201017,1065.299354609999909
59
+58,TP20-BPR,34484832.932700000703335,2955023.599770000204444,1065.457569670000112
60
+59,TP22-BPR,34484812.034599997103214,2954966.490730000194162,1095.858027230000062
61
+60,TP14-BPR,34484808.192500002682209,2955008.787930000107735,1095.339208469999903
62
+61,TP19-BPR,34484806.986900001764297,2955021.151490000076592,1095.250029909999967
63
+62,TP01-RFH,34484899.642599999904633,2954736.631430000066757,1017.912639150000018
64
+63,TP02-RFH,34484896.574199996888638,2954723.139570000115782,1017.699740379999980
65
+64,TP03-RFH,34484897.558399997651577,2954707.180430000182241,1017.873773700000015
66
+65,TP04-RFH,34484868.719300001859665,2954744.574450000189245,1042.403225510000084
67
+66,TP05-RFH,34484861.998599998652935,2954726.964439999777824,1042.403357950000100
68
+67,TP06-RFH,34484860.441299997270107,2954706.285240000113845,1042.508420410000099
69
+68,TP07-RFH,34484847.303499996662140,2954712.146069999784231,1060.535635530000036
70
+69,TP08-RFH,34484846.909100003540516,2954680.893999999854714,1060.133341420000079
71
+70,TP01-KHP,34485588.634300000965595,2955523.311129999812692,1125.639228049999929
72
+71,TP02-KHP,34485440.770199999213219,2955505.694600000046194,1033.598063859999911
73
+72,TP03-KHP,34485351.769699998199940,2955498.918899999931455,1019.138097489999950
74
+73,TP04-KHP,34485532.134900003671646,2955441.079220000188798,1084.900584790000039
75
+74,TP05-KHP,34485441.527199998497963,2955493.222109999973327,1035.194786329999943
76
+75,TP06-KHP,34485527.265100002288818,2955422.496129999868572,1083.266359599999987
77
+76,TP07-KHP,34485452.079800002276897,2955434.074250000063330,1044.625217589999920
78
+77,TP08-KHP,34485361.193800002336502,2955343.832560000009835,1019.116060660000016
79
+78,TP09-KHP,34485509.223499998450279,2955462.949349999893457,1058.024445150000020
80
+79,TP10-KHP,34485445.439599998295307,2955399.688939999789000,1035.184220780000032
81
+80,TP02-THP,34485374.653599999845028,2956446.380669999867678,1016.710949499999970
82
+81,TP05-THP,34485372.968900002539158,2956403.745300000067800,1017.084909730000049
83
+82,TP08-THP,34485377.395700000226498,2956368.041780000086874,1017.059842320000030
84
+83,TP10-THP,34485383.044100001454353,2956337.302649999968708,1016.600180150000028
85
+84,TP04-THP,34485453.789099998772144,2956395.612470000050962,1022.566278560000001
86
+85,TP07-THP,34485449.338399998843670,2956373.114969999995083,1021.461417800000049
87
+86,TP01-THP,34485508.151600003242493,2956397.168049999978393,1046.965977040000098
88
+87,TP03-THP,34485560.619300000369549,2956396.729299999773502,1065.229743589999998
89
+88,TP06-THP,34485540.476800002157688,2956368.596439999993891,1052.296595439999919
90
+89,TP09-THP,34485506.225100003182888,2956337.631060000043362,1046.775322060000008

+ 1
- 0
代码/20240226桐梓林/实际在用的数据和代码/CGCS2000_3_Degree_GK_Zone_34.prj 查看文件

@@ -0,0 +1 @@
1
+PROJCS["CGCS2000_3_Degree_GK_Zone_34",GEOGCS["GCS_China_Geodetic_Coordinate_System_2000",DATUM["D_China_2000",SPHEROID["CGCS2000",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Gauss_Kruger"],PARAMETER["False_Easting",34500000.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",102.0],PARAMETER["Scale_Factor",1.0],PARAMETER["Latitude_Of_Origin",0.0],UNIT["Meter",1.0],AUTHORITY["EPSG",4522]]

+ 1
- 0
代码/20240226桐梓林/实际在用的数据和代码/GCS_WGS_1984.prj 查看文件

@@ -0,0 +1 @@
1
+GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],VERTCS["EGM96_Geoid",VDATUM["EGM96_Geoid"],PARAMETER["Vertical_Shift",0.0],PARAMETER["Direction",1.0],UNIT["Meter",1.0]]

+ 11
- 0
代码/20240226桐梓林/实际在用的数据和代码/Memo.txt 查看文件

@@ -0,0 +1,11 @@
1
+格式:
2
+2020/11/27Q184
3
+点号;首期与最后一期位移量;2016-2021位移量
4
+(首先临空面垂直,再临空面)
5
+(首先横河向,再顺河向)
6
+用,分割
7
+end
8
+
9
+前面两组数据不用夸张,只夸张后面
10
+
11
+3倍夸张

+ 678
- 0
代码/20240226桐梓林/实际在用的数据和代码/Newjson2023.py 查看文件

@@ -0,0 +1,678 @@
1
+import re
2
+import math
3
+import json
4
+import arcpy
5
+import os
6
+
7
+#基准点txt,位移list,夸张系数,输出txt(?),输出文件夹
8
+def drawline(shppath,linelist,ran1,outpath,txtpath,ran22):
9
+    ran0 = float(ran1)
10
+    ran2 = float(ran22)
11
+    mm = 0
12
+    nameA = ''
13
+    #结果点(?)
14
+    resultp = []
15
+    #坐标系文件
16
+    prjpath = r'D:\4work_now\20240226TZL\CGCS2000_3_Degree_GK_Zone_34.prj'
17
+    prjpath1 = r'D:\4work_now\20240226TZL\GCS_WGS_1984.prj'
18
+    #大概是先把计算结果写上
19
+    with open(outpath,'w') as files:
20
+        #循环列表 
21
+        while mm < len(linelist):
22
+            kk = 0
23
+            #读基准点文件
24
+            with open(shppath,'r') as filesA:      
25
+                for ppstr1 in filesA:
26
+                    #基准点的信息
27
+                    pname = ppstr1.split(',',-1)[1]
28
+                    #这里加一点,识别角度值
29
+                    angleA = readangle(pname)
30
+                    xP = float(ppstr1.split(',',-1)[2])
31
+                    yP = float(ppstr1.split(',',-1)[3])
32
+                    zP = float(ppstr1.split(',',-1)[4])
33
+                    #读位移是否有和这个匹配的
34
+                    str0 = linelist[mm]
35
+                    #把一些数据反过来写
36
+                    nameA = str0.split(',',-1)[0]
37
+                    nameP = nameA.split('-',-1)[-1]
38
+                    if  nameP == 'BPL':
39
+                        xA1= float(str0.split(',',-1)[2])
40
+                        yA1= float(str0.split(',',-1)[1])
41
+                        xA= float(str0.split(',',-1)[4])
42
+                        yA= float(str0.split(',',-1)[3])
43
+                        xA122= float(str0.split(',',-1)[2])
44
+                        yA122= float(str0.split(',',-1)[1])
45
+                        xA22= float(str0.split(',',-1)[4])
46
+                        yA22= float(str0.split(',',-1)[3])
47
+                    elif nameP == 'KHP':
48
+                        xA1= float(str0.split(',',-1)[1])* (-1)
49
+                        yA1= float(str0.split(',',-1)[2])* (-1)
50
+                        xA= float(str0.split(',',-1)[3])* (-1)
51
+                        yA= float(str0.split(',',-1)[4])* (-1)
52
+                        xA122= float(str0.split(',',-1)[1])
53
+                        yA122= float(str0.split(',',-1)[2])
54
+                        xA22= float(str0.split(',',-1)[3])
55
+                        yA22= float(str0.split(',',-1)[4])
56
+                    elif nameP == 'RFH':
57
+                        xA1= float(str0.split(',',-1)[1])
58
+                        yA1= float(str0.split(',',-1)[2])
59
+                        xA= float(str0.split(',',-1)[3])
60
+                        yA= float(str0.split(',',-1)[4])
61
+                        xA122= float(str0.split(',',-1)[1])
62
+                        yA122= float(str0.split(',',-1)[2])
63
+                        xA22= float(str0.split(',',-1)[3])
64
+                        yA22= float(str0.split(',',-1)[4])
65
+                    elif nameP == 'BPR':
66
+                        xA1= float(str0.split(',',-1)[2])*(-1)
67
+                        yA1= float(str0.split(',',-1)[1])
68
+                        xA= float(str0.split(',',-1)[4])*(-1)
69
+                        yA= float(str0.split(',',-1)[3])
70
+                        xA122= float(str0.split(',',-1)[2])
71
+                        yA122= float(str0.split(',',-1)[1])
72
+                        xA22= float(str0.split(',',-1)[4])
73
+                        yA22= float(str0.split(',',-1)[3])
74
+                    elif nameP == 'THP':
75
+                        xA1= float(str0.split(',',-1)[2])*(-1)
76
+                        yA1= float(str0.split(',',-1)[1])
77
+                        xA= float(str0.split(',',-1)[4])*(-1)
78
+                        yA= float(str0.split(',',-1)[3])
79
+                        xA122= float(str0.split(',',-1)[2])
80
+                        yA122= float(str0.split(',',-1)[1])
81
+                        xA22= float(str0.split(',',-1)[4])
82
+                        yA22= float(str0.split(',',-1)[3])
83
+                    else:
84
+                        xA1= float(str0.split(',',-1)[1])
85
+                        yA1= float(str0.split(',',-1)[2])
86
+                        xA= float(str0.split(',',-1)[3])
87
+                        yA= float(str0.split(',',-1)[4])
88
+                        xA122= float(str0.split(',',-1)[1])
89
+                        yA122= float(str0.split(',',-1)[2])
90
+                        xA22= float(str0.split(',',-1)[3])
91
+                        yA22= float(str0.split(',',-1)[4])
92
+                    if nameA == pname:
93
+                        #一些距离参数
94
+                        xB = (xA * ran0)
95
+                        yB = (yA * ran0)
96
+                        xB1 = (xA1 * ran2)
97
+                        yB1 = (yA1 * ran2)
98
+                        #总距离
99
+                        xA2 = xA * xA
100
+                        yA2 = yA * yA
101
+                        xA21 = xA1 * xA1
102
+                        yA21 = yA1 * yA1
103
+                        disA = math.sqrt(xA2 + yA2)
104
+                        disA1 = math.sqrt(xA21 + yA21)
105
+                        #这里分别对应x方向和y方向
106
+                        xpx = xP - xB
107
+                        xpy = yP
108
+                        ypx = xP
109
+                        ypy = yB + yP
110
+                        xpx1 = xP - xB1
111
+                        xpy1 = yP
112
+                        ypx1 = xP
113
+                        ypy1 = yB1 + yP
114
+                        #一同计算得到第二个点(大概)
115
+                        xangle = float(angleA)
116
+                        yangle = float(angleA)
117
+                        arrpointx = rotatecordiateX(xangle,xpx,xpy,xP,yP,xB)
118
+                        arrpointy = rotatecordiateY(yangle,ypx,ypy,xP,yP,yB)
119
+                        arrpointx1 = rotatecordiateX(xangle,xpx1,xpy1,xP,yP,xB1)
120
+                        arrpointy1 = rotatecordiateY(yangle,ypx1,ypy1,xP,yP,yB1)
121
+                        pppointx = float(arrpointx[0]) + float(arrpointy[0]) - xP
122
+                        pppointy = float(arrpointx[1]) + float(arrpointy[1]) - yP
123
+                        pppointx1 = float(arrpointx1[0]) + float(arrpointy1[0]) - xP
124
+                        pppointy1 = float(arrpointx1[1]) + float(arrpointy1[1]) - yP
125
+                        #写入
126
+                        files.write(pname + "," + "px," + str(arrpointx[0]) + "," + str(arrpointx[1]) + "," + str(zP) + "," +str(xA22)+ "\n")
127
+                        files.write(pname + "," + "py," + str(arrpointy[0]) + "," + str(arrpointy[1]) + "," + str(zP) + "," +str(yA22)+ "\n")
128
+                        files.write(pname + "," + "pp," + str(pppointx) + "," + str(pppointy) + "," + str(zP) + ","+ str(disA) + "\n")
129
+                        files.write(pname + "," + "px1," + str(arrpointx1[0]) + "," + str(arrpointx1[1]) + "," + str(zP) + "," +str(xA122)+ "\n")
130
+                        files.write(pname + "," + "py1," + str(arrpointy1[0]) + "," + str(arrpointy1[1]) + "," + str(zP) + "," +str(yA122)+ "\n")
131
+                        files.write(pname + "," + "pp1," + str(pppointx1) + "," + str(pppointy1) + "," + str(zP) + ","+ str(disA1) + "\n")
132
+                        mm = mm + 1
133
+                        kk = 1
134
+                        break
135
+                    else:
136
+                        #意思是继续寻找和位移匹配的点
137
+                        continue
138
+            if kk == 0 :
139
+                mm = mm + 1
140
+                # print(nameA)
141
+    #最后输出
142
+    resultp.append(outpath)
143
+    resultp.append(prjpath)
144
+    resultp.append(prjpath1)
145
+    resultp.append(txtpath)
146
+    return resultp
147
+
148
+def rotatecordiateX(rang,xpx,xpy,xP,yP,zf):
149
+    rx = float(xpx)
150
+    ry = float(xpy)
151
+    ox = float(xP)
152
+    oy = float(yP)
153
+    aa = 1
154
+    dis = math.sqrt((rx - ox)*(rx-ox) + (ry - oy)*(ry-oy))
155
+    if aa == 0:
156
+        if zf > 0:
157
+            if rang <= 90:
158
+                angle = math.radians(rang)
159
+                cosA = math.cos(angle)
160
+                sinA = math.sin(angle) 
161
+                x0 = dis * cosA
162
+                y0 = dis * sinA
163
+                x0n = ox +x0
164
+                y0n = oy +y0
165
+            elif rang > 90 and rang <= 180:
166
+                ang = 180 - rang
167
+                angle = math.radians(ang)
168
+                cosA = math.cos(angle)
169
+                sinA = math.sin(angle)  
170
+                x0 = dis * cosA
171
+                y0 = dis * sinA
172
+                x0n = ox-x0
173
+                y0n = oy+y0
174
+            elif rang > 180 and rang <=270:
175
+                ang = rang - 180
176
+                angle = math.radians(ang)
177
+                cosA = math.cos(angle)
178
+                sinA = math.sin(angle)
179
+                x0 = dis * cosA
180
+                y0 = dis * sinA
181
+                x0n =ox-x0
182
+                y0n = oy-y0
183
+            else:
184
+                ang = 360 - rang
185
+                angle = math.radians(ang)
186
+                cosA = math.cos(angle)
187
+                sinA = math.sin(angle)
188
+                x0 = dis * cosA
189
+                y0 = dis * sinA
190
+                x0n = ox + x0
191
+                y0n = oy-y0
192
+        else:
193
+            if rang <= 90:
194
+                angle = math.radians(rang)
195
+                cosA = math.cos(angle)
196
+                sinA = math.sin(angle) 
197
+                x0 = dis * cosA
198
+                y0 = dis * sinA
199
+                x0n = ox - x0
200
+                y0n = oy -y0
201
+            elif rang > 90 and rang <= 180:
202
+                ang = 180 - rang
203
+                angle = math.radians(ang)
204
+                cosA = math.cos(angle)
205
+                sinA = math.sin(angle)  
206
+                x0 = dis * cosA
207
+                y0 = dis * sinA
208
+                x0n = ox + x0
209
+                y0n = oy - y0
210
+            elif rang > 180 and rang <=270:
211
+                ang = rang - 180
212
+                angle = math.radians(ang)
213
+                cosA = math.cos(angle)
214
+                sinA = math.sin(angle)
215
+                x0 = dis * cosA
216
+                y0 = dis * sinA
217
+                x0n =ox + x0
218
+                y0n = oy + y0
219
+            else:
220
+                ang = 360 - rang
221
+                angle = math.radians(ang)
222
+                cosA = math.cos(angle)
223
+                sinA = math.sin(angle)
224
+                x0 = dis * cosA
225
+                y0 = dis * sinA
226
+                x0n = ox - x0
227
+                y0n = oy + y0
228
+    else:
229
+        if zf < 0:
230
+            if rang <= 90:
231
+                angle = math.radians(rang)
232
+                cosA = math.cos(angle)
233
+                sinA = math.sin(angle) 
234
+                x0 = dis * cosA
235
+                y0 = dis * sinA
236
+                x0n = ox +x0
237
+                y0n = oy +y0
238
+            elif rang > 90 and rang <= 180:
239
+                ang = 180 - rang
240
+                angle = math.radians(ang)
241
+                cosA = math.cos(angle)
242
+                sinA = math.sin(angle)  
243
+                x0 = dis * cosA
244
+                y0 = dis * sinA
245
+                x0n = ox-x0
246
+                y0n = oy+y0
247
+            elif rang > 180 and rang <=270:
248
+                ang = rang - 180
249
+                angle = math.radians(ang)
250
+                cosA = math.cos(angle)
251
+                sinA = math.sin(angle)
252
+                x0 = dis * cosA
253
+                y0 = dis * sinA
254
+                x0n =ox-x0
255
+                y0n = oy-y0
256
+            else:
257
+                ang = 360 - rang
258
+                angle = math.radians(ang)
259
+                cosA = math.cos(angle)
260
+                sinA = math.sin(angle)
261
+                x0 = dis * cosA
262
+                y0 = dis * sinA
263
+                x0n = ox + x0
264
+                y0n = oy-y0
265
+        else:
266
+            if rang <= 90:
267
+                angle = math.radians(rang)
268
+                cosA = math.cos(angle)
269
+                sinA = math.sin(angle) 
270
+                x0 = dis * cosA
271
+                y0 = dis * sinA
272
+                x0n = ox - x0
273
+                y0n = oy -y0
274
+            elif rang > 90 and rang <= 180:
275
+                ang = 180 - rang
276
+                angle = math.radians(ang)
277
+                cosA = math.cos(angle)
278
+                sinA = math.sin(angle)  
279
+                x0 = dis * cosA
280
+                y0 = dis * sinA
281
+                x0n = ox + x0
282
+                y0n = oy - y0
283
+            elif rang > 180 and rang <=270:
284
+                ang = rang - 180
285
+                angle = math.radians(ang)
286
+                cosA = math.cos(angle)
287
+                sinA = math.sin(angle)
288
+                x0 = dis * cosA
289
+                y0 = dis * sinA
290
+                x0n =ox + x0
291
+                y0n = oy + y0
292
+            else:
293
+                ang = 360 - rang
294
+                angle = math.radians(ang)
295
+                cosA = math.cos(angle)
296
+                sinA = math.sin(angle)
297
+                x0 = dis * cosA
298
+                y0 = dis * sinA
299
+                x0n = ox - x0
300
+                y0n = oy + y0
301
+    return [x0n,y0n]
302
+
303
+def rotatecordiateY(rang,xpx,xpy,xP,yP,zf):
304
+    rx = float(xpx)
305
+    ry = float(xpy)
306
+    ox = float(xP)
307
+    oy = float(yP)
308
+    bb = 1
309
+    dis = math.sqrt((rx - ox)*(rx-ox) + (ry - oy)*(ry-oy))
310
+    if bb == 0:
311
+        if zf > 0:
312
+            if rang <= 90:
313
+                 angle = math.radians(rang)
314
+                 cosA = math.cos(angle)
315
+                 sinA = math.sin(angle)
316
+                 x0 = dis * sinA
317
+                 y0 = dis * cosA
318
+                 x0n1 = ox+x0
319
+                 y0n1 = oy-y0
320
+            elif rang > 90 and rang <= 180:
321
+                 ang = 180 - rang
322
+                 angle = math.radians(ang)
323
+                 cosA = math.cos(angle)
324
+                 sinA = math.sin(angle) 
325
+                 x0 = dis * sinA
326
+                 y0 = dis * cosA
327
+                 x0n1 = ox+x0
328
+                 y0n1 = oy+y0
329
+            elif rang > 180 and rang <=270:
330
+                 ang = rang - 180
331
+                 angle = math.radians(ang)
332
+                 cosA = math.cos(angle)
333
+                 sinA = math.sin(angle) 
334
+                 x0 = dis * sinA
335
+                 y0 = dis * cosA 
336
+                 x0n1 = ox-x0
337
+                 y0n1 = oy+y0
338
+            else:
339
+                 ang = 360 - rang
340
+                 angle = math.radians(ang)
341
+                 cosA = math.cos(angle)
342
+                 sinA = math.sin(angle) 
343
+                 x0 = dis * sinA
344
+                 y0 = dis * cosA
345
+                 x0n1 = ox-x0
346
+                 y0n1 = oy-y0
347
+        else:
348
+            if rang <= 90:
349
+                angle = math.radians(rang)
350
+                cosA = math.cos(angle)
351
+                sinA = math.sin(angle)
352
+                x0 = dis * sinA
353
+                y0 = dis * cosA
354
+                x0n1 = ox-x0
355
+                y0n1 = oy+y0
356
+            elif rang > 90 and rang <= 180:
357
+                ang = 180 - rang
358
+                angle = math.radians(ang)
359
+                cosA = math.cos(angle)
360
+                sinA = math.sin(angle) 
361
+                x0 = dis * sinA
362
+                y0 = dis * cosA
363
+                x0n1 = ox-x0
364
+                y0n1 = oy-y0
365
+            elif rang > 180 and rang <=270:
366
+                ang = rang - 180
367
+                angle = math.radians(ang)
368
+                cosA = math.cos(angle)
369
+                sinA = math.sin(angle) 
370
+                x0 = dis * sinA
371
+                y0 = dis * cosA 
372
+                x0n1 = ox+x0
373
+                y0n1 = oy-y0
374
+            else:
375
+                ang = 360 - rang
376
+                angle = math.radians(ang)
377
+                cosA = math.cos(angle)
378
+                sinA = math.sin(angle) 
379
+                x0 = dis * sinA
380
+                y0 = dis * cosA
381
+                x0n1 = ox+x0
382
+                y0n1 = oy+y0
383
+    else:
384
+        if zf < 0:
385
+            if rang <= 90:
386
+                 angle = math.radians(rang)
387
+                 cosA = math.cos(angle)
388
+                 sinA = math.sin(angle)
389
+                 x0 = dis * sinA
390
+                 y0 = dis * cosA
391
+                 x0n1 = ox+x0
392
+                 y0n1 = oy-y0
393
+            elif rang > 90 and rang <= 180:
394
+                 ang = 180 - rang
395
+                 angle = math.radians(ang)
396
+                 cosA = math.cos(angle)
397
+                 sinA = math.sin(angle) 
398
+                 x0 = dis * sinA
399
+                 y0 = dis * cosA
400
+                 x0n1 = ox+x0
401
+                 y0n1 = oy+y0
402
+            elif rang > 180 and rang <=270:
403
+                 ang = rang - 180
404
+                 angle = math.radians(ang)
405
+                 cosA = math.cos(angle)
406
+                 sinA = math.sin(angle) 
407
+                 x0 = dis * sinA
408
+                 y0 = dis * cosA 
409
+                 x0n1 = ox-x0
410
+                 y0n1 = oy+y0
411
+            else:
412
+                 ang = 360 - rang
413
+                 angle = math.radians(ang)
414
+                 cosA = math.cos(angle)
415
+                 sinA = math.sin(angle) 
416
+                 x0 = dis * sinA
417
+                 y0 = dis * cosA
418
+                 x0n1 = ox-x0
419
+                 y0n1 = oy-y0
420
+        else:
421
+            if rang <= 90:
422
+                angle = math.radians(rang)
423
+                cosA = math.cos(angle)
424
+                sinA = math.sin(angle)
425
+                x0 = dis * sinA
426
+                y0 = dis * cosA
427
+                x0n1 = ox-x0
428
+                y0n1 = oy+y0
429
+            elif rang > 90 and rang <= 180:
430
+                ang = 180 - rang
431
+                angle = math.radians(ang)
432
+                cosA = math.cos(angle)
433
+                sinA = math.sin(angle) 
434
+                x0 = dis * sinA
435
+                y0 = dis * cosA
436
+                x0n1 = ox-x0
437
+                y0n1 = oy-y0
438
+            elif rang > 180 and rang <=270:
439
+                ang = rang - 180
440
+                angle = math.radians(ang)
441
+                cosA = math.cos(angle)
442
+                sinA = math.sin(angle) 
443
+                x0 = dis * sinA
444
+                y0 = dis * cosA 
445
+                x0n1 = ox+x0
446
+                y0n1 = oy-y0
447
+            else:
448
+                ang = 360 - rang
449
+                angle = math.radians(ang)
450
+                cosA = math.cos(angle)
451
+                sinA = math.sin(angle) 
452
+                x0 = dis * sinA
453
+                y0 = dis * cosA
454
+                x0n1 = ox+x0
455
+                y0n1 = oy+y0
456
+    return [x0n1,y0n1]
457
+
458
+def readangle(pname):
459
+    nameA = pname.split('-',-1)[-1]
460
+    #作个键值对
461
+    dict = {'BD':101, 'BDZ':101, 'BDY':101,'KHP':191, 'THP':191, 'BPR':11,'RFH':11,'BPL':210,'DQ':101}
462
+    ang1 = dict[nameA] 
463
+    if nameA == 'THP' or nameA == 'BPR':
464
+        ang2 = 360 - ang1
465
+    elif nameA == 'KHP':
466
+        ang2 = 90 - ang1
467
+    else:
468
+        ang2 = 270 - ang1
469
+    return ang2
470
+
471
+def readtxt(listp):
472
+    #输出和两个转换坐标文件
473
+    txtpath = listp[0]
474
+    prjpath = listp[1]
475
+    prjpath1 = listp[2]
476
+    outpath = listp[3]
477
+    #创建需要用的
478
+    gdbpath = outpath + '\\bd.mdb'
479
+    gdbpath1 = outpath + '\\result.mdb'
480
+    mdbpath = gdbpath1 + '\\BDp'
481
+    foutpath = gdbpath + '\\BDp'
482
+    try:
483
+        arcpy.CreatePersonalGDB_management (outpath, 'bd.mdb')
484
+    except:
485
+        arcpy.Delete_management(gdbpath)
486
+        arcpy.CreatePersonalGDB_management (outpath, 'bd.mdb')
487
+    try:
488
+        arcpy.CreatePersonalGDB_management (outpath, 'result.mdb')
489
+    except:
490
+        arcpy.Delete_management(gdbpath1)
491
+        arcpy.CreatePersonalGDB_management (outpath, 'result.mdb')
492
+    try:
493
+        arcpy.CreateFeatureclass_management(gdbpath,'BDp', 'POINT') 
494
+    except:
495
+        arcpy.Delete_management(foutpath)
496
+        arcpy.CreateFeatureclass_management(gdbpath,'BDp', 'POINT')  
497
+    arcpy.MakeFeatureLayer_management(foutpath, 'bd')
498
+    #cgcs2000的坐标系文件(务必放入输出文件夹)
499
+    arcpy.DefineProjection_management('bd', prjpath)
500
+    arcpy.AddField_management('bd','pname','TEXT')
501
+    arcpy.AddField_management('bd','pxyp','TEXT')
502
+    arcpy.AddField_management('bd','elevation','FLOAT')
503
+    arcpy.AddField_management('bd','dis','FLOAT')
504
+    with arcpy.da.InsertCursor('bd',['SHAPE@X','SHAPE@Y','elevation','pname','pxyp','dis']) as cursorZ:
505
+        with open(txtpath,'r') as filesA:      
506
+                for ppstr1 in filesA:
507
+                    str1 = ppstr1.split(',',-1)[0]
508
+                    str2 = ppstr1.split(',',-1)[1]
509
+                    str3 = float(ppstr1.split(',',-1)[2])
510
+                    str4 = float(ppstr1.split(',',-1)[3])
511
+                    str5 = float(ppstr1.split(',',-1)[4])
512
+                    str61 = ppstr1.split(',',-1)[5]
513
+                    str62 = str61.replace('\n','')
514
+                    str6 = float(str62)
515
+                    listp1 = []
516
+                    listp1.append(str3)
517
+                    listp1.append(str4)
518
+                    listp1.append(str5)
519
+                    listp1.append(str1)
520
+                    listp1.append(str2)
521
+                    listp1.append(str6)
522
+                    cursorZ.insertRow(listp1)
523
+    # print('3')
524
+    listp2 = []
525
+    listp2.append(foutpath)
526
+    listp2.append(mdbpath)
527
+    listp2.append(prjpath1)
528
+    return listp2
529
+
530
+def transzb(listp):
531
+    #原始点,转换点,转换文件
532
+    shppath = listp[0]
533
+    mdbpath = listp[1]
534
+    prjpath = listp[2]
535
+    try:
536
+        arcpy.Project_management(shppath, mdbpath, prjpath)
537
+    except:
538
+        #检查空几何
539
+        arcpy.MakeFeatureLayer_management(shppath, 'SHP2')
540
+        with arcpy.da.UpdateCursor('SHP2',['SHAPE@']) as cursorD:
541
+            for curD in cursorD:
542
+                shp1 = curD[0]
543
+                if shp1 == None:
544
+                    cursorD.deleteRow()
545
+        arcpy.Project_management(shppath, mdbpath, prjpath)
546
+    # print('4')
547
+    return mdbpath
548
+
549
+def rejson(inpath,outpath):
550
+    #这里的点就是位移两个点
551
+    foutpath = outpath + '\\Result.json'
552
+    arcpy.MakeFeatureLayer_management(inpath, 'bdlayer')
553
+    #根据属性归类
554
+    mm = 0
555
+    pxstr = ''
556
+    pystr = ''
557
+    ppstr = ''
558
+    pxstr1 = ''
559
+    pystr1 = ''
560
+    ppstr1 = ''
561
+    pname = ''
562
+    lx = ''
563
+    ly = ''
564
+    lp = ''
565
+    lx1 = ''
566
+    ly1 = ''
567
+    lp1 = ''
568
+    nameA = ''
569
+    resultp = []
570
+    with arcpy.da.SearchCursor('bdlayer',['SHAPE@X','SHAPE@Y','elevation','pname','pxyp','dis']) as cursorZ:
571
+        for curZ in cursorZ:
572
+            if mm == 0:
573
+                #px
574
+                pname = curZ[3]
575
+                nameA = pname.split('-',-1)[-1]
576
+                if nameA =='BPR' or nameA == 'THP':
577
+                    pystr = str(curZ[0]) + " ," + str(curZ[1]) + " ," + str(curZ[2])
578
+                    ly = str(round(curZ[5],1))
579
+                # pxstr = str(round(curZ[0],2)) + " ," + str(round(curZ[1],2)) + " ," + str(round(curZ[2]))
580
+                # lx = str(round(curZ[5],2))
581
+                else:
582
+                    pxstr = str(curZ[0]) + " ," + str(curZ[1]) + " ," + str(curZ[2])
583
+                    lx = str(round(curZ[5],1))
584
+                mm = mm + 1
585
+            elif mm == 1 and curZ[3] == pname:
586
+                if nameA =='BPR' or nameA == 'THP':
587
+                    pxstr = str(curZ[0]) + " ," + str(curZ[1]) + " ," + str(curZ[2])
588
+                    lx = str(round(curZ[5],1))
589
+                else:
590
+                #py
591
+                    pystr = str(curZ[0]) + " ," + str(curZ[1]) + " ," + str(curZ[2])
592
+                    ly = str(round(curZ[5],1))
593
+                mm = mm + 1
594
+            elif mm == 2 and curZ[3] == pname:
595
+                #pp
596
+                ppstr = str(curZ[0]) + " ," + str(curZ[1]) + " ," + str(curZ[2])
597
+                lp = str(round(curZ[5],1))
598
+                mm = mm + 1
599
+                
600
+            elif mm == 3 and curZ[3] == pname:
601
+                if nameA =='BPR' or nameA == 'THP':
602
+                    pystr1 = str(curZ[0]) + " ," + str(curZ[1]) + " ," + str(curZ[2])
603
+                    ly1 = str(round(curZ[5],1))
604
+                else:
605
+                    pxstr1 = str(curZ[0]) + " ," + str(curZ[1]) + " ," + str(curZ[2])
606
+                    lx1 = str(round(curZ[5],1))
607
+                mm = mm + 1
608
+            elif mm == 4 and curZ[3] == pname:
609
+                if nameA =='BPR' or nameA == 'THP':
610
+                    pxstr1 = str(curZ[0]) + " ," + str(curZ[1]) + " ," + str(curZ[2])
611
+                    lx1 = str(round(curZ[5],1))
612
+                else:
613
+                    pystr1 = str(curZ[0]) + " ," + str(curZ[1]) + " ," + str(curZ[2])
614
+                    ly1 = str(round(curZ[5],1))
615
+                mm = mm + 1
616
+            elif mm == 5 and curZ[3] == pname:
617
+                ppstr1 = str(curZ[0]) + " ," + str(curZ[1]) + " ," + str(curZ[2])
618
+                lp1 = str(round(curZ[5],1))
619
+                #此时加入item
620
+                item = {
621
+                            "name": pname,
622
+                            "px": pxstr,
623
+                            "lx": lx,
624
+                            "py": pystr,
625
+                            "ly": ly,
626
+                            "pp": ppstr,
627
+                            "lp": lp,
628
+                            "px1": pxstr1,
629
+                            "lx1": lx1,
630
+                            "py1": pystr1,
631
+                            "ly1": ly1,
632
+                            "pp1": ppstr1,
633
+                            "lp1": lp1 
634
+                        }
635
+                resultp.append(item)
636
+                mm = 0
637
+    # print('5')
638
+    with open(foutpath, 'w') as dump_f:
639
+        json.dump(resultp,dump_f) 
640
+
641
+
642
+def linew(bppath,inpath,outpath,ranA,ranB):
643
+    # ang1 = 270 - float(angle1) 
644
+    ran = float(ranA)
645
+    ran1 = float(ranB)
646
+    #存储位移array
647
+    txtarr = []
648
+    #获取位移量文件名字
649
+    txtfilename = inpath.split('\\',-1)[-1]
650
+    txtfile = txtfilename.split('.',-1)[0]
651
+    #读的是位移量文件
652
+    with open(inpath,'r+') as fileA:
653
+        for lineA in fileA:
654
+            #直接读
655
+            if lineA == '\n':
656
+                continue
657
+            elif 'end' in lineA:
658
+                fulloutpath = outpath + '\\Resulttxt.txt'
659
+                #进入第二步
660
+                # print('1')
661
+                #这里把所有的都理出来了
662
+                resultp = drawline(bppath,txtarr,ran,fulloutpath,outpath,ran1)
663
+                #这里读取
664
+                list2 = readtxt(resultp)
665
+                #坐标转换
666
+                mdbpath = transzb(list2)
667
+                #再输出为json
668
+                rejson(mdbpath,outpath)
669
+                # print('finish')
670
+                break
671
+            else:
672
+                txtarr.append(lineA)
673
+
674
+
675
+
676
+if __name__ == '__main__':
677
+    # 第一个是基准点,第二个是位移量,第三个是输出文件夹,夸张系数
678
+    linew(r"D:\4work_now\20240226TZL\BP2024_cgcs2000.txt",r"D:\4work_now\20240226TZL\TZL2023.txt",r"D:\4work_now\20240226TZL\result",2,2)

+ 91
- 0
代码/20240226桐梓林/实际在用的数据和代码/TZL2023.txt 查看文件

@@ -0,0 +1,91 @@
1
+TP01-BD,-1.5 ,2.9 ,-1.4 ,2.5 
2
+TP02-BD,-1.5 ,2.8 ,-0.1 ,1.7 
3
+TP03-BD,1.8 ,1.8 ,-0.1 ,1.7 
4
+TP04-BD,-0.4 ,1.9 ,-0.9 ,0.9 
5
+TP05-BD,-0.1 ,1.1 ,-0.4 ,1.0 
6
+TP06-BD,0.1 ,-2.5 ,0.3 ,2.1 
7
+TP07-BD,0.2 ,0.4 ,-0.5 ,2.2 
8
+TP08-BDZ,-1.5 ,-1.1 ,-1.0 ,1.5 
9
+TP08-BDY,-0.5 ,-2.6 ,0.0 ,1.5 
10
+TP09-BD,1.7 ,-0.8 ,-0.3 ,2.4 
11
+TP10-BD,-0.3 ,3.3 ,-0.4 ,2.1 
12
+TP11-BD,1.3 ,2.1 ,-0.1 ,1.9 
13
+TP12-BD,-2.0 ,0.8 ,-3.5 ,-3.0 
14
+TP13-BD,-1.1 ,2.7 ,-1.8 ,0.1 
15
+TP14-BD,0.1 ,2.7 ,-1.2 ,-0.1 
16
+TP01-DQ,0.1 ,0.4 ,0.5 ,1.7 
17
+TP02-DQ,-2.2 ,3.9 ,0.1 ,-0.3 
18
+TP03-DQ,-1.1 ,2.2 ,-0.3 ,0.4 
19
+TP04-DQ,1.6 ,3.4 ,1.8 ,1.9 
20
+TP05-DQ,-2.1 ,2.8 ,-2.1 ,-1.6 
21
+TP06-DQ,-0.6 ,0.7 ,0.0 ,1.7 
22
+TP07-DQ,-3.6 ,5.3 ,-2.3 ,1.0 
23
+TP08-DQ,-1.7 ,1.3 ,-0.6 ,0.3 
24
+TP09-DQ,-1.6 ,1.4 ,-1.1 ,-1.4 
25
+TP10-DQ,-3.2 ,3.3 ,-1.4 ,-0.5 
26
+TP11-DQ,-3.6 ,3.6 ,0.1 ,-0.5 
27
+TP12-DQ,-4.4 ,5.7 ,-1.0 ,0.4 
28
+TP13-DQ,-4.1 ,9.9 ,-0.8 ,0.0 
29
+TP14-DQ,-6.1 ,6.7 ,-0.7 ,-0.3 
30
+TP15-DQ,-4.4 ,4.9 ,-1.3 ,0.7 
31
+TP16-DQ,-5.5 ,6.6 ,-0.1 ,0.6 
32
+TP17-DQ,-5.2 ,4.0 ,0.4 ,-0.2 
33
+TP03-BPL,7.4 ,6.7 ,6.6 ,3.0 
34
+TP04-BPL,7.5 ,4.6 ,6.5 ,3.4 
35
+TP05-BPL,10.1 ,6.9 ,6.7 ,1.4 
36
+TP06-BPL,5.5 ,6.8 ,5.4 ,0.7 
37
+TP07-BPL,7.3 ,8.0 ,5.0 ,2.1 
38
+TP08-BPL,16.7 ,7.2 ,5.2 ,1.5 
39
+TP01-BPR,-2.5 ,-0.6 ,2.8 ,0.4 
40
+TP02-BPR,8.8 ,-0.6 ,3.2 ,0.7 
41
+TP03-BPR,0.9 ,4.3 ,1.3 ,-0.3 
42
+TP04-BPR,1.2 ,-1.7 ,3.5 ,-0.7 
43
+TP05-BPR,3.4 ,1.1 ,3.0 ,1.4 
44
+TP06-BPR,4.5 ,0.8 ,3.4 ,0.2 
45
+TP07-BPR,1.1 ,2.7 ,2.8 ,-0.6 
46
+TP08-BPR,3.2 ,5.7 ,4.5 ,2.0 
47
+TP09-BPR,14.6 ,9.7 ,2.8 ,1.1 
48
+TP10-BPR,1.2 ,5.7 ,3.1 ,-0.6 
49
+TP11-BPR,6.7 ,9.6 ,1.1 ,0.9 
50
+TP12-BPR,1.2 ,2.7 ,-0.1 ,0.7 
51
+TP13-BPR,9.5 ,2.8 ,3.5 ,0.4 
52
+TP14-BPR,2.1 ,-0.1 ,2.0 ,-2.5 
53
+TP15-BPR,9.6 ,11.0 ,5.3 ,-0.9 
54
+TP16-BPR,7.4 ,8.2 ,3.5 ,1.1 
55
+TP17-BPR,5.5 ,0.0 ,2.3 ,-0.4 
56
+TP18-BPR,0.6 ,2.4 ,3.3 ,-3.5 
57
+TP19-BPR,7.4 ,9.6 ,5.6 ,1.4 
58
+TP20-BPR,8.0 ,4.4 ,2.1 ,-0.1 
59
+TP21-BPR,4.8 ,12.5 ,5.7 ,3.0 
60
+TP22-BPR,3.1 ,10.1 ,1.7 ,-0.5 
61
+TP23-BPR,19.2 ,22.9 ,5.3 ,1.6 
62
+TP24-BPR,-0.2 ,-7.3 ,1.8 ,-0.9 
63
+TP01-RFH,10.8 ,6.9 ,1.8 ,1.7 
64
+TP02-RFH,10.3 ,5.4 ,2.4 ,-1.1 
65
+TP03-RFH,9.7 ,5.2 ,1.5 ,0.0 
66
+TP04-RFH,18.3 ,4.8 ,2.5 ,-1.7 
67
+TP05-RFH,11.9 ,9.6 ,1.5 ,-0.3 
68
+TP06-RFH,13.0 ,10.4 ,2.9 ,1.1 
69
+TP07-RFH,19.5 ,16.1 ,4.2 ,1.5 
70
+TP08-RFH,9.2 ,8.1 ,2.0 ,0.4 
71
+TP01-THP,-3.3 ,5.4 ,-2.2 ,1.1 
72
+TP02-THP,0.3 ,2.2 ,-4.4 ,1.8 
73
+TP03-THP,1.4 ,0.3 ,-4.7 ,1.5 
74
+TP04-THP,1.2 ,2.5 ,-3.7 ,3.1 
75
+TP05-THP,-0.8 ,-1.9 ,-4.2 ,0.5 
76
+TP06-THP,-0.8 ,4.1 ,-6.6 ,2.8 
77
+TP07-THP,0.8 ,2.0 ,-5.4 ,-0.3 
78
+TP08-THP,-0.9 ,1.5 ,-5.3 ,-1.1 
79
+TP09-THP,9.6 ,20.6 ,-4.5 ,3.9 
80
+TP10-THP,2.2 ,2.7 ,-3.5 ,1.2 
81
+TP01-KHP,13.2 ,-8.8 ,7.1 ,-2.5 
82
+TP02-KHP,10.1 ,3.8 ,5.1 ,0.1 
83
+TP03-KHP,6.5 ,-4.1 ,5.5 ,1.7 
84
+TP04-KHP,-11.2 ,27.7 ,4.9 ,3.5 
85
+TP05-KHP,14.5 ,6.3 ,7.5 ,-1.8 
86
+TP06-KHP,26.4 ,-2.9 ,8.5 ,2.0 
87
+TP07-KHP,6.5 ,6.4 ,7.5 ,-0.2 
88
+TP08-KHP,10.3 ,1.2 ,7.0 ,1.6 
89
+TP09-KHP,28.9 ,3.5 ,7.9 ,-1.2 
90
+TP10-KHP,8.8 ,-3.1 ,7.2 ,-1.8 
91
+end

+ 218
- 0
代码/20241016断面自动生成/drawDMlineCOM1022_pan.py 查看文件

@@ -0,0 +1,218 @@
1
+# -*- coding: utf-8 -*-
2
+import arcpy
3
+import math
4
+
5
+def drawDM(shppath,outpath,jj0,bj0):
6
+    jj = float(jj0)
7
+    bj = float(bj0)
8
+    szd = 'Sp'
9
+    mzd = 'Ep'
10
+    sx = 'SX'
11
+    sw = 'S_Weizhi'
12
+    arcpy.MakeFeatureLayer_management(shppath, 'DMshp')
13
+    shppath1 = outpath + '\\DMpoint.shp'
14
+    try:
15
+        arcpy.CreateFeatureclass_management(outpath, 'DMpoint.shp', 'POINT')
16
+    except:
17
+        arcpy.Delete_management(shppath1)
18
+        arcpy.CreateFeatureclass_management(outpath, 'DMpoint.shp', 'POINT')
19
+    arcpy.MakeFeatureLayer_management(shppath1, 'DMP')
20
+    shppath2 = outpath + '\\DMpolyline.shp'
21
+    try:
22
+        arcpy.CreateFeatureclass_management(outpath, 'DMpolyline.shp', 'POLYLINE')
23
+    except:
24
+        arcpy.Delete_management(shppath2)
25
+        arcpy.CreateFeatureclass_management(outpath, 'DMpolyline.shp', 'POLYLINE')
26
+    arcpy.MakeFeatureLayer_management(shppath2, 'DML')
27
+    arcpy.AddField_management('DMP','ZH','TEXT')
28
+    arcpy.AddField_management('DML','ZH','TEXT')
29
+    with arcpy.da.InsertCursor('DMP', ['SHAPE@','ZH']) as cursorA:
30
+        with arcpy.da.InsertCursor('DML', ['SHAPE@','ZH']) as cursorB:
31
+            with arcpy.da.SearchCursor('DMshp',['SHAPE@',szd,mzd,sw,sx,'length']) as cursorC:
32
+                for curC in cursorC:
33
+                    dm = curC[0]
34
+                    zf = curC[4]
35
+                    pts = dm.getPart(0)
36
+                    if zf == 1:
37
+                        sk = int(curC[1]) // 1000
38
+                        sj = int(curC[1]) % 1000
39
+                        len = curC[3]
40
+                        dmgeopt = dm.positionAlongLine(len)
41
+                        dmpt = dmgeopt.firstPoint
42
+                        zh = 'K' + str(sk) + '+' + str(str(sj).zfill(3))
43
+                        minp = findminp(dm,pts,len)
44
+                        pl = jsdp(dmpt,minp,bj)
45
+                        list1 = []
46
+                        list1.append(dmgeopt)
47
+                        list1.append(zh)
48
+                        cursorA.insertRow(list1)
49
+                        list2 = []
50
+                        list2.append(pl)
51
+                        list2.append(zh)
52
+                        cursorB.insertRow(list2)
53
+                        len = len + 50
54
+                        while len <= curC[5]:
55
+                            ptg1 = dm.positionAlongLine(len)
56
+                            pt1 = ptg1.firstPoint
57
+                            minp = findminp(dm,pts,len)
58
+                            pl = jsdp(pt1,minp,bj)
59
+                            sj = sj + 50
60
+                            if sj == 1000:
61
+                                sk = sk + 1
62
+                                sj = 0
63
+                            zh = 'K' + str(sk) + '+' + str(str(sj).zfill(3))
64
+                            listp1 = []
65
+                            listp1.append(ptg1)
66
+                            listp1.append(zh)
67
+                            cursorA.insertRow(listp1)
68
+                            listl1 = []
69
+                            listl1.append(pl)
70
+                            listl1.append(zh)
71
+                            cursorB.insertRow(listl1)
72
+                            len = len + 50
73
+                            print('B2')
74
+                        if curC[2] == -1:
75
+                            pass
76
+                        else:
77
+                            mk = int(curC[2]) // 1000
78
+                            mj = int(curC[2]) % 1000
79
+                            zh1 = 'K' + str(mk) + '+' + str(str(mj).zfill(3))
80
+                            if zh1 == zh:
81
+                                pass
82
+                            else:
83
+                                qd = dm.lastPoint
84
+                                plZ = jsdp(qd,pts[pts.count - 2],bj)
85
+                                lens = curC[5] - (len - 50)
86
+                                sj = sj + int(lens)
87
+                                zh = 'K' + str(sk) + '+' + str(str(sj).zfill(3))
88
+                                listp1 = []
89
+                                listp1.append(arcpy.PointGeometry(qd))
90
+                                listp1.append(zh)
91
+                                cursorA.insertRow(listp1)
92
+                                listl1 = []
93
+                                listl1.append(plZ)
94
+                                listl1.append(zh)
95
+                                cursorB.insertRow(listl1)
96
+                        print('B')                 
97
+                    else:
98
+                        sk = int(curC[1]) // 1000
99
+                        sj = int(curC[1]) % 1000
100
+                        len = curC[5] - curC[3]
101
+                        dmgeopt = dm.positionAlongLine(len)
102
+                        dmpt = dmgeopt.firstPoint
103
+                        zh = 'K' + str(sk) + '+' + str(str(sj).zfill(3))
104
+                        minp = findminp(dm,pts,len)
105
+                        pl = jsdp(dmpt,minp,bj)
106
+                        list1 = []
107
+                        list1.append(dmgeopt)
108
+                        list1.append(zh)
109
+                        cursorA.insertRow(list1)
110
+                        list2 = []
111
+                        list2.append(pl)
112
+                        list2.append(zh)
113
+                        cursorB.insertRow(list2)
114
+                        len = len - 50
115
+                        while len >= 0:
116
+                            ptg1 = dm.positionAlongLine(len)
117
+                            pt1 = ptg1.firstPoint
118
+                            minp = findminp(dm,pts,len)
119
+                            pl = jsdp(pt1,minp,bj)
120
+                            sj = sj + 50
121
+                            if sj == 1000:
122
+                                sk = sk + 1
123
+                                sj = 0
124
+                            zh = 'K' + str(sk) + '+' + str(str(sj).zfill(3))
125
+                            listp1 = []
126
+                            listp1.append(ptg1)
127
+                            listp1.append(zh)
128
+                            cursorA.insertRow(listp1)
129
+                            listl1 = []
130
+                            listl1.append(pl)
131
+                            listl1.append(zh)
132
+                            cursorB.insertRow(listl1)
133
+                            len = len - 50
134
+                            print('B2')
135
+                        if curC[2] == -1:
136
+                            pass
137
+                        else:
138
+                            mk = int(curC[2]) // 1000
139
+                            mj = int(curC[2]) % 1000
140
+                            zh1 = 'K' + str(mk) + '+' + str(str(mj).zfill(3))
141
+                            if zh1 == zh:
142
+                                pass
143
+                            else:
144
+                                qd = dm.firstPoint
145
+                                plZ = jsdp(qd,pts[1],bj)
146
+                                lens = len + 50
147
+                                sj = sj + int(lens)
148
+                                zh = 'K' + str(sk) + '+' + str(str(sj).zfill(3))
149
+                                listp1 = []
150
+                                listp1.append(arcpy.PointGeometry(qd))
151
+                                listp1.append(zh)
152
+                                cursorA.insertRow(listp1)
153
+                                listl1 = []
154
+                                listl1.append(plZ)
155
+                                listl1.append(zh)
156
+                                cursorB.insertRow(listl1)             
157
+                        print('C')
158
+
159
+def findminp(dm,pts,len):
160
+    mm = 1
161
+    disM = 9999
162
+    minp = pts[0]
163
+    while mm < (pts.count - 1):
164
+        dis2 = dm.measureOnLine(pts[mm])
165
+        dis = abs(dis2 - len)
166
+        if dis == 0:
167
+            minp = pts[mm - 1]
168
+            break
169
+        if dis < disM:
170
+            disM = dis
171
+            minp = pts[mm]
172
+        mm = mm + 1   
173
+    return minp
174
+
175
+def jsdp(pt1,pt2,bj):
176
+    qdx = pt1.X
177
+    qdy = pt1.Y
178
+    qdx1 = pt2.X
179
+    qdy1 = pt2.Y
180
+    qdk = (qdx1 - qdx) / (qdy1-qdy) * (-1) 
181
+    num0 = qdk * qdx
182
+    qdb = qdy - num0
183
+    numA = (qdk * qdk) + 1
184
+    num1 = qdb - qdy
185
+    num2 = 2 * qdk * num1
186
+    num3 = 2 * qdx
187
+    numB = num2 - num3
188
+    num4 = num1 * num1
189
+    num5 = qdx * qdx
190
+    num51 = bj * bj
191
+    numC = num4 + num5 - num51
192
+    num6 = numB * numB
193
+    num7 = 4 * numA * numC
194
+    num8 =  math.sqrt(num6 - num7)
195
+    num9 = (-1) * numB
196
+    num101 = num9 + num8
197
+    num102 = num9 - num8
198
+    num11 = 2 * numA
199
+    numX1 = num101 / num11
200
+    numX2 = num102 / num11
201
+    numY1 = qdk * numX1 + qdb
202
+    numY2 = qdk * numX2 + qdb
203
+    pt1 = arcpy.Point(numX1, numY1)
204
+    pt2 = arcpy.Point(numX2, numY2)
205
+    arr1 = arcpy.Array()
206
+    arr1.append(pt1)
207
+    arr1.append(pt2)
208
+    pl1 = arcpy.Polyline(arr1)
209
+    return pl1
210
+    
211
+                    
212
+
213
+
214
+if __name__ == '__main__':
215
+    try:
216
+        drawDM(r"D:\4work_now\20241017dm\P1.shp",r'D:\4work_now\20241017dm\1',50,30)
217
+    except arcpy.ExecuteError:
218
+        arcpy.AddMessage (arcpy.GetMessages())

+ 231
- 0
代码/20241016断面自动生成/drawDMlineCOM1022_pan_1.py 查看文件

@@ -0,0 +1,231 @@
1
+# -*- coding: utf-8 -*-
2
+import arcpy
3
+import math
4
+
5
+def drawDM(shppath,outpath,jj0,bj0):
6
+    jj = float(jj0)
7
+    bj = float(bj0)
8
+    szd = 'Sp'
9
+    sx = 'SX'
10
+    sw = 'S_Weizhi'
11
+    arcpy.MakeFeatureLayer_management(shppath, 'DMshp')
12
+    shppath1 = outpath + '\\DMpoint.shp'
13
+    try:
14
+        arcpy.CreateFeatureclass_management(outpath, 'DMpoint.shp', 'POINT')
15
+    except:
16
+        arcpy.Delete_management(shppath1)
17
+        arcpy.CreateFeatureclass_management(outpath, 'DMpoint.shp', 'POINT')
18
+    arcpy.MakeFeatureLayer_management(shppath1, 'DMP')
19
+    shppath2 = outpath + '\\DMpolyline.shp'
20
+    try:
21
+        arcpy.CreateFeatureclass_management(outpath, 'DMpolyline.shp', 'POLYLINE')
22
+    except:
23
+        arcpy.Delete_management(shppath2)
24
+        arcpy.CreateFeatureclass_management(outpath, 'DMpolyline.shp', 'POLYLINE')
25
+    arcpy.MakeFeatureLayer_management(shppath2, 'DML')
26
+    arcpy.AddField_management('DMP','ZH','TEXT')
27
+    arcpy.AddField_management('DML','ZH','TEXT')
28
+    with arcpy.da.InsertCursor('DMP', ['SHAPE@','ZH']) as cursorA:
29
+        with arcpy.da.InsertCursor('DML', ['SHAPE@','ZH']) as cursorB:
30
+            with arcpy.da.SearchCursor('DMshp',['SHAPE@',szd,sw,sx,'length']) as cursorC:
31
+                for curC in cursorC:
32
+                    dm = curC[0]
33
+                    zf = curC[3]
34
+                    pts = dm.getPart(0)
35
+                    if zf == 1:
36
+                        sk = int(curC[1]) // 1000
37
+                        sj = int(curC[1]) % 1000
38
+                        len = curC[2]
39
+                        dmgeopt = dm.positionAlongLine(len)
40
+                        dmpt = dmgeopt.firstPoint
41
+                        zh = 'K' + str(sk) + '+' + str(str(sj).zfill(3))
42
+                        minp = findminp(dm,pts,len)
43
+                        try:
44
+                            pl = jsdp(dmpt,minp,bj)
45
+                            list1 = []
46
+                            list1.append(dmgeopt)
47
+                            list1.append(zh)
48
+                            cursorA.insertRow(list1)
49
+                            list2 = []
50
+                            list2.append(pl)
51
+                            list2.append(zh)
52
+                            cursorB.insertRow(list2)
53
+                        except:
54
+                            pass
55
+                        len = len + 50
56
+                        while len <= curC[4]:
57
+                            ptg1 = dm.positionAlongLine(len)
58
+                            pt1 = ptg1.firstPoint
59
+                            minp = findminp(dm,pts,len)
60
+                            sj = sj + 50
61
+                            if sj == 1000:
62
+                                sk = sk + 1
63
+                                sj = 0
64
+                            zh = 'K' + str(sk) + '+' + str(str(sj).zfill(3))
65
+                            try:
66
+                                pl = jsdp(pt1,minp,bj)
67
+                                listp1 = []
68
+                                listp1.append(ptg1)
69
+                                listp1.append(zh)
70
+                                cursorA.insertRow(listp1)
71
+                                listl1 = []
72
+                                listl1.append(pl)
73
+                                listl1.append(zh)
74
+                                cursorB.insertRow(listl1)
75
+                            except:
76
+                                pass
77
+                            len = len + 50
78
+                            print('B2')
79
+
80
+                        mk = int(curC[2]) // 1000
81
+                        mj = int(curC[2]) % 1000
82
+                        zh1 = 'K' + str(mk) + '+' + str(str(mj).zfill(3))
83
+                        if zh1 == zh:
84
+                            pass
85
+                        else:
86
+                            qd = dm.lastPoint
87
+                            lens = curC[5] - (len - 50)
88
+                            sj = sj + int(lens)
89
+                            zh = 'K' + str(sk) + '+' + str(str(sj).zfill(3))
90
+                            try:
91
+                                plZ = jsdp(qd,pts[pts.count - 2],bj)
92
+                                listp1 = []
93
+                                listp1.append(arcpy.PointGeometry(qd))
94
+                                listp1.append(zh)
95
+                                cursorA.insertRow(listp1)
96
+                                listl1 = []
97
+                                listl1.append(plZ)
98
+                                listl1.append(zh)
99
+                                cursorB.insertRow(listl1)
100
+                            except:
101
+                                pass
102
+                        print('B')                 
103
+                    else:
104
+                        sk = int(curC[1]) // 1000
105
+                        sj = int(curC[1]) % 1000
106
+                        len = curC[4] - curC[2]
107
+                        dmgeopt = dm.positionAlongLine(len)
108
+                        dmpt = dmgeopt.firstPoint
109
+                        zh = 'K' + str(sk) + '+' + str(str(sj).zfill(3))
110
+                        minp = findminp(dm,pts,len)
111
+                        try:
112
+                            pl = jsdp(dmpt,minp,bj)
113
+                            list1 = []
114
+                            list1.append(dmgeopt)
115
+                            list1.append(zh)
116
+                            cursorA.insertRow(list1)
117
+                            list2 = []
118
+                            list2.append(pl)
119
+                            list2.append(zh)
120
+                            cursorB.insertRow(list2)
121
+                        except:
122
+                            pass
123
+                        len = len - 50
124
+                        while len >= 0:
125
+                            ptg1 = dm.positionAlongLine(len)
126
+                            pt1 = ptg1.firstPoint
127
+                            minp = findminp(dm,pts,len)
128
+                            sj = sj + 50
129
+                            if sj == 1000:
130
+                                sk = sk + 1
131
+                                sj = 0
132
+                            zh = 'K' + str(sk) + '+' + str(str(sj).zfill(3))
133
+                            try:
134
+                                pl = jsdp(pt1,minp,bj)
135
+                                listp1 = []
136
+                                listp1.append(ptg1)
137
+                                listp1.append(zh)
138
+                                cursorA.insertRow(listp1)
139
+                                listl1 = []
140
+                                listl1.append(pl)
141
+                                listl1.append(zh)
142
+                                cursorB.insertRow(listl1)
143
+                            except:
144
+                                pass
145
+                            len = len - 50
146
+                            print('C2')
147
+
148
+                        mk = int(curC[2]) // 1000
149
+                        mj = int(curC[2]) % 1000
150
+                        zh1 = 'K' + str(mk) + '+' + str(str(mj).zfill(3))
151
+                        if zh1 == zh:
152
+                            pass
153
+                        else:
154
+                            qd = dm.firstPoint
155
+                            lens = len + 50
156
+                            sj = sj + int(lens)
157
+                            zh = 'K' + str(sk) + '+' + str(str(sj).zfill(3))
158
+                            try:
159
+                                plZ = jsdp(qd, pts[1], bj)
160
+                                listp1 = []
161
+                                listp1.append(arcpy.PointGeometry(qd))
162
+                                listp1.append(zh)
163
+                                cursorA.insertRow(listp1)
164
+                                listl1 = []
165
+                                listl1.append(plZ)
166
+                                listl1.append(zh)
167
+                                cursorB.insertRow(listl1)
168
+                            except:
169
+                                pass
170
+                        print('C')
171
+
172
+def findminp(dm,pts,len):
173
+    mm = 1
174
+    disM = 9999
175
+    minp = pts[0]
176
+    while mm < (pts.count - 1):
177
+        dis2 = dm.measureOnLine(pts[mm])
178
+        dis = abs(dis2 - len)
179
+        if dis == 0:
180
+            minp = pts[mm - 1]
181
+            break
182
+        if dis < disM:
183
+            disM = dis
184
+            minp = pts[mm]
185
+        mm = mm + 1   
186
+    return minp
187
+
188
+def jsdp(pt1,pt2,bj):
189
+    qdx = pt1.X
190
+    qdy = pt1.Y
191
+    qdx1 = pt2.X
192
+    qdy1 = pt2.Y
193
+    qdk = (qdx1 - qdx) / (qdy1-qdy) * (-1) 
194
+    num0 = qdk * qdx
195
+    qdb = qdy - num0
196
+    numA = (qdk * qdk) + 1
197
+    num1 = qdb - qdy
198
+    num2 = 2 * qdk * num1
199
+    num3 = 2 * qdx
200
+    numB = num2 - num3
201
+    num4 = num1 * num1
202
+    num5 = qdx * qdx
203
+    num51 = bj * bj
204
+    numC = num4 + num5 - num51
205
+    num6 = numB * numB
206
+    num7 = 4 * numA * numC
207
+    num8 =  math.sqrt(num6 - num7)
208
+    num9 = (-1) * numB
209
+    num101 = num9 + num8
210
+    num102 = num9 - num8
211
+    num11 = 2 * numA
212
+    numX1 = num101 / num11
213
+    numX2 = num102 / num11
214
+    numY1 = qdk * numX1 + qdb
215
+    numY2 = qdk * numX2 + qdb
216
+    pt1 = arcpy.Point(numX1, numY1)
217
+    pt2 = arcpy.Point(numX2, numY2)
218
+    arr1 = arcpy.Array()
219
+    arr1.append(pt1)
220
+    arr1.append(pt2)
221
+    pl1 = arcpy.Polyline(arr1)
222
+    return pl1
223
+    
224
+                    
225
+
226
+
227
+if __name__ == '__main__':
228
+    try:
229
+        drawDM(r"D:\4work_now\20241017dm\1024gq\MYQ\1\myqzxx.shp",r'D:\4work_now\20241017dm\1024gq\MYQ\1',50,30)
230
+    except arcpy.ExecuteError:
231
+        arcpy.AddMessage (arcpy.GetMessages())

+ 144
- 0
代码/20241017都江堰断面/DMzl20241023.py 查看文件

@@ -0,0 +1,144 @@
1
+import arcpy
2
+import math
3
+
4
+def pp():
5
+    dmxpath = r'D:\4work_now\20241017dm\20241129\hltdm3\dmx.shp'
6
+    dmdpath = r'D:\4work_now\20241017dm\20241129\hltdm3\dmd.shp'
7
+    # zdpath = r'D:\4work_now\20241017dm\1024gq\RMQ7\rmq200zdmd.shp'
8
+    dwgpath = r'D:\4work_now\20241017dm\20241129\hltdm3\dm.dwg'
9
+    gqpath = r'D:\4work_now\20241017dm\20241129\hltdm3\zxx.shp'
10
+    roadpath = r'D:\4work_now\20241017dm\20241129\hltdm3\road.shp'
11
+    arcpy.MakeFeatureLayer_management(dmxpath, 'DMshp')
12
+    arcpy.MakeFeatureLayer_management(dmdpath, 'DMDshp')
13
+    # arcpy.MakeFeatureLayer_management(zdpath, 'ZDshp')
14
+    arcpy.MakeFeatureLayer_management(gqpath, 'GQshp')
15
+    arcpy.MakeFeatureLayer_management(roadpath, 'roadshp')
16
+    annopath = dwgpath + '\\Annotation'
17
+    arcpy.MakeFeatureLayer_management(annopath, 'ANNO')
18
+    arcpy.AddField_management('DMshp','KZ','LONG')
19
+    arcpy.AddField_management('DMshp','JZ','LONG')
20
+    arcpy.AddField_management('DMshp','ZH','TEXT')
21
+    # arcpy.AddField_management('DMshp', 'ZH_1', 'TEXT')
22
+    arcpy.AddField_management('DMDshp','ZH','TEXT')
23
+    arcpy.AddField_management('DMDshp','LJ','FLOAT')
24
+    arcpy.AddField_management('DMDshp','SFR','LONG')
25
+    arcpy.AddField_management('DMDshp', 'SFL', 'LONG')
26
+    nonehz = -1
27
+    with arcpy.da.SearchCursor('GQshp',['SHAPE@']) as cursorZ:
28
+        for curZ in cursorZ:
29
+            GQline = curZ[0]
30
+
31
+    # with arcpy.da.UpdateCursor('DMshp',['SHAPE@','KZ','JZ','ZH']) as cursorA:
32
+    #     for curA in cursorA:
33
+    #         zh = ''
34
+    #         line1 = curA[0]
35
+    #         buf1 = line1.buffer(10)
36
+    #         arcpy.SelectLayerByLocation_management('ANNO','WITHIN',buf1)
37
+    #         pc = int(arcpy.GetCount_management('ANNO')[0])
38
+    #         if pc == 0:
39
+    #             curA[1] = nonehz
40
+    #             curA[2] = nonehz
41
+    #             curA[3] = 'None' + str(nonehz)
42
+    #             cursorA.updateRow(curA)
43
+    #         elif pc == 1:
44
+    #             with arcpy.da.SearchCursor('ANNO',['SHAPE@','Text']) as cursorAA:
45
+    #                 for curAA in cursorAA:
46
+    #                     zh = curAA[1]
47
+    #                     try:
48
+    #                         kstr = zh.split('+',-1)[0]
49
+    #                         kz = kstr.replace('K','')
50
+    #                         jstr = zh.split('+',-1)[1]
51
+    #                         try:
52
+    #                             jz = jstr.split(' ',-1)[0]
53
+    #                         except:
54
+    #                             jz = jstr
55
+    #                         curA[1] = int(kz)
56
+    #                         curA[2] = int(float(jz))
57
+    #                         zh = 'K' + str(int(kz)) + '+' +str(str(int(float(jz))).zfill(3))
58
+    #                         curA[3] = zh
59
+    #                         cursorA.updateRow(curA)
60
+    #                     except:
61
+    #                         print(zh)
62
+    #         else:
63
+    #             dis1 = 99999
64
+    #             zh = ''
65
+    #             with arcpy.da.SearchCursor('ANNO',['SHAPE@','Text']) as cursorAA:
66
+    #                 for curAA in cursorAA:
67
+    #                     if 'K' in curAA[1]:
68
+    #                         annopt = curAA[0]
69
+    #                         dis2 = line1.distanceTo (annopt)
70
+    #                         if dis2 < dis1:
71
+    #                             dis1 = dis2
72
+    #                             zh = curAA[1]
73
+    #                     else:
74
+    #                         pass
75
+    #             try:
76
+    #                 kstr = zh.split('+',-1)[0]
77
+    #                 kz = kstr.replace('K','')
78
+    #                 jstr = zh.split('+', -1)[1]
79
+    #                 try:
80
+    #                     jz = jstr.split(' ', -1)[0]
81
+    #                 except:
82
+    #                     jz = jstr
83
+    #                 curA[1] = int(kz)
84
+    #                 curA[2] = int(float(jz))
85
+    #                 zh1 = 'K' + str(int(kz)) + '+' + str(str(int(float(jz))).zfill(3))
86
+    #                 curA[3] = zh1
87
+    #                 cursorA.updateRow(curA)
88
+    #             except:
89
+    #                 pass
90
+    #         print('A')
91
+    with arcpy.da.SearchCursor('DMshp', ['SHAPE@', 'KZ', 'JZ', 'ZH']) as cursorA:
92
+        for curA in cursorA:
93
+            line1 = curA[0]
94
+            # len = line1.length / 2
95
+            # cpt = line1.positionAlongLine (len)
96
+            buf1 = line1.buffer(1)
97
+            zh = curA[3]
98
+            arcpy.SelectLayerByLocation_management('DMDshp','WITHIN',buf1)
99
+            pc2 = int(arcpy.GetCount_management('DMDshp')[0])
100
+            if pc2 > 0:
101
+                min = 999
102
+                with arcpy.da.SearchCursor('DMDshp',['SHAPE@']) as cursorZ:
103
+                    for curZ in cursorZ:
104
+                        pt = curZ[0].firstPoint
105
+                        lj = round(GQline.distanceTo(pt), 4)
106
+                        if lj < min:
107
+                            min = lj
108
+                            cpt = curZ[0]
109
+                with arcpy.da.UpdateCursor('DMDshp',['SHAPE@','ZH','LJ','SFR','SFL']) as cursorB:
110
+                    for curB in cursorB:
111
+                        tuple1 = GQline.queryPointAndDistance(curB[0])
112
+                        lj = round(cpt.distanceTo(curB[0]),4)
113
+                        if tuple1[3] == False:
114
+                            curB[3] = -1
115
+                        else:
116
+                            curB[3] = 1
117
+                        pt = curB[0]
118
+                        buf2 = pt.buffer(1)
119
+                        arcpy.SelectLayerByLocation_management('roadshp', 'INTERSECT', buf2)
120
+                        pc3 = int(arcpy.GetCount_management('roadshp')[0])
121
+                        # arcpy.SelectLayerByLocation_management('roadshp', 'CONTAINS', buf2)
122
+                        # pc4 = int(arcpy.GetCount_management('roadshp')[0])
123
+                        if pc3 > 0 :
124
+                            curB[4] = 1
125
+                        curB[1] = zh
126
+                        curB[2] = lj
127
+                        cursorB.updateRow(curB)
128
+                        print('1')
129
+
130
+
131
+    
132
+
133
+
134
+
135
+
136
+
137
+if __name__ == '__main__':
138
+    try:
139
+        # arcpy.AddMessage ('start at {0}\n'.format(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())))
140
+        pp()
141
+        # Lake(arcpy.GetParameterAsText(0),arcpy.GetParameterAsText(1),arcpy.GetParameterAsText(2),arcpy.GetParameterAsText(3),arcpy.GetParameterAsText(4))
142
+        # arcpy.AddMessage ('end at {0}\n'.format(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())))
143
+    except arcpy.ExecuteError:
144
+        arcpy.AddMessage (arcpy.GetMessages())

+ 59
- 0
代码/20241017都江堰断面/ZDMDexcel.py 查看文件

@@ -0,0 +1,59 @@
1
+from shapefile import Reader
2
+from openpyxl import Workbook
3
+
4
+def start():
5
+    dmxpath = r'D:\4work_now\20241017dm\20241129\hltdm\dmxZ.shp'
6
+    outpath = r'D:\4work_now\20241017dm\20241129\hltdm\hlt_zdm.xlsx'
7
+    list1 = []
8
+    max1 = 0
9
+    with Reader(dmxpath) as dmx:
10
+        dmxrec = dmx.records()
11
+        for dmxr in dmxrec:
12
+            knum = dmxr.KZ
13
+            jnum = dmxr.JZ
14
+            zh = dmxr.ZH_1
15
+            if zh == '':
16
+                gc = -1
17
+            else:
18
+                try:
19
+                    gc = zh.split(' ',-1)[1]
20
+                except:
21
+                    gc = -1
22
+            lista = []
23
+            lista.append(knum)
24
+            lista.append(jnum)
25
+            lista.append(gc)
26
+            list1.append(lista)
27
+            if max1 < knum:
28
+                max1 = knum
29
+    wb = Workbook() # 新建工作簿
30
+    ws = wb.active
31
+    mm = 0
32
+    nn = 0
33
+    ii = 1
34
+    while mm <= max1:
35
+        while nn < 1000:
36
+            lj = mm * 1000 + nn
37
+            for re in list1:
38
+                if re[0] == mm and re[1] == nn:
39
+                    ws.cell(row=ii, column=1, value=ii)
40
+                    ws.cell(row=ii, column=3, value=1000000)
41
+                    ws.cell(row=ii, column=4, value=lj)
42
+                    if ii == 1:
43
+                        ws.cell(row=ii, column=2, value=1)
44
+                    else:
45
+                        ws.cell(row=ii, column=2, value='+')
46
+                    if re[2] == -1:
47
+                        pass
48
+                    else:
49
+                        ws.cell(row=ii, column=5, value=re[2])
50
+                    print(str(lj))
51
+                    ii = ii + 1
52
+            nn = nn + 10   
53
+        mm = mm + 1
54
+        nn = 0
55
+    wb.save(outpath)       
56
+    
57
+
58
+if __name__ == '__main__':
59
+    start()

+ 70
- 0
代码/20241017都江堰断面/ZDMDexcel_1108.py 查看文件

@@ -0,0 +1,70 @@
1
+from shapefile import Reader
2
+from openpyxl import Workbook
3
+
4
+def start():
5
+    dmxpath = r'D:\4work_now\20241017dm\20241129\dzgq\dmx.shp'
6
+    outpath = r'D:\4work_now\20241017dm\20241129\dzgq\DZGQzdm.xlsx'
7
+    list1 = []
8
+    max1 = 0
9
+    with Reader(dmxpath) as dmx:
10
+        dmxrec = dmx.records()
11
+        for dmxr in dmxrec:
12
+            knum = dmxr.KZ
13
+            jnum = dmxr.JZ
14
+            zh = dmxr.ZH_1
15
+            if zh == '':
16
+                gc = -1
17
+            else:
18
+                try:
19
+                    gc = zh.split(' ',-1)[1]
20
+                except:
21
+                    gc = -1
22
+            lista = []
23
+            lista.append(knum)
24
+            lista.append(jnum)
25
+            lista.append(gc)
26
+            list1.append(lista)
27
+            if max1 < knum:
28
+                max1 = knum
29
+    wb = Workbook() # 新建工作簿
30
+    ws = wb.active
31
+    mm = 0
32
+    nn = 0
33
+    ii = 1
34
+    while mm <= max1:
35
+        while nn < 1000:
36
+            lj = mm * 1000 + nn
37
+            fn = -1
38
+            for re in list1:
39
+                if re[0] == mm and re[1] == nn:
40
+                    ws.cell(row=ii, column=1, value=ii)
41
+                    ws.cell(row=ii, column=3, value=1000000)
42
+                    ws.cell(row=ii, column=4, value=lj)
43
+                    if ii == 1:
44
+                        ws.cell(row=ii, column=2, value=1)
45
+                    else:
46
+                        ws.cell(row=ii, column=2, value='+')
47
+                    if re[2] == -1:
48
+                        pass
49
+                    else:
50
+                        ws.cell(row=ii, column=5, value=re[2])
51
+                    print(str(lj))
52
+                    ii = ii + 1
53
+                    fn = 1
54
+            if fn == -1:
55
+                ws.cell(row=ii, column=1, value=ii)
56
+                ws.cell(row=ii, column=3, value=1000000)
57
+                ws.cell(row=ii, column=4, value=lj)
58
+                if ii == 1:
59
+                    ws.cell(row=ii, column=2, value=1)
60
+                else:
61
+                    ws.cell(row=ii, column=2, value='+')
62
+                ii = ii + 1
63
+            nn = nn + 50   
64
+        mm = mm + 1
65
+        nn = 0
66
+    wb.save(outpath)       
67
+    
68
+
69
+if __name__ == '__main__':
70
+    start()

+ 55
- 0
代码/20241017都江堰断面/dmname.py 查看文件

@@ -0,0 +1,55 @@
1
+import arcpy
2
+import math
3
+
4
+def zhname(gc,zh):
5
+    try:
6
+        zh1 = zh.replace('.000','')
7
+    except:
8
+        zh1 = zh
9
+    str1 = zh1 + ' ' + str(gc)
10
+    return str1
11
+
12
+def dmname():
13
+    dmxpath = r'D:\4work_now\20241017dm\20241129\hltdm2\dmx.shp'
14
+    dmdpath = r'D:\4work_now\20241017dm\20241129\hltdm2\dmd.shp'
15
+    arcpy.MakeFeatureLayer_management(dmxpath, 'DMshp')
16
+    arcpy.MakeFeatureLayer_management(dmdpath, 'DMDshp')
17
+
18
+    arcpy.AddField_management('DMshp', 'ZH_1', 'TEXT')
19
+    with arcpy.da.UpdateCursor('DMshp',['SHAPE@','ZH','ZH_1']) as cursorA:
20
+        for curA in cursorA:
21
+            zh = curA[1]
22
+            if ' ' in zh:
23
+                str2 = zh
24
+            else:
25
+                line1 = curA[0]
26
+                buf1 = line1.buffer(0.5)
27
+                arcpy.SelectLayerByLocation_management('DMDshp','WITHIN',buf1)
28
+                pc = int(arcpy.GetCount_management('DMDshp')[0])
29
+                if pc == 0:
30
+                    curA[2] = zh
31
+                    cursorA.updateRow(curA)
32
+                    print('2')
33
+                else:
34
+                    list1 = []
35
+                    minnum = 9999
36
+                    gc = 0
37
+                    with arcpy.da.SearchCursor('DMDshp',['SHAPE@','LJ','height']) as cursorAA:
38
+                        for curAA in cursorAA:
39
+                            lj = curAA[1]
40
+                            if lj < minnum:
41
+                                minnum = lj
42
+                                gc = curAA[2]
43
+
44
+                    str2 = zhname(gc,zh)
45
+                    curA[2] = str2
46
+                    cursorA.updateRow(curA)
47
+                    print('1')
48
+
49
+
50
+
51
+if __name__ == '__main__':
52
+    try:
53
+        dmname()
54
+    except arcpy.ExecuteError:
55
+        arcpy.AddMessage (arcpy.GetMessages())

+ 139
- 0
代码/20241017都江堰断面/dmname_onZH.py 查看文件

@@ -0,0 +1,139 @@
1
+import arcpy
2
+import math
3
+
4
+def fillzh(str1):
5
+    if len(str1) == 1:
6
+        str2 = '00' + str1
7
+    elif len(str1) == 2:
8
+        str2 = '0' + str1
9
+    elif len(str1) == 4:
10
+        str2 = '000'
11
+    else:
12
+        str2 = str1
13
+    return  str2
14
+
15
+def dmname():
16
+    dmxpath = r'D:\4work_now\20241017dm\20241129\dzgq1\dmx.shp'
17
+    dmdpath = r'D:\4work_now\20241017dm\20241129\dzgq1\dmd.shp'
18
+    gqpath = r'D:\4work_now\20241017dm\20241129\dzgq1\zxx.shp'
19
+    arcpy.MakeFeatureLayer_management(dmxpath, 'DMshp')
20
+    arcpy.MakeFeatureLayer_management(dmdpath, 'DMDshp')
21
+    arcpy.MakeFeatureLayer_management(gqpath, 'GQshp')
22
+    arcpy.AddField_management('DMshp', 'ZH', 'TEXT')
23
+    arcpy.AddField_management('DMshp','KZ','LONG')
24
+    arcpy.AddField_management('DMshp','JZ','LONG')
25
+    with arcpy.da.SearchCursor('GQshp',['SHAPE@']) as cursorZ:
26
+        for curZ in cursorZ:
27
+            GQline = curZ[0]
28
+            length = GQline.length
29
+    # mm = 0
30
+    # nn = 0
31
+    with arcpy.da.UpdateCursor('DMshp',['SHAPE@','ZH','KZ','JZ']) as cursorA:
32
+        for curA in cursorA:
33
+            line1 = curA[0]
34
+            buf1 = line1.buffer(1)
35
+            arcpy.SelectLayerByLocation_management('DMDshp', 'WITHIN', buf1)
36
+            pc = int(arcpy.GetCount_management('DMDshp')[0])
37
+            if pc == 0:
38
+                pass
39
+            else:
40
+                minnum = 9999
41
+                with arcpy.da.SearchCursor('DMDshp', ['SHAPE@']) as cursorAA:
42
+                    for curAA in cursorAA:
43
+                        tuple1 = GQline.queryPointAndDistance(curAA[0])
44
+                        lj = tuple1[2]
45
+                        if lj < minnum:
46
+                            minnum = lj
47
+                            pt = curAA[0]
48
+                len1 =GQline.measureOnLine(pt)
49
+                kz = int(len1 // 1000)
50
+                jz = int(len1 % 1000)
51
+                if jz % 10 <5:
52
+                    num1 = jz % 10
53
+                    jz = jz - num1
54
+                else:
55
+                    num1 = jz % 10
56
+                    num2 = 10 - num1
57
+                    jz = jz + num2
58
+                str2 = fillzh(str(jz))
59
+                if jz == 1000:
60
+                    kz = kz+1
61
+                    str1 = 'K' + str(kz) + '+' + str2 + ' '
62
+                    jz = 0
63
+                else:
64
+                    str1 = 'K' + str(kz) + '+' + str2 + ' '
65
+                curA[1] = str1
66
+                curA[2] = kz
67
+                curA[3] = jz
68
+                cursorA.updateRow(curA)
69
+                print(str1)
70
+    #         if curA[1] == '':
71
+    #             line1 = curA[0]
72
+    #             if nn < 1000:
73
+    #                 str1 = fillzh(str(nn))
74
+    #                 zh1 = 'K' + str(mm) + '+' + str1
75
+    #                 curA[2] = mm
76
+    #                 curA[3] = nn
77
+    #                 curA[1] = zh1
78
+    #                 cursorA.updateRow(curA)
79
+    #                 nn = nn + 50
80
+    #             else:
81
+    #                 nn = 0
82
+    #                 mm = mm + 1
83
+    #                 str1 = fillzh(str(nn))
84
+    #                 zh1 = 'K' + str(mm) + '+' + str1
85
+    #                 curA[2] = mm
86
+    #                 curA[3] = nn
87
+    #                 curA[1] = zh1
88
+    #                 cursorA.updateRow(curA)
89
+    #                 nn = nn + 50
90
+
91
+            # arcpy.SelectLayerByLocation_management('DMDshp','WITHIN',buf1)
92
+            # pc = int(arcpy.GetCount_management('DMDshp')[0])
93
+            # if pc == 0:
94
+            #     pass
95
+            # else:
96
+            #     with arcpy.da.SearchCursor('DMDshp',['SHAPE@','height']) as cursorAA:
97
+            #         for curAA in cursorAA:
98
+            #             len1 = GQline.measureOnLine(curAA[0])
99
+            #             len2 = round(length - len1)
100
+            #             kz = int(len2 // 1000)
101
+            #             jz = int(len2 % 1000)
102
+            #             if jz % 10 != 0:
103
+            #                 jz = jz + 1
104
+            #             gc = round(curAA[1],1)
105
+            #             str2 = fillzh(str(jz))
106
+            #             str1 = 'K' + str(kz) + '+' + str2 + ' '
107
+            #             curA[1] = str1
108
+            #             cursorA.updateRow(curA)
109
+            #     print('1')
110
+            # arcpy.SelectLayerByLocation_management('DMDshp', 'WITHIN', buf1)
111
+            # pc2 = int(arcpy.GetCount_management('DMDshp')[0])
112
+            # if pc2 > 0:
113
+            #     with arcpy.da.UpdateCursor('DMDshp', ['SHAPE@', 'ZH', 'LJ', 'SFR', 'SFL']) as cursorB:
114
+            #         for curB in cursorB:
115
+            #             tuple1 = GQline.queryPointAndDistance(curB[0])
116
+            #             lj = round(tuple1[2], 4)
117
+            #             if tuple1[3] == False:
118
+            #                 curB[3] = -1
119
+            #             else:
120
+            #                 curB[3] = 1
121
+            #             pt = curB[0]
122
+            #             buf2 = pt.buffer(1)
123
+            #             arcpy.SelectLayerByLocation_management('roadshp', 'INTERSECT', buf2)
124
+            #             pc3 = int(arcpy.GetCount_management('roadshp')[0])
125
+            #             # arcpy.SelectLayerByLocation_management('roadshp', 'CONTAINS', buf2)
126
+            #             # pc4 = int(arcpy.GetCount_management('roadshp')[0])
127
+            #             if pc3 > 0:
128
+            #                 curB[4] = 1
129
+            #             curB[1] = zh
130
+            #             curB[2] = lj
131
+            #             cursorB.updateRow(curB)
132
+
133
+
134
+
135
+if __name__ == '__main__':
136
+    try:
137
+        dmname()
138
+    except arcpy.ExecuteError:
139
+        arcpy.AddMessage (arcpy.GetMessages())

+ 108
- 0
代码/20241017都江堰断面/dmname_onZH_rename.py 查看文件

@@ -0,0 +1,108 @@
1
+import arcpy
2
+import math
3
+
4
+def fillzh(str1):
5
+    if len(str1) == 1:
6
+        str2 = '00' + str1
7
+    elif len(str1) == 2:
8
+        str2 = '0' + str1
9
+    else:
10
+        str2 = str1
11
+    return  str2
12
+
13
+def dmname():
14
+    dmxpath = r'D:\4work_now\20241017dm\1028gq\RMQ7\rmqdmx.shp'
15
+    # dmdpath = r'D:\4work_now\20241017dm\1028gq\PYH\PYH2\pyhzdmd.shp'
16
+    gqpath = r'D:\4work_now\20241017dm\1028gq\RMQ7\rmqzxx.shp'
17
+    arcpy.MakeFeatureLayer_management(dmxpath, 'DMshp')
18
+    # arcpy.MakeFeatureLayer_management(dmdpath, 'DMDshp')
19
+    arcpy.MakeFeatureLayer_management(gqpath, 'GQshp')
20
+    arcpy.AddField_management('DMshp', 'ZH', 'TEXT')
21
+    mm = 0
22
+    nn = 0
23
+    ii = 0
24
+    with arcpy.da.SearchCursor('GQshp',['SHAPE@']) as cursorZ:
25
+        for curZ in cursorZ:
26
+            GQline = curZ[0]
27
+            length = GQline.length
28
+    with arcpy.da.SearchCursor('DMshp', ['SHAPE@', 'KZ', 'JZ', 'ZH']) as cursorA:
29
+        for curA in cursorA:
30
+            line1 = curA[0]
31
+            # while ii <= GQline.length:
32
+            #     pt1 = GQline.positionAlongLine (ii)
33
+            #     buf1 = pt1.buffer(1)
34
+            #     arcpy.SelectLayerByLocation_management('DMshp', 'INTERSECT', buf1)
35
+            #     pc = int(arcpy.GetCount_management('DMshp')[0])
36
+            #     if pc != 0:
37
+            #         with arcpy.da.UpdateCursor('DMshp',['SHAPE@','ZH','KZ','JZ']) as cursorA:
38
+            #             for curA in cursorA:
39
+            #                 # if curA[1] == '':
40
+            #                     line1 = curA[0]
41
+            #                     if nn < 1000:
42
+            #                         str1 = fillzh(str(nn))
43
+            #                         zh1 = 'K' + str(mm) + '+' + str1
44
+            #                         curA[2] = mm
45
+            #                         curA[3] = nn
46
+            #                         curA[1] = zh1
47
+            #                         cursorA.updateRow(curA)
48
+            #                         nn = nn + 50
49
+            #                     else:
50
+            #                         nn = 0
51
+            #                         mm = mm + 1
52
+            #                         str1 = fillzh(str(nn))
53
+            #                         zh1 = 'K' + str(mm) + '+' + str1
54
+            #                         curA[2] = mm
55
+            #                         curA[3] = nn
56
+            #                         curA[1] = zh1
57
+            #                         cursorA.updateRow(curA)
58
+            #                         nn = nn + 50
59
+            #     ii = ii + 50
60
+            #     print('1')
61
+
62
+            arcpy.SelectLayerByLocation_management('DMDshp','WITHIN',buf1)
63
+            pc = int(arcpy.GetCount_management('DMDshp')[0])
64
+            if pc == 0:
65
+                pass
66
+            else:
67
+                with arcpy.da.SearchCursor('DMDshp',['SHAPE@','height']) as cursorAA:
68
+                    for curAA in cursorAA:
69
+                        len1 = GQline.measureOnLine(curAA[0])
70
+                        len2 = round(length - len1)
71
+                        kz = int(len2 // 1000)
72
+                        jz = int(len2 % 1000)
73
+                        gc = round(curAA[1],1)
74
+                        str2 = fillzh(str(jz))
75
+                        str1 = 'K' + str(kz) + '+' + str2 + ' '
76
+                        curA[1] = str1
77
+                        cursorA.updateRow(curA)
78
+                print('1')
79
+            # arcpy.SelectLayerByLocation_management('DMDshp', 'WITHIN', buf1)
80
+            # pc2 = int(arcpy.GetCount_management('DMDshp')[0])
81
+            # if pc2 > 0:
82
+            #     with arcpy.da.UpdateCursor('DMDshp', ['SHAPE@', 'ZH', 'LJ', 'SFR', 'SFL']) as cursorB:
83
+            #         for curB in cursorB:
84
+            #             tuple1 = GQline.queryPointAndDistance(curB[0])
85
+            #             lj = round(tuple1[2], 4)
86
+            #             if tuple1[3] == False:
87
+            #                 curB[3] = -1
88
+            #             else:
89
+            #                 curB[3] = 1
90
+            #             pt = curB[0]
91
+            #             buf2 = pt.buffer(1)
92
+            #             arcpy.SelectLayerByLocation_management('roadshp', 'INTERSECT', buf2)
93
+            #             pc3 = int(arcpy.GetCount_management('roadshp')[0])
94
+            #             # arcpy.SelectLayerByLocation_management('roadshp', 'CONTAINS', buf2)
95
+            #             # pc4 = int(arcpy.GetCount_management('roadshp')[0])
96
+            #             if pc3 > 0:
97
+            #                 curB[4] = 1
98
+            #             curB[1] = zh
99
+            #             curB[2] = lj
100
+            #             cursorB.updateRow(curB)
101
+
102
+
103
+
104
+if __name__ == '__main__':
105
+    try:
106
+        dmname()
107
+    except arcpy.ExecuteError:
108
+        arcpy.AddMessage (arcpy.GetMessages())

+ 614
- 0
代码/20241017都江堰断面/drawDMtable_20241202_QT.py 查看文件

@@ -0,0 +1,614 @@
1
+from pyautocad import Autocad, APoint, aDouble
2
+import shapefile
3
+from shapefile import Reader
4
+
5
+def takeSec(elem):
6
+    return elem[1]
7
+
8
+def fill3(str1):
9
+    if len(str1) == 5:
10
+        str2 = str1
11
+    elif len(str1) == 4:
12
+        str2 = '0' + str1
13
+    elif len(str1) == 3:
14
+        str2 = '00' + str1
15
+    else:
16
+        str2 = '000' + str1
17
+    return str2
18
+
19
+def start():
20
+    dmdpath = r'D:\4work_now\20241017dm\20241129\hltdm3\dmd.shp'
21
+    dmxpath = r'D:\4work_now\20241017dm\20241129\hltdm3\dmx.shp'
22
+    mbpath = r'D:\4work_now\20241017dm\20241129\hltdm3\mb.dwg'
23
+    #要手动建
24
+    outpath = r'D:\4work_now\20241017dm\20241129\hltdm3\HLT.dwg'
25
+    txtpath = r'D:\4work_now\20241017dm\20241129\hltdm3\log.txt'
26
+
27
+    #读取shapefile
28
+    #线用来索引
29
+    max1 = 0
30
+    dmxdict = dict()
31
+    with Reader(dmdpath) as dmd:
32
+        dmdrec = dmd.records()
33
+    with Reader(dmxpath) as dmx:
34
+        dmxrec = dmx.records()
35
+        for dmxr in dmxrec:
36
+            knum = dmxr.KZ
37
+            kzh = dmxr.ZH
38
+            try:
39
+                zzh = kzh.split('.',-1)[0]
40
+            except:
41
+                zzh = kzh
42
+            if knum > max1:
43
+                max1 = knum
44
+            list1 = []
45
+            #记录要删除的index,统一删
46
+            index1 = []
47
+            id = 0
48
+            for dmdr in dmdrec:
49
+                dzh = dmdr.ZH
50
+                if dzh == kzh:
51
+                    lista = []
52
+                    #这里就计算累距
53
+                    lj1 = dmdr.LJ * dmdr.SFR
54
+                    lista.append(dmdr.height)
55
+                    lista.append(lj1)
56
+                    lista.append(dmdr.SFL)
57
+                    list1.append(lista)
58
+                    index1.append(id)
59
+                id = id + 1
60
+            # #因为会有区别,所以要用个值
61
+            # zz = 0
62
+            # for ind in index1:
63
+            #     num0 = ind - zz
64
+            #     dmdrec.pop(num0)
65
+            #     zz = zz + 1 
66
+            dmxdict[zzh] = list1
67
+    kk = max1
68
+    #链接cad
69
+    acad = Autocad(create_if_not_exists=True)
70
+    acad.Application.Documents.Open(outpath)
71
+    target_doc = acad.ActiveDocument
72
+    if kk > 20:
73
+        #要那个大框的
74
+        num1 = kk // 20
75
+        nn = 0
76
+        while nn <= num1:
77
+            yy = 0
78
+            if nn == num1:
79
+                max2 = kk
80
+                num2 = kk % 20
81
+                min2 = max2 - num2
82
+                numa1 = (nn*4200) + 10
83
+                numa2 = ((nn+1) * 4200) + 120
84
+                numa3 = (num2 * 200) + 270
85
+                jx1 = [numa1,-10,0]
86
+                jx2 = [numa2,-10,0]
87
+                jx3 = [numa2,numa3,0]
88
+                jx4 = [numa1,numa3,0]
89
+                line1 = jx1 + jx2 + jx3 + jx4 + jx1
90
+                pnts1 = aDouble(line1)
91
+                plineObj1 = acad.model.AddPolyLine(pnts1)
92
+                #文字
93
+                stra1 = 'K' + str(min2) +'+000 - K' + str(max2) + '+950'
94
+                numa5 = (numa1 + numa2) / 2
95
+                numa6 = (num2 * 200) + 210
96
+                p1 = APoint(numa5,numa6)
97
+                text1 = acad.model.AddText(stra1,p1,30)
98
+                text1.Color = 1
99
+            else:
100
+                max2 = 19 + (nn * 20)
101
+                min2 = nn * 20
102
+                numa1 = (nn*4200) + 10
103
+                numa2 = ((nn+1) * 4200) +120
104
+                numa3 = 4070
105
+                jx1 = [numa1,-10,0]
106
+                jx2 = [numa2,-10,0]
107
+                jx3 = [numa2,numa3,0]
108
+                jx4 = [numa1,numa3,0]
109
+                line1 = jx1 + jx2 + jx3 + jx4 + jx1
110
+                pnts1 = aDouble(line1)
111
+                plineObj1 = acad.model.AddPolyLine(pnts1)
112
+                #文字
113
+                stra1 = 'K' + str(min2) +'+000 - K' + str(max2) + '+950'
114
+                numa5 = (numa1 + numa2) / 2
115
+                numa6 = 4010
116
+                p1 = APoint(numa5,numa6)
117
+                text1 = acad.model.AddText(stra1,p1,30)
118
+                text1.Color = 1
119
+            mm = max2
120
+            x0 = (nn * 4220) + 300
121
+            while mm >= min2:
122
+                xx = x0
123
+                jj = 0
124
+                jj1 = 0
125
+                while jj < 1000:
126
+                    zhA = 'K' + str(mm) + '+' + str(str(jj).zfill(3))
127
+                    key1 = dmxdict.get(zhA, 'none')
128
+                    if key1 == 'none':
129
+                        # pass
130
+                        xx = xx + 210
131
+                    else:
132
+                        if len(key1) == 0:
133
+                            dmxdict.pop(zhA,'nonevalue')
134
+                            xx = xx + 210
135
+                        else:
136
+                            list2 = key1
137
+                            list2.sort(key=takeSec)
138
+                            slj = 0
139
+                            list3 = []
140
+                            for li4 in list2:
141
+                                if li4[1] == list2[0][1]:
142
+                                    slj = li4[1]
143
+                                    xs = 1
144
+                                    listb1 = []
145
+                                    listb1.append(li4[0])
146
+                                    listb1.append(li4[1])
147
+                                    listb1.append(xs)
148
+                                    listb1.append(li4[2])
149
+                                    list3.append(listb1)
150
+                                else:
151
+                                    listb1 = []
152
+                                    #区分下正负交替的部分
153
+                                    if slj < 0 and li4[1] >=0:
154
+                                        dis = 5
155
+                                        slj = li4[1]
156
+                                    else:
157
+                                        dis = abs(abs(slj) - abs(li4[1]))
158
+                                    if dis >= 3:
159
+                                        xs = 1
160
+                                        slj = li4[1]
161
+                                    else:
162
+                                        xs = -1 
163
+                                    listb1.append(li4[0])
164
+                                    listb1.append(li4[1])
165
+                                    listb1.append(xs)
166
+                                    listb1.append(li4[2])
167
+                                    list3.append(listb1)
168
+                            #只对模板进行开关
169
+                            acad.Application.Documents.Open(mbpath)
170
+                            doc = acad.ActiveDocument
171
+                            #先写,再移动
172
+                            text1 = list(acad.iter_objects("Text"))
173
+                            #防止重复
174
+                            k1 = 1
175
+                            k2 = 1
176
+                            minnum = 0
177
+                            pd1 = -1
178
+                            if abs(list3[0][1])>=28.7 or abs(list3[len(list3)-1][1])>=28.7:
179
+                                pd1 = 1
180
+                            for t2 in text1:
181
+                                if 'K' in t2.TextString:
182
+                                    #最下面那个桩号
183
+                                    t2.TextString = zhA
184
+                                if '+' in t2.TextString and 'K' not in t2.TextString:
185
+                                    if k1 == -1:
186
+                                        pass
187
+                                    else:
188
+                                        for li1 in list3:
189
+                                            if li1[2] == -1:
190
+                                                pass
191
+                                            else: 
192
+                                                #找到相对位置进行位移并赋值
193
+                                                if li1[1] == list3[0][1]:
194
+                                                    if pd1 ==1:
195
+                                                        #就以那个为起点
196
+                                                        num4 = str(format(li1[1], '.1f')).replace('-','')
197
+                                                        str5 = fill3(num4)
198
+                                                        str2 = '-0+' + str5
199
+                                                        t2.TextString = str2
200
+                                                    else:
201
+                                                        # jl1 = abs(abs(li1[1]) - 28.7)
202
+                                                        # center = APoint(0,0,0)
203
+                                                        # pt = APoint(jl1,0,0)
204
+                                                        # t2.move(center,pt)
205
+                                                        num4 = str(format(li1[1], '.1f')).replace('-','')
206
+                                                        str5 = fill3(num4)
207
+                                                        str2 = '-0+' + str5
208
+                                                        t2.TextString = str2
209
+                                                    minnum = abs(li1[1])
210
+                                                else:
211
+                                                    #复制
212
+                                                    copy = t2.Copy()  
213
+                                                    #移动
214
+                                                    jl1 = minnum + li1[1]
215
+                                                    center = APoint(0,0,0)
216
+                                                    pt = APoint(jl1,0,0)
217
+                                                    copy.move(center,pt)
218
+                                                    #重新赋值
219
+                                                    if li1[1] < 0:
220
+                                                        num4 = str(format(li1[1], '.1f')).replace('-','')
221
+                                                        str5 = fill3(num4)
222
+                                                        str2 = '-0+' + str5
223
+                                                    else:
224
+                                                        try:
225
+                                                            num4 = str(format(li1[1], '.1f')).replace('-','')
226
+                                                        except:
227
+                                                            num4 = str(format(li1[1], '.1f'))
228
+                                                        str5 = fill3(num4)
229
+                                                        str2 = '0+' + str5
230
+                                                    copy.TextString = str2
231
+                                    k1 = -1
232
+                                if '.' in t2.TextString and '+' not in t2.TextString:
233
+                                    if k2 == -1:
234
+                                        pass
235
+                                    else:
236
+                                        for li1 in list3:
237
+                                            if li1[2] == -1:
238
+                                                pass
239
+                                            else: 
240
+                                                #找到相对位置进行位移并赋值
241
+                                                if li1[1] == list3[0][1]:
242
+                                                    if pd1 == 1:
243
+                                                        #就以那个为起点
244
+                                                        str2 = str(format(li1[0], '.1f'))
245
+                                                        t2.TextString = str2
246
+                                                    else:
247
+                                                        # jl1 = abs(abs(li1[1]) - 28.7)
248
+                                                        # center = APoint(0,0,0)
249
+                                                        # pt = APoint(jl1,0,0)
250
+                                                        # t2.move(center,pt)
251
+                                                        str2 = str(format(li1[0], '.1f'))
252
+                                                        t2.TextString = str2
253
+                                                else:
254
+                                                    #复制
255
+                                                    copy = t2.Copy()  
256
+                                                    #移动
257
+                                                    jl1 = minnum + li1[1]
258
+                                                    center = APoint(0,0,0)
259
+                                                    pt = APoint(jl1,0,0)
260
+                                                    copy.move(center,pt)
261
+                                                    #重新赋值
262
+                                                    str2 = str(format(li1[0], '.1f'))
263
+                                                    copy.TextString = str2
264
+                                    k2 = -1
265
+                            print('B')
266
+                            #设置一条二位多段线line
267
+                            line1 = []
268
+                            road = -1
269
+                            mn = 0
270
+                            for li3 in list3:
271
+                                hh = li3[0]    
272
+                #-----------------------------------------------------------------------------------------------------------------------
273
+                                gc = abs(410 - hh)
274
+                #-----------------------------------------------------------------------------------------------------------------------
275
+                                # gc = abs(670 - hh)
276
+                                lj4 = minnum + li3[1]
277
+                                lj5 = 0
278
+                                # if pd1 == 1:
279
+                                #     zbx = 91.6 + lj4
280
+                                # else:
281
+                                #     lj5 = abs(abs(li3[1]) - 28.7)
282
+                                #     zbx = 91.6 + lj4+lj5
283
+                                zbx = 91.6 + lj4
284
+                                zby = gc + 56.7
285
+                                pt1 = [zbx,zby,0]
286
+                                line1 = line1 + pt1
287
+                                if li3[2] ==-1:
288
+                                    #那个竖线
289
+                                    ptA = APoint(zbx,zby)
290
+                                    ptB = APoint(zbx,57)
291
+                                    # ptB = APoint(zbx,(yy+25+37))
292
+                                    lnobj2 = acad.model.AddLine(ptA,ptB)
293
+                                    #这个要调一下
294
+                                    lnobj2.Color = 3
295
+                                else:
296
+                                    #那个竖线
297
+                                    ptA = APoint(zbx,zby)
298
+                                    ptB = APoint(zbx,22)
299
+                                    # ptB = APoint(zbx,(yy+27))
300
+                                    lnobj2 = acad.model.AddLine(ptA,ptB)
301
+                                    #这个要调一下
302
+                                    lnobj2.Color = 3
303
+                                #单独看下需要写出路的部分
304
+                                try:
305
+                                    if li3[3] == 1 and list3[mn+1][3] == 1 and abs(list3[mn+1][0] -li3[0]) <1:
306
+                                        if road == -1:
307
+                                            # str6 = '水泥路'
308
+                                            # text3 = acad.model.AddText(str6,ptA,1)
309
+                                            # text3.Color = 1
310
+                                            text3 = list(acad.iter_objects("Text"))
311
+                                            for t3 in text3:
312
+                                                if '路' in t3.TextString:
313
+                                                    center = APoint(0,0)
314
+                                                    numb1 = 91.5+lj4
315
+                                                    # if pd1 == 1:
316
+                                                    #     numb1 = 91.5+lj4
317
+                                                    # else:
318
+                                                    #     numb1 = 91.5 + lj4+lj5
319
+                                                    numb2 = 58+gc
320
+                                                    pt3 = APoint(numb1,numb2)
321
+                                                    t3.move(center,pt3)
322
+                                            road = 1
323
+                                except:
324
+                                    pass
325
+                                mn = mn + 1
326
+                            if road == -1:
327
+                                #删除标注
328
+                                text3 = list(acad.iter_objects("Text"))
329
+                                for t3 in text3:
330
+                                    if '路' in t3.TextString:
331
+                                        t3.Delete()
332
+                            #把线绘制出来
333
+                            pnts = aDouble(line1)
334
+                            try:
335
+                                plineObj = acad.model.AddPolyLine(pnts)
336
+                            except:
337
+                                with open(txtpath,'a+')as line1:
338
+                                    line1.write(zhA)
339
+                                    line1.flush()
340
+                            print('C')
341
+                            handle_string = 'select'
342
+                            text1 = list(acad.iter_objects(["Text", "Line","Circle"]))
343
+                            for t1 in text1:
344
+                                handle_string += ' (handent "'+t1.Handle+'")'
345
+                            #命令
346
+                            handle_string += '\n\n'
347
+                            doc.SendCommand(handle_string)
348
+                            #移动的距离
349
+                            str1 = 'move\n0,0,0\n' + str(xx) + ','+ str(yy) + ',0\n'
350
+                            #移动
351
+                            # doc.SendCommand('move\n-80,-140,0\n760,-140,0\n')
352
+                            doc.SendCommand(str1)
353
+                            #再次选择
354
+                            doc.SendCommand(handle_string)
355
+                            doc.SendCommand('copybase\n0,0,0\n')
356
+                            # target_doc.SendCommand('PASTEORIG\n')
357
+                            target_doc.SendCommand('PASTEORIG\n')
358
+                            #过程的不保存(删除所有要素)
359
+                            doc.Close(False)
360
+                            print(zhA + 'Finish')
361
+                            xx = xx + 210
362
+                            dmxdict.pop(zhA,'nonevalue')
363
+                    jj = jj + 50
364
+                mm = mm - 1
365
+                yy =yy + 200
366
+            nn = nn + 1
367
+
368
+    else:
369
+        yy = 0
370
+        while kk >= 0:
371
+            xx = 0
372
+            jj = 0
373
+            while jj < 1000:
374
+                zhA = 'K' + str(kk) + '+' + str(str(jj).zfill(3))
375
+                key1 = dmxdict.get(zhA, 'none')
376
+                if key1 == 'none':
377
+                    # xx = xx + 210 
378
+                    pass
379
+                else:
380
+                    if len(key1) == 0:
381
+                        dmxdict.pop(zhA,'nonevalue')
382
+                        xx = xx + 210
383
+                    else:
384
+                        list2 = key1
385
+                        list2.sort(key=takeSec)
386
+                        slj = 0
387
+                        list3 = []
388
+                        for li4 in list2:
389
+                            if li4[1] == list2[0][1]:
390
+                                slj = li4[1]
391
+                                xs = 1
392
+                                listb1 = []
393
+                                listb1.append(li4[0])
394
+                                listb1.append(li4[1])
395
+                                listb1.append(xs)
396
+                                listb1.append(li4[2])
397
+                                list3.append(listb1)
398
+                            else:
399
+                                listb1 = []
400
+                                #区分下正负交替的部分
401
+                                if slj < 0 and li4[1] >=0:
402
+                                    dis = 5
403
+                                    slj = li4[1]
404
+                                else:
405
+                                    dis = abs(abs(slj) - abs(li4[1]))
406
+                                if dis >= 3:
407
+                                    xs = 1
408
+                                    slj = li4[1]
409
+                                else:
410
+                                    xs = -1 
411
+                                listb1.append(li4[0])
412
+                                listb1.append(li4[1])
413
+                                listb1.append(xs)
414
+                                listb1.append(li4[2])
415
+                                list3.append(listb1)
416
+                        #只对模板进行开关
417
+                        acad.Application.Documents.Open(mbpath)
418
+                        doc = acad.ActiveDocument
419
+                        #先写,再移动
420
+                        text1 = list(acad.iter_objects("Text"))
421
+                        #防止重复
422
+                        k1 = 1
423
+                        k2 = 1
424
+                        minnum = 0
425
+                        pd1 = -1
426
+                        if abs(list3[0][1])>=28.7 or abs(list3[len(list3)-1][1])>=28.7:
427
+                            pd1 = 1
428
+                        for t2 in text1:
429
+                            if 'K' in t2.TextString:
430
+                                #最下面那个桩号
431
+                                t2.TextString = zhA
432
+                            if '+' in t2.TextString and 'K' not in t2.TextString:
433
+                                if k1 == -1:
434
+                                    pass
435
+                                else:
436
+                                    for li1 in list3:
437
+                                        if li1[2] == -1:
438
+                                            pass
439
+                                        else: 
440
+                                            #找到相对位置进行位移并赋值
441
+                                            if li1[1] == list3[0][1]:
442
+                                                if pd1 ==1:
443
+                                                    #就以那个为起点
444
+                                                    num4 = str(format(li1[1], '.1f')).replace('-','')
445
+                                                    str5 = fill3(num4)
446
+                                                    str2 = '-0+' + str5
447
+                                                    t2.TextString = str2
448
+                                                else:
449
+                                                    jl1 = abs(abs(li1[1]) - 28.7)
450
+                                                    center = APoint(0,0,0)
451
+                                                    pt = APoint(jl1,0,0)
452
+                                                    t2.move(center,pt)
453
+                                                    num4 = str(format(li1[1], '.1f')).replace('-','')
454
+                                                    str5 = fill3(num4)
455
+                                                    str2 = '-0+' + str5
456
+                                                    t2.TextString = str2
457
+                                                minnum = abs(li1[1])
458
+                                            else:
459
+                                                #复制
460
+                                                copy = t2.Copy()  
461
+                                                #移动
462
+                                                jl1 = minnum + li1[1]
463
+                                                center = APoint(0,0,0)
464
+                                                pt = APoint(jl1,0,0)
465
+                                                copy.move(center,pt)
466
+                                                #重新赋值
467
+                                                if li1[1] < 0:
468
+                                                    num4 = str(format(li1[1], '.1f')).replace('-','')
469
+                                                    str5 = fill3(num4)
470
+                                                    str2 = '-0+' + str5
471
+                                                else:
472
+                                                    try:
473
+                                                        num4 = str(format(li1[1], '.1f')).replace('-','')
474
+                                                    except:
475
+                                                        num4 = str(format(li1[1], '.1f'))
476
+                                                    str5 = fill3(num4)
477
+                                                    str2 = '0+' + str5
478
+                                                copy.TextString = str2
479
+                                k1 = -1
480
+                            if '.' in t2.TextString and '+' not in t2.TextString:
481
+                                if k2 == -1:
482
+                                    pass
483
+                                else:
484
+                                    for li1 in list3:
485
+                                        if li1[2] == -1:
486
+                                            pass
487
+                                        else: 
488
+                                            #找到相对位置进行位移并赋值
489
+                                            if li1[1] == list3[0][1]:
490
+                                                if pd1 == 1:
491
+                                                    #就以那个为起点
492
+                                                    str2 = str(format(li1[0], '.1f'))
493
+                                                    t2.TextString = str2
494
+                                                else:
495
+                                                    jl1 = abs(abs(li1[1]) - 28.7)
496
+                                                    center = APoint(0,0,0)
497
+                                                    pt = APoint(jl1,0,0)
498
+                                                    t2.move(center,pt)
499
+                                                    str2 = str(format(li1[0], '.1f'))
500
+                                                    t2.TextString = str2
501
+                                            else:
502
+                                                #复制
503
+                                                copy = t2.Copy()  
504
+                                                #移动
505
+                                                jl1 = minnum + li1[1]
506
+                                                center = APoint(0,0,0)
507
+                                                pt = APoint(jl1,0,0)
508
+                                                copy.move(center,pt)
509
+                                                #重新赋值
510
+                                                str2 = str(format(li1[0], '.1f'))
511
+                                                copy.TextString = str2
512
+                                k2 = -1
513
+                        print('B')
514
+                        #设置一条二位多段线line
515
+                        line1 = []
516
+                        road = -1
517
+                        mn = 0
518
+                        for li3 in list3:
519
+                            hh = li3[0]    
520
+            #-----------------------------------------------------------------------------------------------------------------------
521
+                            gc = abs(420- hh)
522
+            #-----------------------------------------------------------------------------------------------------------------------
523
+                            # gc = abs(670 - hh)
524
+                            lj4 = minnum + li3[1]
525
+                            zbx = 91.6 + lj4 
526
+                            zby = gc + 56.7
527
+                            pt1 = [zbx,zby,0]
528
+                            line1 = line1 + pt1
529
+                            if li3[2] ==-1:
530
+                                #那个竖线
531
+                                ptA = APoint(zbx,zby)
532
+                                ptB = APoint(zbx,56.7)
533
+                                # ptB = APoint(zbx,(yy+25+37))
534
+                                lnobj2 = acad.model.AddLine(ptA,ptB)
535
+                                #这个要调一下
536
+                                lnobj2.Color = 3
537
+                            else:
538
+                                #那个竖线
539
+                                ptA = APoint(zbx,zby)
540
+                                ptB = APoint(zbx,22)
541
+                                # ptB = APoint(zbx,(yy+27))
542
+                                lnobj2 = acad.model.AddLine(ptA,ptB)
543
+                                #这个要调一下
544
+                                lnobj2.Color = 3
545
+                            #单独看下需要写出路的部分
546
+                            try:
547
+                                if li3[3] == 1 and list3[mn+1][3] == 1 and abs(list3[mn+1][0] -li3[0]) <1:
548
+                                    if road == -1:
549
+                                        # str6 = '水泥路'
550
+                                        # text3 = acad.model.AddText(str6,ptA,1)
551
+                                        # text3.Color = 1
552
+                                        text3 = list(acad.iter_objects("Text"))
553
+                                        for t3 in text3:
554
+                                            if '路' in t3.TextString:
555
+                                                center = APoint(0,0)
556
+                                                numb1 = 91.5+lj4
557
+                                                numb2 = 58+gc
558
+                                                pt3 = APoint(numb1,numb2)
559
+                                                t3.move(center,pt3)
560
+                                                gc1 = hh
561
+                                        road = 1
562
+                            except:
563
+                                pass
564
+                            mn = mn + 1
565
+                        if road == -1:
566
+                            #删除标注
567
+                            text3 = list(acad.iter_objects("Text"))
568
+                            for t3 in text3:
569
+                                if '路' in t3.TextString:
570
+                                    t3.Delete()
571
+                        #把线绘制出来
572
+                        pnts = aDouble(line1)
573
+                        try:
574
+                            plineObj = acad.model.AddPolyLine(pnts)
575
+                        except:
576
+                            with open(txtpath,'a+')as line1:
577
+                                line1.write(zhA)
578
+                                line1.flush()
579
+                        print('C')
580
+                        handle_string = 'select'
581
+                        text1 = list(acad.iter_objects(["Text", "Line","Circle"]))
582
+                        for t1 in text1:
583
+                            handle_string += ' (handent "'+t1.Handle+'")'
584
+                        #命令
585
+                        handle_string += '\n\n'
586
+                        doc.SendCommand(handle_string)
587
+                        #移动的距离
588
+                        str1 = 'move\n0,0,0\n' + str(xx) + ','+ str(yy) + ',0\n'
589
+                        #移动
590
+                        # doc.SendCommand('move\n-80,-140,0\n760,-140,0\n')
591
+                        doc.SendCommand(str1)
592
+                        #再次选择
593
+                        doc.SendCommand(handle_string)
594
+                        doc.SendCommand('copybase\n0,0,0\n')
595
+                        # target_doc.SendCommand('PASTEORIG\n')
596
+                        target_doc.SendCommand('PASTEORIG\n')
597
+                        #过程的不保存(删除所有要素)
598
+                        doc.Close(False)
599
+                        print(zhA + 'Finish')
600
+                        xx = xx + 210
601
+                        dmxdict.pop(zhA,'nonevalue')
602
+                jj = jj + 10
603
+            kk = kk - 1
604
+            yy =yy + 200
605
+    target_doc.Close()
606
+
607
+                     
608
+
609
+if __name__ == '__main__':
610
+    start()
611
+        
612
+
613
+
614
+    

二進制
加密后软件工具/exe/平面控制网稳定性已知系统分析软件(最最最终版).exe 查看文件


二進制
未加密软件工具/CAD插件工具/右上角图框方位/T_cad_2024.dll 查看文件


+ 2
- 0
未加密软件工具/CAD插件工具/右上角图框方位/更新命令部分.txt 查看文件

@@ -0,0 +1,2 @@
1
+tt2024 未加带号,接图表8列成16列,其他和原来的tt无差。
2
+tt2020 也就是原来的tt。

二進制
未加密软件工具/CAD插件工具/右上角图框方位/最老版本/GIS/UtilityManager02TK.tbx 查看文件


二進制
未加密软件工具/CAD插件工具/右上角图框方位/最老版本/GIS/UtilityManager02V1.tbx 查看文件


二進制
未加密软件工具/CAD插件工具/右上角图框方位/最老版本/cass/Debug2w/T_cad.dll 查看文件


+ 3
- 0
未加密软件工具/CAD插件工具/右上角图框方位/最老版本/cass/Debug2w/T_cad.dll.config 查看文件

@@ -0,0 +1,3 @@
1
+<?xml version="1.0"?>
2
+<configuration>
3
+	<startup/></configuration>

二進制
未加密软件工具/CAD插件工具/右上角图框方位/最老版本/cass/Debug2w/T_cad.pdb 查看文件


二進制
未加密软件工具/CAD插件工具/右上角图框方位/最老版本/示例数据/原始模板1.dwg 查看文件


二進制
未加密软件工具/CAD插件工具/右上角图框方位/最老版本/示例数据/成图模板.bak 查看文件


二進制
未加密软件工具/CAD插件工具/右上角图框方位/最老版本/示例数据/成图模板.dwg 查看文件


二進制
未加密软件工具/CAD插件工具/右上角图框方位/最老版本/示例数据/需求模板.dwg 查看文件


+ 3
- 0
未加密软件工具/CAD插件工具/右上角图框方位/最老版本/示例数据/需求模板.dwl 查看文件

@@ -0,0 +1,3 @@
1
+10445
2
+LAPTOP-DPUTUM3D 
3
+2024定1埖12晩  10:58:25

+ 7
- 0
未加密软件工具/CAD插件工具/右上角图框方位/最老版本/示例数据/需求模板.dwl2 查看文件

@@ -0,0 +1,7 @@
1
+<?xml version="1.0" encoding="UTF-8">
2
+<whprops>
3
+<username>10445</username>
4
+<machinename>LAPTOP-DPUTUM3D </machinename>
5
+<fullname></fullname>
6
+<datetime>2024年1月12日  10:58:25</datetime>
7
+</whprops>

二進制
未加密软件工具/CAD插件工具/右上角图框方位/需求模板_1.dwg 查看文件


二進制
未加密软件工具/arcgis工具箱/DEM1.2.tbx 查看文件


二進制
未加密软件工具/arcgis工具箱/DLG检查1.5版.tbx 查看文件


二進制
未加密软件工具/arcgis工具箱/DM1.2.tbx 查看文件


二進制
未加密软件工具/arcgis工具箱/DOM1.2.tbx 查看文件


二進制
未加密软件工具/arcgis工具箱/dmgl(忘了这缩写是什么了)/dmgl0817new.tbx 查看文件


二進制
未加密软件工具/arcgis工具箱/dmgl(忘了这缩写是什么了)/dmgl0817使用说明.docx 查看文件


二進制
未加密软件工具/arcgis工具箱/倒流工具箱.tbx 查看文件


二進制
未加密软件工具/arcgis工具箱/公路断面工具.tbx 查看文件


二進制
未加密软件工具/arcgis工具箱/图斑操作/图斑操作0310.tbx 查看文件


二進制
未加密软件工具/arcgis工具箱/图斑操作/图斑操作0310使用说明.docx 查看文件


二進制
未加密软件工具/arcgis工具箱/批处理库容2_0.tbx 查看文件


二進制
未加密软件工具/arcgis工具箱/批量TIN转GRID.tbx 查看文件


二進制
未加密软件工具/arcgis工具箱/批量mdb转dwg.tbx 查看文件


二進制
未加密软件工具/arcgis工具箱/批量导入投影坐标系(最新版1.0).tbx 查看文件


二進制
未加密软件工具/arcgis工具箱/批量提取图斑new_3.tbx 查看文件


+ 0
- 0
未加密软件工具/arcgis工具箱/批量提取图斑注记2024_1_9.tbx 查看文件


部分文件因文件數量過多而無法顯示

Loading…
取消
儲存