R中多边形的CRATING核密度估计 [英] Crating Kernel density estimate for polygon in R

查看:0
本文介绍了R中多边形的CRATING核密度估计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个多边形的shapefile和分布在这些多边形上的另一个点。我想为每个多边形创建一个基于它所包含的点的核密度估计。不幸的是,我只能使用MASS包中的kde2d函数创建平方的KDE。我希望KDEs被塑造成多边形。 有什么建议吗?

 kde1 <- kde2d(poly$X, poly$Y, n=100,)

enter image description here

推荐答案

您可以使用spatstat包来执行此操作。下面是一个阅读的例子 在sf的shapefile中,生成随机点并运行内核密度 点强度估计值(单位面积点数):

library(sf)
#> Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
nc <- st_read(system.file("shape/nc.shp", package="sf"))
#> Reading layer `nc' from data source `/usr/lib/R/site-library/sf/shape/nc.shp' using driver `ESRI Shapefile'
#> Simple feature collection with 100 features and 14 fields
#> geometry type:  MULTIPOLYGON
#> dimension:      XY
#> bbox:           xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965
#> geographic CRS: NAD27
nc_flat <- st_transform(nc, crs = 26917)
W <- as.owin(nc_flat$geometry[1]) # First county of North Carolina data set in spatstat format

library(spatstat)
X <- runifpoint(100, win = W)
plot(X, "Random points")

D <- density(X)
plot(D, main = "KDE")

这篇关于R中多边形的CRATING核密度估计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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