I have a point file with observation data, and a line file with segmented transect lines. I'm trying to come up with a count of observations on each line segment. The attached map shows that some line segments have more than one observation, while others have no observations (lines_points_map.JPG). Using the Spatial Join Tool from the Analysis/Overlay Toolbox, I specified the line layer as my target input, observation point layer as the join input and choose a "one to one" join operation with a match option of "closest". Because the default count field kept returning a value of 1 for every record, I added a Value field to my observation point layer and assigned a value of 1 to each record in the observation layer. I tried running the Spatial Join tool again, this time using the field map to add a new field called ObsCount and specified a merge rule to sum the Value field from the observation layer (spatialjoindialogue.JPG). So each line segment should have a count of all observations in the ObsCount field. Or so I thought. Each record had a value of 1 (spatialjoinoutput.JPG).
When I use the joins & relate option available by right clicking on my line segment layer in the table of contents (toc_join.JPG) and select the "Join data from another layer based on spatial location" option, specifying my observation layer as the join layer and selecting "closest" as the join option (toc_joindialogue.JPG), my output file gives me the expected results in the Count field (toc_joinoutput.JPG).
I'm trying to add the spatial join into a larger geoprocessing flow, so ideally I'd like to be able to achieve this using a python script. Since I can't get the proper results using the Spatial Join analysis tool manually, I don't think using arcpy.SpatialJoin_analysis in a script would work. I haven't been able to find python code for the spatial join achieved through the table of contents joins & relates menu. I'm a python novice, so I'm sure there's a way to do it....I'm just kind of stumped right now. If anyone has any suggestions, I would really love to hear them.
Thanks