Shortest distance between points and a line

3312
6
08-19-2011 09:23 AM
Highlighted
New Contributor
I???m working with ArcGIS 9.3 (shortly to be updated!).   I have two layers, one with points and one with a line.  Both layers are in spatial reference WGS84.  I want to find the shortest distance (in meters, if possible) between each point and the line.  I???ve read some previous threads trying to do a similar thing using the IProximityOperator, and I???ve tried some of the code that was posted on these threads, but am a VBA novice and can???t get it to work at all.

Any help (in the most basic language possible 🐵 would be much appreciated!

Best wishes

Jo
Reply
0 Kudos
6 Replies
Highlighted
New Contributor III
please post code that doesn't work.

I found example of BufferSnap in help

IProximityOperator proximityOp = point as IProximityOperator;
double Dist = proximityOp.ReturnDistance(outPoly);
Reply
0 Kudos
Highlighted
New Contributor
Hi there

I've build myself a code to find the nearest street of a point, and it is quite simple. I did not use any namespace, only math functions. So, if you want to give it a try, look for Heron's formula, which I think is the cheapest for computing. The formula gives you a height of a triangule using the sides. Maybe IProximityOperator give you best results, but I've never worked with it.

Good luck

Rodrigo Salvador
Reply
0 Kudos
Highlighted
New Contributor
Hiya!

Thanks for the speedy responses Dubravko & Rodrigo.

I�??ve attached the code I am trying to get to work to this reply (I hope!).
It was taken off one of the old forum subjects from 2002, so maybe the problem is that I�??m using a newer version of ArcGIS?  This code has the proximity operator function in it.  I just don�??t know if it won�??t run because of an issue with the code, or the way I�??m trying to run it.  It does seem that the Macro function doesn�??t register any more than the first Sub.  Could this be the issue?  If so, how do I fix it?

Rodrigo �?? thanks for your advice.  I�??m not sure how Heron�??s formula works though.  If it needs a triangle, where does it get the three points from?  I�??m afraid my maths skills are almost as bad as my computer skills!  😮

Jo
Reply
0 Kudos
Highlighted
New Contributor
Jo

I can't run your code right now, I'll do it since I can. About the points, one may be the point you are interested, and the other two may be the edges of your line. You must calculate de distance from one tho another (you have one, the length of the segment, so it's just two calculations). After that, you use the 3 sides in Heron's formula, to get the distance of each point to the line.

I assure you, it's not difficult to do.

Good luck

Rodrigo Salvador
Reply
0 Kudos
Highlighted
New Contributor III
Jo this is simple task to do. If you would like to dive into ArcObjects you should get a lot of patience and reading SDK.
This is simple code that you can adopt to your needs.

               
IFeature pLine = Temp_Line.GetLayer().FeatureClass.GetFeature(6);
IFeature pPoint = Temp_Point.GetLayer().FeatureClass.GetFeature(1);

IProximityOperator pProximity = pPoint.Shape as IProximityOperator;
double distance = pProximity.ReturnDistance(pLine.Shape);
This is all you should do to calculate distance.
Highlighted
Regular Contributor
Run the geoprocessing tool called Near with points as input and lines as near features. Or run Generate Near Table if you want more than one closest lines.

Follow examples in this topic (valid for 9.2 onward):
http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/How_to_run_a_geoprocess...

Take the avtange of built-in ArcGIS validation.
Reply
0 Kudos