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.

Nearest Feature Problem

  • 2
    I think this problem is not a weakness for near tool, I recommend create copy of line feature and delete EF line in new feature(copied version) and then calculate distance again with Near tool. – Predator X Nov 17 '15 at 13:55
  • Yes to add to what @Predator X is saying, it sounds like you would want to run the near tool on every individual line feature and for each point keep the closest feature from every run. – jbchurchill Nov 17 '15 at 13:59

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.

  1. select PointID,
  2. (select top 1 ID from [roads]
  3. where points.geometry.STDistance([roads].[Geometry])<= 100
  4. order by points.geometry.STDistance([roads].[Geometry])) as [RoadID]
  5. 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.

  • It isn't a weakness of the Near tool, and I believe that's what @PredatorX was saying. Rather, the behavior the question-asker is explaining arises from having all the lines, including BE, in the search space, in which case BE is of course nearer to those points than anything in AC. – Paulo Raposo Nov 23 '15 at 2:55

I tried the following steps and it worked out. Say road shapefile and point data on road as road.shp and route.shp.

  1. 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.
  2. Transfer Road id to from road_point.shp to route.shp with Near (Analysis) tool.
  3. Using UpdateCursor, update road id in all intermediate route points.

P.S. - Thanks for all the suggestions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.