I am new to R and a new to programming. I have a shapefile which I have imported into R and found that it is a Spatial Polygons Data Frame. I want to use the crossdist function in spatstat but before that I am attempting to convert this into owin and then class psp as that is how I have read to address this issue. My problem is that I am not sure how to convert my data to owin. Any help on how to address this would be greatly appreciated. Thanks.
A SpatialPolygons or SpatialPolygonsDataFrame object represents a list of several distinct spatial regions, e.g. states of the USA, while an owin object represents a single spatial region (possibly consisting of several disjoint pieces), e.g. Hawaii.
To convert a SpatialPolygonsDataFrame (say x) to a list of owin objects:
y <- as(x, "SpatialPolygons")
p <- slot(y, "polygons")
v <- lapply(p, function(z) { SpatialPolygons(list(z)) }
winlist <- lapply(v, as.owin)
The result winlist is a list, each entry of which is an 'owin' object representing one of the polygonal regions in x.
For further information see the spatstat vignette on shapefiles: start R, load the spatstat package, type vignette('shapefiles') and view the section on SpatialPolygonsDataFrame objects.
For more detailed information, see the book on spatstat.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With