In the image given below, solid lines are showing as road elements and points are showing as data collected for those road segments. I want to update road element id to the points shapefile. "Near" tool of ArcMap has almost solved this problem except for the points lying in red region (marked in the image) which is obvious as per the algorithm of this tool. In this red region, "Near" tool updates the id of BE road element but I want to update the id of AB and BC road elements respectively because those points belong to AB and BC road elements.
I agree with PredatorX that this is a bit of a weakness in the tool; if you have access to SQL Server 2008 or higher though you could just make a spatial query that would do exactly that. The example below should give you an idea and it will work with SQL Server Express which is free.
- select PointID,
- (select top 1 ID from [roads]
- where points.geometry.STDistance([roads].[Geometry])<= 100
- order by points.geometry.STDistance([roads].[Geometry])) as [RoadID]
- from points
The first line is just asking for the point ID. Lines 2 through 4 run the spatial expression (STDistance) that asks for the ID from the roads (line 2) that are within 100m or less (line 3 - my data sets are usually in UTM).
There are some other things you can add to bring in more information or as an example, draw lines from the points to the line in question so that you can visually see the relationship etc. Since this is just a sql query, it will auto-update as well which is nice in case someone starts moving your roads / dots or add more to one or the other. Including the <=100 is an important key though for performance. Otherwise things will be evaluated across the whole set many to many which may take some time depending on the size of your data sets.
I tried the following steps and it worked out. Say road shapefile and point data on road as road.shp and route.shp.
- Convert Road Polyline shapefile to Point Shapefile containing all points at vertices with Feature Vertices To Points (Data Management) tool, say this point shapefile as road_point.shp.
- Transfer Road id to from road_point.shp to route.shp with Near (Analysis) tool.
- Using UpdateCursor, update road id in all intermediate route points.
P.S. - Thanks for all the suggestions.