I have been asked to select point features that fall into a polygon in its own shapefile then copy the points selected to a new shapefile. There are around 300 shapefiles with an indiviidual polygon. Although only a very beginnner in python i thought it would be possible to automate the process.
I based my script of one found on this site but cannot get it too work. Im not sure if it is fit for purpose or not.
We are using arcmap 9.3 so no arcpy unfortunately.
# Import system modules import sys, string, os, arcgisscripting # Create the Geoprocessor object gp = arcgisscripting.create() # Load required toolboxes... gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx") # Script arguments... Layer_A = sys.argv # polygon Layer_B = sys.argv # points outfolder = sys.argv basename = sys.argv # create search Cursor that ref the features in layer B rows = gp.searchcursor(Layer_B) row = rows.next() # Create a numbering system for new output files filenum = 0 while row: # Report a message back to the user about progress gp.addmessage("Creating Selection #" + str(filenum) + " from " + Layer_A) # Create a feature layer to cycle through selection features fidvalue = row.GetValue("FID") gp.MakeFeatureLayer(Layer_B,"cursor_lyr","FID =" + str(fidvalue)) # Process: Select Layer By Location... gp.SelectLayerByLocation_management(Layer_A, "INTERSECT", "cursor_lyr", "", "NEW_SELECTION") outname = outfolder + "\\" + basename + str(filenum) # Process: Copy Features... gp.CopyFeatures_management(Layer_A, outname, "", "0", "0", "0") #iterate the output file number filenum = filenum + 1 #go to next row row = rows.next