我希望将一个 sf
对象转换成一个未标记的 ppp
对象。(根据 这篇文章,现在支持从 sf
转换成 ppp
。)
library(sf)
#Initialise sf object
pp <- structure(list(X = c(959207.877070254, 959660.734838225, 951483.685462513, 951527.767554883, 958310.673042469, 950492.05212104, 959660.734838225, 959207.877070254, 960500.020456073, 959660.734838225), Y = c(1944457.42827898, 1955543.76027363, 1939982.16629396, 1940216.55143212, 1954704.68186897, 1951434.68524296, 1955543.76027363, 1944457.42827898, 1955292.64874361, 1955543.76027363), geometry = structure(list(structure(c(959207.877070254, 1944457.42827898), class = c("XY", "POINT", "sfg")), structure(c(959660.734838225, 1955543.76027363), class = c("XY", "POINT", "sfg")), structure(c(951483.685462513, 1939982.16629396), class = c("XY", "POINT", "sfg")), structure(c(951527.767554883, 1940216.55143212), class = c("XY", "POINT", "sfg")), structure(c(958310.673042469, 1954704.68186897), class = c("XY", "POINT", "sfg")), structure(c(950492.05212104, 1951434.68524296), class = c("XY", "POINT", "sfg")), structure(c(959660.734838225, 1955543.76027363), class = c("XY", "POINT", "sfg")), structure(c(959207.877070254, 1944457.42827898), class = c("XY", "POINT", "sfg")), structure(c(960500.020456073, 1955292.64874361), class = c("XY", "POINT", "sfg")), structure(c(959660.734838225, 1955543.76027363), class = c("XY", "POINT", "sfg"))), class = c("sfc_POINT", "sfc"), precision = 0, bbox = structure(c(xmin = 950492.05212104, ymin = 1939982.16629396, xmax = 960500.020456073, ymax = 1955543.76027363 ), class = "bbox"), crs = structure(list(input = "EPSG:5179", wkt = "PROJCRS[\"Korea 2000 / Unified CS\",\n BASEGEOGCRS[\"Korea 2000\",\n DATUM[\"Geocentric datum of Korea\",\n ELLIPSOID[\"GRS 1980\",6378137,298.257222101,\n LENGTHUNIT[\"metre\",1]]],\n PRIMEM[\"Greenwich\",0,\n ANGLEUNIT[\"degree\",0.0174532925199433]],\n ID[\"EPSG\",4737]],\n CONVERSION[\"Korea Unified Belt\",\n METHOD[\"Transverse Mercator\",\n ID[\"EPSG\",9807]],\n PARAMETER[\"Latitude of natural origin\",38,\n ANGLEUNIT[\"degree\",0.0174532925199433],\n ID[\"EPSG\",8801]],\n PARAMETER[\"Longitude of natural origin\",127.5,\n ANGLEUNIT[\"degree\",0.0174532925199433],\n ID[\"EPSG\",8802]],\n PARAMETER[\"Scale factor at natural origin\",0.9996,\n SCALEUNIT[\"unity\",1],\n ID[\"EPSG\",8805]],\n PARAMETER[\"False easting\",1000000,\n LENGTHUNIT[\"metre\",1],\n ID[\"EPSG\",8806]],\n PARAMETER[\"False northing\",2000000,\n LENGTHUNIT[\"metre\",1],\n ID[\"EPSG\",8807]]],\n CS[Cartesian,2],\n AXIS[\"northing (X)\",north,\n ORDER[1],\n LENGTHUNIT[\"metre\",1]],\n AXIS[\"easting (Y)\",east,\n ORDER[2],\n LENGTHUNIT[\"metre\",1]],\n USAGE[\n SCOPE[\"unknown\"],\n AREA[\"Korea, Republic of (South Korea)\"],\n BBOX[28.6,122.71,40.27,134.28]],\n ID[\"EPSG\",5179]]"), class = "crs"), n_empty = 0L)), row.names = c(4177L, 15721L, 21365L, 21973L, 24836L, 59359L, 66313L, 70379L, 83277L, 90828L), class = c("sf", "data.frame"), sf_column = "geometry", agr = structure(c(X = NA_integer_, Y = NA_integer_), .Label = c("constant", "aggregate", "identity" ), class = "factor"))
library(spatstat)
#Convert to ppp format: method 1
pp1 <- as.ppp(pp)
#Warning message:
#In as.ppp.sf(pp) : only first attribute column is used for marks
pp1 <- unmark(pp1)
#Convert to ppp format: method 2
pp2 <- as.ppp(st_coordinates(pp), st_convex_hull(st_union(pp)))
#Warning message:
#data contain duplicated points
identical(pp1, pp2)
[1] FALSE
第一种方法需要使用标记,我没有找到如何关闭它的方法(指定
marks=NULL
无法生效)。此后我会将标记移除,但这只是个权宜之计。第二种方法可能有误,因为有警告出现,尽管我是依据这个解决方案来制作的。这两个输出并不相同。
这两种方法中是否存在正确的方法?为什么第二种方法会产生重复的点?有没有更直接的方法可以进行转化而不需要解决问题?
sf
中足以定位点,所以我无用地将坐标 X 和 Y 复制到单独的列中,然后spatstat
将其解释为标记... - syre