[R-sig-Geo] Merging SpatialPolygonsDataFrame and SpatialLinesDataFrame

Jim Burke j.burke at earthlink.net
Tue Mar 17 06:43:32 CET 2009


Hi everyone,

Been scratching my head on this. A common
operation. Google seems to be mute on this,
so I turn to you.

I have a nice SpatialPolygonsDataFrame that I
can plot with wonderful colors using spplot.

I would like to

1. MERGE SpatialLinesDataFrame (PolyLine) over
the SpatialPolygonsDataFrame (Polygons). And
plot with spplot().

2. CLIP the PolyLine to the area of the Polygons.
The polygons are within the larger main_main roads
Polyline

3. COLOR PolyLine main_roads different than
black for example; white or gray.


NOTES. FILE READS ARE BELOW

 >tx3_sp <- readShapePoly("tx3_sp.shp", IDvar="PCT",
proj4string=CRS("+proj=aea +ellps=GRS80 +datum=WGS84"),
verbose=TRUE, repair=FALSE)
Shapefile type: Polygon, (5), # of Shapes: 39

 >main_roads <-readShapeLines("main roads.shp",
proj4string=CRS("+proj=aea +ellps=GRS80 +datum=WGS84"),
verbose=TRUE,repair=FALSE)
Shapefile type: PolyLine, (3), # of Shapes: 29161

 > class(tx3_sp)
[1] "SpatialPolygonsDataFrame"
attr(,"package")
[1] "sp"

 > class(main_roads)
[1] "SpatialLinesDataFrame"
attr(,"package")
[1] "sp"

Thanks and I am grateful for all thoughts and assistance,
Jim Burke



More information about the R-sig-Geo mailing list