Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import arcpy
- from math import sqrt
- ##Declare map and layers, split layer from all layers and then parse .shp files
- ##declare map
- mxd=arcpy.mapping.MapDocument("CURRENT")
- ##dataframe
- df=arcpy.mapping.ListDataFrames(mxd,"Layers")[0]
- ##pipelayer
- listLayers=arcpy.mapping.ListLayers(mxd,"PL_PIPELINE_LN",df)
- staging="c:\staging"
- fileName="Report.txt"
- path=os.path.join(staging,fileName)
- f=open(path,"w+")
- ##point features to get elevation from
- where=""""CODE" = 'BEND' OR "CODE" = 'FLN' OR "CODE" = 'NIP' OR "CODE" = 'RED' OR "CODE" = 'TAP' OR "CODE" = 'TEE' OR "CODE" = 'VLV' OR "CODE" = 'WELD'"""
- #lists and dicts for values
- pointDict={}
- pointList=[]
- pointPair=[]
- featureList=["FLN","NIP","RED","TAP","TEE","VLV","WELD"]
- featurePoints={}
- lines=[]
- #spatial reference to measure stateplane values
- spatialRef=sr_state=arcpy.SpatialReference(6578)
- #get centerline name so we can select those features
- cenName=""
- with arcpy.da.SearchCursor("PL_PIPELINE_LN","CENTERLINE_NAME") as sc:
- for row in sc:
- cenName = row[0]
- ##get count of features for iteration , haven't used this yet but may to control iteration
- arcpy.SelectLayerByAttribute_management("PL_PIPELINE_LN","NEW_SELECTION","""CENTERLINE_NAME = '{}'""".format(cenName))
- result=arcpy.GetCount_management("PL_PIPELINE_LN")
- count=int(result.getOutput(0))
- print(count)
- ##clear selection and begin process
- arcpy.SelectLayerByAttribute_management("PL_PIPELINE_LN","CLEAR_SELECTION")
- ##select line features with cen name
- with arcpy.da.SearchCursor("PL_PIPELINE_LN",["SHAPE@","OBJECTID"],spatial_reference=spatialRef) as sc:
- for row in sc:
- ##access geometry and get into vertex
- geometry=row[0]
- objId=row[1]
- print (objId)
- pts=geometry.getPart(0)
- for point in pts:
- ##for vertex in vertices
- #print (pointList)
- linePoint=arcpy.PointGeometry(point)
- #featurePoints={}
- ##clear pointDict for each vertex
- pointDict={}
- ##iterate through the survey shape file store values to point dictionary
- with arcpy.da.SearchCursor("1708031_20180611",["SHAPE@","CODE","ELEV","FID"],where,spatial_reference=spatialRef) as sc2:
- for row2 in sc2:
- pointGeometry= row2[0]
- code=row2[1]
- elev=row2[2]
- oid=row2[3]
- shpPoint=pointGeometry.getPart(0)
- ##get distance to vertex
- dist=sqrt((point.X-shpPoint.X)**2+(point.Y-shpPoint.Y)**2)
- ##print(dist)
- ##add values to point dictionary
- pointDict[oid]=dist,elev,code
- ##find smallest distance in dictioanry
- minDist=(min(pointDict.items(), key=lambda x:x[1]))
- print(minDist[1][0])
- ##minDist=(min(featurePoints.items(),key=lambda x:x[1]))
Add Comment
Please, Sign In to add comment