dwww Home | Show directory contents | Find package

R version 4.2.1 (2022-06-23) -- "Funny-Looking Kid"
Copyright (C) 2022 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> suppressPackageStartupMessages(library(sf))
> if (require(spatstat.random, quietly = TRUE)) {
+ 
+ data(chicago)
+ st_as_sf(chicago)
+ # ppp:
+ g = gorillas
+ st_as_sf(g)
+ marks(g) = NULL
+ st_as_sf(g)
+ 
+ # multipolygon: https://github.com/r-spatial/sf/issues/1161
+ window = read_sf(system.file("shape/nc.shp", package = "sf")) %>%
+   st_transform(32119)
+ 
+ win = spatstat.geom::as.owin(window)
+ 
+ set.seed(1331)
+ pp2a = runifpoint(n = 50, win = win)
+ print(st_as_sf(pp2a))
+ 
+ # st_sample going the spatstat way
+ x <- sf::st_sfc(sf::st_polygon(list(rbind(c(0, 0), c(10, 0), c(10, 10), c(0, 0)))))
+ try(pts <- st_sample(x, type = "thomas"))
+ try(pts <- st_sample(x, kappa = 1, mu = 10, type = "Thomas"))
+ # points expected
+ set.seed(1331)
+ pts <- st_sample(x, kappa = 1, mu = 10, scale = 0.1, type = "Thomas")
+ #plot(x)
+ #plot(pts, add = TRUE)
+ pts
+ 
+ # see https://github.com/r-spatial/sf/issues/1233
+ # png("/tmp/spa%03d.png")
+ 
+ p1 = st_point(0:1)
+ p2 = st_point(1:2)
+ p3 = st_point(c(-1,2))
+ p = st_sfc(p1, p2, p3)
+ as.ppp(p)
+ try(as.ppp(st_set_crs(p, 4326)))
+ 
+ sf = st_sf(geom = p)
+ try(as.ppp(sf))
+ sf = st_sf(a = 1:3, geom = p)
+ as.ppp(sf)
+ sf = st_sf(a = 1:3, b=3:1, geom = p)
+ as.ppp(sf) # warns
+ 
+ w = st_as_sfc(st_bbox(st_sfc(p1, p2)))
+ sf = st_sf(a = 1:3, geom = p)
+ (p0 = rbind(st_sf(a = 0, geom = w), sf))
+ try(as.ppp(p0)) # errors: one point outside window
+ 
+ w = st_as_sfc(st_bbox(p))
+ sf = st_sf(a = 1:3, geom = p)
+ (p0 = rbind(st_sf(a = 0, geom = w), sf))
+ as.ppp(p0)
+ 
+ # as.owin.sf, as.owin.sfc_*
+ nc = st_read(system.file("gpkg/nc.gpkg", package="sf"), check_ring_dir = TRUE, quiet = TRUE)
+ try(as.owin(nc)) # should be projected
+ nc = st_transform(nc, 32119)
+ plot(as.owin(nc), col = 'grey')
+ plot(as.owin(st_geometry(nc)), col = 'grey')
+ 
+ sq = rbind(c(-1,-1), c(1, -1), c(1,1), c(-1,1), c(-1,-1))
+ pol = st_polygon(list(0.5 * sq, sq[5:1,] * 0.45)) # w hole
+ plot(as.owin(pol), col = 'grey')
+ plot(as.owin(st_sfc(pol)), col = 'grey')
+ mpol = st_multipolygon(list(
+       list(sq, sq[5:1,] * 0.9),
+       list(sq * 2, sq[5:1,] * 1.8)))
+ plot(as.owin(mpol), col = 'grey')
+ plot(as.owin(st_sfc(mpol)), col = 'grey')
+ plot(as.owin(st_sfc(pol, mpol)), col = 'grey')
+ plot(as.owin(st_sf(a=1:2, st_sfc(pol, mpol))), col = 'grey')
+ (o = as.owin(st_sf(a=1:2, st_sfc(pol, mpol))))
+ st_as_sfc(o)
+ 
+ plot(st_as_sfc(o), col = 'blue', main = 'st_as_sfc(o)')
+ plot(st_as_sf(o), col = 'blue', main = 'st_as_sf(o)')
+ 
+ data(japanesepines)
+ st_as_sf(japanesepines) # warns about multiplier
+ jp = rescale(japanesepines)
+ st_as_sf(jp) # No warning
+ 
+ data(nztrees)
+ qNZ <- quadratcount(nztrees, nx=4, ny=3)
+ ts = as.tess(qNZ)
+ plot(st_as_sfc(ts))
+ 
+ ls = st_linestring(rbind(c(0,0), c(1,1), c(2,0)))
+ plot(as.psp(ls))
+ mls = st_multilinestring(list(rbind(c(0,0), c(1,1), c(2,0)), rbind(c(3,3), c(4,2))))
+ plot(as.psp(mls))
+ 
+ plot(as.psp(st_sfc(ls)))
+ plot(as.psp(st_sfc(mls)))
+ plot(as.psp(st_sfc(ls, mls)))
+ 
+ sf = st_sf(st_cast(st_sfc(ls, mls), "MULTILINESTRING"), marks = 1:2, foo = 2:1)
+ as.psp(sf) # picks marks itself
+ as.psp(sf, marks = 5:1)
+ 
+ (x = st_as_sf(as.psp(sf)))
+ (y = st_as_sfc(as.psp(sf)))
+ all.equal(st_geometry(x), y)
+ }
spatstat.geom 3.0-3
spatstat.random 3.0-0
Simple feature collection with 51 features and 1 field
Geometry type: GEOMETRY
Dimension:     XY
Bounding box:  xmin: 123829 ymin: 14744.69 xmax: 930521.8 ymax: 318259.9
CRS:           NA
First 10 features:
    label                           geom
1  window MULTIPOLYGON (((886136 3141...
2   point      POINT (339121.3 257815.9)
3   point      POINT (827443.1 246572.7)
4   point          POINT (451340 207948)
5   point      POINT (268749.6 203327.8)
6   point      POINT (516677.7 198560.6)
7   point        POINT (692368 238647.5)
8   point        POINT (843281.2 287246)
9   point        POINT (648479.4 235471)
10  point      POINT (852595.8 267252.6)
Error in st_poly_sample(x, size = size, ..., type = type, by_polygon = by_polygon) : 
  rthomas is not an exported function from spatstat.random.
Error in st_poly_sample(x, size = size, ..., type = type, by_polygon = by_polygon) : 
  The spatstat function rThomas did not return a valid result. Consult the help file.
Error message from spatstat:
Error : 'scale' should be a single number

Error : Only projected coordinates may be converted to spatstat class objects
Error in `marks<-.ppp`(`*tmp*`, value = value) : 
  number of rows of data frame != number of points
In addition: Warning messages:
1: In as.ppp.sf(sf) : only first attribute column is used for marks
2: 1 point was rejected as lying outside the specified window 
Error in as.owin.sfc_MULTIPOLYGON(st_cast(W, "MULTIPOLYGON"), ...) : 
  Only projected coordinates may be converted to spatstat class objects
[1] TRUE
Warning message:
In st_as_sfc.owin(spatstat.geom::as.owin(x)) :
  The spatstat object has an measurement unit multiplier != 1. Consider rescaling before converting.
> 
> proc.time()
   user  system elapsed 
  2.495   0.845   2.446 

Generated by dwww version 1.15 on Sun Jun 30 09:51:32 CEST 2024.