在R中的空间点数据周围创建缓冲区,并计算缓冲区中有多少个点 [英] Create buffer around spatial point data in R and count how many points are in the buffer

查看:481
本文介绍了在R中的空间点数据周围创建缓冲区,并计算缓冲区中有多少个点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用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

I am trying to analyze spatial density of gas station points using R. I need to create a buffer (circle) around the gas stations and count the number of gas stations within the buffer. I'll then need to play around with buffer distances to see what's a reasonable buffer to see something interesting. These are the files I am working with: 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

# 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)

任何帮助都非常感谢!

推荐答案

我发现了我的问题的答案: 5公里<-cbind(坐标(位置),X = rowSums(distm(坐标(位置)[,1:2],fun = distHaversine))/ 1000< = 5 ))#5公里内的点数

I found an answer to my question: fivekm <- cbind(coordinates(locs), X=rowSums(distm (coordinates(locs)[,1:2], fun = distHaversine) / 1000 <= 5)) # number of points within 5 km

这篇关于在R中的空间点数据周围创建缓冲区,并计算缓冲区中有多少个点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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