简体   繁体   English

Append spatstat 跨镶嵌表面(源自 shapefile)的强度输出返回到 SpatialPolygonsDataFrame 以在 R 中绘图

[英]Append spatstat intensity outputs across tesselated surface (derived from shapefile) back to SpatialPolygonsDataFrame for plotting in R

Anyone have advice for retaining (or appending) attributes from a Spatial Polygons Data Frame after conversion to an owin object for pattern analysis in Spatstat?有人建议转换为 owin object 以在 Spatstat 中进行模式分析后从空间多边形数据框中保留(或附加)属性吗?

Using spatstat to calculate point intensities across a tesselated surface.使用 spatstat 计算镶嵌曲面上的点强度。 No issue with this except I lose the polygon labels when I convert the Spatial Polygons Data Frame to an owin object (and subsequently a tess object).没有问题,除了当我将空间多边形数据框转换为 owin object(以及随后的 tess 对象)时丢失了多边形标签。 See sample code.请参阅示例代码。 Thanks!谢谢!


SF <- readOGR(dsn="D:/",layer="sf")
class(SF) # "SpatialPolygonsDataFrame"

# Convert SpatialPolygonsDataFrame to OWIN object for use in spatstat package

y <- as(SF, "SpatialPolygons")
p <- slot(y, "polygons")
v <- lapply(p, function(z) { SpatialPolygons(list(z)) })
winlist <- lapply(v, as.owin)

# establish window needed for creating tesseslated surface
SF2 <- as(SF, "owin")

# create tesselates surface
e <-tess(tiles = winlist, window = SF2)

## compute counts and density values, across tessellated area, of point data 

# B - point pattern object created from *.csv of point locations

QB   <- quadratcount(B, tess = e)  # tally counts of 'biotic pseudo-variables' by tess tiles
Qi.B <- intensity(QB)  # Compute intensity

# Plot results
plot(intensity(QB, image=TRUE), las=1, main=NULL) # plot tess units using intensity for legend
plot(B, pch=20, cex=0.5, col="white", add=TRUE)```

You will need to manually extract the polygon labels from the SpatialPolygonsDataFrame object SF as a character vector, and then assign them to the names of the tiles in the tessellation object e .您需要从SpatialPolygonsDataFrame object SF手动提取多边形标签作为字符向量,然后将它们分配给镶嵌 object e中的瓦片名称。

To extract the polygon labels you can probably type nama <- rownames(SF) but it depends which labels you require.要提取多边形标签,您可以键入nama <- rownames(SF) ,但这取决于您需要哪些标签。

There are two ways to assign the tile names:有两种方法可以分配磁贴名称:

  1. Assign names to the list of tiles before creating the tessellation.在创建曲面细分之前为图块列表分配名称。 In the command e <- tess(tiles=winlist, window=SF2) , if names(winlist) is not NULL then the names will be retained as the names of the tiles.在命令e <- tess(tiles=winlist, window=SF2)中,如果names(winlist)不是NULL则名称将保留为图块的名称。 So you could first do names(winlist) <- nama and then e <- tess(tiles=winlist, window=SF2) .所以你可以先做names(winlist) <- nama然后e <- tess(tiles=winlist, window=SF2)

  2. Assign tile names after creating the tessellation using "tilenames<-" ,as in tilenames(e) <- nama where nama is a character vector.使用"tilenames<-"创建曲面细分后分配图块名称,如tilenames(e) <- nama其中nama是字符向量。

In either case, once the tiles of e have names, the results of calculations such as Qi.B will also have these names.无论哪种情况,一旦e的瓦片有了名字, Qi.B等计算结果也会有这些名字。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM