Home > Net >  Finding a point on a straight line with DbGeography.Intersect()
Finding a point on a straight line with DbGeography.Intersect()

Time:12-22

I am currently learning about DbGeography in C# and playing around with some functionality.

I have been trying to ascertain whether the Intersects() method will return true for a point lying on a straight line (represented as a LineString DbGeography object) if the point lies between the starting and end points.

So, my question is: Can the [myPoint].Intersects([myLine]) method be trusted to tell me if myPoint lies on myLine?

CodePudding user response:

Yes, you can use the Intersects method to determine whether a point lies on a line, as long as the point is within the bounding box of the line.

for example:

DbGeography myPoint = DbGeography.PointFromText("POINT(10 10)", 4326);
DbGeography myLine = DbGeography.LineFromText("LINESTRING(0 0, 20 20)", 4326);

bool myPointIntersectsWithmyLine = myPoint.Intersects(myLine);

the variable myPointIntersectsWithmyLine should be true here since myPoint lies on myline object.

  • Related