Skip to contents

Overview

orbis is an R package that provides a comprehensive suite of tools for streamlining spatial data analysis workflows. It follows the tidyverse principles and integrates naturally with the tidyverse ecosystem.

If you find this project useful, please consider giving it a star!   GitHub Repository Stars

Installation

You can install orbis using the remotes package:

# install.packages("remotes")
remotes::install_github("danielvartan/orbis", dependencies = TRUE)

Usage

orbis is equipped with several functions to help with your analysis, such as:

Here are some examples of how to use a few of these functions.

shift_and_rotate()

shift_and_rotate() was developed to simplify shifting and rotating spatial data, especially for rasters and vectors that cross the dateline (e.g. the Russian territory).

Set the Environment

plot_vector <- function(vector) {
  plot <-
    vector |>
    ggplot() +
    geom_spatvector(fill = "#3243A6", color = "white")

  print(plot)
}

Define a World Vector

world_vector <- world(path = tempdir())

Visualize the World Vector

world_vector |> plot_vector()

Define the Country Vector

russia_vector <- gadm(country = "rus", level = 0, path = tempdir())

Visualize the Country Vector

russia_vector |> plot_vector()

Shift and Rotate the Country Vector -45 Degrees to the Left

russia_vector |> shift_and_rotate(-45) |> plot_vector()

remove_unique_outliers()

remove_unique_outliers() was developed to simplify the removal of abnormal values in raster files. It can be used with GeoTIFF and Esri ASCII raster formats.

Set the Environment

Create a Fictional Esri ASCII File

asc_content <- c(
  "ncols         5",
  "nrows         5",
  "xllcorner     0.0",
  "yllcorner     0.0",
  "cellsize      1.0",
  "NODATA_value  -9999",
  "1 2 3 4 5 ",
  "6 7 8 9 10 ",
  "11 12 1000 14 15 ", # Extreme outlier (1000)
  "16 1 18 19 20 ",
  "21 22 23 24 25 "
)
temp_file <- tempfile(fileext = ".asc")

asc_content |> write_lines(temp_file)

Visualize Values Before remove_unique_outliers()

temp_file |> rast() |> values(mat = FALSE)
#>  [1]    1    2    3    4    5    6    7    8    9   10   11   12 1000   14
#> [15]   15   16    1   18   19   20   21   22   23   24   25

Visualize Values After remove_unique_outliers()

temp_file |> remove_unique_outliers()
temp_file |> rast() |> values(mat = FALSE)
#>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 NA 14 15 16  1 18 19 20 21 22 23 24
#> [25] 25

map_fill_data()

map_fill_data() was developed to simplify the preparation of data to fill a map.

Set the Environment

plot_vector_shape <- function(vector) {
  plot <-
    vector |>
    ggplot() +
    geom_spatvector(fill = "white", color = "#3243A6")

  print(plot)
}
plot_vector_data <- function(data, vector) {
  plot <-
    data |>
    ggplot() +
    geom_spatvector(aes(fill = value), color = "white") +
    scale_fill_continuous(
        palette = c("#072359", "#3243A6", "#9483AF"),
        na.value = "white"
    ) +
    labs(fill = NULL)

  print(plot)
}

Define the Map

brazil_states_vector <- gadm("BRA", level = 1, path = tempdir())

Visualize the Map

brazil_states_vector |> plot_vector_shape()

Define the Data

data <- tibble(
  state = sample(brazil_states_vector$NAME_1, size = 1000, replace = TRUE),
  value = sample(1:1000, size = 1000, replace = TRUE)
)
data
#> # A tibble: 1,000 × 2
#>   state              value
#>   <chr>              <int>
#> 1 Minas Gerais         881
#> 2 Mato Grosso do Sul   300
#> 3 Amazonas             778
#> 4 Sergipe              393
#> 5 Acre                 682
#> 6 Roraima              369
#> # ℹ 994 more rows

Create the Map Fill Data

data <- data |> map_fill_data(col_fill = "value", col_ref = "state")
#> ! There are duplicated values in state. value will be aggregated using the mean.

data
#> # A tibble: 27 × 2
#>   state              value
#>   <chr>              <dbl>
#> 1 Minas Gerais        581.
#> 2 Mato Grosso do Sul  538.
#> 3 Amazonas            543.
#> 4 Sergipe             464.
#> 5 Acre                546.
#> 6 Roraima             530.
#> # ℹ 21 more rows

Visualize the Map Fill Data

brazil_states_vector |>
  left_join(data, by = c("NAME_1" = "state")) |>
  plot_vector_data()

filter_points()

filter_points() was developed to filter latitude/longitude points that intersect with a given sf geometry. This is particularly useful for removing points that fall in the ocean when working with country or state boundaries.

Set the Environment

plot_geometry <- function(geometry) {
  plot <-
    geometry |>
    ggplot() +
    geom_sf(
      color = "gray75",
      fill = "white",
      inherit.aes = FALSE
    ) +
    labs(x = "Longitude", y = "Latitude")

  print(plot)
}
plot_points <- function(data, geometry) {
  plot <-
    data |>
    ggplot(aes(x = longitude, y = latitude)) +
    geom_sf(
      data = geometry,
      color = "gray75",
      fill = "white",
      inherit.aes = FALSE
    ) +
    geom_point(color = "#3243A6") +
    labs(x = "Longitude", y = "Latitude")

  print(plot)
}

Define the Points

data <- tibble(
  latitude = brazil_state_latitude(),
  longitude = brazil_state_longitude()
)

data
#> # A tibble: 27 × 2
#>   latitude longitude
#>      <dbl>     <dbl>
#> 1  -9.98       -67.8
#> 2  -9.65       -35.7
#> 3   0.0402     -51.1
#> 4  -3.13       -60.0
#> 5 -13.0        -38.5
#> 6  -3.73       -38.5
#> # ℹ 21 more rows

Visualize the Points on a Map

brazil_states_geometry <- read_state()
#> Using year/date 2010
data |> plot_points(brazil_states_geometry)

Set the Geometry to Filter the Points

sp_state_geometry <- read_state(code = "SP")
#> Using year/date 2010
sp_state_geometry |> plot_geometry()

Filter the Points

data <- data |> filter_points(sp_state_geometry)

data
#> # A tibble: 1 × 2
#>   latitude longitude
#>      <dbl>     <dbl>
#> 1    -23.6     -46.6

Visualize the Filtered Points

data |> plot_points(brazil_states_geometry)

Click here to see the full list of functions.

Citation

If you use this package in your research, please cite it to acknowledge the effort put into its development and maintenance. Your citation helps support its continued improvement.

citation("orbis")
#> To cite orbis in publications use:
#> 
#>   Vartanian, D. (2025). orbis: Spatial data analysis tools [Computer
#>   software]. https://danielvartan.github.io/orbis
#> 
#> A BibTeX entry for LaTeX users is
#> 
#>   @Misc{,
#>     title = {orbis: Spatial data analysis tools},
#>     author = {Daniel Vartanian},
#>     year = {2025},
#>     url = {https://danielvartan.github.io/orbis},
#>     note = {R package},
#>   }

License

Copyright (C) 2025 Daniel Vartanian

orbis is free software: you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with
this program. If not, see <https://www.gnu.org/licenses/>.

Contributing

Contributions are welcome! Whether you want to report bugs, suggest features, or improve the code or documentation, your input is highly valued. Please check the issues tab for existing issues or to open a new one.

You can also support the development of orbis by becoming a sponsor. Click here to make a donation. Please mention orbis in your donation message.