Most geoprocessing tools, if run from within ArcMap, operate on the selected set of features by default if the input is a feature layer with an active selection. I don't think Feature Set is the right parameter type in this situation, so try Feature Layer.I would probably use Make Feature Layer first to capture the set of selected features and then iterate over the features in the created layer using a search cursor.In your loop:
- Use select by location with the points layer as the input layer and the shape (geometry object) of the current house as the selecting layer.
- Use Copy Features, which operates on the selected set of features, to save the selected points to their own feature class, using the house number attribute to appropriately name each feature class
example script:## Parameters:
## 0 (input) - Input Features (Feature Layer)
## 1 (input) - Selecting Features (Feature Layer)
## 2 (input) - Selecting Features Field (Field, obtained from Selecting Features)
## 3 (input) - Output Workspace (Workspace)
## 4 (output, derived) - Output Feature Class(es) (Feature Class, multivalue)
import arcpy, os
from arcpy import env
env.overwriteOutput = True
inputFeatures = arcpy.GetParameterAsText(0)
selectingFeatures = arcpy.GetParameterAsText(1)
selectingFeaturesFieldName = arcpy.GetParameterAsText(2)
outputWorkspace = arcpy.GetParameterAsText(3)
env.workspace = outputWorkspace
arcpy.AddMessage("Current workspace: %s" % outputWorkspace)
inputLayer = arcpy.MakeFeatureLayer_management(inputFeatures)
selectingLayer = arcpy.MakeFeatureLayer_management(selectingFeatures)
desc = arcpy.Describe(inputLayer)
inputLayerName = desc.name
desc = arcpy.Describe(selectingLayer)
selectingLayerName = desc.name
selectingLayerShapeFieldName = desc.featureClass.shapeFieldName
outputFCs = []
rows = arcpy.SearchCursor(selectingLayer)
for row in rows:
arcpy.management.SelectLayerByLocation(inputLayer, "HAVE_THEIR_CENTER_IN", row.getValue(selectingLayerShapeFieldName), "", "NEW_SELECTION")
count = int((arcpy.GetCount_management(inputLayer))[0])
rowValue = str(row.getValue(selectingFeaturesFieldName))
arcpy.AddMessage("%d feature(s) of layer %s found in layer %s (%s: %s)" % (count, inputLayerName, selectingLayerName, selectingFeaturesFieldName, rowValue))
if (count > 0):
outputFC = inputLayerName + "_" + rowValue
arcpy.AddMessage("Copying selected feature(s) to %s" % outputFC)
arcpy.CopyFeatures_management(inputLayer, outputFC)
outputFCs.append(outputFC)
del row, rows
arcpy.SetParameterAsText(4, ";".join(outputFCs))