[R-sig-Geo] spsample() ok with type= 'stratified', but gives error with 'random'

Don MacQueen macq at llnl.gov
Thu Jun 7 18:27:36 CEST 2007


I don't know enough to assess whether I have a misunderstanding or a mistake.

spsample() with type='random' is giving an error, but succeeding with 
type='stratified'.

Maybe random sampling requires projection information and stratified doesn't?
I may have constructed my SpatialPolygonsDataFrame incorrectly?

Thanks
-Don

Details:

spgd consists of two rectangles, one inside the other, and the inside 
one is a hole.
The outer one has vertices in counter-clockwise order; the inner one 
in clockwise order.

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

>  summary(tst)
Object of class SpatialPolygonsDataFrame
Coordinates:
         min      max
r1 990396.8 990762.3
r2 213369.4 213702.6
Is projected: NA
proj4string : [NA]
Data attributes:
     ID
  zone:1


>  stst <- spsample(tst,type='stratified',n=50)
>  plot(tst)
>  points(stst)
>  stst <- spsample(tst,type='random',n=50)
Error in `proj4string<-`(`*tmp*`, value = <S4 object of class "CRS">) :
         proj4string only works for class(es extending) Spatial


##########
>  sessionInfo()
R version 2.5.0 (2007-04-23)
powerpc-apple-darwin8.9.1

locale:
C

attached base packages:
[1] "stats"     "graphics"  "grDevices" "utils"     "datasets" 
"methods"   "base"

other attached packages:
maptools       sp  foreign    rmacq
"0.6-12" "0.9-14" "0.8-20"    "1.0"

##########
## since tst is fairly small, here it is:
##########
>  tst
An object of class "SpatialPolygonsDataFrame"
Slot "data":
        ID
zone zone

Slot "polygons":
[[1]]
An object of class "Polygons"
Slot "Polygons":
$zn
An object of class "Polygon"
Slot "labpt":
[1] 990579.4 213536.2

Slot "area":
[1] 64601.13

Slot "hole":
[1] FALSE

Slot "ringDir":
[1] 1

Slot "coords":
             x        y
[1,] 990499.3 213702.6
[2,] 990762.3 213559.8
[3,] 990658.2 213369.4
[4,] 990396.8 213513.2
[5,] 990499.3 213702.6


$zn2
An object of class "Polygon"
Slot "labpt":
[1] 990584.4 213537.3

Slot "area":
[1] 30367.20

Slot "hole":
[1] TRUE

Slot "ringDir":
[1] -1

Slot "coords":
             x        y
[1,] 990492.6 213650.8
[2,] 990441.8 213549.4
[3,] 990673.3 213423.7
[4,] 990728.1 213525.6
[5,] 990492.6 213650.8



Slot "plotOrder":
[1] 1 2

Slot "labpt":
[1] 990579.4 213536.2

Slot "ID":
[1] "zone"

Slot "area":
[1] 94968.33



Slot "plotOrder":
[1] 1

Slot "bbox":
         min      max
r1 990396.8 990762.3
r2 213369.4 213702.6

Slot "proj4string":
CRS arguments: NA

-- 
--------------------------------------
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA




More information about the R-sig-Geo mailing list