I’m trying to check whether a line passes through a point (or pair of coordinates more specifically) using MapBasic. I’ve done the following:
1) Selected from a polyline table where the object intersects with my line object into selection called ‘Intersections’
2) Determined the line/polyline point of intersection using:
_x = (yIntercept2 - yIntercept1) / (slope2 - slope1)
_y = (slope1 * _x) + yIntercept1
This is causing me some trouble for starters… the x coordinate comes out negative to its actual value when I plot the lines and check against the map. This in turn makes my y value incorrect. If I invert (set to negative) either the difference in slope or difference in intercept then the correct x value comes out. I have no idea why?!
3) Once I have my X and Y coordinates using the above, I then check these against each line section from the intersecting polyline object to determine which section intersects with the point:
slope = GetSlope(_lineSection)
intercept = GetYIntercept(_lineSection, slope)
v = _y - (slope * _x) - intercept
If v = 0 then
PointIntersectsLine = true
else
PointIntersectsLine = false
End If
The second step obviously has a problem but I can get it to work by inverting one of the calculated differences. The third step seems to work for some intersections but not others. All my variables (coordinates, slope, intercept, etc.) are floats but I’m wondering whether this might be a problem with rounding. This is all done in British National Grid.
Any ideas what might be going wrong?
Thanks,
Tom Bacon
GIS Engineer, Mouchel
T 01444 472380 │ E thomas...@mouchel.com │ W www.mouchel.com
Our values: innovation │ excellence │ integrity │ responsibility
Mouchel Limited (Mouchel) is registered in England and Wales with registered number 01686040 at Export House, Cawsey Way, Woking, Surrey, UK, GU21 6QX. The information in this e-mail is confidential and may be legally privileged. It is intended solely for the addressee. Access to this email by anyone else is unauthorised. Any views or opinions expressed in this e-mail may be solely those of the author and are not necessarily those of Mouchel. No contracts may be concluded on behalf of Mouchel by means of email communications. Mouchel reserves the right to monitor and intercept emails sent and received on our network. |
No virus found in this
message.
Checked by AVG - www.avg.com
Version: 2014.0.4765 / Virus
Database: 4025/8276 - Release Date: 09/26/14
Thanks Tony, that’s what I’m using (v = _y - (slope * _x) – intercept). I think I’ve determined that the intersection check failure is down to rounding of the coordinate, slope and intercept values. I’m going to have to rethink how I’m calculating this as a very tiny difference in one of those values means that v will no longer equal 0 in some instances where I know it should. Back to the drawing board…
Tom Bacon
GIS Engineer, Mouchel
T 01444 472380 │ E thomas...@mouchel.com │ W www.mouchel.com
Our values: innovation │ excellence │ integrity │ responsibility
Having revised linear functions with my daughter this week, I thought I'd chip in.
The general equation for a straight line is indeed y = mx+c. For those that don't use this kind of stuff daily, and for whom High School was a long, long time ago... m is the gradient and c is the intercept with the y axis. For a road and stream that are represented by simple lines and running side-by-side, the gradient should be quite similar. However, given the vast space of a country- or state-wide Cartesian coordinate system, even a minor difference in the gradient could make a big difference when the line is extended to the y-axis.
Another problem is that of representation. A road or stream would typically be represented by a polyline, so you may have many line sections representing meanderings in the road. On top of that you have polyline direction. The stream may well be expressed as flowing downstream, but if the road is two-way, it could be "flowing" in the opposite direction. This has a real impact on your relative notions of "on the left" and "on the right".
So, while derivations of y=mx+c are mathematically sound, you may have to go a long way to develop this. I Googled "measuring parallelism" and there are lots of pages you might find useful for alternative approaches.
Regards,
Warren Vick
Europa Technologies Ltd.
Version: 2014.0.4765 / Virus Database: 4025/8278 - Release Date: 09/26/14
Thanks all. I decided to just take the simple route and use MapInfo’s intersection analysis and buffer the point slightly; works quite well now.
Function PointIntersectsLine(ByVal _x as Float, ByVal _y as Float, ByVal _line as Object) as Logical
Dim slope, intercept as Float
Dim v as Float
Dim bufferPoint as Object
bufferPoint = Buffer(CreatePoint(_x, _y), 50, 0.5, "m")
If bufferPoint intersects _line then
PointIntersectsLine = true
Else
PointIntersectsLine = false
End If
End Function
Regards,
Tom Bacon
GIS Engineer, Mouchel
T 01444 472380 │ E thomas...@mouchel.com │ W www.mouchel.com
Our values: innovation │ excellence │ integrity │ responsibility
Looking at that, I think I went a bit overboard on the resolution. 50 nodes for a 1m diameter circle is probably a bit much… might drop that down a bit.
Tom Bacon
GIS Engineer, Mouchel
T 01444 472380 │ E thomas...@mouchel.com │ W www.mouchel.com
Our values: innovation │ excellence │ integrity │ responsibility
There's a feature I'd love to see in Pro/MB, that might be helpful to Thomas, which is a one-sided buffer. It's been discussed before from time-to-time. It's would be useful for both regions and lines/polylines for a number of applications where "side" is important. Additionally, the notion of advancement perpendicular to a line. e.g. the movement of a burn line for a wildfire.
Anyway, one more for the wish list.