snapping stop points to streets

4649
11
08-15-2010 10:28 AM
sarmadhussain
New Contributor
Hello
I am totally new to arcgis programming. I get a gps coordinates for vehicles and these coordinates are not exactly on the road, they are mostly off by 4-5 meters. When i load my network dataset and try to find the route based on these points, the solver is not able to snap the points to any of the roads. Is there a threshold value in the settings which i can specify to get the points to snap to the road ?

Thanks
macher
0 Kudos
11 Replies
MichaelRice
New Contributor III
How are you doing this programmatically? Are you using the Network Analyst API (e.g., the NAClassLoader or NALocator objects)? If so, I can show you how to do snapping. If not, please let me know what API you are working with.
0 Kudos
sarmadhussain
New Contributor
yes i am using the network analyst api and i would definitely appreciate your help in not only snapping the points to the roads but also to optimize my purely noob and unoptimized code.

thanks
0 Kudos
MichaelRice
New Contributor III
Feel free to post any of your code in this thread for further discussion.

The most basic programming pattern used to load data into a network analysis layer is to use the NAClassLoader. See here for more detail and some simple code samples: http://resources.esri.com/help/9.3/ArcGISDesktop/ArcObjects/esriNetworkAnalyst/NAClassLoader.htm

The link above will provide code samples in several programming languages showing the most basic way to use the NAClassLoader for loading data from an input source feature class. If you want to enable snapping, then use the INAClassLoader2 interface (look under the 'Interfaces' section at the above link, and click on 'INAClassLoader2' to see more information).

In your case, if you want to snap directly to the network, then simply set INAClassLoader2.SnapToNetwork = True before calling Load.
0 Kudos
sarmadhussain
New Contributor
Unfortunately i am stuck with version 9.1 and it does not contain INAClassLoader2 interface. Looking forward to your help.
0 Kudos
MichaelRice
New Contributor III
Okay, then let's try a different approach. The other technique is a little more involved, so I would ask that you first view the Network Analyst presentation from the 2007 ESRI Developer Summit:

http://edn.esri.com/index.cfm?fa=media.detail&media=74

This details a lot of the basic Network Analyst API, as well as some of the most common Network Analyst programmatic workflows. When watching this, pay special attention to the part (about 1/3 of the way through) where we discuss finding NALocations (the slide title is "Find NALocation Using NALocator"). Here, we discuss how to use the INALocator.QueryLocationByPoint method to locate an individual input point on the network. This method returns a parameter called 'outputPoint', which represents the actual point location on the network that your input point references (this is essentially the "snap point" you are looking for). On the next slide (titled "Create New NALocationObject"), we then show how to use this information to create a new feature in your analysis layer. If you want to enable snapping, then you can simply replace the following line of code...

stopFeature.shape = inputPoint;

...with this line of code...

stopFeature.shape = outputPoint;

...to enable snapping. Let me know if you have any related questions.
0 Kudos
sarmadhussain
New Contributor
thanks for your help, i am unable to see the video. i tried all browsers just to be sure. can you please give an alternate link for the lecture ?
0 Kudos
MichaelRice
New Contributor III
Unfortunately, I do not know of any other links to this video. Please make sure your browsers are up-to-date. If you are still having troubles viewing this and you do not feel it is because of your machine configuration, you can try contacting ESRI customer service to let them know.

I am attaching a .pdf of the slides from this presentation. This is certainly not as useful as being able to see and hear the video, which offers more detailed discussions of each slide, but hopefully it is better than nothing. Please let me know if this helps.
0 Kudos
JasonTaylor
New Contributor
Hello, I am having a similar issue with snapping GPS points to a stream layer. I am hoping to find a way to do it via a model or python.

Thanks for your help.
0 Kudos
MichaelRice
New Contributor III
Is your stream layer a network dataset or something else (e.g., a geometric network)? For locating points on network datasets, you can use the 'Add Locations' GP tool (either using ModelBuilder or directly through Python), and just check/turn on the 'Snap to Network' option for the tool.
0 Kudos