for row in rows: a = row[0]
is there a way to preserve the attributes from the original shapefile with the new geometries
def shift_features(in_features, x_shift=None, y_shift=None): with arcpy.da.UpdateCursor(in_features, ['SHAPE@XY']) as cursor: for row in cursor: cursor.updateRow([[row[0][0] + x_shift, row[0][1] + y_shift]]) return # Set the spatial reference infc = Saved_Layer rows = arcpy.da.SearchCursor(infc, ["Easting", "Northing", "Test_Type"]) for row in rows: x = row[0] y = row[1] TestType = row[2] if TestType == 'MTU': distance = .3535535 angle = 45 disp_x = distance * sin(radians(angle)) disp_y = distance * cos(radians(angle)) elif TestType == 'TU': distance = .707107 angle = 45 disp_x = distance * sin(radians(angle)) disp_y = distance * cos(radians(angle)) shift_features(infc, x_shift=disp_x, y_shift=disp_y)
import arcpy, os, sys from math import radians, sin, cos arcpy.env.workspace = "C:/data" arcpy.env.overwriteOutput = True def shift_features(in_features): with arcpy.da.UpdateCursor(in_features, ('SHAPE@XY', 'Test_Type')) as cursor: for row in cursor: if row[1] == 'MTU': distance = .3535535 elif row[1] == 'TU': distance = .707107 else: print row[1] distance = 0 cursor.updateRow([[row[0][0] + distance * sin(radians(45)), row[0][1] + distance * cos(radians(45))]]) return 0 #Variables for creating the XY event infc = r'Database Connections\Test.odc\Units' x_coords = "Easting" y_coords = "Northing" z_coords = "" out_Layer = "points_layer" Saved_Layer = "Point.shp" # Add a spatial reference to the new shapefile prjfile = "C:/data/LocalGrid.prj" spRef = arcpy.SpatialReference(prjfile) # Make the XY event layer... arcpy.MakeXYEventLayer_management(infc, x_coords, y_coords, out_Layer, spRef, z_coords) arcpy.CopyFeatures_management(out_Layer, Saved_Layer) shift_features(Saved_Layer) # Print feature count and messages print arcpy.GetMessages()
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.