|
15 | 15 | #' @examples
|
16 | 16 | #' d <- read.table(header=TRUE, sep=",", text="
|
17 | 17 | #' lat, long
|
18 |
| -#' 52.514687, 13.350012 # Berlin |
19 |
| -#' 35.685024, 139.753365 # Tokio |
20 |
| -#' 51.503162, -0.131082") # London |
21 |
| -#' earthDist(lat, long, d) # from Berlin to T and L: 8922 and 928 km |
22 |
| -#' earthDist(lat, long, d, i=3) # from London to B and T: 928 and 9562 km |
| 18 | +#' 52.514687, 13.350012 # Berlin |
| 19 | +#' 51.503162, -0.131082 # London |
| 20 | +#' 35.685024, 139.753365") # Tokio |
| 21 | +#' earthDist(lat, long, d) # from Berlin to L and T: 928 and 8922 km |
| 22 | +#' earthDist(lat, long, d, i=2) # from London to B and T: 928 and 9562 km |
| 23 | +#' # slightly different with other formulas: |
| 24 | +#' # install.packages("geosphere") |
| 25 | +#' # geosphere::distHaversine(as.matrix(d[1,2:1]), as.matrix(d[2,2:1])) / 1000 |
| 26 | +#' |
| 27 | +#' \dontrun{ # don't download stuff in R CMD check |
23 | 28 | #' map <- pointsMap(lat, long, d, zoom=2, abslen=5000, y=0.7)
|
24 | 29 | #' scaleBar(map, y=0.5, abslen=5000) # in mercator projections, scale bars are not
|
25 | 30 | #' scaleBar(map, y=0.3, abslen=5000) # transferable to other latitudes
|
26 |
| -#' # slightly different with other formulas: |
27 |
| -#' # geosphere::distHaversine(as.matrix(d[1,2:1]), as.matrix(d[2,2:1])) / 1000 |
| 31 | +#' |
| 32 | +#' map_utm <- pointsMap(lat, long, d[1:2,], proj=putm(long=d$long[1:2]), |
| 33 | +#' zoom=4, y=0.7, abslen=500) |
| 34 | +#' scaleBar(map_utm, y=0.5, abslen=500) # transferable in UTM projection |
| 35 | +#' scaleBar(map_utm, y=0.3, abslen=500) |
| 36 | +#' } |
28 | 37 | #'
|
29 | 38 | #' # compare with UTM distance
|
30 | 39 | #' set.seed(42)
|
@@ -76,7 +85,8 @@ x2 <- long*pi/180
|
76 | 85 | # angle preparation (numerical inaccuracies may lead to 1.0000000000000002):
|
77 | 86 | cosinusangle <- sin(y1)*sin(y2) + cos(y1)*cos(y2)*cos(x1-x2)
|
78 | 87 | cosinusangle <- replace(cosinusangle, cosinusangle>1, 1)
|
79 |
| -cosinusangle <- replace(cosinusangle, cosinusangle<0, 0) |
| 88 | +#cosinusangle <- replace(cosinusangle, cosinusangle<0, 0) |
| 89 | +cosinusangle[ sapply(cosinusangle, function(x) isTRUE(all.equal(x,1))) ] <- 1 |
80 | 90 | # angle between lines from earth center to coordinates:
|
81 | 91 | angle <- acos( cosinusangle )
|
82 | 92 | # compute great-circle-distance:
|
|
0 commit comments