Home > Net >  How to obtain some points located around a points with GPS coordinates in R?
How to obtain some points located around a points with GPS coordinates in R?

Time:01-31

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.

Imagine that I have a data.table as follows:

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? I wanted to use a WGS 84 standard ellipsoid.

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.

CodePudding user response:

Using the R package terra, you can create 3 points from the lat / lon co-ordinates like this:

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:

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

  • Related