Closed stalkerGH closed 10 months ago
I think the defaultRadius
is measured in geographical coordinates (i.e., degrees lat / long).
So if coordinates are X,Y (with decimal parts), then radius is (X+/- defaultRadius) and the same for Y?
Basically, but I think it depends on the zoom as well.
We do:
defaultRadius <- 0.0225
if (!is.null(zoom)) { # We enter this statement since we are not in the app
radius <- geosphere::distm(x = c(city[["long"]], city[["lat"]]), y = c(city[["long"]], city[["lat"]] + defaultRadius * (1 / zoom)), fun = geosphere::distHaversine)
} else {
radius <- geosphere::distm(x = c(city[["long"]], city[["lat"]]), y = c(city[["long"]], input[["osm_bounds"]][["north"]]), fun = geosphere::distHaversine)
}
cropped <- data.frame(lat = city[["lat"]], long = city[["long"]]) |>
sf::st_as_sf(coords = c("long", "lat"), crs = 4326) |>
# sf::st_buffer(dist = radius) |> # see https://github.com/r-spatial/sf/issues/1692
s2::s2_buffer_cells(distance = radius, max_cells = 5000) |>
sf::st_as_sf()
So in coordinates the view box (cropped
) is [xmin: city[["lat"]] - defaultRadius (1 / zoom), xmax: city[["lat"]] + defaultRadius (1 / zoom)] and the same for ymin and ymax but then with long. However, we do not use the default radius directly but compute a radius (I believe in meters) based on the location on earth (geosphere::distHaversine
). Then we get the actual view box.
Thank you forn in-depth explanation. Now I understand why zoom > 1 is faster than zoom < 1.
And thanks for pointing to distHaversine
function!
It's rather a question than the bug. What is
defaultRadius
meaning in builders.R? What units does it use?