travel time map

> setwd("C:/akila")
> install.packages("remotes")
Error in install.packages : Updating loaded packages
> remotes::install_github(
+   "GIScience/openrouteservice-r"
+ )
Skipping install of 'openrouteservice' from a github remote, the SHA1 (b840b4ae) has not changed since last install.
  Use `force = TRUE` to force installation
> 
> libs <- c(
+   "tidyverse", "openrouteservice",
+   "sf", "leaflet", "maptiles",
+   "tidyterra"
+ )
> 
> installed_libs <- libs %in% rownames(
+   installed.packages()
+ )
> 
> if(any(installed_libs == F)){
+   install.packages(
+     libs[!installed_libs]
+   )
+ }
> 
> invisible(
+   lapply(
+     libs,
+     library,
+     character.only = T
+   )
+ )
> openrouteservice::ors_profile()
               car                hgv               bike           roadbike 
     "driving-car"      "driving-hgv"  "cycling-regular"     "cycling-road" 
               mtb             e-bike            walking             hiking 
"cycling-mountain" "cycling-electric"     "foot-walking"      "foot-hiking" 
        wheelchair 
      "wheelchair" 
> lat <- 7.2906
> lon <- 80.6337
> api_key <- "5b3ce3597851110001cf6248194f809445c147129bd1356000556a26" # PLEASE INSERT HERE YOUR API KEY
> coords <- data.frame(lon, lat)
> cycling_ams <- openrouteservice::ors_isochrones(
+   locations = coords,
+   profile = "cycling-regular",
+   range = 3600,
+   interval = 600,
+   api_key = api_key,
+   output = "sf"
+ )
> sf::sf_use_s2(F)
> cycling_ams$mins <- cycling_ams$value / 60
> cycling_ams$mins <- factor(
+   cycling_ams$mins
+ )
> 
> cycling_ams_cropped <- cycling_ams |>
+   dplyr::group_by(mins) |>
+   sf::st_intersection() |>
+   dplyr::ungroup()
although coordinates are longitude/latitude, st_intersection assumes that they are
planar
> pal_fact <- leaflet::colorFactor(
+   "RdPu",
+   domain = cycling_ams_cropped$mins,
+   reverse = T,
+   na.color = "transparent"
+ )
> 
> leaflet::leaflet(
+   cycling_ams_cropped
+ ) |>
+   leaflet::addPolygons(
+     fill = T,
+     stroke = T,
+     color = pal_fact,
+     weight = .3,
+     fillColor = ~pal_fact(mins),
+     fillOpacity = .3
+   ) |>
+   leaflet::addProviderTiles(
+     "CartoDB.Positron"
+   ) |>
+   leaflet::addLegend(
+     "bottomright",
+     pal = pal_fact,
+     values = cycling_ams_cropped$mins,
+     labels = cycling_ams_cropped$mins,
+     opacity = .5,
+     title = "Cycling distance in Kandy"
+   )
> cycling_ams_merc <- sf::st_transform(
+   cycling_ams_cropped2,
+   5234
+ )
> ams_layer <- maptiles::get_tiles(
+   cycling_ams_merc,
+   provider = "CartoDB.Positron",
+   zoom = 11
+ )
Error: [rast] empty srs
In addition: Warning message:
PROJ: proj_create_from_database: Cannot find proj.db (GDAL error 1)

Hello! This code and output is very hard to read in it's current state.
To better help us answer your question, put code and output in a code block. That can be done by putting your code between two sets of 3 backticks (`) each. That results in something like this:

# Test line 1
# Test line 2

Also you may want to follow the advice here on creating a reproducible example

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.