Git Product home page Git Product logo

rvalhalla's Introduction

Vallhala for R

R-CMD-check

This package is based on tests and the demo in the setup.qmd file.

Installation

devtools::install_github("robinlovelace/rvalhalla")

Usage

# download a file to custom_files and start valhalla
mkdir custom_files
wget -O custom_files/andorra-latest.osm.pbf https://download.geofabrik.de/europe/andorra-latest.osm.pbf
docker stop valhalla_gis-ops
docker rm valhalla_gis-ops
docker run -dt --name valhalla_gis-ops -p 8002:8002 -v $PWD/custom_files:/custom_files -e tile_urls=https://download.geofabrik.de/europe/andorra-latest.osm.pbf ghcr.io/gis-ops/docker-valhalla/valhalla:latest

# If the container already exists:
docker start valhalla_gis-ops

After that navigate to http://localhost:8002/ and you’ll see the endpoint.

library(rvalhalla)
# devtools::load_all() # for development

Let’s calculate a single route in Andorra, between two well known places: Andorra la Vella and Pas de la Casa.

andorra_la_vella = c(1.5218, 42.5075)
pas_de_la_casa = c(1.7333, 42.5425)
# Calculate the route
route1 = vh_route(andorra_la_vella, pas_de_la_casa, costing = "pedestrian")
route2 = vh_route(andorra_la_vella, pas_de_la_casafrom = andorra_la_vella, to = pas_de_la_casa, costing = "bicycle")
route3 = vh_route(from = andorra_la_vella, to = pas_de_la_casa, costing = "bicycle", costing_options = list(bicycle = list(use_roads = 0.9)))

We can compare them with {waldo}:

# waldo::compare(route2, route3)

Let’s plot them all with ggplot2 (not shown):

library(ggplot2)
ggplot() +
  geom_sf(data = route1, color = "red") +
  geom_sf(data = route2, color = "blue") +
  geom_sf(data = route3, color = "green")

And with {tmap}:

library(tmap)
tmap_mode("view")
m = tm_shape(route1) +
  tm_lines("red", lwd = 6) +
  tm_shape(route2) +
  tm_lines("blue", lwd = 6) +
  tm_shape(route3) +
  tm_lines("green", lwd = 6)
m

Links

This project builds on and was inspired by the following projects, which are worth checking out:

system("quarto render benchmark.qmd")

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.