0

I have a point layer and a polygon layer, both containing hundreds of records. Each point feature can be within multiple polygon features (max. 4), and each polygon feature can contain multiple point features.

I would like to

  1. know which points are inside each polygon feature and based on that analysis,
  2. have a new field in the point attribute table identifying which polygon it's within. In case of a point being within multiple polygons the point attribute table would have multiple new fields.

I have used Near-tool which would work perfectly if a point could be only within one polygon (distance to the nearest polygon is 0 and the tool identifies one of the polygons), but in my case it's missing the other polygons a point is within.

1
  • Try Spatial Join tool
    – BERA
    Dec 6, 2017 at 20:25

1 Answer 1

5

Use Spatial Join tool.

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.

target_features: Point FC

join_features: Polygon FC

join_operation: One_To_Many

join_type: Keep_All

match_option: It's depend on your project( Contains, Completely Contains and Intersect are suitable based on the shape types)

  1. Look at the Pivot table. It can be help you without scripting.

  2. Spatial join output remains join and target id's. Point id's(JOIN_FID) and Polygon id's(TARGET_FID).For many reasons (datamodel standards, field number limitations, data management, etc) using one field for each record is better than multiple fields.

The below code writes polygon id's related to each point in a record.The result prints in a string field (in this case "test_1"). You can change this code easily.Just create multiple fields with this code. But if you have many points with many polygon intersect each other, you faced with many fields.

import arcpy,collections
arcpy.env.workspace = "D:/dissolve.gdb"
fc = "myjoin2"
l = []
valueDict1 = collections.defaultdict(list)
tableFields = ["JOIN_FID","TARGET_FID"]
joinFields = ["JOIN_FID","TARGET_FID","test_1"]
with arcpy.da.SearchCursor(fc, tableFields) as searchRows:
    for searchRow in searchRows:
        KeyValue = searchRow[0]
        valueDict1[KeyValue].append(searchRow[1])
        l.append(searchRow[0])
valueDict2 = collections.defaultdict(list)
print valueDict1

with arcpy.da.UpdateCursor(fc, joinFields) as curjoin:
    for rowjoin in curjoin:
        KeyValue2 = rowjoin[0]
        if KeyValue2 not in l:
            rowjoin[2] = 0
            curjoin.updateRow(rowjoin)
        for key1 in valueDict1:
            if KeyValue2 == key1:
                codelinestr = '-'.join(str(b) for b in valueDict1[key1])
                rowjoin[2] = codelinestr
                # rowjoin[2] = len(valueDict1[key1])
                curjoin.updateRow(rowjoin)
5
  • This is a good advice and the tool does the job. The only problem is that instead of creating new fields (one field per polygon a point is in), it multiplies the records which isn't desirable for further analysis with the data. Any advice on how to convert these records to fields?
    – Sn0W
    Dec 6, 2017 at 20:44
  • 1
    use summarize to summarize a point field based on a polygon field. In the table of content.Right click to a field. Select summarize.
    – BBG_GIS
    Dec 6, 2017 at 21:00
  • @P.Kortsalo, that's what spatial join does, there will be one point record in the output for every polygon that the original intersects. If you want to add new fields representing each and every polygon the point is in be prepared to do some scripting. To get a table representing all the polygons a point is near use Generate Near Table which will populate a row for each instance of a polygon within a given tolerance (or all polygons with a distance), from there you would need to do some scripting to copy the matching rows into new fields in your point table. Dec 6, 2017 at 21:03
  • @ wetland: Summarize counts how many point records match each polygon. Unfortunately it won't help with organizing the output table into more useful form in this case.
    – Sn0W
    Dec 6, 2017 at 22:23
  • @ Michael Stimson: I had a feeling this analysis might require scripting. Thank you for your tips, I'll try and work this out.
    – Sn0W
    Dec 6, 2017 at 22:25

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.