Solved! Go to Solution.
#import required modules import arcpy from arcpy import env #specify workspace env.workspace = "C:/Columbus_OH_LiDAR_2011/Canopy.gdb" #specify source geometry points = "C:/Columbus_OH_LiDAR_2011/Canopy.gdb/Extract_BS868661" #create comparison geometry feature class ind_trees = arcpy.CreateFeatureclass_management(env.workspace, "ind_trees", "POINT", points, "DISABLED", "SAME_AS_TEMPLATE", points) #find nearest features arcpy.Near_analysis(points, ind_trees) #create update cursor Ucur = arcpy.updateCursor(points, "", "", "", "HEIGHT D") #declare variable used to assign tree ID number x = 0 for row_u in Ucur: #tree ID assigned where no near feature was found within search radius if row_u.NEAR_DIST > row_u.HEIGHT / 4: row_u.TREE_NUM = x Ucur.updateRow(row_u) x = x + 1 #assign tree ID from near feature else: Scur = arcpy.SearchCursor(ind_trees) for row_s in Scur: if row_s.OBJECTID == row_u.NEAR_FID: row_u.TREE_NUM = row_s.TREE_NUM Ucur.updateRow(row_u) del row_s del Scur #insert a copy of current update cursor row object to comparison geometry feature class Icur = arcpy.InsertCursor(ind_trees) Nrow = Icur.newRow() Nrow.Shape = row_u.Shape Nrow.PointCount = row_u.PointCount Nrow.ORIG_FID = row_u.ORIG_FID Nrow.Z = row_u.Z Nrow.RASTERVALU = row_u.RASTERVALU Nrow.HEIGHT = row_u.HEIGHT Nrow.TREE_NUM = row_u.TREE_NUM Nrow.NEAR_FID = row_u.NEAR_FID Nrow.NEAR_DIST = row_u.NEAR_DIST Icur.insertRow(Nrow) del Icur del row_u del Ucur
#import required modules import arcpy from arcpy import env #specify workspace env.workspace = "C:/Columbus_OH_LiDAR_2011/Canopy.gdb" #specify source geometry points = "C:/Columbus_OH_LiDAR_2011/Canopy.gdb/Extract_BS868661" #create comparison geometry feature class ind_trees = arcpy.CreateFeatureclass_management(env.workspace, "ind_trees", "POINT", points, "DISABLED", "SAME_AS_TEMPLATE", points) #find nearest features arcpy.Near_analysis(points, ind_trees) #create update cursor Ucur = arcpy.updateCursor(points, "", "", "", "HEIGHT D") #declare variable used to assign tree ID number x = 0 for row_u in Ucur: #tree ID assigned where no near feature was found within search radius if row_u.NEAR_DIST > row_u.HEIGHT / 4: row_u.TREE_NUM = x Ucur.updateRow(row_u) x = x + 1 #assign tree ID from near feature else: Scur = arcpy.SearchCursor(ind_trees) for row_s in Scur: if row_s.OBJECTID == row_u.NEAR_FID: row_u.TREE_NUM = row_s.TREE_NUM Ucur.updateRow(row_u) del row_s del Scur #insert a copy of current update cursor row object to comparison geometry feature class Icur = arcpy.InsertCursor(ind_trees) Nrow = Icur.newRow() Nrow.Shape = row_u.Shape Nrow.PointCount = row_u.PointCount Nrow.ORIG_FID = row_u.ORIG_FID Nrow.Z = row_u.Z Nrow.RASTERVALU = row_u.RASTERVALU Nrow.HEIGHT = row_u.HEIGHT Nrow.TREE_NUM = row_u.TREE_NUM Nrow.NEAR_FID = row_u.NEAR_FID Nrow.NEAR_DIST = row_u.NEAR_DIST Icur.insertRow(Nrow) del Icur del row_u del Ucur
#import required modules
import arcpy
from arcpy import env
#specify workspace
env.workspace = "C:/Columbus_OH_LiDAR_2011/Canopy.gdb"
#specify source geometry
points = "C:/Columbus_OH_LiDAR_2011/Canopy.gdb/Extract_BS868661"
#create comparison geometry feature class
ind_trees = arcpy.CreateFeatureclass_management(env.workspace, "ind_trees", "POINT", points, "DISABLED", "SAME_AS_TEMPLATE", points)
#declare variable used to assign tree ID number
x = 0
sCur2=arcpy.SearchCursor(points, "", "", "", "HEIGHT D")
#get nearest for each point
for row in Scur2:
#Create feature layer for current point:
arcpy.MakeFeatureLayer_management(points, "TargetPoint_lyr", '"FID" = '+str(row.FID))
#find nearest feature within a search distance (for current point only)
arcpy.Near_analysis("TargetPoint_lyr", ind_trees, row.HEIGHT / 4)
del row
del Scur2
#create update cursor
Ucur = arcpy.updateCursor(points, "", "", "", "HEIGHT D")
for row_u in Ucur:
#tree ID assigned where no near feature was found
if row_u.NEAR_FID == -1:
row_u.TREE_NUM = x
Ucur.updateRow(row_u)
x = x + 1
#assign tree ID from near feature
else:
Scur = arcpy.SearchCursor(ind_trees)
for row_s in Scur:
if row_s.OBJECTID == row_u.NEAR_FID:
row_u.TREE_NUM = row_s.TREE_NUM
Ucur.updateRow(row_u)
del row_s
del Scur
#insert a copy of current update cursor row object to comparison geometry feature class
Icur = arcpy.InsertCursor(ind_trees)
Nrow = Icur.newRow()
Nrow.Shape = row_u.Shape
Nrow.PointCount = row_u.PointCount
Nrow.ORIG_FID = row_u.ORIG_FID
Nrow.Z = row_u.Z
Nrow.RASTERVALU = row_u.RASTERVALU
Nrow.HEIGHT = row_u.HEIGHT
Nrow.TREE_NUM = row_u.TREE_NUM
Nrow.NEAR_FID = row_u.NEAR_FID
Nrow.NEAR_DIST = row_u.NEAR_DIST
Icur.insertRow(Nrow)
del Icur
del row_u
del Ucur