简体   繁体   English

如何获取R中坐标为GPS的点周围的一些点?

[英]How to obtain some points located around a points with GPS coordinates in R?

I am quite new to cartography operations with R. I would like to know if the there is a way to find some points located around a given GPS point.我对 R 的制图操作很陌生。我想知道是否有办法找到给定 GPS 点周围的一些点。

Imagine that I have a data.table as follows:假设我有一个 data.table,如下所示:

Reference_Coordinates <- data.table(Latitude=c(1,2,3), Longitude=c(4,5,6), Point_ID=c("Point1","Point2","Point3")).

If I assume that each point is the centre of a circle, how could I get some points located at equal distance from the origin?如果我假设每个点都是一个圆的中心,我怎样才能得到一些与原点距离相等的点? For instance, 10 points forming a 1-km radius circle around point 1, then another 10 points around point 2, et cetera?例如,10 个点围绕点 1 形成一个 1 公里半径的圆,然后另外 10 个点围绕点 2,等等? I wanted to use a WGS 84 standard ellipsoid.我想使用 WGS 84 标准椭圆体。

Thank you very much.非常感谢。

I've read some answers in this forum and I supose I could use some packages such as sf or sp, but I couldn't find the solution to my question.我在这个论坛上阅读了一些答案,我想我可以使用一些包,如 sf 或 sp,但我找不到我的问题的解决方案。

Using the R package terra , you can create 3 points from the lat / lon co-ordinates like this:使用 R package terra ,您可以从纬度/经度坐标创建 3 个点,如下所示:

library(terra)

v <-vect(cbind(Reference_Coordinates$Longitude, Reference_Coordinates$Latitude),
        type = 'points', crs = 'WGS84')

To get a collection of points 10km from each starting point, you can do:要从每个起点收集 10 公里的点,您可以执行以下操作:

p <- as.points(buffer(v, 10000, quadsegs = 3))

Which looks like this:看起来像这样:

plot(p, xlab = 'longitude', ylab = 'latitude')

To get the co-ordinates of each of these points, you can simply do要获得每个点的坐标,您可以简单地做

crds(p)
#>              x         y
#>  [1,] 4.000000 1.0904366
#>  [2,] 4.044924 1.0783201
#>  [3,] 4.077809 1.0452174
#>  [4,] 4.089845 0.9999988
#>  [5,] 4.077807 0.9547807
#>  [6,] 4.044922 0.9216792
#>  [7,] 4.000000 0.9095633
#>  [8,] 3.955078 0.9216792
#>  [9,] 3.922193 0.9547807
#> [10,] 3.910155 0.9999988
#> [11,] 3.922191 1.0452174
#> [12,] 3.955076 1.0783201
#> [13,] 5.000000 2.0904358
#> [14,] 5.044945 2.0783191
#> [15,] 5.077846 2.0452160
#> [16,] 5.089886 1.9999975
#> [17,] 5.077841 1.9547802
#> [18,] 5.044941 1.9216796
#> [19,] 5.000000 1.9095641
#> [20,] 4.955059 1.9216796
#> [21,] 4.922159 1.9547802
#> [22,] 4.910114 1.9999975
#> [23,] 4.922154 2.0452160
#> [24,] 4.955055 2.0783191
#> [25,] 6.000000 3.0904344
#> [26,] 6.044980 3.0783175
#> [27,] 6.077906 3.0452144
#> [28,] 6.089954 2.9999963
#> [29,] 6.077899 2.9547800
#> [30,] 6.044974 2.9216805
#> [31,] 6.000000 2.9095655
#> [32,] 5.955026 2.9216805
#> [33,] 5.922101 2.9547800
#> [34,] 5.910046 2.9999963
#> [35,] 5.922094 3.0452144
#> [36,] 5.955020 3.0783175

Created on 2023-01-31 with reprex v2.0.2创建于 2023-01-31,使用reprex v2.0.2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM