[R-sig-Geo] Determine if a line segment intersects a polygon

adrian at maths.uwa.edu.au adrian at maths.uwa.edu.au
Sun Aug 12 09:40:32 CEST 2007


Scott Waichler writes:

> I am looking for a method that would determine whether any part of a
> line segment defined by (x0, y0) and (x1, y1) intersects a given polygon
> (true or false).

In the `spatstat' package you can use `crossing.psp' to do this.
Create a line segment pattern ("psp" object) A containing the edges of the
polygon. Create another "psp" object B containing the line segment.
Then C <- crossing.psp(A,B) returns all the intersection points, and
hit <- (C$n != 0) tells you whether there was an intersection.

Adrian Baddeley.




More information about the R-sig-Geo mailing list