I am trying to assign a number value field to different habitat shapefile polygons that is the number of other habitat type shapefiles that overlap or share a boundary. For example, I have 5 different habitat type shapefiles. I want each habitat polygon within each habitat shapefile to have a value indicating the number of different habitats that it touches. So if a particular wetland polygon touches a forest polygon and a beach polygon, that wetland polygon would receive a score of 2. Thanks!

2 Answers 2


Pat, you should be able to do this with a series of iterations through each polygon. You can get a list of ID's, then using select statements get the touching polygons - then using a search cursor, figure out what the touching polygon attributes are. Something like this. This is only a example and template of the workflow and will produce a python dictionary of all the habitats that intersect the source polygon.


habitats = {}
row, cur = None, None
cur = arcpy.SearchCursor(in_fc)
idlist = []
for row in cur:


for id in idlist:
    arcpy.SelectLayerByAttribute_management("lyr1", "NEW_SELECTION", "OBJECTID = " + str(id))
    arcpy.SelectLayerByLocation_management("lyr2", "INTERSECT", "lyr1", "", "NEW_SELECTION")
    habitats[id] = []
    cur,row = None, None
    cur = arcpy.SearchCursor("lyr2")
    for row in cur:

For a rather labour intensive option, you could make a field for each other habitat in each shapefile, then use a select by location against each habitat type, and calculate the selected features value as 1 in each corresponding habitat field, and then add a column that adds together the values of each other habitat type. so in your forest table, you'd have a field for wetland; water; grassland etc., each with a value of either 0 or 1 depending on if that habitat touches, and a total column that counts the number of 1's for each polygon using the field calculator (i.e. = [wetland] + [water] +....).

  • Thanks TDavis. This is how I was going to approach it however you're right it would be quite labour intensive. I was hoping there was a tool that would do this in one go by adding a field to each feature table with the number of other features it touches. May have to do it the long way, if there is no other way. Unfortunately I'm not familiar enough with scripting to write something in Python.
    – Pat
    Jan 15, 2014 at 17:40
  • you could use a union, if you set your tables up properly, and would join the attributes of all overlapping features, which you could use to pull out habitat occurences in each polygon in the combined shapefiles. this approach wouldn't capture adjacent features without some pre-emptive buffering though. not sure this approach would save that much time over the manual selection approach
    – TDavis
    Jan 15, 2014 at 18:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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