Guest User

Untitled

a guest
Jun 19th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. import os
  2. import arcpy
  3. from math import sqrt
  4. ##Declare map and layers, split layer from all layers and then parse .shp files
  5. ##declare map
  6. mxd=arcpy.mapping.MapDocument("CURRENT")
  7. ##dataframe
  8. df=arcpy.mapping.ListDataFrames(mxd,"Layers")[0]
  9. ##pipelayer
  10. listLayers=arcpy.mapping.ListLayers(mxd,"PL_PIPELINE_LN",df)
  11. staging="c:\staging"
  12. fileName="Report.txt"
  13. path=os.path.join(staging,fileName)
  14. f=open(path,"w+")
  15. ##point features to get elevation from
  16. where=""""CODE" = 'BEND' OR "CODE" = 'FLN' OR "CODE" = 'NIP' OR "CODE" = 'RED' OR "CODE" = 'TAP' OR "CODE" = 'TEE' OR "CODE" = 'VLV' OR "CODE" = 'WELD'"""
  17.  
  18. #lists and dicts for values
  19. pointDict={}
  20. pointList=[]
  21. pointPair=[]
  22. featureList=["FLN","NIP","RED","TAP","TEE","VLV","WELD"]
  23. featurePoints={}
  24. lines=[]
  25.  
  26. #spatial reference to measure stateplane values
  27. spatialRef=sr_state=arcpy.SpatialReference(6578)
  28.  
  29. #get centerline name so we can select those features
  30. cenName=""
  31. with arcpy.da.SearchCursor("PL_PIPELINE_LN","CENTERLINE_NAME") as sc:
  32. for row in sc:
  33. cenName = row[0]
  34.  
  35.  
  36.  
  37.  
  38.  
  39. ##get count of features for iteration , haven't used this yet but may to control iteration
  40. arcpy.SelectLayerByAttribute_management("PL_PIPELINE_LN","NEW_SELECTION","""CENTERLINE_NAME = '{}'""".format(cenName))
  41. result=arcpy.GetCount_management("PL_PIPELINE_LN")
  42. count=int(result.getOutput(0))
  43. print(count)
  44.  
  45. ##clear selection and begin process
  46. arcpy.SelectLayerByAttribute_management("PL_PIPELINE_LN","CLEAR_SELECTION")
  47.  
  48.  
  49. ##select line features with cen name
  50. with arcpy.da.SearchCursor("PL_PIPELINE_LN",["SHAPE@","OBJECTID"],spatial_reference=spatialRef) as sc:
  51. for row in sc:
  52. ##access geometry and get into vertex
  53. geometry=row[0]
  54. objId=row[1]
  55. print (objId)
  56. pts=geometry.getPart(0)
  57. for point in pts:
  58. ##for vertex in vertices
  59. #print (pointList)
  60. linePoint=arcpy.PointGeometry(point)
  61. #featurePoints={}
  62. ##clear pointDict for each vertex
  63. pointDict={}
  64. ##iterate through the survey shape file store values to point dictionary
  65. with arcpy.da.SearchCursor("1708031_20180611",["SHAPE@","CODE","ELEV","FID"],where,spatial_reference=spatialRef) as sc2:
  66. for row2 in sc2:
  67. pointGeometry= row2[0]
  68. code=row2[1]
  69. elev=row2[2]
  70. oid=row2[3]
  71. shpPoint=pointGeometry.getPart(0)
  72. ##get distance to vertex
  73. dist=sqrt((point.X-shpPoint.X)**2+(point.Y-shpPoint.Y)**2)
  74. ##print(dist)
  75. ##add values to point dictionary
  76. pointDict[oid]=dist,elev,code
  77.  
  78. ##find smallest distance in dictioanry
  79. minDist=(min(pointDict.items(), key=lambda x:x[1]))
  80. print(minDist[1][0])
  81.  
  82. ##minDist=(min(featurePoints.items(),key=lambda x:x[1]))
Add Comment
Please, Sign In to add comment