Dear Alexander,
You can use the function readShapePoly function from maptools. This
directly reads the shapefile into a SpatialPolygons object. You also
need to install the sp package (don't know if you did that already).
You could consider joining the r-sig-geo mailing list. These kinds of
questions are better suited for that mailing list.
hope this helps,
Paul
Alexander Nervedi schreef:> 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 at 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.
>
--
Drs. Paul Hiemstra
Department of Physical Geography
Faculty of Geosciences
University of Utrecht
Heidelberglaan 2
P.O. Box 80.115
3508 TC Utrecht
Phone: +31302535773
Fax: +31302531145
http://intamap.geo.uu.nl/~paul