Map2poly {maptools} | R Documentation |
Map2poly() is a simple function to make imported GIS vector polygons into a "polylist" object from a "Map" object, and Map2bbs() retrieves polygon bounding boxes; analogous functions for the "shapefiles" package are shape2poly() and shape2bbs() (thanks to Stéphane Dray for his contribution); convert.pl() serves to convert the deprecated "multipart" "polylist" format to an NA-separated format now used by plotpolys() and poly2nb().
*2lines()
and *2points()
do the same as *2poly()
for shapefiles of types 3=lines and 1=points; polygons are type=5.
Map2poly(Map, region.id = NULL) Map2lines(Map) Map2points(Map) Map2bbs(Map) shape2poly(shape, region.id = NULL) shape2lines(shape) shape2points(shape) shape2bbs(shape) convert.pl(pl)
Map |
object of class "Map" , imported from a GIS polygon vector file using unpublished package "maptools" |
shape |
list returned by read.shapefile() , imported from a GIS polygon vector file using the package "shapefiles" |
region.id |
character vector of region ids to be added to the neighbours list as attribute region.id |
pl |
list of old-style multipart polygons of class polylist |
http://sal.agecon.uiuc.edu/datasets/columbus.zip
Map2poly
, shape2poly
, convert.pl
return polylist objects, lists of polygon boundary coordinates (divided by NA where the polygon object is represented by more than one polygon;
Map2lines
, shape2lines
return lineslist objects;
Map2points
, shape2points
return (n x 2) matrices; and
Map2bbs
, shape2bbs
return bounding box matrixes, c(x1, y1, x2, y2) with coordinates for the lower left corner and upper right corner.
Roger Bivand and Stéphane Dray, Roger.Bivand@nhh.no
shp <- try(library(shapefiles)) if (class(shp) != "try-error") { ShapeDir <- system.file("shapes", package="maptools")[1] try1 <- read.shapefile(paste(ShapeDir, "columbus", sep="/")) shppolys <- shape2poly(try1, as.character(try1$dbf$dbf$NEIGNO)) plotpolys(shppolys) title(main="Polygons for Columbus OH from shapefiles package") try3a <- read.shapefile(paste(ShapeDir, "baltim", sep="/")) baltptsa <- shape2points(try3a) xylims <- attr(baltptsa, "maplim") plot(xylims$x, xylims$y, asp=1, type='n', xlab="", ylab="") points(baltptsa) title(main="Baltimore points from shapefiles package") try4a <- read.shapefile(paste(ShapeDir, "fylk-val", sep="/")) fylk.vala <- shape2lines(try4a) xylims <- attr(fylk.vala, "maplim") plot(xylims$x, xylims$y, asp=1, type='n', xlab="", ylab="") for (i in 1:length(fylk.vala)) lines(fylk.vala[[i]]) title(main="Norwegian river centrelines from shapefiles package") } try2 <- read.shape(system.file("shapes/columbus.shp", package="maptools")[1]) mappolys <- Map2poly(try2, as.character(try2$att.data$NEIGNO)) plotpolys(mappolys) title(main="Polygons for Columbus OH from maptools package") if (class(shp) != "try-error") { plotpolys(shppolys) plotpolys(mappolys, add=TRUE, border="red", lty="dotted") title(main="Polygons for Columbus OH overplotted from both packages") } try3 <- read.shape(system.file("shapes/baltim.shp", package="maptools")[1]) baltpts <- Map2points(try3) xylims <- attr(baltpts, "maplim") plot(xylims$x, xylims$y, asp=1, type='n', xlab="", ylab="") points(baltpts) title(main="Baltimore points from maptools package") try4 <- read.shape(system.file("shapes/fylk-val.shp", package="maptools")[1]) fylk.val <- Map2lines(try4) xylims <- attr(fylk.val, "maplim") plot(xylims$x, xylims$y, asp=1, type='n', xlab="", ylab="") for (i in 1:length(fylk.val)) lines(fylk.val[[i]]) title(main="Norwegian river centrelines from maptools package")