AnsweredAssumed Answered

Update fields and redraw points based on updated fields

Question asked by kidrew_flc on Mar 29, 2020
Latest reply on Mar 29, 2020 by bixb0012
import arcpy
from arcpy.sa import *
from arcpy import env
arcpy.CheckOutExtension("spatial")
main_dir = "F:\Independent_Study\\"
flow_dir = main_dir + "Flow"
env.workspace = main_dir
env.overwriteOutput = True
threshold = 3000
dem = Raster("F:\\Independent_Study\\Newfiles\\Newfiles\\UDW1_dtm.tif")
#invert DEM
dem_neg = dem * -1
gps_pts = "F:\\Independent_Study\\UDW_with_UTM_Coordinates\\UDW_with_UTM_Coordinates.shp"
#run flow direction on DEM
neg_Direction = FlowDirection(dem_neg)
neg_Direction.save(flow_dir + "\\neg_flow_direction.tif")
#Extracts values at GPS Points
direction_value = ExtractValuesToPoints(gps_pts, neg_Direction, flow_dir + "\\direction_values.shp")
values = arcpy.ListFields(direction_value)
#create an update cursor to update the X and Y coordinate values based on flow direction.
cursor = arcpy.da.UpdateCursor(flow_dir + "\\direction_values.shp", ["*"])
#Save spatial reference information
spatial_reference = arcpy.Describe(flow_dir + "\\direction_values.shp").spatialReference
#Create new feature class for updated values
arcpy.CreateFeatureclass_management(flow_dir, "\\updated_dir_values.shp", "POINT", flow_dir + "\\direction_values.shp", "DISABLED", "DISABLED", spatial_reference)
cur = arcpy.InsertCursor(flow_dir + "\\updated_dir_values.shp",["SHAPE@"])
#for loop that iterates through feature class and modifies X and Y coordinates based on the flow direction at that point
for row in cursor:
                       #East
    if (row [10] == 1):
        row[9] = int(row[9]) + 1
        cursor.updateRow(row)
        print "EAST"
                        #SE
    elif (row [10] == 2):
        row[8] = int(row[8]) - 1
        row[9] = int(row[9]) + 1
        cursor.updateRow(row)
               
        print "SOUTH-EAST"
                    #SW
    elif (row [10] == 8):
        row[8] = int(row[8]) - 1
        row[9] = int(row[9]) - 1
        cursor.updateRow(row)
        print "SOUTHWEST"
                        #NW
    elif (row [10] == 32):
        row[8] = int(row[8]) + 1
        row[9] = int(row[9]) - 1
        cursor.updateRow(row)
        print "NORTHWEST"
                        #NE
    elif (row [10] == 128):
        row[8] = int(row[8]) + 1
        row[9] = int(row[9]) + 1
        cursor.updateRow(row)
        print "NORTHEAST"
                        #North
    elif (row [10] == 64):
        row[8] = int(row[8]) + 1
        cursor.updateRow(row)
        print "NORTH"
                        #South
    elif (row [10] == 4):
        row[8] = int(row[8]) - 1
        cursor.updateRow(row)
        print "SOUTH"
                        #West
    elif (row [10] == 16):
        row[9] = int(row[9]) - 1
        cursor.updateRow(row)
        print "WEST"

arcpy.Append_management(flow_dir + "\\direction_values.shp", flow_dir + "\\updated_dir_values.shp", "TEST","","")

Hi, there, I'm trying to run a for-loop that iterates through a shape feature class of GPS points, extracts the value for the flow direction at that point, and modifies the x (UTM_E) and y (UTM_N) coordinates based on which direction the flow path will take. I'm trying to then redraw that point based on the new x and y coordinates, but I'm having trouble writing the code that actually redraws the points using the new coordinate values, which are stored as fields in the feature class. And finally, I want to put that into another loop that it updates the values and redraws them N number of times.

Thank you!

Attachments

Outcomes