import arcpy from arcpy import env env.workspace = "C:/Temp/Python/test.gdb" fc = "Parker_R6_Manhole_1" pnt = arcpy.Point() rows = arcpy.UpdateCursor(fc) for row in rows: pnt.X = row.GPS_X pnt.Y = row.GPS_Y row.shape = pnt rows.updateRow(row) del row, rows
import arcpy from arcpy import env env.overwriteOutput = True env.workspace = r"C:\Temp\Python\test.gdb" fc = "swManhole" fc2 = "swGravityMain" pnt = arcpy.Point() # Move Manholes to GPS location rows = arcpy.UpdateCursor(fc) for row in rows: pnt.X = row.POINT_X pnt.Y = row.POINT_Y row.shape = pnt rows.updateRow(row) del row, rows # Convert Main endpoints to points feature class arcpy.FeatureVerticesToPoints_management(fc2, "Main_EndPts", "END") # Find all Main endpoints within 5 feet of manholes arcpy.Near_analysis("Main_EndPts", fc, "5") # Create a layer of all Main endpoints within 5 feet of manholes lyr = arcpy.MakeFeatureLayer_management("Main_EndPts", "Main_EndPts_Lyr", "NEAR_DIST > 0") list = [] # Append X & Y values of Main endpoints to list rows = arcpy.SearchCursor(lyr) for row in rows: list.append(float(row.shape.centroid.X) + float(row.shape.centroid.Y)) del row, rows OBJECTIDs = [] # Find OBJECTIDs of the Mains that need to be moved rows = arcpy.SearchCursor(fc2) for row in rows: geom = row.shape XY = float(geom.lastPoint.X) + float(geom.lastPoint.Y) if XY in list: OBJECTIDs.append(row.OBJECTID) del row, rows arcpy.Delete_management("Main_EndPts") print OBJECTIDs
def update(): fc = r"C:\temp\python\test.gdb\Vehicle" pnt = arcpy.Point() rows = arcpy.UpdateCursor(fc) for row in rows: pnt.X = row.GPS_X pnt.Y = row.GPS_Y row.shape = pnt rows.updateRow(row) del row, rows
Hi Alan,
You can place the code within a function and execute it using the field calculator. Ex:def update(): fc = r"C:\temp\python\test.gdb\Vehicle" pnt = arcpy.Point() rows = arcpy.UpdateCursor(fc) for row in rows: pnt.X = row.GPS_X pnt.Y = row.GPS_Y row.shape = pnt rows.updateRow(row) del row, rows
Be sure that you have 'Python' checked at the top of the field calculator, and you will want to specify 'update()' under the Pre-logic script code dialog. Ex:
[ATTACH=CONFIG]33269[/ATTACH]
Alan and Jake,
The Python script works great, but unfortunately I have some Null Values in my GPS Data(we had to digitize some data). Is there any way to use the python script you provided and have it leave all Null or blank values alone? When I use the python script it will remove any points with no GPS data thus I'm losing points, any help would be appreciated thank you!