Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I've got a point featureclass, and I'm trying to individually intersect each feature with a polygon featureclass to get some information about which polygon each feature is in. I did one intersect with an entire point featureclass against a polygon featureclass, which was straightforward, but I'm not grasping the model for doing the individual intersections. First attempt below:

# -*- coding: utf-8 *-*
# Name: IntersectingPolygon.py
# Description: Find intersecting polygon on a feature by feature basis

# Import arcpy and set path to data
import arcpy
import csv
arcpy.env.workspace = "C:/dev/FGDBs/test.gdb"
intersecting_polygon_layer = 'pg_lyr'
feature_layer = 'feature_lyr'
test_feature = 'some_feature'

# Make a layer of the polygons
arcpy.MakeFeatureLayer_management('polygons', intersecting_polygon_layer)

feature_rows = arcpy.SearchCursor(test_feature)

count_features = 0
for feature_row in feature_rows:
    # This line fails, I think because you can't make a layer this way
    arcpy.MakeFeatureLayer_management(feature_row, feature_layer)
    arcpy.SelectLayerByLocation_management(intersecting_polygon_layer, 'intersect', feature_row)
    polygon_rows = arcpy.SearchCursor(intersecting_polygon_layer)
    print 'Feature Globalid:',feature_row.getValue('globalid')
    for polygon_row in polygon_rows:
        print '\tPolygon objectid:',polygon_row.getValue('objectid')

    if count_features > 5:
        break
    count_features = count_features + 1
share|improve this question
    
Would you be able to include a picture to illustrate why doing the "entire point featureclass against a polygon featureclass" does not meet your requirements, please? You can certainly do the individual intersections by using the point geometries in place of the point feature layer but I am not clear why, in this instance, you might be wanting to. –  PolyGeo Jul 7 at 22:10
    
Say for example that the points are homes and the polygons are districts, and I want to know which district each home is in, not which homes are in districts. –  Nathan Spears Jul 7 at 22:14

1 Answer 1

up vote 4 down vote accepted

To do this I would use the Intersect (Analysis) tool.

The ArcPy code will be:

import arcpy
homesFC = <your path to input Homes>
districtsFC = <your path to input Districts>
homesWithDistrictFC = <your path to output>

arcpy.Intersect_analysis ([homesFC, districtsFC], homesWithDistrictFC)
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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