1

What I have is a buffer which is then used to select a number of point features which intersect the polygon. I would like to take that number and add the value to a table. The row where the value will need to be located corresponds with the name of the original feature class the buffer was created from.

import arcpy
from arcpy import env
import os
from os.path import join



arcpy.env.workspace = r'MyWorkspace'
updateTable = r'table'
shortField = "FieldName"
arcpy.MakeFeatureLayer_management("FieldName", "fieldname_layer")
fcs = arcpy.arcpy.ListFeatureClasses("*_Value", "POLYGON")
for fc in fcs:
    select = arcpy.SelectLayerByLocation_management("fieldname_layer", "INTERSECT", short)
    result = int(arcpy.GetCount_management(select).getOutput(0))
    print short.replace('Buffer_','') + " " + str(result)

So far the best I can come up with is printing the file name less the Buffer_ portion which precedes the name I need. I cannot wrap my head around how to go from there to updating only relevant records using the update cursor.

  • What version of arcmap are you using? At 10.1+, you have access to the data access module cursors. – Paul Jul 23 '14 at 19:00
  • Sorry, forgot to mention 10.1 – standard Jul 23 '14 at 19:02
0

At the moment your code looks like it would produce errors.

I think you should change it from:

fcs = arcpy.arcpy.ListFeatureClasses("*_Value", "POLYGON")
for fc in fcs:
    select = arcpy.SelectLayerByLocation_management("fieldname_layer", "INTERSECT", short)
    result = int(arcpy.GetCount_management(select).getOutput(0))
    print short.replace('Buffer_','') + " " + str(result)

to:

print short  # we cannot see what it is set to but it seems to be a layer or geometry object
fcs = arcpy.ListFeatureClasses("*_Value", "POLYGON")
for fc in fcs:
    select = arcpy.SelectLayerByLocation_management("fieldname_layer", "INTERSECT", short)
    result = int(arcpy.GetCount_management(select).getOutput(0))
    print result
    print short.replace('Buffer_','') + " " + str(result)

However, mainly I think you should look at Does ArcPy have a spatial search function for geometry? because I think it may provide you with a better starting point for your code.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.