arcpy.Geometry's Intersect method - how does it work?

3983
4
10-07-2013 12:43 AM
JosteinSvegården
New Contributor
I'm creating a script to find the coordinates of the point on a polyline that is at shortest distance from another point. Since the script can only use an ArcGIS Desktop Basic license, I can not use any of the Near-tools. So, I try to use the ArcPy Geometry class to do the calculations.

First, I calculate the distance between the point and the polyline:
distance = Point1.distanceTo(Polyline1)


Then I try to find the actual nearest point on the polyline by creating a buffer with radius distance around the point and then do an intersect between the buffer polygon and the polyline:
Buffer1 = Point1.buffer(distance)
IntersectPoint = Buffer1.intersect(Polyline1, 1)


The intersect does not return any geometry even though a run of
Buffer1.touches(Polyline1)
returns a True value, indicating that the features intersect. What am I not gettig here? Any idea woud be appreciated
Tags (2)
0 Kudos
4 Replies
NeilAyres
MVP Alum
Jostein,

Note the operator "touches". It just touches the line. There is no area overlap to intersect.
You could add a tiny extra distance to "distance" (what are your geometry coordinates?), then there will be an overlap.

Cheers,
Neil
0 Kudos
JosteinSvegården
New Contributor
From ArcGIS Resources: "touches(second_geometry): indicates if the boundaries of the geometries intersect"
So I hoped that would be enough for intersect to return to me the point where their boundaries intersect..

Yes, adding a small distance to get a result from intersect has been my solution so far. I even applied code to calculate the added distance to be as small as possible. Though, I have hoped for another solution that is more accurate.
0 Kudos
ChrisSnyder
Regular Contributor III
find the coordinates of the point on a polyline that is at shortest distance from another point


I think what you would want to do is to actually get the two vertices along the polyline that are closest to the point (pnts b and c in the ASCII art below). Once you know the x,y pairs of these three points (corners of a triangle) you can then derive all sorts of other values, including the one you are looking for (coordinates of pnt d). The angle of adc and adb is of course 90 degrees.


                . a

                           
b ._____________._____. c

                 d

0 Kudos
DouglasSands
Occasional Contributor II
I'm creating a script to find the coordinates of the point on a polyline that is at shortest distance from another point. Since the script can only use an ArcGIS Desktop Basic license, I can not use any of the Near-tools. So, I try to use the ArcPy Geometry class to do the calculations.

First, I calculate the distance between the point and the polyline:
distance = Point1.distanceTo(Polyline1)


Then I try to find the actual nearest point on the polyline by creating a buffer with radius distance around the point and then do an intersect between the buffer polygon and the polyline:
Buffer1 = Point1.buffer(distance)
IntersectPoint = Buffer1.intersect(Polyline1, 1)


The intersect does not return any geometry even though a run of
Buffer1.touches(Polyline1)
returns a True value, indicating that the features intersect. What am I not gettig here? Any idea woud be appreciated


If you only need the distance, this may be fairly straight forward. Having looked into this before (trying to move points to the closest edge segment of a polygon) it is however a bit more complicated than at face value.

But this article here http://math.ucsd.edu/~wgarner/math4c/derivations/distance/distptline.htm is a great place to start. The basic equation is given towards the bottom:

Shortest distance from y=m*x + b to (x1, y1):

|y1 - m*x1 - b| / root(m^2 + 1)

To get the point of intersection, you then need to "draw" a line with the inverse slope, and intersect it with your original line. To do this you will need to solve for the new y-intercept, and handle two special cases:
1. Original slope was undefined (vertical eg X = 2): new line equation is Y = Y1
2. Original slope was 0 (horizontal eg Y = 2): new line equation is X = X1

On intersecting two lines:
http://www.wikihow.com/Algebraically-Find-the-Intersection-of-Two-Lines

Good luck!
0 Kudos