Hello - this is a new task for me so please answer as if I'm in primary school. Shapefile contains 70 points which each need a point added at 25 and 50 m in each direction. What is the easiest way to do/automate this? So far I have only added x, y fields. Thanks.
Solved! Go to Solution.
Easiest way is probably to use Python:
# Name of the layer (if loaded in map) or path to the feature class / shape file
layer = "test"
# fields that are copied. First one has to be SHAPE@
fields = ["SHAPE@", "TextField"]
# read the original points
original_points = [row for row in arcpy.da.SearchCursor(layer, fields)]
with arcpy.da.InsertCursor(layer, fields) as cursor:
for point in original_points:
# create the 8 new coordinate pairs
coords = point[0].firstPoint
new_coords = [
[coords.X - 25, coords.Y],
[coords.X - 50, coords.Y],
[coords.X + 25, coords.Y],
[coords.X + 50, coords.Y],
[coords.X, coords.Y - 25],
[coords.X, coords.Y - 50],
[coords.X, coords.Y + 25],
[coords.X, coords.Y + 50],
]
for nc in new_coords:
# create a copy of the original point's attributes
new_point = list(point)
# change the copy's geometry
new_point[0] = arcpy.PointGeometry(arcpy.Point(nc[0], nc[1]))
# write copied point to shape file
cursor.insertRow(new_point)
Before
After (note that I only specified "TextField" to be copied)
Easiest way is probably to use Python:
# Name of the layer (if loaded in map) or path to the feature class / shape file
layer = "test"
# fields that are copied. First one has to be SHAPE@
fields = ["SHAPE@", "TextField"]
# read the original points
original_points = [row for row in arcpy.da.SearchCursor(layer, fields)]
with arcpy.da.InsertCursor(layer, fields) as cursor:
for point in original_points:
# create the 8 new coordinate pairs
coords = point[0].firstPoint
new_coords = [
[coords.X - 25, coords.Y],
[coords.X - 50, coords.Y],
[coords.X + 25, coords.Y],
[coords.X + 50, coords.Y],
[coords.X, coords.Y - 25],
[coords.X, coords.Y - 50],
[coords.X, coords.Y + 25],
[coords.X, coords.Y + 50],
]
for nc in new_coords:
# create a copy of the original point's attributes
new_point = list(point)
# change the copy's geometry
new_point[0] = arcpy.PointGeometry(arcpy.Point(nc[0], nc[1]))
# write copied point to shape file
cursor.insertRow(new_point)
Before
After (note that I only specified "TextField" to be copied)
Thank you Johannes, I will try this.
@JohannesLindner this was a brilliant solution. It took me a few times to play with it to get the fields right, but in the end it worked and your solution really impressed my team. A few made comments they wouldn't have thought of doing it that way, Very much appreciated. Apologies for taking a week to respond.