## ---- echo=FALSE, include=FALSE----------------------------------------------- library(knitr) library(geosphere) opts_chunk$set( fig.width = 5, fig.height = 5, fig.cap = '',collapse = TRUE ) ## ---- geo5a------------------------------------------------------------------- library(geosphere) LA <- c(-118.40, 33.95) NY <- c(-73.78, 40.63) destPoint(LA, b=65, d=100000) circle=destPoint(c(0,80), b=1:365, d=1000000) circle2=destPoint(c(0,80), b=1:365, d=500000) circle3=destPoint(c(0,80), b=1:365, d=100000) plot(circle, type='l') polygon(circle, col='blue', border='black', lwd=4) polygon(circle2, col='red', lwd=4, border='orange') polygon(circle3, col='white', lwd=4, border='black') ## ---- geo10------------------------------------------------------------------- MS <- c(-93.26, 44.98) gc1 <- greatCircleBearing(NY, 281) gc2 <- greatCircleBearing(MS, 195) gc3 <- greatCircleBearing(LA, 55) data(wrld) plot(wrld, type='l', xlim=c(-125, -70), ylim=c(20, 60)) lines(gc1, col='green') lines(gc2, col='blue') lines(gc3, col='red') int <- gcIntersectBearing(rbind(NY, NY, MS), c(281, 281, 195), rbind(MS, LA, LA), c(195, 55, 55)) int distm(rbind(int[,1:2], int[,3:4])) int <- int[,1:2] points(int) poly <- rbind(int, int[1,]) centr <- centroid(poly) poly2 <- makePoly(int) polygon(poly2, col='yellow') points(centr, pch='*', col='dark red', cex=2) ## ---- geo5b------------------------------------------------------------------- d <- distCosine(LA, NY) d b <- bearing(LA, NY) b destPoint(LA, b, d) NY finalBearing(LA, NY) ## ---- geo12------------------------------------------------------------------- atd <- alongTrackDistance(LA, NY, MS) p <- destPoint(LA, b, atd) plot(wrld, type='l', xlim=c(-130,-60), ylim=c(22,52)) gci <- gcIntermediate(LA, NY) lines(gci, col='blue', lwd=2) points(rbind(LA, NY), col='red', pch=20, cex=2) points(MS[1], MS[2], pch=20, col='blue', cex=2) lines(gcIntermediate(LA, p), col='green', lwd=3) lines(gcIntermediate(MS, p), col='dark green', lwd=3) points(p, pch=20, col='red', cex=2) dist2gc(LA, NY, MS) distCosine(p, MS) ## ---- , geo16, fig.width=9---------------------------------------------------- NP <- c(0, 85) SF <- c(-122.44, 37.74) bearing(SF, NP) b <- bearingRhumb(SF, NP) b dc <- distCosine(SF, NP) dr <- distRhumb(SF, NP) dc / dr pr <- destPointRhumb(SF, b, d=round(dr/100) * 1:100) pc <- rbind(SF, gcIntermediate(SF, NP), NP) par(mfrow=c(1,2)) plot(wrld, type='l', xlim=c(-140,10), ylim=c(15,90), main='Equirectangular') lines(pr, col='blue') lines(pc, col='red') data(merc) plot(merc, type='l', xlim=c(-15584729, 1113195), ylim=c(2500000, 22500000), main='Mercator') lines(mercator(pr), col='blue') lines(mercator(pc), col='red')