将 sf 转换为标记的 ppp [英] Convert sf to marked ppp

查看:39
本文介绍了将 sf 转换为标记的 ppp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用下面的代码成功地将一个 sf 对象转换为 ppp:

I successfully converted an sf object to ppp using the code below:

sf_owin = maptools::as.ppp.SpatialPointsDataFrame(as_Spatial(sf_points__flat))

sf_owin = maptools::as.ppp.SpatialPointsDataFrame(as_Spatial(sf_points__flat))

sf_points__flat 看起来像这样:

sf_points__flat looks like this:

Simple feature collection with 131 features and 3 fields
geometry type:  MULTIPOINT
dimension:      XY
bbox:           xmin: -1932934 ymin: 4958872 xmax: -1439558 ymax: 5861173
projected CRS:  NAD83(2011) / UTM zone 16N
# A tibble: 131 x 4
# Groups:   COOPID [131]
   COOPID STATION_NA                         geometry Annual_Precipitation
 *  <dbl> <chr>                      <MULTIPOINT [m]>                <dbl>
 1      0 Ontario                ((-1899685 5335073))                 9.24
 2 100010 ABERDEEN EXPERIMNT STN ((-1610453 5091311))                12.4 
 3 100227 AMERICAN FALLS 3 NW    ((-1623401 5075011))                20.4 
 4 100282 ANDERSON DAM           ((-1807106 5212322))                16.3 
 5 100347 ARBON 2 NW             ((-1606302 5034484))                10.2 
 6 100375 ARCO                   ((-1622855 5179969))                19.5 
 7 100448 ARROWROCK DAM          ((-1834338 5254236))                20.1 
 8 100470 ASHTON                 ((-1458491 5179214))                37.5 
 9 100528 AVERY RS #2            ((-1678382 5654084))                25.3 
10 100667 BAYVIEW MODEL BASIN    ((-1691954 5753129))                 9.69
# ... with 121 more rows

sf_owin 看起来像这样:

sf_owin looks like this:

Marked planar point pattern: 131 points
Mark variables: COOPID, STATION_NA, Annual_Precipitation 
window: rectangle = [-1932934.3, -1439558.2] x [4958872, 5861173] units

现在当我尝试创建 ppp 标记类型时出现错误

Now when I try to create a ppp mark type I get an error

Stations_ppp_types = split(sf__owin, which.marks = "Type")
Error in split.ppp(sf__owin, which.marks = "Type") : 
  Data frame of marks contains no factors

如何通过将 sf 对象转换为 ppp 来按标记(STATION_NA)拆分 ppp

How to split a ppp by marks(STATION_NA) by converting an sf object to ppp

推荐答案

这个问题是关于 spatstat 包的.

This question is about the spatstat package.

错误信息表明split命令被分派到split.ppp,所以你可以查找split.ppp的帮助找出问题所在.

The error message indicates that the split command is dispatched to split.ppp, so you could look up the help for split.ppp to figure out the problem.

帮助文件会告诉你 split.ppp 忽略了参数 which.marks.所以你可以删除那个参数.

The help file would tell you that the argument which.marks is ignored by split.ppp. So you can remove that argument.

要拆分点模式,您需要一个 factor(指定分组的分类值向量).点图案中的标记不是因素.(这就是错误消息所说的.)根据您的打印输出,列 STATION_NA 是字符值.如果要根据这些值拆分模式,则需要将它们转换为因子值.例如

To split the point pattern, you need a factor (a vector of categorical values which specify the grouping). The marks in the point pattern are not factors. (This is what the error message is saying.) According to your printed output, the column STATION_NA is character valued. If you want to split the pattern according to these values, you need to convert them to factor values. For example

f <- marks(sf_owin)$"STATION_NA"
f <- factor(f)
Y <- split(sf_owin, f)

或者您可以先修复点模式中的标记,以便split.ppp自动运行:

or you could repair the marks in the point pattern first, so that split.ppp would work automatically:

marks(sf_owin)$"STATION_NA" <- factor(marks(sf_owin)$"STATION_NA")
Y <- split(sf_owin)

这篇关于将 sf 转换为标记的 ppp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆