R and leaflet plot an incorrect circle radius? -


here's code:

library(leaflet) library(geosphere)  startloc <- c(-100, 45) #long/lat endloc <- c(-100, 42) #long/lat  totaldist <- disthaversine(startloc, endloc)   leaflet() %>%   addtiles() %>%  # add default openstreetmap map tiles   addmarkers(lng=c(startloc[1],endloc[1]), lat=c(startloc[2], endloc[2]), popup  = paste(totaldist)) %>%   addcircles(lng = endloc[1], lat = endloc[2], radius = totaldist) 

as can see, top point not included in circle. think it's because "add circles" doesn't account curvature of earth? correct?

if use 2 points closer together, better...

this because web mercator not distance-preserving projection. leaflet drawing geometric circle on map, not finding points equidistant center. projection stretches distances go north, northern point outside geometric circle. if try

  startloc <- c(-103, 42) #long/lat   endloc <- c(-100, 42) #long/lat 

then left-hand point on circle; if reverse original points lower point inside circle.

try this:

library(geosphere) library(plyr) startloc <- c(-100, 45) #long/lat endloc <- c(-100, 42) #long/lat  totaldist <- disthaversine(startloc, endloc)  points = ldply(1:360, function(angle) destpoint(endloc, angle, totaldist)) leaflet() %>%   addtiles() %>%  # add default openstreetmap map tiles   addmarkers(lng=c(startloc[1],endloc[1]), lat=c(startloc[2], endloc[2]), popup  = paste(totaldist)) %>%   addpolygons(lng = points$lon, lat = points$lat) 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -