import arcpy arcpy.env.overwriteOutput = True # Coords stored in a csv csv = r'G:\PROJECTS\Cedar\GeneralScripts\PyLibrary\temp_end_coords.csv' gdb = r'C:\Testing\test2.gdb' SR = 3418 # Factory code for state plane Iowa South # Get coords list as a tuple coords = [] with open(csv, 'r') as r: for line in r.readlines()[1:]: # skip headers coords.append(tuple(float(i) for i in line.split(',')[1:3])) # Create new feature class fc = arcpy.CreateFeatureclass_management(gdb, 'Points_test','POINT',spatial_reference=SR) with arcpy.da.InsertCursor(fc, ['SHAPE@']) as irows: for cord in coords: irows.insertRow((cord,)) print 'Done'
Sean, here's how you do it using the Calculate Field tool in 10.x.
Field: Shape
Expression:
pointMove(!SHAPE@!, !XNEW!, !YNEW!)
Code Block:
def pointMove(shape, x_value, y_value):
point = shape.getPart(0)
point.X = x_value
point.Y = y_value
return point
Parser: PYTHON_9.3
How did you get your coordinates? You could use arcpy point geometry or an insert cursor to build your point feature class. Here is an example of how you can do this by reading x,y coords from a csv and making a point feature class.
This is what the csv looks like:
Line_ID,X_Coord,Y_Coord,Length,NAME1,JOIN_FID,Type
1,2317355.49962,681731.016618,1315.40287879,SPICER AVENUE,1,Start
2,2317485.73951,676450.010776,5316.04898921,SPICER AVENUE,2,Start
3,2317627.9246,671135.874095,5294.36015714,190TH STREET,3,Start
4,2317355.49962,681731.016618,5376.75305576,170TH STREET,4,Start
I just split this list by commas to get the 2nd and third columns which are the x and y coordinates and created a tuple for the shape field. Here is how it can be done in 10.1.import arcpy arcpy.env.overwriteOutput = True # Coords stored in a csv csv = r'G:\PROJECTS\Cedar\GeneralScripts\PyLibrary\temp_end_coords.csv' gdb = r'C:\Testing\test2.gdb' SR = 3418 # Factory code for state plane Iowa South # Get coords list as a tuple coords = [] with open(csv, 'r') as r: for line in r.readlines()[1:]: # skip headers coords.append(tuple(float(i) for i in line.split(',')[1:3])) # Create new feature class fc = arcpy.CreateFeatureclass_management(gdb, 'Points_test','POINT',spatial_reference=SR) with arcpy.da.InsertCursor(fc, ['SHAPE@']) as irows: for cord in coords: irows.insertRow((cord,)) print 'Done'
I manually entered the coords in the attribute table.
import arcpy, os arcpy.env.overwriteOutput = True def CreatePoints(in_table, x_field, y_field, output, SR): # Create new feature class if arcpy.Exists(output): arcpy.Delete_management(output) arcpy.CreateFeatureclass_management(os.path.dirname(output), os.path.basename(output), 'POINT',spatial_reference=SR) # Get coords list irows = arcpy.InsertCursor(output) rows = arcpy.SearchCursor(in_table) for srow in rows: x = srow.getValue(x_field) y = srow.getValue(y_field) point = arcpy.Point(x,y) # Insert point objects into shape field row = irows.newRow() row.Shape = point irows.insertRow(row) print 'Done' if __name__ == '__main__': in_table = r'C:\Testing\test2.gdb\Roads_Points2' x_field = 'X_Coord' y_field = 'Y_Coord' output = r'C:\Testing\test2.gdb\Roads_Points3' SR = 3418 # Factory code for state plane Iowa South CreatePoints(in_table, x_field, y_field, output, SR)