【问题标题】:Generating GPS Coordinates / creating a raster of evenly distributed points 1km apart生成 GPS 坐标/创建相距 1 公里的均匀分布点的栅格
【发布时间】:2020-11-11 17:50:56
【问题描述】:

我想覆盖一个由 bbox lat long 坐标与相距 1 公里的 gps 点 raster 定义的区域。目前我通过以下方式为 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 安德烈亚斯

【问题讨论】:

  • runif 将给出随机分布,即不均匀分布。您需要 1 公里栅格上的点吗?
  • 是的,我需要一个相距 1 公里的定义区域内的 GPS 点。
  • 您能否具体说明“相距 1 公里”和“栅格”是什么意思?我们是在谈论一个正方形网格,其中一个点与其直接邻居之间的距离正好是 1km(这也意味着到当前点对角线的点的距离是 sqrt(2)km)?抱歉,也许我在空间分析方面还不够准确,无法正确理解您的问题。
  • 嗨@mabreitling,谢谢你的回复。是的,这正是我的意思:“我们正在谈论一个正方形网格,其中一个点与其直接邻居之间的距离正好为 1 公里(这也意味着与当前点对角线的点的距离是 sqrt(2)公里)”
  • 看起来好像geosphere package 中的destPoint 函数应该给你你想要的:函数 destPoint 返回给定原点的点的位置,以及距离和方位.

标签: r gis sf geosphere


【解决方案1】:

我对空间数据和分析不太感兴趣,但第一步可能会有所帮助(我采用不同的坐标来获得一个可重复的示例,它适合德国的维度,我对这些维度有一些感觉)。我确信有一种更优雅的方式,但它应该可以满足您的需求。 geosphere::destPoint() 用于计算给定距离和方向的点,geosphere::distGeo() 计算给定框的南北/东西距离,以计算每个方向需要多少点。然后使用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)

【讨论】:

  • 非常感谢mabreitling!另一个问题:初始坐标 nw,se:它们来自哪里?例如,如果我想为每个德州推广这种方法,我会怎么做?
  • 嗯,这些只是德国边界框的近似值(如您所见,这并不完全正确)。 nw 是最北端(在丹麦边境某处)的纬度值和最西端经度的组合。对于每个联邦,这些值可以从各自的 shapefile 中计算出来。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-09-14
  • 2019-01-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多