AnsweredAssumed Answered

Copy attribute fields from one feature class to New output feature class

Question asked by hmohamed_collin on Oct 30, 2018
Latest reply on Oct 30, 2018 by hmohamed_collin

I have the following script - it creates lines from two points feature classes,  Both point feature classes  have a field
# that identifies the center point ID to relate them.

I would like to modify this script so I can I get all the fields from the related points  relfc to spiderfc

# Description: Creates spider diagram lines from two point feature classes.
# Note: You need one point feature class for the center points and another
#       for the related points.  Both point feature classes must have a field
#       that identifies the center point ID to relate them.
# ---------------------------------------------------------------------------

# Import modules
import arcpy

# Local variables
cenfc = r"\\GIS\starburst.gdb\CenterPoints"
cenfld = "SiteID"
relfc = r"\\GIS\starburst.gdb\EV102218" " copy all fields from here
relfld = "USER_SiteID"
spiderfc = r"\\GIS\starburst.gdb\Spider"  #  to here

# Read in the ID values and coordinates of the center points
print "Reading in center point IDs and coordinates..."
cendict = {}
for row in arcpy.da.SearchCursor(cenfc, [cenfld, "SHAPE@XY"]):
  cendict[row[0]] = row[1]

# Read in the ID values and coordinates of the related points and create line geometry objects
print "Reading in related point IDs and coordinates..."
linelist = []
for row in arcpy.da.SearchCursor(relfc, [relfld, "SHAPE@XY"]):
  relxy = row[1]
  cenxy = cendict[row[0]]
  polyline = arcpy.Polyline(arcpy.Array([arcpy.Point(cenxy[0], cenxy[1]), arcpy.Point(relxy[0], relxy[1])]))
  linelist.append([row[0], polyline])

# Setup line feature for spider lines
print "Setting up line feature for spider lines..."
sr = arcpy.Describe(cenfc).spatialReference
tempfc = "in_memory/tempfc"
arcpy.CreateFeatureclass_management(tempfc.split("/")[0], tempfc.split("/")[1], "POLYLINE", "", "", "", sr)
field = arcpy.ListFields(cenfc, cenfld)
fielddict = {"SmallInteger": "SHORT", "Integer": "LONG", "Single": "FLOAT", "Double": "DOUBLE", "String": "TEXT", "Date": "DATE", "BLOB": "BLOB"}
fieldtype = fielddict.get(field[0].type)
if fieldtype == "TEXT":
  arcpy.AddField_management(tempfc, cenfld, fieldtype, "", "", str(field[0].length))
else:
  arcpy.AddField_management(tempfc, cenfld, fieldtype, "", "", "", "", "NULLABLE")

# Add spider lines
print "Adding spider lines..."
cursor = arcpy.da.InsertCursor(tempfc, [cenfld, "SHAPE@"])
for line in linelist:
  cursor.insertRow(line)
del cursor

# Save spider lines to spider line feature
print "Saving spider lines..."
arcpy.env.overwriteOutput = True
arcpy.CopyFeatures_management(tempfc, spiderfc)
arcpy.Delete_management(tempfc)

# All done
print "All done!"

 

Many thanks

Outcomes