I have 2 layers, one representing streets, and one representing pipes. The pipe layer has a street field that I want it to be automatically filled (I want the pipe to show the street that it's on) I tried performing a spatial join based on 'closest' but I encountered the following problem: many pipes never intersect the center of the streets they're on (they are usually parallel), and, at the spatial join, those respective pipes don't get the needed data from the street they go along but from the ones that are perpendicular (cause they intersect the pipes, so they have one point that is closest).
I've face a similar problem and created a programmatic tool that would:
Shorten my street centerline. Here I would take it from .4 to .6 for example (in this case I would consider only the dashes)
I would buffer it for a small ammout, let's say 10% of the original street lenght. Imagine that you are buffering only the dashes in the schematic "drawing above".
Try to intersect it with pipes.
You can repeat 2 and three until you've found a certain number of pipes. The idea for shortening the center line is to eliminate the cases where you other perpendicular lines that you do not want.
Check a less ugly scheme:
Another approach is to just buffer, intersect and compare the angles. You can safely set a threshold of what "parallel" is. You will never have straight and parallel lines in this cases (some will be parallel, but that depends on digitizing). You take only the pipes that have similar angles to your centerline.
I wrote a tool that does exactly this. It's called Spatial Angle Join.
Joining line features based on their polar angle
Polar angle: The angle the line would form with the equator if it was extended to intersect it.
- Calculate the polar angle of the pipes.
- Calculate the polar angle of the roads.
- Spatially join the road lines to the pipe lines within a radius (one to many).
- Find the difference between the pipe angles and the joined road angles.
- Keep the road that had the smallest difference in polar angle.
Joining road features with sanitary mains. A road pointing north will have an angle of 90 degrees with respect to the equator and a road pointing east will have an angle of 0 degrees because it is parallel to the equator. The sewers mostly run parallel to the road so if there is a sewer with an angle of 85 degrees it will be matched with the road going north because 85 degrees is closer to 90 degrees than 0 degrees.
Joining the color of the roads to the sanitary mains.
You could try using the Near geoprocessing tool:
Determines the distance from each feature in the input features to the nearest feature in the near features, within the search radius.