I am trying to write a Python code for creating a geoprocessing tool which will be added as a toolbox in ArcGIS Pro (v2.6).
The tool will
- Ask for a "Target point feature" as input for the (X, Y) coordinates
- Ask for a set of "Input point features" whose coordinates will be changed to the target's coordinates to stack together.
import arcpy
def move_points_to_target(target_feature, input_features):
# Get the coordinates of the target feature
with arcpy.da.SearchCursor(target_feature, ["SHAPE@XY"]) as cursor:
for row in cursor:
target_x, target_y = row[0]
# Loop through each input feature and move it to the target location
for feature in input_features:
with arcpy.da.UpdateCursor(feature, ["SHAPE@XY"]) as cursor:
for row in cursor:
# Update the coordinates of the input feature to match the target location
row[0] = (target_x, target_y)
cursor.updateRow(row)
def parameterInfo(self):
"""Define parameter definitions"""
# First parameter - Target Point Feature
target_param = arcpy.Parameter(
displayName="Target Point Feature",
name="target_feature",
datatype="DEFeatureClass",
parameterType="Required",
direction="Input"
)
# Second parameter - Input Point Features
input_param = arcpy.Parameter(
displayName="Input Point Features",
name="input_features",
datatype="DEFeatureClass",
parameterType="Required",
direction="Input",
multiValue=True
)
return [target_param, input_param]
if __name__ == "__main__":
# Get parameters from tool
target_feature = arcpy.GetParameterAsText(0)
input_features = arcpy.GetParameterAsText(1)
# Call the function to move the points to the target location
move_points_to_target(target_feature, input_features)
When I added it to my ArcGIS Pro toolbox, it does not ask for any inputs and the parameters seems to go back to default string.
I am just starting to learn how to make a geoprocessing tool.
What am I doing wrong?
Also,

