123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- # -*- coding: utf-8 -*-
- import arcpy
- import math
-
- def drawDM(shppath,outpath,jj0,bj0):
- jj = float(jj0)
- bj = float(bj0)
- szd = 'Sp'
- sx = 'SX'
- sw = 'S_Weizhi'
- arcpy.MakeFeatureLayer_management(shppath, 'DMshp')
- shppath1 = outpath + '\\DMpoint.shp'
- try:
- arcpy.CreateFeatureclass_management(outpath, 'DMpoint.shp', 'POINT')
- except:
- arcpy.Delete_management(shppath1)
- arcpy.CreateFeatureclass_management(outpath, 'DMpoint.shp', 'POINT')
- arcpy.MakeFeatureLayer_management(shppath1, 'DMP')
- shppath2 = outpath + '\\DMpolyline.shp'
- try:
- arcpy.CreateFeatureclass_management(outpath, 'DMpolyline.shp', 'POLYLINE')
- except:
- arcpy.Delete_management(shppath2)
- arcpy.CreateFeatureclass_management(outpath, 'DMpolyline.shp', 'POLYLINE')
- arcpy.MakeFeatureLayer_management(shppath2, 'DML')
- arcpy.AddField_management('DMP','ZH','TEXT')
- arcpy.AddField_management('DML','ZH','TEXT')
- with arcpy.da.InsertCursor('DMP', ['SHAPE@','ZH']) as cursorA:
- with arcpy.da.InsertCursor('DML', ['SHAPE@','ZH']) as cursorB:
- with arcpy.da.SearchCursor('DMshp',['SHAPE@',szd,sw,sx,'length']) as cursorC:
- for curC in cursorC:
- dm = curC[0]
- zf = curC[3]
- pts = dm.getPart(0)
- if zf == 1:
- sk = int(curC[1]) // 1000
- sj = int(curC[1]) % 1000
- len = curC[2]
- dmgeopt = dm.positionAlongLine(len)
- dmpt = dmgeopt.firstPoint
- zh = 'K' + str(sk) + '+' + str(str(sj).zfill(3))
- minp = findminp(dm,pts,len)
- try:
- pl = jsdp(dmpt,minp,bj)
- list1 = []
- list1.append(dmgeopt)
- list1.append(zh)
- cursorA.insertRow(list1)
- list2 = []
- list2.append(pl)
- list2.append(zh)
- cursorB.insertRow(list2)
- except:
- pass
- len = len + 50
- while len <= curC[4]:
- ptg1 = dm.positionAlongLine(len)
- pt1 = ptg1.firstPoint
- minp = findminp(dm,pts,len)
- sj = sj + 50
- if sj == 1000:
- sk = sk + 1
- sj = 0
- zh = 'K' + str(sk) + '+' + str(str(sj).zfill(3))
- try:
- pl = jsdp(pt1,minp,bj)
- listp1 = []
- listp1.append(ptg1)
- listp1.append(zh)
- cursorA.insertRow(listp1)
- listl1 = []
- listl1.append(pl)
- listl1.append(zh)
- cursorB.insertRow(listl1)
- except:
- pass
- len = len + 50
- print('B2')
-
- mk = int(curC[2]) // 1000
- mj = int(curC[2]) % 1000
- zh1 = 'K' + str(mk) + '+' + str(str(mj).zfill(3))
- if zh1 == zh:
- pass
- else:
- qd = dm.lastPoint
- lens = curC[5] - (len - 50)
- sj = sj + int(lens)
- zh = 'K' + str(sk) + '+' + str(str(sj).zfill(3))
- try:
- plZ = jsdp(qd,pts[pts.count - 2],bj)
- listp1 = []
- listp1.append(arcpy.PointGeometry(qd))
- listp1.append(zh)
- cursorA.insertRow(listp1)
- listl1 = []
- listl1.append(plZ)
- listl1.append(zh)
- cursorB.insertRow(listl1)
- except:
- pass
- print('B')
- else:
- sk = int(curC[1]) // 1000
- sj = int(curC[1]) % 1000
- len = curC[4] - curC[2]
- dmgeopt = dm.positionAlongLine(len)
- dmpt = dmgeopt.firstPoint
- zh = 'K' + str(sk) + '+' + str(str(sj).zfill(3))
- minp = findminp(dm,pts,len)
- try:
- pl = jsdp(dmpt,minp,bj)
- list1 = []
- list1.append(dmgeopt)
- list1.append(zh)
- cursorA.insertRow(list1)
- list2 = []
- list2.append(pl)
- list2.append(zh)
- cursorB.insertRow(list2)
- except:
- pass
- len = len - 50
- while len >= 0:
- ptg1 = dm.positionAlongLine(len)
- pt1 = ptg1.firstPoint
- minp = findminp(dm,pts,len)
- sj = sj + 50
- if sj == 1000:
- sk = sk + 1
- sj = 0
- zh = 'K' + str(sk) + '+' + str(str(sj).zfill(3))
- try:
- pl = jsdp(pt1,minp,bj)
- listp1 = []
- listp1.append(ptg1)
- listp1.append(zh)
- cursorA.insertRow(listp1)
- listl1 = []
- listl1.append(pl)
- listl1.append(zh)
- cursorB.insertRow(listl1)
- except:
- pass
- len = len - 50
- print('C2')
-
- mk = int(curC[2]) // 1000
- mj = int(curC[2]) % 1000
- zh1 = 'K' + str(mk) + '+' + str(str(mj).zfill(3))
- if zh1 == zh:
- pass
- else:
- qd = dm.firstPoint
- lens = len + 50
- sj = sj + int(lens)
- zh = 'K' + str(sk) + '+' + str(str(sj).zfill(3))
- try:
- plZ = jsdp(qd, pts[1], bj)
- listp1 = []
- listp1.append(arcpy.PointGeometry(qd))
- listp1.append(zh)
- cursorA.insertRow(listp1)
- listl1 = []
- listl1.append(plZ)
- listl1.append(zh)
- cursorB.insertRow(listl1)
- except:
- pass
- print('C')
-
- def findminp(dm,pts,len):
- mm = 1
- disM = 9999
- minp = pts[0]
- while mm < (pts.count - 1):
- dis2 = dm.measureOnLine(pts[mm])
- dis = abs(dis2 - len)
- if dis == 0:
- minp = pts[mm - 1]
- break
- if dis < disM:
- disM = dis
- minp = pts[mm]
- mm = mm + 1
- return minp
-
- def jsdp(pt1,pt2,bj):
- qdx = pt1.X
- qdy = pt1.Y
- qdx1 = pt2.X
- qdy1 = pt2.Y
- qdk = (qdx1 - qdx) / (qdy1-qdy) * (-1)
- num0 = qdk * qdx
- qdb = qdy - num0
- numA = (qdk * qdk) + 1
- num1 = qdb - qdy
- num2 = 2 * qdk * num1
- num3 = 2 * qdx
- numB = num2 - num3
- num4 = num1 * num1
- num5 = qdx * qdx
- num51 = bj * bj
- numC = num4 + num5 - num51
- num6 = numB * numB
- num7 = 4 * numA * numC
- num8 = math.sqrt(num6 - num7)
- num9 = (-1) * numB
- num101 = num9 + num8
- num102 = num9 - num8
- num11 = 2 * numA
- numX1 = num101 / num11
- numX2 = num102 / num11
- numY1 = qdk * numX1 + qdb
- numY2 = qdk * numX2 + qdb
- pt1 = arcpy.Point(numX1, numY1)
- pt2 = arcpy.Point(numX2, numY2)
- arr1 = arcpy.Array()
- arr1.append(pt1)
- arr1.append(pt2)
- pl1 = arcpy.Polyline(arr1)
- return pl1
-
-
-
-
- if __name__ == '__main__':
- try:
- drawDM(r"D:\4work_now\20241017dm\1024gq\MYQ\1\myqzxx.shp",r'D:\4work_now\20241017dm\1024gq\MYQ\1',50,30)
- except arcpy.ExecuteError:
- arcpy.AddMessage (arcpy.GetMessages())
|