Giter VIP home page Giter VIP logo

Comments (4)

koenderks avatar koenderks commented on June 11, 2024 1

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.

from rcityviews.

koenderks avatar koenderks commented on June 11, 2024

I think the defaultRadius is measured in geographical coordinates (i.e., degrees lat / long).

from rcityviews.

stalkerGH avatar stalkerGH commented on June 11, 2024

So if coordinates are X,Y (with decimal parts), then radius is (X+/- defaultRadius) and the same for Y?

from rcityviews.

stalkerGH avatar stalkerGH commented on June 11, 2024

Thank you forn in-depth explanation. Now I understand why zoom > 1 is faster than zoom < 1.

And thanks for pointing to distHaversine function!

from rcityviews.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.