Order a SpatialLine passes through a SpatialPolygons
I’m trying to write a function that returns the polygons through which a line passes, but I want the polygons to be listed in order. For example, in the code below, I get a list of polygons over which the lines passes, but the polygons are listed in numeric order, not spatial order. I would like the polygons to be listed as 21, 24, 25, 26, and 22 (the reverse would be fine to). Any ideas.
if the line goes back into a polygon with the same ID you'll see that too -
"21 24 25 26 24 22" for example.
Problem with this is that you have to make enough points on the line to
make sure one point hits each intersecting polygon. Maybe compare the list
from the points with the polygon intersection and then...
Wait, another idea. Get all the line-polygon intersections points to cut
your line into segments, and then compute the midpoints of each segment,
and see which polygon they lie in. Coffee time now, so can't implement
Note that SpatialLines objects can be more than one line segment in which
case the ordering is undefined, so make sure your SpatialLines have one
On Thu, Aug 31, 2017 at 9:06 PM, Thayn, Jonathan <[hidden email]> wrote:
> I’m trying to write a function that returns the polygons through which a
> line passes, but I want the polygons to be listed in order. For example, in
> the code below, I get a list of polygons over which the lines passes, but
> the polygons are listed in numeric order, not spatial order. I would like
> the polygons to be listed as 21, 24, 25, 26, and 22 (the reverse would be
> fine to). Any ideas.
> coords <- coordinates(columbus)
> the.line <- SpatialLines(list(Lines(Line(coords[c(21,22),]),ID="A")))
> Jonathan B. Thayn, Ph.D.
> Associate Professor
> Department of Geography – Geology
> Illinois State University
> Felmley Hall of Science, Rm 200A
> Normal, IL 61790
> [hidden email]<mailto:[hidden email]>
> [[alternative HTML version deleted]]
> R-sig-Geo mailing list
> [hidden email] > https://stat.ethz.ch/mailman/listinfo/r-sig-geo