0

I am trying to calculate sunrise/sunset times based on lat/long coordinates and have done it previously with an sp object and maptools::sunriset. This function doesn't take sf objects and sp is being deprecated so we need to switch over our code. Is anyone aware of a similar function that takes sf objects?

pts <- sf::st_as_sf(latLon, coords=c("lon", "lat"), crs=4326)

Where latLon is a data frame with latitude and longitude, we want to use pts object to get sunrise and sunset times.

Thank you in advance for your help!

  • 2
    [methods to coerce simple features](https://r-spatial.github.io/sf/reference/coerce-methods.html), you can use `as(pts, 'Spatial') or sf::as_Spatial(), from would = pts, then pass that to your maptools::sunriset. – Chris Dec 26 '21 at 18:58
  • 1
    [`site:cran.r-project.org sunrise`](https://www.google.com/search?q=site%3Acran.r-project.org+sunrise) suggests the [`suncalc`](https://cran.r-project.org/web/packages/suncalc/) package. (The google search pattern/link is offered as a mechanism for improving the quality of searching, since the "R" language is otherwise a bit difficult to find packages.) – r2evans Dec 26 '21 at 19:27
  • As to searching, one can also use 'in R', as it increases matches under google for the elusive 'R'. I generally start with r, then R, then CRAN, and then 'in R' at the start of my phrase. And welcome to Stackoverflow. And @r2evans is a better googler than me, but it is also worth remembering the extensive work done to facilitate backward compatibility across the R Spatial arc, and that a given R spatial object can be coerced to one's needs. Thoughtful effort went into this continuum. – Chris Dec 26 '21 at 23:18

0 Answers0