Skip to content

SpatialPolygons to SpatialLines?

2 messages · Jonathan Greenberg, Lyndon Estes

#
R-sig-geo'ers:

Is there a quick way to create a line object from a polygon object
(representing the boundary)?

--j
#
Hi Jonathan,

You can do this as follows:

x <- yourSpatialPolygons
xl <- as(x, "SpatialLines")

e.g.

library(maptools)
library(rgdal)
nc <- readShapePoly(system.file("shapes/sids.shp",
package="maptools")[1], proj4string=CRS("+proj=longlat +datum=NAD27"))
quartz()
plot(nc[1, ], col = "blue")
nc1l <- as(nc[1, ], "SpatialLines")
plot(nc1l, col = "blue")


Cheers, Lyndon



On Tue, Aug 9, 2011 at 6:51 PM, Jonathan Greenberg
<greenberg at ucdavis.edu> wrote: