Skip to content

Commit

Permalink
Merge pull request #51 from ropensci/unified
Browse files Browse the repository at this point in the history
Add direct hooks to Unity, move to terra, take over the world (fixes #45 )
  • Loading branch information
mikemahoney218 authored May 4, 2022
2 parents f1e749c + b2c703a commit 105469f
Show file tree
Hide file tree
Showing 45 changed files with 806 additions and 524 deletions.
2 changes: 1 addition & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ methods-in-ecology-and-evolution.csl
^CRAN-RELEASE$
^CRAN-SUBMISSION$
^CITATION\.cff$
R/make_unity.R

7 changes: 4 additions & 3 deletions .github/workflows/run-examples.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
RSPM: ${{ matrix.config.rspm }}
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v2
Expand All @@ -43,25 +44,25 @@ jobs:
shell: Rscript {0}

- name: Cache R packages
if: runner.os != 'Windows'
uses: actions/cache@v2
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-

- name: Install system dependencies
- name: Install Linux dependencies
if: runner.os == 'Linux'
run: |
while read -r cmd
do
eval sudo $cmd
done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))')
- name: Install dependencies
run: |
remotes::install_cran("devtools")
remotes::install_github("mikemahoney218/unifir")
remotes::install_deps(dependencies = TRUE)
remotes::install_cran("rcmdcheck")
shell: Rscript {0}

- name: Check
Expand Down
71 changes: 35 additions & 36 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,53 +1,52 @@
Package: terrainr
Type: Package
Package: terrainr
Title: Landscape Visualizations in R and 'Unity'
Version: 0.6.1
Version: 0.7.0
Authors@R: c(
person(given = "Michael",
family = "Mahoney",
role = c("aut", "cre"),
email = "[email protected]",
person("Michael", "Mahoney", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-2402-304X")),
person(given = "Mike",
family = "Johnson",
role = c("rev"),
comment = c("Mike reviewed the package (v. 0.2.1) for rOpenSci, see <https://github.com/ropensci/software-review/issues/416>")),
person(given = "Sydney",
family = "Foks",
role = c("rev"),
comment = c("Sydney reviewed the package (v. 0.2.1) for rOpenSci, see <https://github.com/ropensci/software-review/issues/416>")))
Description: Functions for the retrieval, manipulation, and visualization of
'geospatial' data, with an aim towards producing '3D' landscape
visualizations in the 'Unity' '3D' rendering engine. Functions are also
provided for retrieving elevation data and base map tiles from the 'USGS'
National Map <https://apps.nationalmap.gov/services/>.
URL: https://docs.ropensci.org/terrainr/, https://github.com/ropensci/terrainr
BugReports: https://github.com/ropensci/terrainr/issues
person("Mike", "Johnson", role = "rev",
comment = "Mike reviewed the package (v. 0.2.1) for rOpenSci, see <https://github.com/ropensci/software-review/issues/416>"),
person("Sydney", "Foks", role = "rev",
comment = "Sydney reviewed the package (v. 0.2.1) for rOpenSci, see <https://github.com/ropensci/software-review/issues/416>")
)
Description: Functions for the retrieval, manipulation, and visualization
of 'geospatial' data, with an aim towards producing '3D' landscape
visualizations in the 'Unity' '3D' rendering engine. Functions are
also provided for retrieving elevation data and base map tiles from
the 'USGS' National Map <https://apps.nationalmap.gov/services/>.
License: MIT + file LICENSE
Encoding: UTF-8
URL: https://docs.ropensci.org/terrainr/,
https://github.com/ropensci/terrainr
BugReports: https://github.com/ropensci/terrainr/issues
Imports:
base64enc,
ggplot2,
grDevices,
httr,
raster,
rgdal,
magick (>= 2.5.0),
methods,
png,
sf (>= 1.0-5),
units,
grDevices,
ggplot2
RoxygenNote: 7.1.2
terra,
unifir,
units
Suggests:
testthat,
brio,
covr,
progressr,
jpeg,
knitr,
rmarkdown,
progress,
jpeg,
tiff,
brio
Config/testthat/parallel: true
progressr,
raster,
rgdal,
rmarkdown,
testthat,
tiff
VignetteBuilder:
knitr
Config/testthat/edition: 3
VignetteBuilder: knitr
Config/testthat/parallel: true
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.2
5 changes: 5 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# Generated by roxygen2: do not edit by hand

S3method(add_bbox_buffer,Raster)
S3method(add_bbox_buffer,SpatRaster)
S3method(add_bbox_buffer,sf)
S3method(get_tiles,Raster)
S3method(get_tiles,SpatRaster)
S3method(get_tiles,list)
S3method(get_tiles,sf)
S3method(get_tiles,sfc)
S3method(set_bbox_side_length,Raster)
S3method(set_bbox_side_length,SpatRaster)
S3method(set_bbox_side_length,sf)
export(StatSpatialRGB)
export(add_bbox_buffer)
Expand All @@ -16,6 +19,7 @@ export(georeference_overlay)
export(get_tiles)
export(hit_national_map_api)
export(make_manifest)
export(make_unity)
export(merge_rasters)
export(raster_to_raw_tiles)
export(set_bbox_side_length)
Expand All @@ -24,3 +28,4 @@ export(transform_elevation)
export(transform_overlay)
export(vector_to_overlay)
importFrom(grDevices,rgb)
importFrom(unifir,find_unity)
35 changes: 35 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,38 @@
# terrainr 0.7.0
* New features:
* `make_unity` is a new function which uses the new `unifir` package to
automatically create Unity scenes, no clicking necessary.
* Internally, all calls to functions from {raster} have been replaced with
calls to {terra}. This future-proofs the package against any coming
deprecations and takes advantage of newer, faster terra code.
This is not intended to be a breaking change; any methods that previously
took {raster} objects should still work (and silently convert to {terra}
under the hood). If you have any workflows impacted by this change,
please file a bug report!
* Improvements and bug fixes:
* `make_manifest`, `transform_elevation`, and `transform_overlay` no longer
error when providing non-standard side lengths; they now warn as intended.
* `make_manifest`, `transform_elevation`, and `transform_overlay`
should no longer give warnings about nodata values in most cases.
being clamped to 0.
* Fixed some documentation, unused objects, restyled and removed lints.
* `transform_overlay` (and by extension, every Unity overlay importer) now
tries to automatically guess the scale of the input raster. Values under
1 are scaled from 0-1, integers under 255 are scaled 0-255, and integers
under 65535 are scaled 0-65536. The main effect of this is more realistic
coloring when importing terrain. Floats above 1 won't be affected.
* Dependency changes:
* `terra` is now included as an Import (had been recursively imported
through `raster` previously).
* `raster` and `rgdal` are now in Suggests (used temporarily in
`Raster*` methods for `get_tiles` and `add_bbox_buffer`, until the new
version of `raster` hits CRAN).
* Internal changes:
* `raster_to_raw_tiles` is now a thin wrapper around the functions
`transform_overlay` and `transform_elevation`. It is no longer tested;
it will be removed entirely in the next release (see deprecation notice
in terrainr 0.5.0).

# terrainr 0.6.1
* Improvements and bug fixes:
* The README of version 0.6.0 has a disclaimer at the top stating that the
Expand Down
53 changes: 44 additions & 9 deletions R/add_bbox_buffer.R
Original file line number Diff line number Diff line change
Expand Up @@ -126,20 +126,39 @@ add_bbox_buffer.Raster <- function(data,
distance,
distance_unit = "meters",
error_crs = NULL) {
bbox <- raster::extent(data)
tmp <- tempfile(fileext = ".tiff")
raster::writeRaster(data, tmp)
data <- terra::rast(tmp)
add_bbox_buffer(
data = data,
distance = distance,
distance_unit = distance_unit,
error_crs = error_crs
)
}

#' @rdname addbuff
#' @export
add_bbox_buffer.SpatRaster <- function(data,
distance,
distance_unit = "meters",
error_crs = NULL) {
bbox <- as.vector(terra::ext(data))
data_sf <- data.frame(
lat = c(bbox@ymin, bbox@ymax),
lng = c(bbox@xmin, bbox@xmax)
lat = c(bbox[[3]], bbox[[4]]),
lng = c(bbox[[1]], bbox[[2]])
)
data_sf <- sf::st_as_sf(data_sf, coords = c("lng", "lat"))
data_sf <- sf::st_set_crs(data_sf, sf::st_crs(data))
add_bbox_buffer(data_sf,
distance = distance,
distance_unit = distance_unit,
error_crs = error_crs
distance = distance,
distance_unit = distance_unit,
error_crs = error_crs
)
}



#' @rdname addbuff
#' @examples
#'
Expand Down Expand Up @@ -193,10 +212,26 @@ set_bbox_side_length.Raster <- function(data,
distance,
distance_unit = "meters",
error_crs = NULL) {
bbox <- raster::extent(data)
data <- terra::rast(data@file@name)
set_bbox_side_length(
data = data,
distance = distance,
distance_unit = distance_unit,
error_crs = error_crs
)
}


#' @rdname addbuff
#' @export
set_bbox_side_length.SpatRaster <- function(data,
distance,
distance_unit = "meters",
error_crs = NULL) {
bbox <- terra::ext(data)@ptr$vector
data_sf <- data.frame(
lat = c(bbox@ymin, bbox@ymax),
lng = c(bbox@xmin, bbox@xmax)
lat = c(bbox[[3]], bbox[[4]]),
lng = c(bbox[[1]], bbox[[2]])
)
data_sf <- sf::st_as_sf(data_sf, coords = c("lng", "lat"))
data_sf <- sf::st_set_crs(data_sf, sf::st_crs(data))
Expand Down
Loading

0 comments on commit 105469f

Please sign in to comment.