2016-05-27 5 views
1

Rでシェープファイル(.shp)から空間ウェイト行列を構築しようとしています。そして私は参照を見つけるのが難しいです。ほとんどのチュートリアルでは、一般的にshapefile/mapを使って作業する方法や、すでに利用可能な近傍リスト(例:columbus.nb)を使用する方法についてのみ説明しています。シェイプファイルからウェイト行列を構築するR

本当にありがとうございます。前もって感謝します。

+0

多分、この[post](http://stackoverflow.com/questions/27304797/r-spatial-weights-asymmetric-adjacency-matrix)が始まります。 – lmo

答えて

1

私は、次のコードを助けるかもしれない願っています:

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個の最近隣行列または逆行列を得るために容易に変更することができる。

必要なパッケージは、::演算子の前に書かれています。インストールする必要があります。

関連する問題