123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- import arcpy
- import math
-
- def pp():
- dmxpath = r'D:\4work_now\20241017dm\20241129\hltdm3\dmx.shp'
- dmdpath = r'D:\4work_now\20241017dm\20241129\hltdm3\dmd.shp'
- # zdpath = r'D:\4work_now\20241017dm\1024gq\RMQ7\rmq200zdmd.shp'
- dwgpath = r'D:\4work_now\20241017dm\20241129\hltdm3\dm.dwg'
- gqpath = r'D:\4work_now\20241017dm\20241129\hltdm3\zxx.shp'
- roadpath = r'D:\4work_now\20241017dm\20241129\hltdm3\road.shp'
- arcpy.MakeFeatureLayer_management(dmxpath, 'DMshp')
- arcpy.MakeFeatureLayer_management(dmdpath, 'DMDshp')
- # arcpy.MakeFeatureLayer_management(zdpath, 'ZDshp')
- arcpy.MakeFeatureLayer_management(gqpath, 'GQshp')
- arcpy.MakeFeatureLayer_management(roadpath, 'roadshp')
- annopath = dwgpath + '\\Annotation'
- arcpy.MakeFeatureLayer_management(annopath, 'ANNO')
- arcpy.AddField_management('DMshp','KZ','LONG')
- arcpy.AddField_management('DMshp','JZ','LONG')
- arcpy.AddField_management('DMshp','ZH','TEXT')
- # arcpy.AddField_management('DMshp', 'ZH_1', 'TEXT')
- arcpy.AddField_management('DMDshp','ZH','TEXT')
- arcpy.AddField_management('DMDshp','LJ','FLOAT')
- arcpy.AddField_management('DMDshp','SFR','LONG')
- arcpy.AddField_management('DMDshp', 'SFL', 'LONG')
- nonehz = -1
- with arcpy.da.SearchCursor('GQshp',['SHAPE@']) as cursorZ:
- for curZ in cursorZ:
- GQline = curZ[0]
-
- # with arcpy.da.UpdateCursor('DMshp',['SHAPE@','KZ','JZ','ZH']) as cursorA:
- # for curA in cursorA:
- # zh = ''
- # line1 = curA[0]
- # buf1 = line1.buffer(10)
- # arcpy.SelectLayerByLocation_management('ANNO','WITHIN',buf1)
- # pc = int(arcpy.GetCount_management('ANNO')[0])
- # if pc == 0:
- # curA[1] = nonehz
- # curA[2] = nonehz
- # curA[3] = 'None' + str(nonehz)
- # cursorA.updateRow(curA)
- # elif pc == 1:
- # with arcpy.da.SearchCursor('ANNO',['SHAPE@','Text']) as cursorAA:
- # for curAA in cursorAA:
- # zh = curAA[1]
- # try:
- # kstr = zh.split('+',-1)[0]
- # kz = kstr.replace('K','')
- # jstr = zh.split('+',-1)[1]
- # try:
- # jz = jstr.split(' ',-1)[0]
- # except:
- # jz = jstr
- # curA[1] = int(kz)
- # curA[2] = int(float(jz))
- # zh = 'K' + str(int(kz)) + '+' +str(str(int(float(jz))).zfill(3))
- # curA[3] = zh
- # cursorA.updateRow(curA)
- # except:
- # print(zh)
- # else:
- # dis1 = 99999
- # zh = ''
- # with arcpy.da.SearchCursor('ANNO',['SHAPE@','Text']) as cursorAA:
- # for curAA in cursorAA:
- # if 'K' in curAA[1]:
- # annopt = curAA[0]
- # dis2 = line1.distanceTo (annopt)
- # if dis2 < dis1:
- # dis1 = dis2
- # zh = curAA[1]
- # else:
- # pass
- # try:
- # kstr = zh.split('+',-1)[0]
- # kz = kstr.replace('K','')
- # jstr = zh.split('+', -1)[1]
- # try:
- # jz = jstr.split(' ', -1)[0]
- # except:
- # jz = jstr
- # curA[1] = int(kz)
- # curA[2] = int(float(jz))
- # zh1 = 'K' + str(int(kz)) + '+' + str(str(int(float(jz))).zfill(3))
- # curA[3] = zh1
- # cursorA.updateRow(curA)
- # except:
- # pass
- # print('A')
- with arcpy.da.SearchCursor('DMshp', ['SHAPE@', 'KZ', 'JZ', 'ZH']) as cursorA:
- for curA in cursorA:
- line1 = curA[0]
- # len = line1.length / 2
- # cpt = line1.positionAlongLine (len)
- buf1 = line1.buffer(1)
- zh = curA[3]
- arcpy.SelectLayerByLocation_management('DMDshp','WITHIN',buf1)
- pc2 = int(arcpy.GetCount_management('DMDshp')[0])
- if pc2 > 0:
- min = 999
- with arcpy.da.SearchCursor('DMDshp',['SHAPE@']) as cursorZ:
- for curZ in cursorZ:
- pt = curZ[0].firstPoint
- lj = round(GQline.distanceTo(pt), 4)
- if lj < min:
- min = lj
- cpt = curZ[0]
- with arcpy.da.UpdateCursor('DMDshp',['SHAPE@','ZH','LJ','SFR','SFL']) as cursorB:
- for curB in cursorB:
- tuple1 = GQline.queryPointAndDistance(curB[0])
- lj = round(cpt.distanceTo(curB[0]),4)
- if tuple1[3] == False:
- curB[3] = -1
- else:
- curB[3] = 1
- pt = curB[0]
- buf2 = pt.buffer(1)
- arcpy.SelectLayerByLocation_management('roadshp', 'INTERSECT', buf2)
- pc3 = int(arcpy.GetCount_management('roadshp')[0])
- # arcpy.SelectLayerByLocation_management('roadshp', 'CONTAINS', buf2)
- # pc4 = int(arcpy.GetCount_management('roadshp')[0])
- if pc3 > 0 :
- curB[4] = 1
- curB[1] = zh
- curB[2] = lj
- cursorB.updateRow(curB)
- print('1')
-
-
-
-
-
-
-
-
- if __name__ == '__main__':
- try:
- # arcpy.AddMessage ('start at {0}\n'.format(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())))
- pp()
- # Lake(arcpy.GetParameterAsText(0),arcpy.GetParameterAsText(1),arcpy.GetParameterAsText(2),arcpy.GetParameterAsText(3),arcpy.GetParameterAsText(4))
- # arcpy.AddMessage ('end at {0}\n'.format(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())))
- except arcpy.ExecuteError:
- arcpy.AddMessage (arcpy.GetMessages())
|