## ---- echo=FALSE, include=FALSE----------------------------------------------- library(knitr) opts_chunk$set( fig.width = 5, fig.height = 5, fig.cap = '', collapse = TRUE ) ## ---- geo1-------------------------------------------------------------------- library(geosphere) Lon = c(1:9/1000, 1:9/100, 1:9/10, 1:90*2) Lat = c(1:9/1000, 1:9/100, 1:9/10, 1:90) dcos = distCosine(c(0,0), cbind(Lon, Lat)) dhav = distHaversine(c(0,0), cbind(Lon, Lat)) dvsp = distVincentySphere(c(0,0), cbind(Lon, Lat)) par(mfrow=(c(1,2))) plot(log(dcos), dcos-dhav, col='red', ylim=c(-1e-05, 1e-05), xlab="Log 'Law of Cosines' distance (m)", ylab="Law of Cosines minus Haversine distance") plot(log(dhav), dhav-dvsp, col='blue', xlab="Log 'Haversine' distance (m)", ylab="Vincenty Sphere minus Haversine distance") ## ---- geo2-------------------------------------------------------------------- dvse = distVincentyEllipsoid(c(0,0), cbind(Lon, Lat)) plot(dvsp/1000, (dvsp-dvse)/1000, col='blue', xlab='Vincenty Sphere Distance (km)', ylab="Difference between 'Vincenty Sphere' and 'Vincenty Ellipsoid' methods (km)") ## ---- geo14------------------------------------------------------------------- line <- rbind(c(-180,-20), c(-150,-10), c(-140,55), c(10, 0), c(-140,-60)) pnts <- rbind(c(-170,0), c(-75,0), c(-70,-10), c(-80,20), c(-100,-50), c(-100,-60), c(-100,-40), c(-100,-20), c(-100,-10), c(-100,0)) d = dist2Line(pnts, line) plot( makeLine(line), type='l') points(line) points(pnts, col='blue', pch=20) points(d[,2], d[,3], col='red', pch='x', cex=2) for (i in 1:nrow(d)) lines(gcIntermediate(pnts[i,], d[i,2:3], 10), lwd=2, col='green')