[R-sig-Geo] Difficulties handling objects of class "psp"

Michael Sumner mdsumner at gmail.com
Mon Dec 13 11:54:06 CET 2010


I think you simply neglect to replace the original object with the
converted one.

This does not modify "x", it converts and then prints out that result:

as.psp(x)

We need to assign it to a new (or a replacement) object so we can use
it further:

x <- as.psp(x)

Here's a concrete example with the maptools and spatstat packages:


x <- readShapeSpatial(system.file("shapes/fylk-val.shp",
       package="maptools")[1], proj4string=CRS("+proj=utm +zone=33
+datum=WGS84"))
 class(x)
##[1] "SpatialLinesDataFrame"

library(spatstat)
x <- as.psp(x) ###store the fractures as a single object of class psp
##Warning message:
##In as.psp.SpatialLinesDataFrame(x) : 9 columns of data frame discarded
head(lengths.psp(x))
##[1] 1429.48681   33.56846 7282.03901   54.00531 4272.47990 6721.92176

(The warning about discarded attributes is expected).

Cheers, Mike.



On Mon, Dec 13, 2010 at 9:46 PM, Eric Boeker <eric.boeker at gmail.com> wrote:
> Dear list members,
>
>
>
> I want to use some spatstat facilities for handling my geological faults
> shapefile data.
>
>
> First step I read my data into spatstat
>
> (Thanks for the vignette of Adrian Baddeley “Handling shapefiles in the
> spatsat”
> http://cran.r-project.org/web/packages/spatstat/vignettes/shapefiles.pdf ).
>
>
> Then I convert them either into a single object of class “psp” or into a
> list of object of class “psp”.
>
> But after those transformations, I still cannot use the facilities of
> spatstat for handling my fracture line segment list of class “psp”.
>
> For example by using angles.psp or crossing.psp facilities I keep receiving
> the error message = Error in verifyclass(x, "psp") : argument 'x' is not of
> class 'psp'. What am I doing wrong!!!
>
> I'd welcome any hints on this question. Does anyone have experience with
> this or possibly an idea on how I might solve the issue?
> Below some commands and results used so far.
>
>
>  Sincerely
>
>
>
> x<-readShapeSpatial("fractureshp.shp")
>
>> class(x)
>
> [1] "SpatialLinesDataFrame"
>
> attr(,"package")
>
> [1] "sp"
>
>> as.psp(x) ###store the fractures as a single object of class psp
>
> planar line segment pattern: 6 line segments
>
> window: rectangle = [234027.52, 235479.43] x [1700993, 1702270.7] units
>
> Marks vector of type 'integer'
>
> plot(x) # #### plot of the fractures =>>ok
>
> lengths.psp(x) #####   Error in verifyclass(x, "psp") : argument 'x' is not
> of class 'psp'
>
>
>
> #######To convert the SpatialLinesDataFrame to psp:
>
> ydata<-slot(x,"data")
>
> yl<-as(x,"SpatialLines")
>
> ycurves<-slot(yl,"lines")
>
> ycurves<-lapply(ycurves,function(x){SpatialLines(list(x))} )
>
> ypatterns<-lapply(ycurves,as.psp)
>
>> class(ypatterns)
>
> [1] "list"
>
>> summary(ypatterns)
>
>     Length Class Mode
>
> [1,] 4      psp   list
>
> [2,] 4      psp   list
>
> [3,] 4      psp   list
>
> [4,] 4      psp   list
>
> [5,] 4      psp   list
>
> [6,] 4      psp   list
>
> lengths.psp(ypatterns) #####   Error in verifyclass(x, "psp") : argument 'x'
> is not of class 'psp'
>
> --
> Mit freundlichen Grüßen / Kind regards / Meilleures Salutations
>
>
> Eric Böker
>
> Hydrogéologue
> Chef Projet PMRE
> Hippodrome
> Rue 326, Porte 21
> BP 701 BAMAKO (MALI)
> Cell: (00223) 766 87 477
> e-mail: eric.boeker at gmail.com
>
>        [[alternative HTML version deleted]]
>
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
>



-- 
Michael Sumner
Institute for Marine and Antarctic Studies, University of Tasmania
Hobart, Australia
e-mail: mdsumner at gmail.com



More information about the R-sig-Geo mailing list