2017-02-28 74 views
0

我正在尝试使用R来分析加油站点的空间密度。我需要在加油站周围创建缓冲区(圆圈)并计算缓冲区内的加油站数量。然后,我需要充分利用缓冲距离来查看什么是合理的缓冲区,以查看有趣的内容。这些是我正在使用的文件:https://dl.dropboxusercontent.com/u/45095175/sbc_gas.shp; https://dl.dropboxusercontent.com/u/45095175/sbc_gas.shx; https://dl.dropboxusercontent.com/u/45095175/sbc_gas.dbf在R中的空间点数据周围创建缓冲区并计算缓冲区中的点数

# Install packages 
x <- c("ggmap", "rgdal", "rgeos", "maptools", "ks") 
lapply(x, library, character.only = TRUE) 
all <- readShapePoints("sbc_gas.shp") 
all.df <- as(all, "data.frame") 
locs <- subset(all.df, select = c("OBJECTID", "Latitude", "Longitude")) 
head(locs) # a simple data frame with coordinates 
coordinates(locs) <- c("Longitude", "Latitude") # set spatial coordinates 
plot(locs) 

任何帮助极大赞赏!

回答

0

我找到了我的问题的答案:fivekm <- cbind(coordinates(locs), X=rowSums(distm (coordinates(locs)[,1:2], fun = distHaversine)/1000 <= 5)) # number of points within 5 km

0

我们无法使用您提供的数据,因为.shp文件本身不够用。至少,您还必须提供.shx和.dbf文件才能加载此数据。

但是,应该工作的东西是得到包geosphere。它包含一个名为distGeo的函数。您可以使用它来获得从每个加油站到所有其他工作站的距离。从距离矩阵中,您应该能够选择指定距离内的所有站点。

+0

Thanks @ G5W!我添加了其他文件的链接。 – JAG2024

+0

@ JAG2024当我试图获得另外两个文件时,我收到一条消息,说他们无法下载。你必须设置一些权限才能下载? – G5W

+0

立即尝试?我更新了链接。您可能仍然有.dbf文件的问题。有什么方法可以直接发送给你? – JAG2024