Select to view content in your preferred language

Use python to ASsign Upstream and Downstream Elevations

504
1
01-24-2013 06:18 AM
GarySchells
Occasional Contributor
Hi all,
Iam using python to manipulate survey data being collected in the field.  I am receiving point text files of stormwater drainage data.  Some of these are point pairs representing pipe ends.  Each point has an elevation.  The surveyors don't know if they are upstream or down stream.  I need to look at the point pairs, read the elvation for each and then place the value in the correct downstream or upstream column when creating the line file.  Can anyone assist me with doing this?  I have a table of just the pipe points.  Each pair has the same pipcode value indicating that pair makes up one pipe.  How do I examine each record of that pair, look at the two elevations and assign them correctly when I create a line file?

Thank you for any assistance.
0 Kudos
1 Reply
by Anonymous User
Not applicable
Something like this may work:

import arcpy
arcpy.env.overwriteOutput = True
pipesFC = r'C:\Testing\outputs\test.shp'
minMax = r'in_memory\table'

stats = [['Elevation', 'MIN'],['Elevation','MAX']]
arcpy.Statistics_analysis(pipesFC, minMax, stats,'Pipe_ID')

# Generate dictionary to hold pipe ID min/max elevations
val_dict = {}
with arcpy.da.SearchCursor(minMax, ['Pipe_ID','MIN_Elevation','MAX_Elevation']) as rows:
    for row in rows:
        val_dict[row[0]] = [row[1],row[2]]

# Update records in table
with arcpy.da.UpdateCursor(pipesFC,['Pipe_ID','DownElv','UpElv']) as rows:
    for row in rows:
        if row[0] in val_dict:
            down = val_dict[row[0]][0]
            up = val_dict[row[0]][1]
            row[1] = down
            row[2] = up
            rows.updateRow(row)
           
print 'done'
0 Kudos