Thread: Shortest distance between points and a line

1. Shortest distance between points and a line

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

2. Re: Shortest distance between points and a line

please post code that doesn't work.

I found example of BufferSnap in help

IProximityOperator proximityOp = point as IProximityOperator;
double Dist = proximityOp.ReturnDistance(outPoly);

3. Re: Shortest distance between points and a line

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

4. Re: Shortest distance between points and a line

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

5. Re: Shortest distance between points and a line

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

6. Re: Shortest distance between points and a line

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.

Code:
```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.

7. Re: Shortest distance between points and a line

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/a...00003rr000000/

Take the avtange of built-in ArcGIS validation.

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts