Generally, I am trying to find the # of features in one shapefile within 1000 feet of EACH feature in a second shapefile - and then populate a field in the first shapefile with that #.
More specifically, I trying to get a count of features in one shapefile (call it Practice_Stops.shp) that lie within a certain proximity (1000 feet) of EACH feature in a second shapefile (called Practice_Stops1.shp). I also want to restrict the count of features to only include those that also occurred within a certain time period, determined by the date attached to the feature in Practice_Sales1.shp.
I think this script is pretty close, but I have messed up some syntax and I don't know where:
Import arcpy module Practice_Sales1 = "Practice_Sales1" Practice_Stops = "Practice_Stops" I_Practice_Sales1_FID = "I_Practice_Sales1_FID" cursor = arcpy.SearchCursor("Y:\\mfriedma\\Practice_Sales1.shp", "") #Iterate through the rows in the cursor for row in cursor: #Select all features in Practice_Stops within 1000 feet of the current row in Practice_Sales1 arcpy.SelectLayerByLocation_management(Practice_Stops, "WITHIN_A_DISTANCE", row.POINT_X, row.POINT_Y, "1000 Feet", "NEW_SELECTION", "NOT_INVERT") #Within selected features, further select only those features that occurred within >365 days of the current row in Practice_Sales1 arcpy.SelectLayerByAttribute_management("lyr", "SUBSET_SELECTION", ' "stopdateindex" >=< row.getValue(saledateinndex) AND "stopdateindex" > (row.getValue(saledateinndex)- >365) ') #Returns the # of selected features count = int(arcpy.GetCount_management(Practice_Stops).getOutput(0)) #Replace row value in COUNT field of Practice_Sales1 with row.setValue("COUNT", count) row = rows.next()
Using model builder I have come up with the following:
The idea is that I go row by row in the Practice_Sales1.shp file, where the Iterate Row Selection tool conditions on date and location so as to select every row in the table. For each row, I use the Select Layer By Location tool to compare the Sale location to features in the Practice_Stops.shp file and select those within 1000 feet. This selection is then input for the Select Layer By Attribute tool, which refines the selection to only include features from the Practice_Stops file that occurred within a certain time proximity from "Value (2)" - the date field in each row of the Practice_Sales(1).shp file. Finally, I want to count all the features and populate a field in the row currently being iterated from the Practice.Sales.shp file. The problem I have is that the Get Count tool doesn't seem to give me output that I can populate a table field with - how can this be done.