import arcpy
import os
arcpy.env.overwriteOutput = True
def CreateLinkFeatures(in_text_file, in_data):
sr = arcpy.Describe(in_data).spatialReference
features = []
f = open(in_text_file, "r")
for line in f.readlines():
points = line.strip().split()
point1 = arcpy.Point(float(points[1]), float(points[2]))
point2 = arcpy.Point(float(points[3]), float(points[4]))
features.append(arcpy.Polyline(arcpy.Array([point1, point2]), sr))
f.close()
result = arcpy.CopyFeatures_management(features, in_data + "_links")
return result.getOutput(0)
if __name__ == "__main__":
arcpy.CopyFeatures_management(r"C:\data\Tutorial.gdb\Parcels", r"C:\data\Tutorial.gdb\Parcels_copy")
links_file = r"C:\data\TF_links.txt"
tf_link_features = CreateLinkFeatures(links_file, r"C:\data\Tutorial.gdb\Parcels")
try:
arcpy.TransformFeatures_edit(r"C:\data\Tutorial.gdb\Parcels_copy", tf_link_features)
print(arcpy.GetMessages())
except arcpy.ExecuteError as aex:
print(arcpy.GetMessages(2))
except Exception as ex:
print(ex.args[0])