2

I have two feature classes one with points one with polygons (in ArcGis 10.2). Now, I want to write into a String Field of the polygon layer a list of all the Point-FIDs that are within each polygon (often more than one, which is why join doesn't help). I was hoping that there is a possibility using Field Calculator and somehow concatenate the FIDs. But I don't know how to access the other feature class within the calculation code - is that possible? Also a Python code would be appreciated or anything else...

1

@PolyGeo's solution will work, but here is how to do it with just Spatial Join (and Add/Calculate Field if you need the FID, which needs to be copied to a real field for this to work). This will almost certainly be faster than using nested cursors.

  1. If you need a FID from a shapefile, use Add Field followed by Calculate Field to first copy the FID field to a new user-defined field, because Spatial Join does not allow you to join FID because it is not a real field.
  2. In the Spatial Join tool, select the ONE_TO_ONE relationship type (this still lets us concatenate all the spatially related records, just with one output record per target record).
  3. In the Field Map, for the field(s) that you want to get a concatenated list of values, right-click the output field and click Properties.
  4. Select 'Join' for the merge rule and enter the desired delimiter, e.g. a comma.

Beware that if there are many values being concatenated this can very easily go over field length limits, resulting in an error.

3

Use the Spatial Join tool with Match Option set to CONTAINS, instead of the Field Calculator.

Spatial Join (Analysis)

Summary

Joins attributes from one feature to another based on the spatial relationship. The target features and the joined attributes from the join features are written to the output feature class.

  • That was also my first idea. The problem is, where I have more than one point contained there is either the option of losing the FIDs of the second to n point or I take the one to many join but than I increase the number of polygons, which I also don´t want. – oddpodm Oct 15 '13 at 6:00
  • Is there any other option for me? – oddpodm Oct 15 '13 at 6:02
  • If there is a one-to-many relationship, you don't have a field that can be found in both tables and want to avoid redundancy, there's not much to do. See also resources.arcgis.com/en/help/main/10.2/index.html#//… – Antonio Falciano Oct 15 '13 at 8:18
1

This Python script should do what you are after once you have substituted your feature class and field names into it.

import arcpy

arcpy.MakeFeatureLayer_management(r"C:\temp\test.gdb\PolyFC", "PolyLayer")
arcpy.MakeFeatureLayer_management(r"C:\temp\test.gdb\PointFC", "PointLayer")

rows = arcpy.UpdateCursor("PolyLayer")

# iterate through each polygon in PolyLayer
for row in rows:
    polygon = row.SHAPE
    # intersect polygon geometry with points to get list of point OBJECTIDs
    arcpy.SelectLayerByLocation_management("PointLayer","INTERSECT",polygon)
    # use search cursor to read selected points
    selectedPoints = arcpy.SearchCursor("PointLayer")
    objectidList = ""
    for selectedPoint in selectedPoints:
        objectidList = objectidList + "," + str(selectedPoint.OBJECTID)
    # write OBJECTID list to the polygon attribute
    # called (PointIDs which is text field added)
    # lstrip() used to get rid of leading comma
    row.PointIDs = objectidList.lstrip(",")
    rows.updateRow(row)
del row,rows

To do the same thing using Data Access (arcpy.da) cursors, which were new at 10.1 and thus available to you, is slightly more complicated and probably gives little performance gain in this instance so I stayed with this code which will also work at 10.0.

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.