生成 GPS 坐标/创建间隔 1 公里的均匀分布点的栅格
Generating GPS Coordinates / creating a raster of evenly distributed points 1km apart
我想覆盖一个由 bbox lat long
坐标定义的区域,其中 raster
个 gps 点相距 1 公里。目前我通过以下方式为 bboxbbox=8.9771580802,47.2703623267,13.8350427083,50.5644529365
生成 2000
点:
as.data.frame(cbind(runif(2000,8.9771580802 ,13.8350427083),runif(2000,47.2703623267,50.5644529365)))
由于 runif
是正态分布,我想我只需要增加点数以按照我需要的方式覆盖整个区域。
有没有更聪明的方法呢?
我需要多少积分?
更新
我想我也许可以使用包 sp
来完成这项工作,但我仍然不太熟悉设置:
longitudes <- c(8.9771580802, 13.8350427083)
latitudes <- c(47.2703623267, 50.5644529365)
bounding_box <- matrix(c(longitudes, latitudes), nrow = 2, byrow = TRUE, dimnames = list(NULL, c("min", "max")))
projection <- "+proj=longlat"
sp_box<-Spatial(bbox = bounding_box, proj4string = CRS(projection))
p_sample<-spsample(sp_box, 10000, type="regular")
如果我理解正确,这将给我一些均匀分布在我的坐标内的点。 spsample
有单元格大小的选项,但我还没有掌握。
BR
安德烈亚斯
我不太喜欢空间数据和分析,但作为第一步可能会有所帮助(我采用了不同的坐标来获得一个可重现的示例,它适合德国的尺寸,我对尺寸有一些感觉) .我确信有一种更优雅的方式,但它应该能满足您的需求。 geosphere::destPoint()
用于计算给定距离和方向的点,geosphere::distGeo()
计算给定框的 north-south/west-east 距离,以计算每个方向需要多少点。 expand_grid()
然后用于计算计算边界点的每个组合。
另请注意,我将点之间的距离更改为 10,000 米或 10 公里,以获得更少的点和更好的情节。您必须相应地更改数字
nw <- c(5.8 55)
se <- c(15.1, 47)
lon1 <- nw[1]
lat1 <- nw[2]
lon2 <- se[1]
lat2 <- se[2]
#(1) compute the border points in y direction, going south from the nw-point
# while keeping lon constant
lat <- geosphere::destPoint(nw, 180, 1:floor(geosphere::distGeo(c(lon1,lat1),
c(lon1,lat2))/10000)*10000)
lat <- as_tibble(lat)
#(2) compute the border point in x direction (analog to above)
lon <- geosphere::destPoint(nw, 90, 1:floor(geosphere::distGeo(c(lon1,lat1),
c(lon2,lat1))/10000)*10000)
lon <- as_tibble(lon)
# use expand_grid() to compute all combinations
grid <- tidyr::expand_grid(lat$lat, lon$lon)
names(grid) <- c("lat", "lon") #nicer names
### for visualizing what we've done, map germany with a grid overlay
germany <- rnaturalearth::ne_countries(type = "countries",
country = "germany", returnclass = "sf")
ggplot2::ggplot(data = germany)+
ggplot2::geom_sf()+
ggplot2::geom_point(data = grid, mapping = aes(x = lon, y = lat), size = 0.01)
我想覆盖一个由 bbox lat long
坐标定义的区域,其中 raster
个 gps 点相距 1 公里。目前我通过以下方式为 bboxbbox=8.9771580802,47.2703623267,13.8350427083,50.5644529365
生成 2000
点:
as.data.frame(cbind(runif(2000,8.9771580802 ,13.8350427083),runif(2000,47.2703623267,50.5644529365)))
由于 runif
是正态分布,我想我只需要增加点数以按照我需要的方式覆盖整个区域。
有没有更聪明的方法呢?
我需要多少积分?
更新
我想我也许可以使用包 sp
来完成这项工作,但我仍然不太熟悉设置:
longitudes <- c(8.9771580802, 13.8350427083)
latitudes <- c(47.2703623267, 50.5644529365)
bounding_box <- matrix(c(longitudes, latitudes), nrow = 2, byrow = TRUE, dimnames = list(NULL, c("min", "max")))
projection <- "+proj=longlat"
sp_box<-Spatial(bbox = bounding_box, proj4string = CRS(projection))
p_sample<-spsample(sp_box, 10000, type="regular")
如果我理解正确,这将给我一些均匀分布在我的坐标内的点。 spsample
有单元格大小的选项,但我还没有掌握。
BR
安德烈亚斯
我不太喜欢空间数据和分析,但作为第一步可能会有所帮助(我采用了不同的坐标来获得一个可重现的示例,它适合德国的尺寸,我对尺寸有一些感觉) .我确信有一种更优雅的方式,但它应该能满足您的需求。 geosphere::destPoint()
用于计算给定距离和方向的点,geosphere::distGeo()
计算给定框的 north-south/west-east 距离,以计算每个方向需要多少点。 expand_grid()
然后用于计算计算边界点的每个组合。
另请注意,我将点之间的距离更改为 10,000 米或 10 公里,以获得更少的点和更好的情节。您必须相应地更改数字
nw <- c(5.8 55)
se <- c(15.1, 47)
lon1 <- nw[1]
lat1 <- nw[2]
lon2 <- se[1]
lat2 <- se[2]
#(1) compute the border points in y direction, going south from the nw-point
# while keeping lon constant
lat <- geosphere::destPoint(nw, 180, 1:floor(geosphere::distGeo(c(lon1,lat1),
c(lon1,lat2))/10000)*10000)
lat <- as_tibble(lat)
#(2) compute the border point in x direction (analog to above)
lon <- geosphere::destPoint(nw, 90, 1:floor(geosphere::distGeo(c(lon1,lat1),
c(lon2,lat1))/10000)*10000)
lon <- as_tibble(lon)
# use expand_grid() to compute all combinations
grid <- tidyr::expand_grid(lat$lat, lon$lon)
names(grid) <- c("lat", "lon") #nicer names
### for visualizing what we've done, map germany with a grid overlay
germany <- rnaturalearth::ne_countries(type = "countries",
country = "germany", returnclass = "sf")
ggplot2::ggplot(data = germany)+
ggplot2::geom_sf()+
ggplot2::geom_point(data = grid, mapping = aes(x = lon, y = lat), size = 0.01)