Skip to content

conversion to polygons

4 messages · Luis Ridao Cruz, pedro at dpi.inpe.br, Roger Bivand

#
R-Sig-Geo help,

I have an objct of class "SpatialPointsDataFrame"
which I woul like to convert to polygon.

I have used the following:

test1<-Polygon(test)
test2<-SpatialPolygons(list(test),1)
plot(test2,col=2,pbg="white")

but I get en error message like this:

Error in as.list(X) : cannot get a slot ("Polygons") from an object of
type "double"

I also try ploting:

plot(test1)

which gives :

Error in plot.window(xlim, ylim, log, asp, ...) : 
        need finite 'xlim' values
In addition: Warning messages:
1: no non-missing arguments to min; returning Inf 
2: no non-missing arguments to max; returning -Inf 
3: no non-missing arguments to min; returning Inf 
4: no non-missing arguments to max; returning -Inf 




Thank you in advance
1 day later
#
On Wed, 14 Jun 2006, Luis Ridao Cruz wrote:

            
test2<-SpatialPolygons(list(Polygons(list(test)),ID=1)))

should do it - there are two layers, because some "Polygons" objects with 
a single ID can have multiple "Polygon" object members.

Roger

  
    
#
Hi,

I also have same "problem". Sometimes I want to build a SpatialPolygons 
from a set of points (a matrix) representing the border of a region, 
and it has only one polygon.

SP <- SpatialPolygons(list(Polygons(list(Polygon(matrixdata))),ID=1)))

But ID in this case is not "necessary", and also the two levels of 
list. At least for me, it is very common, and I can cite geoR and 
splancs packages, where we have this kind of data. I think in this case 
we could have a simpler code, and we could create it directly from the 
matrix:

SP = SpatialPolygons(matrixdata)

or from the Polygon:

SP = SpatialPolygons(polygon)

The creation of the lists and ID could be hidden in SpatialPolygons-methods.R:

SpatialPolygons <- function(Srl, pO, proj4string=CRS(as.character(NA))) {
     if( is.matrix(Srl) ) Srl <- list(Polygons(list(Polygon(Srl))),ID=1))
     ...
}

What do you think of it?

Pedro

Quoting Roger Bivand <Roger.Bivand at nhh.no>:
#
On Fri, 16 Jun 2006 pedro at dpi.inpe.br wrote:

            
Yes, good idea, I'll implement it once useR 2006 is over for 
SpatialPolygons and Spatial Lines.

Thanks, Roger