Skip to main content
Add alternative method based on intersections
Source Link
user30184
  • 71.8k
  • 4
  • 78
  • 130

My idea may not be most efficient but anyway, I believe you can at least get a correct answer by creating offset lines to the left and to the right from linestring L and computing shortest distances from A and B to the offset lines. If both A and B have shorter distance to the same offset line it means that they are on the same side of L. That's not true if A and/or B locate between the offset lines so check also that distance from A and B to L is greater than the tolerance used with OffsetLine.

I suppose that GEOS has both OffsetLine and Distance functions.

Another idea:

Build linestring from A to B and check if AB crosses L. If not A and B are on the same side. If they cross you must count the number of intersections. If number is odd (1, 3, 5...) A and B are on different sides but if the number is even (2, 4, 6...) then A and B are still on the same side and line AB just goes through loop(s) in L.

My idea may not be most efficient but anyway, I believe you can at least get a correct answer by creating offset lines to the left and to the right from linestring L and computing shortest distances from A and B to the offset lines. If both A and B have shorter distance to the same offset line it means that they are on the same side of L. That's not true if A and/or B locate between the offset lines so check also that distance from A and B to L is greater than the tolerance used with OffsetLine.

I suppose that GEOS has both OffsetLine and Distance functions.

My idea may not be most efficient but anyway, I believe you can at least get a correct answer by creating offset lines to the left and to the right from linestring L and computing shortest distances from A and B to the offset lines. If both A and B have shorter distance to the same offset line it means that they are on the same side of L. That's not true if A and/or B locate between the offset lines so check also that distance from A and B to L is greater than the tolerance used with OffsetLine.

I suppose that GEOS has both OffsetLine and Distance functions.

Another idea:

Build linestring from A to B and check if AB crosses L. If not A and B are on the same side. If they cross you must count the number of intersections. If number is odd (1, 3, 5...) A and B are on different sides but if the number is even (2, 4, 6...) then A and B are still on the same side and line AB just goes through loop(s) in L.

Source Link
user30184
  • 71.8k
  • 4
  • 78
  • 130

My idea may not be most efficient but anyway, I believe you can at least get a correct answer by creating offset lines to the left and to the right from linestring L and computing shortest distances from A and B to the offset lines. If both A and B have shorter distance to the same offset line it means that they are on the same side of L. That's not true if A and/or B locate between the offset lines so check also that distance from A and B to L is greater than the tolerance used with OffsetLine.

I suppose that GEOS has both OffsetLine and Distance functions.