1

i like to create a standalone Python script that reads points(X,Y) from a fc, moves them in a user-defined distance and saves them in a new fc. I tried to do the steps with the data access module, but i dont know so far how to go on, especially with the part "moving the XY-points" .

import arcpy 
arcpy.env.overwriteOutput= 1 
arcpy.env.workspace = "workspace"
outputFC = "New"
inFC = "inFC"

arcpy.CreateFeatureclass_management("workspace","New","POINT")
cur = arcpy.da.InsertCursor("New", "SHAPE@XY")

point=arcpy.Point() 
cur2 =arcpy.da.SearchCursor("inFC",["SHAPE@XY"]) 
for row in cur2:
     print row
outputFC=row.GetValue("Shape")
point=outputFC.getPart() 
point.Y = pnt.Y
point.X = pnt.X  
array.add(point)  
feat.shape=array 
del row 
del cur 
del ins 
2

1 Answer 1

2

Try:

import arcpy

arcpy.env.overwriteOutput = 1
arcpy.env.workspace = r'D:\FileGeodatabase.gdb'
projection = r'D:\SWEREF99TM.prj'

infc = 'inpoints'
outfc = 'outpoints'
#distance to move points
xoffset=1000
yoffset=2000

arcpy.CreateFeatureclass_management(out_path=arcpy.env.workspace, out_name=outfc, geometry_type='POINT', spatial_reference=projection)
with arcpy.da.SearchCursor(infc,["SHAPE@XY"]) as scur:
    with arcpy.da.InsertCursor(outfc, ["SHAPE@XY"]) as icur:
        for row in scur:
            #create a list from the tuple SHAPE@XY which is retrieved by the search cursor
            xy=[element for tupl in row for element in tupl]
            #add xoffset and yoffset and create a tuple for use in the insertcursor
            xy2=((xy[0]+xoffset,)+(xy[1]+yoffset,),)
            #xy2 will for example be ((457591.43539999984, 6577837.267999999),)
            icur.insertRow(xy2)

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.