I have a point features and polygon features. I need to:
- Select points that intersect the polygons
- Copy the points to a new shapefile
- Name this new point shapefile using an attribute of the polygon it intersects
Some of these polygons overlap each other. If one point intersects 2 polygons, this point would need to be included in two new shapefiles.
I'm very new to Python, and therefore I'm trying to achieve this by modifying the code below. I believe most of the basic pieces are there.
#import libraries
import arcpy, os, sys
#set current workspace
arcpy.env.workspace = r"C:\data"
arcpy.env.overwriteOutput = True
#assign variables
rawSurvey = "rawSurvey" #rawSurvey is the point file from the survey company
surface= "surface" # surface is the approach surface polygon
output = r"C:\Users\data\airspace_Working2.gdb"
#create cursor to cycle through each "Type" of surface
cursor = arcpy.da.UpdateCursor ('surface', "Type")
for row in cursor:
# selects the survey features intersecting (under) the surfaces
# Make a layer and select rawSurvey points which overlap each polygon
arcpy.MakeFeatureLayer_management ('rawSurvey', 'Tes_lyr')
arcpy.SelectLayerByLocation_management ('Tes_lyr', 'intersect', 'surface')
# If features matched criteria write them to new feature classes appSurvey_"type" based on which type of surface they ovelrap
matchcount = int(arcpy.GetCount_management ('Tes_lyr').getOutput(0))
if matchcount == 0:
print ('no features matched spatial and attribute criteria')
else:
arcpy.CopyFeatures_management ('Tes_Lyr', 'appSurvey')
#print the number of features matched
print (str(matchcount) + ' points were under the surfaces and written as appSurvey')