Skip to content

Commit

Permalink
update new funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
billbillbilly committed Jun 7, 2024
1 parent 2a68db0 commit 42eaa5b
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 32 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: viewscape
Type: Package
Title: Viewscape Analysis
Version: 1.0.0
Version: 1.0.1
Authors@R: c(person("Xiaohao", "Yang", role = c("aut", "cre", "cph"), email = "xiaohaoy@umich.edu"),
person("Nathan", "Fox", role = c("aut")),
person("Derek", "Van Berkel", role = c("aut")),
Expand Down
10 changes: 5 additions & 5 deletions R/calculate_diversity.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
#' # load dsm raster
#' dsm <- terra::rast(system.file("test_dsm.tif", package ="viewscape"))
#' #Compute viewshed
#' output <- compute_viewshed(dsm = dsm,
#' viewpoints = test_viewpoint,
#' offset_viewpoint = 6)
#' output <- viewscape::compute_viewshed(dsm = dsm,
#' viewpoints = test_viewpoint,
#' offset_viewpoint = 6)
#' # load landuse raster
#' test_landuse <- terra::rast(system.file("test_landuse.tif",
#' package ="viewscape"))
#' diversity <- calculate_diversity(output,
#' test_landuse)
#' diversity <- viewscape::calculate_diversity(output,
#' test_landuse)
#'

calculate_diversity <- function(viewshed,
Expand Down
12 changes: 5 additions & 7 deletions R/compute_viewshed.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@
#' # load dsm raster
#' dsm <- terra::rast(system.file("test_dsm.tif", package ="viewscape"))
#' #Compute viewshed
#' output <- compute_viewshed(dsm = dsm,
#' viewpoints = test_viewpoint,
#' offset_viewpoint = 6)
#' output <- viewscape::compute_viewshed(dsm = dsm,
#' viewpoints = test_viewpoint,
#' offset_viewpoint = 6)

compute_viewshed <- function(dsm,
viewpoints,
Expand All @@ -75,7 +75,7 @@ compute_viewshed <- function(dsm,
r = NULL,
method = "plane",
parallel = FALSE,
workers = 0,
workers = 1,
raster = FALSE,
plot = FALSE){
multiviewpoints <- FALSE
Expand Down Expand Up @@ -162,9 +162,7 @@ compute_viewshed <- function(dsm,
}
inputs <- split(viewpoints,seq(nrow(viewpoints)))
if (parallel == TRUE){
if (workers == 0) {
workers <- 2
} else if (workers > parallel::detectCores()) {
if (workers > parallel::detectCores()) {
workers <- parallel::detectCores()
}
# inputs <- split(viewpoints,seq(nrow(viewpoints)))
Expand Down
10 changes: 5 additions & 5 deletions man/calculate_diversity.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions man/compute_viewshed.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 13 additions & 10 deletions vignettes/viewscape.Rmd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "viewscape"
author: "Xiaohao Yang"
date: "2023-12-18"
date: "2024-06-06"
vignette: >
%\VignetteIndexEntry{viewscape}
%\VignetteEngine{knitr::rmarkdown}
Expand All @@ -15,13 +15,13 @@ The basic viewshed analysis can be accessed through calling the `compute_viewshe

## 1. Compute viewshed

```{r val=FALSE}
```{r eval=FALSE}
library(viewscape)
```

### 1.1 Compute single viewshed

```{r val=FALSE}
```{r eval=FALSE}
#Load in DSM
test_dsm <- terra::rast(system.file("test_dsm.tif",
package ="viewscape"))
Expand All @@ -33,7 +33,8 @@ test_viewpoint <- sf::read_sf(system.file("test_viewpoint.shp",
#Compute viewshed
output <- viewscape::compute_viewshed(dsm = test_dsm,
viewpoints = test_viewpoint,
offset_viewpoint = 6)
offset_viewpoint = 6,
method = 'plane')
```

```{r eval=FALSE}
Expand All @@ -51,19 +52,21 @@ sector <- viewscape::sector_mask(output, c(40,160))
terra::plot(test_dsm, axes=FALSE, box=FALSE, legend = FALSE)
terra::plot(viewscape::visualize_viewshed(sector, outputtype = 'raster'),
axes=FALSE, box=FALSE, legend = FALSE, add = TRUE, col = "red")
terra::plot(test_viewpoint, add = TRUE, col = "blue", axes=FALSE, box=FALSE, legend = FALSE)
```

### 1.3 Compute visual magnitude

```{r eval=FALSE}
vm <- viewscape::visual_magnitude(output,test_dsm)
terra::plot(vm, axes=FALSE, box=FALSE)
terra::plot(test_viewpoint, add = TRUE, col = "blue", axes=FALSE, box=FALSE, legend = FALSE)
```


### 1.4 Compute the viewshed for multiple viewpoints

```{r val=FALSE}
```{r eval=FALSE}
#Load in DSM
test_dsm <- terra::rast(system.file("test_dsm.tif",
package ="viewscape"))
Expand Down Expand Up @@ -100,7 +103,7 @@ The function of extent analysis can calculate the total area of viewshed and nee

The following function can calculate the area of ground surface and standard deviation of elevations within a viewshed. The function needs a DSM and a DEM/DTM to calculate the metrics.

```{r val=FALSE}
```{r eval=FALSE}
#Load in DSM
test_dsm <- terra::rast(system.file("test_dsm.tif",
package ="viewscape"))
Expand All @@ -118,7 +121,7 @@ test_building <- terra::rast(system.file("test_building.tif",
```

```{r val=FALSE}
```{r eval=FALSE}
# calculate metrics given the viewshed, canopy, and building footprints
test_metrics <- viewscape::calculate_viewmetrics(output[[1]],
test_dsm,
Expand All @@ -131,13 +134,13 @@ test_metrics

calculate_diversity() calculates the proportion of each type of land use/ cover within a viewshed to get the Shannon Diversity Index.

```{r val=FALSE}
```{r eval=FALSE}
# load landuse raster
test_landuse <- terra::rast(system.file("test_landuse.tif",
package ="viewscape"))
```

```{r val=FALSE}
```{r eval=FALSE}
# the Shannon Diversity Index (SDI)
test_diversity <- viewscape::calculate_diversity(output[[1]],
test_landuse,
Expand All @@ -150,7 +153,7 @@ test_diversity

calculate_feature is to calculate the proportion of a feature (including trees, buildings, parking, and roads) within the viewshed. This function can be applied to

```{r val=FALSE}
```{r eval=FALSE}
# load canopy raster
test_canopy <- terra::rast(system.file("test_canopy.tif",
package ="viewscape"))
Expand Down

0 comments on commit 42eaa5b

Please sign in to comment.