Hi ! I have a shapefile that I can easily read into R using library(maptools). My problem stems from some warning messages that come even though everything seems to work fine.
library(maptools) districts <- read.shape(filen = "a_ds", dbf.data = TRUE) length(districts$Shapes) so far so good. when I try and plot this I get a nice plot and a warning message: > plot(districts) Warning message: 'plot.Map' is deprecated. Use 'plot.Spatial' instead. See help("Deprecated") and help("maptools-deprecated"). so i tried the obvious: > ?plot.Spatial No documentation for 'plot.Spatial' in specified packages and libraries: you could try 'help.search("plot.Spatial")' I went back and read the help on plot.Map and it says "This function is deprecated. It is difficult to maintain and there are several alternatives, either by converting Map objects to sp class objects or polylist etc. objects" and so i gather we can either try to move things into sp class. A little search of this archive tells me that there is a function out there called map2SpatialPolygons that is of some help. So after reading the help on this i tried to convert the Map object to an sp object. But I keep failing. > ids <- as.character(districts$att.data$STATE) > ids[1:2] "A AND B" "A AND B" > temp <- map2SpatialPolygons(districts, IDs = ids) Error in to[nParts] <- nrow(xy) : incompatible types (from NULL to integer) in subassignment type fix In addition: Warning message: is.na() applied to non-(list or vector) in: is.na(object) I went back to the help on the function map2SpatialPolygons. And the example code there is: library(maps) nor_coast_poly <- map("world", "norway", fill=TRUE, col="transparent", plot=FALSE) nor_coast_poly$names IDs <- sapply(strsplit(nor_coast_poly$names, ":"), function(x) x[1]) nor_coast_poly_sp <- map2SpatialPolygons(nor_coast_poly, IDs=IDs, proj4string=CRS("+proj=longlat +datum=wgs84")) This works fine. So I was most puzzled. And then i did > is(nor_coast_poly) [1] "map" > is(districts) [1] "Map" So the object i have created is a Map object while the map2SpatialPolygons seems to be using a map object. Can it also handle Map objects? In which case can someone tell me whats wrong with my sepcification of the map2SpatialPolygons call? your man Al _________________________________________________________________ [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.