Copy/paste this script into the Python window, edit the first 5 lines, run it (this edits your feature class, make a backup!)
polygons = "TestPolygons" # name of the polygon layer / path to the fc
points = "TestPoints" # name of the point layer / path to the fc
poly_field = "IntegerField1" # name of the common field in the polygon fc
point_field = "IntegerField1" # name of the common field in the point fc
do_all = False # False: only non-intersecting points are moved. True: all points are moved to the centroid
# read the polygons into a dictionary {CommonField: Geometry}
poly_shapes = dict([row for row in arcpy.da.SearchCursor(polygons, [poly_field, "SHAPE@"])])
# Start editing the point fc
with arcpy.da.UpdateCursor(points, [point_field, "SHAPE@"]) as cursor:
for key, shp in cursor:
try:
# get the corresponding polygon
poly_shp = poly_shapes[key]
# check if the point has to be moved
if do_all or shp.disjoint(poly_shp):
try:
# set the point's geometry to the polygon's centroid
cursor.updateRow([key, poly_shp.centroid])
except:
print(f"Couldn't get the centroid of {key}, sklipping")
except KeyError:
print(f"No polygon found for {key}, skipping")
Before:
With do_all = False
With do_all = True
Have a great day!
Johannes