2017-02-28 75 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