【问题标题】:Constructing weight matrix from shapefile in R从R中的shapefile构造权重矩阵
【发布时间】:2016-09-26 01:48:13
【问题描述】:

我正在尝试从 R 中的 shapefile (.shp) 构造一个空间权重矩阵。问题是,我什至不知道如何去做。而且我很难找到任何参考。我发现大部分教程只描述了如何使用 shapefile/map,或者他们使用了一个已经可用的邻域列表(例如 columbus.nb)。

任何帮助将不胜感激。提前致谢。

【问题讨论】:

  • 也许这post 将是一个开始。

标签: r shapefile


【解决方案1】:

我认为这段代码行

dist2.mat <- spdep::listw2mat(dist2.mat)

有错误,应该是

listw2mat(dist2.listw ) 

改为

【讨论】:

    【解决方案2】:

    我希望下面的代码可以帮助:

    shapefile <- rgdal::readOGR(“shapefile_file.shp”)
    coordinatess <- sp::coordinates(shapefile)
    shapefile.knn <- spdep::knearneigh(coordinatess, k = number_of_shapefile_rows)
    shapefile.nb <- spdep::knn2nb(shapefile.knn)
    
    #list:
    dist <- spdep::nbdists(shapefile.nb,coordinates)
    dist2 <- lapply(dist, function(x) 1/(x^2)) 
    
    #listw:
    dist2.listw <- spdep::nb2listw(shapefile.nb, glist=dist2)
    
    #matrix:
    dist2.mat <- spdep::listw2mat(dist2.mat)
    

    它创建了平方距离矩阵——在我看来,这通常是空间计量经济学的最佳选择。它可以很容易地得到k个最近邻矩阵或倒置距离矩阵。

    必需的包写在 '::' 操作符之前。您需要安装它们。

    【讨论】:

      猜你喜欢
      • 2013-11-29
      • 2020-08-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-16
      相关资源
      最近更新 更多