What does Copy Feature tool returns?

321
1
Jump to solution
05-11-2022 11:59 AM
YinghongLi1
Occasional Contributor

I used this syntax to do copy feature task:

lineFeature=arcpy.management.CopyFeatures(lyr, "SplitFeature")

I do not know what data type is the lineFeature after the copy feature tool finishes running.

I can use list fields function on it and i can get count of the feature from it.  

lineCount = arcpy.GetCount_management(lineFeature)

fields=arcpy.ListFields(lineFeature)
for field in fields:
      print("{0} is a type of {1} with a length of {2}".format(field.name, field.type, field.length))

Now I want to get values from the fields.  How should I do it?  Do i need to use a search cursor?  Then what do I use to search?

Thanks

 

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
YinghongLi1
Occasional Contributor

I think i found a solution to my question.  Here is the code:

arcpy.env.overwriteOutput = True
arcpy.env.workspace = 'in_memory'

global lineFeature
global pointFeature

aprx = arcpy.mp.ArcGISProject("CURRENT")
currentmap = aprx.activeMap
layers = currentmap.listLayers()
for lyr in layers:
if lyr.getSelectionSet():
print (lyr.name)
oid =lyr.getSelectionSet()
print (oid)
desc = arcpy.Describe(lyr)
if desc.shapeType == "Polyline":
print ("Polyline")
lineFeature=arcpy.management.CopyFeatures(lyr, "SplitFeature")
elif desc.shapeType == "Point":
pointFeature =arcpy.management.CopyFeatures(lyr, "PointFeature")
print ("Point")

fields=arcpy.ListFields(lineFeature)
cursor=arcpy.SearchCursor(lineFeature)
for row in cursor:

printf=str(row.getValue("DRAINAGE_ID"))
print("DRAINAGE_ID=="+printf)
del row, cursor

View solution in original post

0 Kudos
1 Reply
YinghongLi1
Occasional Contributor

I think i found a solution to my question.  Here is the code:

arcpy.env.overwriteOutput = True
arcpy.env.workspace = 'in_memory'

global lineFeature
global pointFeature

aprx = arcpy.mp.ArcGISProject("CURRENT")
currentmap = aprx.activeMap
layers = currentmap.listLayers()
for lyr in layers:
if lyr.getSelectionSet():
print (lyr.name)
oid =lyr.getSelectionSet()
print (oid)
desc = arcpy.Describe(lyr)
if desc.shapeType == "Polyline":
print ("Polyline")
lineFeature=arcpy.management.CopyFeatures(lyr, "SplitFeature")
elif desc.shapeType == "Point":
pointFeature =arcpy.management.CopyFeatures(lyr, "PointFeature")
print ("Point")

fields=arcpy.ListFields(lineFeature)
cursor=arcpy.SearchCursor(lineFeature)
for row in cursor:

printf=str(row.getValue("DRAINAGE_ID"))
print("DRAINAGE_ID=="+printf)
del row, cursor

0 Kudos