Can you put ArcGIS geoprocessing tools such as arcpy.SelectLayerByLocation_management()
or arcpy.MakeFeatureLayer_management()
into the code block of the ArcGIS Field-calculator (ArcGIS Desktop 10.4)?
Answer
I generated random points inside 4 polygons shapefile, using field "Points_Cnt". The source of polygons is "C:\FELIX_DATA\SCRARCH\fish_net.shp":
The result of this field caluclator expression on a new field "RESULT":
mxd = arcpy.mapping.MapDocument("CURRENT")
LR=arcpy.mapping.ListLayers(mxd)[0]
d=arcpy.Describe(LR)
def getPoints(fid):
arcpy.MakeFeatureLayer_management ("C:/FELIX_DATA/SCRARCH/fish_net.shp","A",'"FID" ='+str(fid))
arcpy.SelectLayerByLocation_management(LR,"INTERSECT","A")
nSel=len(d.FIDset.split(';'))
return nSel
getPoints( !FID!)
Confirms that it is possible to use tools in field calculator.
No comments:
Post a Comment