[R-sig-Geo] Order a SpatialLine passes through a SpatialPolygons

Thayn, Jonathan jthayn at ilstu.edu
Thu Aug 31 22:06:57 CEST 2017


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.


library(spdep)
example(columbus)
plot(columbus)
coords <- coordinates(columbus)
text(coords,labels=1:49)

the.line <- SpatialLines(list(Lines(Line(coords[c(21,22),]),ID="A")))
plot(the.line,col="red",add=T)

which(!is.na(over(columbus,the.line)))



Jonathan B. Thayn, Ph.D.

Associate Professor
Department of Geography – Geology
Illinois State University
Felmley Hall of Science, Rm 200A
Normal, IL 61790

jthayn at ilstu.edu<mailto:jthayn at ilstu.edu>
my.ilstu.edu/~jthayn<http://my.ilstu.edu/~jthayn>





	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list