def export_gcps(gcp_fc: str, id_field: str, odm_path: str):
"""
Export the gcps in feature class 'gcp_fc' to a csv at odm_path. The id/name
field in the feature class is specified by id_field.
"""
# odm format:
# ID,Y,X,Z
with open(odm_path, 'w') as file:
w = csv.writer(file, lineterminator="\n")
w.writerow(["id", "Y", "X", "Z"])
fields = [id_field, "SHAPE@Y", "SHAPE@X", "SHAPE@Z"]
with arcpy.da.SearchCursor(in_table=gcp_fc, field_names=fields) as cursor:
for row in cursor:
w.writerow(row)
arcpy.AddMessage(f"Wrote ODM/GCP Pro ground control point file to {odm_path}.")
if __name__ == "__main__":
gcp_fc = arcpy.GetParameterAsText(0) # the gcp feature class
id_field = arcpy.GetParameterAsText(1) # the field with gcp id/name
odm_gcp_filepath = arcpy.GetParameterAsText(2) # file to create with odm format
export_gcps(gcp_fc, id_field, odm_gcp_filepath)