Package {rcrisp}


Title: Automate the Delineation of Urban River Spaces
Version: 1.0.0
Description: Provides tools to automate the morphological delineation of riverside urban areas based on a method introduced in Forgaci (2018) <doi:10.7480/abe.2018.31>. Delineation entails the identification of corridor boundaries, segmentation of the corridor, and delineation of the river space using two-dimensional spatial information from street network data and digital elevation data in a projected CRS. The resulting delineation can be used to characterise spatial phenomena that can be related to the river as a central element.
License: Apache License (≥ 2)
URL: https://cityriverspaces.github.io/rcrisp/, https://github.com/CityRiverSpaces/rcrisp, https://doi.org/10.5281/zenodo.15793526
BugReports: https://github.com/CityRiverSpaces/rcrisp/issues
Depends: R (≥ 4.1.0)
Imports: checkmate, cli, dbscan, dplyr, lwgeom, osmdata, rcoins, rlang, rstac, sf (≥ 0.9.0), sfheaders, sfnetworks, stringr, terra, tidygraph, units, visor
Suggests: autotest, ggplot2, knitr, purrr, rmarkdown, testthat (≥ 3.0.0), withr
VignetteBuilder: knitr
Config/testthat/edition: 3
Encoding: UTF-8
LazyData: true
Config/roxygen2/version: 8.1.1
NeedsCompilation: no
Packaged: 2026-10-20 18:54:48 UTC; claudiuforgaci
Author: Claudiu Forgaci ORCID iD [aut, cre, cph], Francesco Nattino ORCID iD [aut], Fakhereh Alidoost ORCID iD [ctb], Meiert Willem Grootes ORCID iD [ctb], Yehan Wu ORCID iD [ctb], Netherlands eScience Center [fnd], Mark Padgham [rev] (Mark reviewed the package (v. 0.3.1) for rOpenSci, see <https://github.com/ropensci/software-review/issues/718>), Anatolii Tsyplenkov [rev] (Anatolii reviewed the package (v. 0.3.1) for rOpenSci, see <https://github.com/ropensci/software-review/issues/718>)
Maintainer: Claudiu Forgaci <c.forgaci@tudelft.nl>
Repository: CRAN
Date/Publication: 2026-10-20 19:10:02 UTC

rcrisp: Automate the Delineation of Urban River Spaces

Description

Provides tools to automate the morphological delineation of riverside urban areas based on a method introduced in Forgaci (2018) doi:10.7480/abe.2018.31. Delineation entails the identification of corridor boundaries, segmentation of the corridor, and delineation of the river space using two-dimensional spatial information from street network data and digital elevation data in a projected CRS. The resulting delineation can be used to characterise spatial phenomena that can be related to the river as a central element.

Author(s)

Maintainer: Claudiu Forgaci c.forgaci@tudelft.nl (ORCID) [copyright holder]

Authors:

Other contributors:

See Also

Useful links:


Add weights to the network.

Description

This is to prepare the network for the search of shortest paths between node pairs. The computed weights can account for edge lenghts, distance from a target geometry, and whether or not an edge falls within a specified region, which we aim to exclude from search of the shortest paths.

Usage

add_weights(
  network,
  target = NULL,
  exclude_area = NULL,
  penalty = 1000,
  weight_name = "weight"
)

Arguments

network

A network object

target

Target geometry to calculate distances from, as a simple feature geometry

exclude_area

Area that we aim to exclude from the shortest-path search, as a simple feature geometry

penalty

Penalty (in the network CRS' units) that is added to the edges that falls within the excluded area

weight_name

Name of the column in the edge table where to add the weights

Details

For the i-th edge of the network, its weight w_i is defined in the following way:

w_i = |e_i| + d_{geom}(e_i) + p_{buf}(e_i)

where the first term is the edge length, the second one is the distance from a target geometry (target, optional) and the last one is a penalty that is added if the centroid of the edge falls within a specified region (exclude_area, optional).

Shortest paths calculated on the resulting network will thus tend to prefer edges close to target and to avoid edges within exclude_area.

Value

A network object of class sfnetworks::sfnetwork with weights added as a column in the edge table


Get the bounding box from the x object

Description

If the x does not have a CRS, WGS84 is assumed.

Usage

as_bbox(x)

Arguments

x

Simple feature object (or compatible) or a bounding box, provided either as a matrix (with x, y as rows and min, max as columns) or as a vector (xmin, ymin, xmax, ymax)

Value

A bbox object as returned by sf::st_bbox()

Examples

library(sf)
bounding_coords <- c(25.9, 44.3, 26.2, 44.5)
bb <- as_bbox(bounding_coords)
class(bb)
st_crs(bb)

Standardise the coordinate reference system (CRS) of an object

Description

Standardise the coordinate reference system (CRS) of an object

Usage

as_crs(x, allow_geographic = FALSE)

Arguments

x

An object of class sf, sfc, bbox, or a numeric or character vector representing a CRS (e.g., EPSG code). If numeric, the value should be an unrestricted positive number representing a valid EPSG code.

allow_geographic

Logical, whether to allow geographic CRS (lat/lon).

Value

An object of class sf::crs with a valid CRS.

Examples

library(sf)

# Standardise a numeric EPSG code
as_crs(4326, allow_geographic = TRUE)

# Standardise a character EPSG code
as_crs("EPSG:4326", allow_geographic = TRUE)

# Standardise a bbox object
bb <- st_bbox(c(xmin = 25.9, ymin = 44.3, xmax = 26.2, ymax = 44.5),
                crs = 4326)
as_crs(bb, allow_geographic = TRUE)

# Standardise a simple feature object
bb_sfc <- st_as_sfc(bb)
bb_sf <- st_as_sf(bb_sfc)
as_crs(bb_sf, allow_geographic = TRUE)
as_crs(bb_sfc, allow_geographic = TRUE)

Create a network from a collection of line strings

Description

Create a network from a collection of line strings

Usage

as_network(edges, flatten = TRUE, clean = TRUE, na_action = "warn")

Arguments

edges

An sf::sf or sf::sfc_LINESTRING object with the network edges

flatten

Whether all intersections between edges should be converted to nodes

clean

Whether general cleaning tasks should be run on the generated network (see clean_network() for the description of tasks)

na_action

A case-insensitive character string specifying how to deal with missing values in non-geometry columns of edges. Possible values:

  • "warn" (default): issue a warning if any NA values are found.

  • "error": stop with an error if any NA values are found.

  • "ignore": silently proceed without checking for NA values

  • "impute": replace NA values before building the network. For character columns, NAs are replaced with "unknown"; for numeric columns, NAs are replaced with the column median.

Value

An sfnetworks::sfnetwork object

Examples

edges <- sf::st_sfc(
  sf::st_linestring(matrix(c(0, 0, 1, 1), ncol = 2, byrow = TRUE)),
  sf::st_linestring(matrix(c(0, 1, 1, 0), ncol = 2, byrow = TRUE)),
  crs = sf::st_crs("EPSG:32635")
)

# Run with default values
as_network(edges)

# Only build the spatial network
as_network(edges, flatten = FALSE, clean = FALSE)

rcrisp example delineation data for Bucharest

Description

Delineation generated with rcrisp example data found at https://zenodo.org/records/16325879

Usage

bucharest_dambovita

Format

A list of sf objects representing:

valley

The valley boundaries of river Dâmbovița.

corridor

The corridor boundaries of river Dâmbovița.

segments

Corridor segments of river Dâmbovița.

riverspace

River space of Dâmbovița.


Apply a buffer region to a sf object

Description

If the input object is in lat/lon coordinates, the buffer is approximately applied by first transforming the object in a suitable projected CRS, expanding it with the given buffer, and then transforming it back to the lat/lon system.

Usage

buffer(obj, buffer_distance, ...)

Arguments

obj

A sf object

buffer_distance

Buffer distance in meters

...

Optional parameters passed on to sf::st_buffer()

Value

An object of class sf::sfc_POLYGON


Build a spatial network from river centerlines

Description

If a bounding box is provided, only the river segments that intersect it are considered. If the river intersects the bounding box multiple times, only the longest intersecting segment will be considered.

Usage

build_river_network(river, bbox = NULL)

Arguments

river

A (MULTI)LINESTRING simple feature geometry representing the river centerline

bbox

Bounding box of the area of interest

Value

An sfnetworks::sfnetwork object


Return the cache directory used by the package

Description

By default, the user-specific directory as returned by tools::R_user_dir() is used. A different directory can be used by setting the environment variable CRISP_CACHE_DIRECTORY. This can also be done by adding the following line to the .Renviron file: ⁠CRISP_CACHE_DIRECTORY=/path/to/crisp/cache/dir⁠.

Usage

cache_directory()

Value

The cache directory used by rcrisp.

Examples


cache_directory()


Cap the corridor by connecting the edge end points

Description

Cap the corridor by connecting the edge end points

Usage

cap_corridor(edges, method = "shortest-path", network = NULL)

Arguments

edges

A simple feature geometry representing the corridor edges

method

The method employed for the capping:

  • shortest-path (default): find the network-based shortest-path connections between the edge end points.

  • direct: connect the start points and the end points of the edges via straight segments

network

A spatial network object, only required if method = 'shortest-path'

Value

An sf::sfc_POLYGON object representing the corridor


Check cache

Description

A message is displayed if the cache size is > 100 MB or if it includes files older than 30 days.

Usage

check_cache()

Value

NULL

Examples


check_cache()


Check and fix invalid geometries

Description

Check and fix invalid geometries

Usage

check_invalid_geometry(sf_obj)

Arguments

sf_obj

An object of class sf::sf or sf::sfc

Value

sf::sf or sf::sfc object with valid geometries


Clean a spatial network

Description

Subdivide edges by adding missing nodes, (optionally) simplify the network (see simplify_network()), remove pseudo-nodes, and discard all but the main connected component.

Usage

clean_network(network, simplify = TRUE)

Arguments

network

A network object of class sfnetworks::sfnetwork

simplify

Whether the network should be simplified with simplify_network()

Value

A cleaned network object of class sfnetworks::sfnetwork

Examples


bucharest_osm <- get_osm_example_data()
edges <- dplyr::bind_rows(bucharest_osm$streets,
                          bucharest_osm$railways)
network <- sfnetworks::as_sfnetwork(edges, directed = FALSE)
clean_network(network)


Remove cache files

Description

Remove files from cache directory either before a given date or entirely.

Usage

clear_cache(before_date = NULL)

Arguments

before_date

Date before which cache files should be removed provided as object of class Date or as a case dependent character vector accepted by as.Date()

Value

NULL

Examples


# Clear all cache
clear_cache()

# Clear cache before given date
before_date <- as.Date("1-1-1999", "%m-%d-%Y")
clear_cache(before_date = before_date)


Clip lines to the extent of the corridor, and select valid segment edges

Description

Lines that intersect the river and that cross the corridor from side to side are considered valid segment edges. We group valid segment edges that cross the river in nearby locations, and select the shortest line per cluster. From these candidate segment edges, we select the ultimate set of non-intersecting lines by dropping the longest segments with most intersections.

Usage

clip_and_filter(lines, corridor, river)

Arguments

lines

Candidate segment edges as a simple feature geometry

corridor

The river corridor as a simple feature geometry

river

The river centerline as a simple feature geometry

Value

Candidate segment edges as object of class sf::sfc_LINESTRING


Combine river centerline and surface

Description

Combine river centerline and surface

Usage

combine_river_features(river_centerline, river_surface)

Arguments

river_centerline

River line as sf::sfc_LINESTRING or sf::sfc_MULTILINESTRING

river_surface

River surface as sf::sfc_POLYGON or sf::sfc_MULTIPOLYGON

Value

Combined river as sf::sfc_MULTILINESTRING


Draw a corridor edge on the spatial network.

Description

The corridor edge is drawn on the network as a shortest-path link between a start- and an end-point. The weights in the shortest-path problem are set to account for a) network edge lengths, b) distance from an initial target edge geometry, and c) an excluded area where corridor edges are aimed not to go through. The procedure is iterative, with the excluded area only being accounted for in the first iteration. The identified corridor edge is used as target edge in the following iteration, with the goal of prioritising the "straightening" of the edge (some overlap with the excluded area is allowed).

Usage

corridor_edge(
  network,
  end_points,
  target_edge,
  exclude_area = NULL,
  max_iterations = 10
)

Arguments

network

The spatial network used for the delineation

end_points

Target start- and end-point

target_edge

Target edge geometry to follow in the delineation

exclude_area

Region that we aim to exclude from the delineation

max_iterations

Maximum number of iterations employed to refine the corridor edges

Value

An sf::sfc_LINESTRING object representing the edge


Find the corridor end points.

Description

Determine the extremes (end points) of the river corridor using the network built from the river center line features (see build_river_network() and the spatial network used for the delineation. The end points are selected as the two furthest river crossings of the spatial network that connect the sub-networks for each river sides.

Usage

corridor_end_points(river_network, spatial_network, regions)

Arguments

river_network

A sfnetworks::sfnetwork object representing the river centerline

spatial_network

A sfnetworks::sfnetwork object representing the spatial network used for the delineation

regions

A simple feature geometry representing the two river sides

Value

An sf::sfc_POINT geometry including a pair of points


Default STAC collection

Description

Endpoint and collection ID of the default STAC collection where to access digital elevation model (DEM) data. This is the global Copernicus DEM 30 dataset hosted on AWS, as listed in the EarthSearch STAC API endpoint. Note that AWS credentials need to be set up in order to access the data (not the catalog). References:

Usage

default_stac_dem

Define delineation parameters within an area of interest

Description

Define delineation parameters within an area of interest

Usage

define_aoi(
  city_name,
  river_name,
  crs = NULL,
  network_buffer = 3000,
  dem_buffer = 2500,
  buildings_buffer = 100
)

Arguments

city_name

A character vector of length one

river_name

A character vector of length one

crs

The projected Coordinate Reference System (CRS) to use. If not provided, the suitable Universal Transverse Mercator (UTM) CRS is selected

network_buffer

Add a buffer (an integer in meters) around river to retrieve additional data (streets, railways, etc.). Default is 3000 m.

dem_buffer

Size of the buffer region (in meters) around the spatial network to retrieve the DEM.

buildings_buffer

Add a buffer (an integer in meters) around the river to retrieve additional data (buildings). Default is 100 m.

Value

A list with delineation parameter values, namely city_name and river_name as character vectors of length one, bb as object of class sf::bbox, crs as object of class sf::crs, and network_buffer, dem_buffer and buildings_buffer as numerical vector of length one.

Examples


# Get default parameters in AOI
aoi <- define_aoi("Bucharest", "Dâmbovița")

# Get parameters in AOI with custom CRS
aoi <- define_aoi("Bucharest", "Dâmbovița",
                  crs = "EPSG:3844")  # National projected CRS


# Get parameters in AOI with non-default buffers
aoi <- define_aoi("Bucharest", "Dâmbovița",
                  network_buffer = 2000,
                  dem_buffer = 2000,
                  buildings_buffer = 150)


Delineate a corridor around a river

Description

Given a set of delineation parameters and input data, carry out corridor delineation, corridor segmentation and/or riverspace delineation as indicated by the user.

Usage

delineate(
  aoi,
  osm,
  dem = NULL,
  corridor_init = "valley",
  max_iterations = 10,
  capping_method = "shortest-path",
  angle_threshold = 100,
  corridor = TRUE,
  segments = FALSE,
  riverspace = FALSE
)

Arguments

aoi

A list of delineation parameters for an area of interest, namely ⁠$city_name⁠, ⁠$river_name⁠, ⁠$crs⁠, ⁠$network_buffer⁠, ⁠$dem_buffer⁠, and ⁠$buildings_buffer⁠. For more info see define_aoi().

osm

A list with OpenStreetMap data sets within the aoi, as objects of class sf::sfc

dem

Digital elevation model (DEM) of the region (only used if corridor_init is "valley")

corridor_init

How to estimate the initial guess of the river corridor. It can take the following values:

  • "valley": use the river valley boundary, as estimated from a Digital Elevation Model (DEM) (for more info see delineate_valley())

  • numeric or integer: use a buffer region of the given size (in meters) around the river centerline

  • An sf::sf or sf::sfc object: use the given input geometry

max_iterations

Maximum number of iterations employed to refine the corridor edges (see corridor_edge()).

capping_method

The method employed to connect the corridor edge end points (i.e., to "cap" the corridor), as character vector of length one. See cap_corridor() for the available methods.

angle_threshold

Only network edges forming angles above this threshold (in degrees) are considered when forming segment edges. See delineate_segments() and rcoins::stroke(). Only used if segments is TRUE.

corridor

Whether to carry out the corridor delineation

segments

Whether to carry out the corridor segmentation

riverspace

Whether to carry out the riverspace delineation

Details

The returned delineation class is a list wrapping objects of class sf::sfc_POLYGON or sf::sfc_MULTIPOLYGON which can be retrieved through subsetting and converted to other common spatial classes in typical sf- or terra-based workflows.

Corridor delineation depends on the availability of OpenStreetMap street and railway data around the river. Sparse OSM data, especially too few river crossings, may lead to failed delineation.

Value

A list object of class delineation containing zero or more of the following elements: "valley", "corridor", "segments", and "riverspace", each as an sf::sfc_POLYGON or sf::sfc_MULTIPOLYGON object (depending on the geometry of the input data). The list contains only the geometries corresponding to the delineation steps that were carried out (e.g., if segments is FALSE, the list will not contain a "segments" element). In any case, the returned object also contains the base layers and a list aoi with the parameters used for delineation.

Examples


# Define delineation parameters within area of interest
aoi <- define_aoi("Bucharest", "Dâmbovița")

# Get data
osm <- get_osm(aoi)
dem <- get_dem(aoi, osm)

# Delineate with defaults
delineate(aoi, osm, dem)

# Carry out all delineations
delineate(aoi, osm, dem, segments = TRUE, riverspace = TRUE)


Delineate a corridor around a river

Description

This is a convenience function used for quick delineation. With only the city name and river name as input, it uses default delineation parameters, it retrieves OSM and DEM data and returns a list with all three delineations.

Usage

delineate_city_river(
  city_name,
  river_name,
  corridor = TRUE,
  segments = TRUE,
  riverspace = TRUE
)

Arguments

city_name

A character vector of length one.

river_name

A character vector of length one.

corridor

Whether to carry out the corridor delineation. Default is TRUE.

segments

Whether to carry out the corridor segmentation. Default is TRUE.

riverspace

Whether to carry out the riverspace delineation. Default is TRUE.

Value

A list with the valley, corridor, segments, and riverspace geometries as sf::sfc_POLYGON objects.

Examples


delineate_city_river("Bucharest", "Dâmbovița")


Delineate a river corridor on a spatial network

Description

The corridor edges on the two river banks are drawn on the provided spatial network starting from an initial guess of the corridor (based e.g. on the river valley).

Usage

delineate_corridor(
  network,
  river,
  corridor_init = 1000,
  max_width = 3000,
  max_iterations = 10,
  capping_method = "shortest-path"
)

Arguments

network

The spatial network of class sfnetworks::sfnetwork to be used for the delineation. Required, no default.

river

A (MULTI)LINESTRING simple feature geometry of class sf::sf or sf::sfc representing the river centerline. Required, no default.

corridor_init

How to estimate the initial guess of the river corridor. It can take the following values:

  • numeric or integer: use a buffer region of the given size (in meters, positive, unrestricted) around the river centerline

  • An sf::sf or sf::sfc object: use the given input geometry

max_width

A positive number representing the (approximate) maximum width of the corridor in meters. The upper limit is unrestricted. The spatial network is trimmed by a buffer region of this size around the river.

max_iterations

A positive integer greater than 0, with upper limit unrestricted, representing the maximum number of iterations employed to refine the corridor edges (see corridor_edge()).

capping_method

Case-insensitive character vector of length 1 with the method employed to connect the corridor edge end points (i.e. to "cap" the corridor). See cap_corridor() for the available methods.

Value

A simple feature geometry of class sf::sfc_POLYGON representing the river corridor

Examples


bucharest_osm <- get_osm_example_data()
streets <- bucharest_osm$streets
railways <- bucharest_osm$railways
river <- bucharest_osm$river_centerline

# Delineate with default values
network <- rbind(streets, railways) |> as_network()
delineate_corridor(network = network, river = river)

# Delineate with user-specified parameters
bucharest_dem <- get_dem_example_data()
corridor_init <- delineate_valley(dem = bucharest_dem, river = river)
delineate_corridor(network = network, river = river,
                   corridor_init = corridor_init,
                   max_width = 4000, max_iterations = 5,
                   capping_method = "direct")


Delineate the space surrounding a river

Description

Delineate the space surrounding a river

Usage

delineate_riverspace(
  river,
  occluders = NULL,
  density = 1/50,
  ray_num = 40,
  ray_length = 100
)

Arguments

river

List with river surface and centerline

occluders

Geometry of occluders

density

Density of viewpoints

ray_num

Number of rays as numeric vector of length one

ray_length

Length of rays in meters as numeric vector of length one

Details

For riverspace delineation, OSM water polygons intersecting the river centerline are treated as part of the river, including connected water bodies such as lakes and reservoirs. Viewpoints are calculated from water edges where available, and from the river centerline when river surface polygons are missing or partial.

Value

Riverspace as object of class sf::sfc_POLYGON

Examples


bucharest_osm <- get_osm_example_data()
delineate_riverspace(bucharest_osm$river_surface, bucharest_osm$buildings)


Split a river corridor into segments

Description

Segments are defined as corridor subregions separated by river-crossing transversal lines that form continuous strokes in the network.

Usage

delineate_segments(corridor, network, river, angle_threshold = 100)

Arguments

corridor

The river corridor as a simple feature geometry of class sfc_POLYGON

network

The spatial network of class sfnetwork to be used for the segmentation

river

The river centerline as a simple feature geometry of class sf::sf or sf::sfc

angle_threshold

Only consider angles above this threshold (in degrees) to form continuous strokes in the network. The value can range between 0 and 180, with the default set to 100. See rcoins::stroke() for more details.

Value

Segment polygons as a simple feature geometry of class sf::sfc_POLYGON

Examples


bucharest_osm <- get_osm_example_data()
corridor <- bucharest_dambovita$corridor
network <- rbind(bucharest_osm$streets, bucharest_osm$railways) |>
  as_network()
river <- bucharest_osm$river_centerline
delineate_segments(corridor, network, river)


Extract the river valley from the DEM

Description

The slope of the digital elevation model (DEM) is used as friction (cost) surface to compute the cost distance from any grid cell of the raster to the river. A characteristic value (default: the mean) of the cost distance distribution in a region surrounding the river (default: a buffer region of 2 km) is then calculated, and used to threshold the cost-distance surface. The resulting area is then "polygonized" to obtain the valley boundary as a simple feature geometry.

Usage

delineate_valley(dem, river)

Arguments

dem

SpatRaster object with the digital elevation model of the region

river

An object of class sf::sf or sf::sfc representing the river

Value

River valley as a simple feature geometry of class sfc_MULTIPOLYGON

Examples


bucharest_osm <- get_osm_example_data()
bucharest_dem <- get_dem_example_data()
delineate_valley(bucharest_dem, bucharest_osm$river_centerline)


The delineation class

Description

An S3 class representing the result of a delineation as returned by delineate().

Value

An object of class delineation containing zero or more of the spatial layers ⁠$valley⁠, ⁠$corridor⁠, ⁠$segments⁠, and ⁠$riverspace⁠ (each an sf::sfc_POLYGON or sf::sfc_MULTIPOLYGON object), plus the base OSM and optionally DEM layers and an ⁠$aoi⁠ list with the delineation parameters produced by define_aoi(). See delineate() for details.

Examples


bd <- delineate_city_river("Bucharest", "Dâmbovița")
class(bd)


Cluster the river crossings and select the shortest crossing per cluster

Description

Create groups of edges that are crossing the river in nearby locations, using a density-based clustering method (DBSCAN). This is to make sure that edges representing e.g. different lanes of the same street are treated as part of the same crossing. For each cluster, select the shortest edge.

Usage

filter_clusters(crossings, river, eps = 100)

Arguments

crossings

Crossing edge geometries as a simple feature object

river

The river geometry as a simple feature object

eps

DBSCAN parameter referring to the size (radius) distance of the neighborhood. Should approximate the distance between edges that we want to consider as a single river crossing

Value

An object of class sf::sfc_LINESTRING including the shortest edge per cluster


Subset a network keeping the components that intersect a target geometry.

Description

If subsetting results in multiple disconnected components, we keep the main one.

Usage

filter_network(network, target, elements = "nodes")

Arguments

network

A spatial network object of class sfnetworks::sfnetwork

target

The target geometry

elements

The elements of the network to filter. It can be "nodes" or "edges"

Value

A spatial network object of class sfnetworks::sfnetwork


Find intersections between the edges of two networks

Description

Find intersections between the edges of two networks

Usage

find_intersections(network_1, network_2)

Arguments

network_1, network_2

The two spatial network objects

Value

An object of class sf::sfc


Flatten a network by adding points at apparent intersections

Description

All crossing edges are identified, and the points of intersections are injected within the edge geometries. Note that the injected points are not converted to network nodes (this can be achieved via sfnetworks' sfnetworks::to_spatial_subdivision(), which is part of the tasks that are included in clean_network().

Usage

flatten_network(network)

Arguments

network

A network object of class sfnetworks::sfnetwork

Details

The functionality is similar to sfnetworks' sfnetworks::st_network_blend(), but in that case an external point is only injected to the closest edge.

Value

An sfnetworks::sfnetwork object with additional points at intersections

Examples


bucharest_osm <- get_osm_example_data()
edges <- dplyr::bind_rows(bucharest_osm$streets,
                          bucharest_osm$railways)
network <- sfnetworks::as_sfnetwork(edges, directed = FALSE)
flatten_network(network)


ggplot2 layer for a delineation object

Description

Creates a list of ggplot2::geom_sf() layers representing the delineation results of a delineation object. The list can be added to a ggplot2::ggplot() object with +, and further layers or themes can be added on top. Base layers (streets, railways, river_centerline, river_surface) are not included and can be added separately with ggplot2::geom_sf().

Usage

geom_delineation(x, extent = "corridor", legend = TRUE)

Arguments

x

An object of class delineation. This is typically the output of the delineate() function.

extent

The delineation layer whose bounding box sets the plot extent. One of "corridor", "valley", "riverspace", or NULL (no restriction, ggplot2 fits all layers). Defaults to "corridor".

legend

Whether the plot should display a legend. Default is TRUE.

Details

The following layers are included (where present in x), in the following order:

Value

A list of ggplot2::geom_sf() and ggplot2::coord_sf() elements to be added to a ggplot2::ggplot() object.

See Also

plot.delineation() for a base R alternative.

Examples


library(ggplot2)
bd <- delineate_city_river("Bucharest", "Dâmbovița")
ggplot() + geom_delineation(bd) + theme_void()
ggplot() + geom_delineation(bd, extent = "valley") + theme_void()


Get characteristic value of distribution of cost distance

Description

Get characteristic value of distribution of cost distance

Usage

get_cd_char(cd, method = "mean")

Arguments

cd

cost distance raster data

method

function used to derive caracteristic value (mean)

Value

characteristic value of cd raster


Split corridor along the river to find edges on the two banks

Description

Split corridor along the river to find edges on the two banks

Usage

get_corridor_edges(corridor, river)

Arguments

corridor

The river corridor as a simple feature geometry

river

The river centerline as a simple feature geometry

Value

Corridor edges as an object of class sf::sfc_LINESTRING


Derive cost distance function from masked slope

Description

Derive cost distance function from masked slope

Usage

get_cost_distance(slope, river, target = 0)

Arguments

slope

raster of slope data

river

vector data of river

target

value for cost distance calculation

Value

raster of cost distance


Access digital elevation model (DEM) for a given region

Description

Access digital elevation model (DEM) for a given region

Usage

get_dem(
  aoi,
  osm,
  dem_source = "STAC",
  stac_endpoint = NULL,
  stac_collection = NULL,
  force_download = FALSE
)

Arguments

aoi

A list of delineation parameters, including ⁠$dem_buffer⁠ used to expand the area of interest covered by the network and ⁠$crs⁠ for the CRS which to transform the DEM to

osm

A list with OpenStreetMap data sets for the a location, as objects of class sf::sfc

dem_source

Source of the DEM:

  • If "STAC" (default), DEM tiles are searched on a SpatioTemporal Asset Catalog (STAC) end point, then accessed and mosaicked to the area of interest

stac_endpoint

URL of the STAC API endpoint (only used if dem_source is "STAC"). For more info, see get_stac_asset_urls()

stac_collection

Identifier of the STAC collection to be queried (only used if dem_source is "STAC"). For more info, see get_stac_asset_urls()

force_download

Download data even if cached data is available

Value

DEM as a terra SpatRaster object

Examples


# Define delineation parameters and get OSM data within area of interest
aoi <- define_aoi("Bucharest", "Dâmbovița")
osm <- get_osm(aoi)

# Get DEM with default values
dem <- get_dem(aoi, osm)

# Get DEM from custom STAC endpoint
get_dem(aoi, osm,
        stac_endpoint = "some endpoint",
        stac_collection = "some collection")

# Specify CRS
get_dem(bb, crs = crs)


Get file path where to cache digital elevation model (DEM) data

Description

The function returns the file path where to serialize a terra::SpatRaster object representing the DEM as retrieved from a set of tiles reachable at the given URLs, cropped and merged for the given bounding box. The directory used is the one returned by cache_directory().

Usage

get_dem_cache_filepath(tile_urls, bbox)

Arguments

tile_urls

URL-paths where to reach the DEM tiles

bbox

A bounding box

Value

A character string representing the file path


Get example DEM data

Description

This function retrieves example Digital Elevation Model (DEM) data from the Zenodo data repository, and it can be used in examples and tests. The code used to generate the example dataset is available at https://github.com/CityRiverSpaces/CRiSpExampleData. Note that the example dataset is cached locally, so that subsequent calls to the function can load the example data from disk without having to re-download the data.

Usage

get_dem_example_data(force_download = FALSE)

Arguments

force_download

Download data even if cached data is available

Value

An object of class terra::SpatRaster containing the DEM data.

Examples


get_dem_example_data(force_download = TRUE)


Get file path where to cache example data files

Description

The function returns the file path where to store example data files that are retrieved from a data repository (see get_osm_example_data() and get_dem_example_data()). The directory used is the one returned by cache_directory().

Usage

get_example_cache_filepath(filename)

Arguments

filename

The name of the file to be retrieved from the data repository

Value

A character string representing the file path


Retrieve an example data file from the data repository

Description

Store the file in the cache directory, for subsequent reuse.

Usage

get_example_data_file(filename, force_download = FALSE)

Arguments

force_download

Download data even if cached data is available

Value

A character string representing the file path


Identify network edges that are intersecting a geometry

Description

Identify network edges that are intersecting a geometry

Usage

get_intersecting_edges(network, geometry, index = FALSE)

Arguments

network

A spatial network object of class sfnetworks::sfnetwork

geometry

An object of class sf::sfc

index

Whether to return the indices of the matchin edges or the geometries

Value

Indices or geometries of the edges intersecting the given geometry of class sf::sfc_LINESTRING


Retrieve OpenStreetMap data for a given location

Description

Retrieve OpenStreetMap data for a given location, including the city boundary, the river centreline and surface, the streets, the railways, and the buildings

Usage

get_osm(
  aoi,
  city_boundary = TRUE,
  network = TRUE,
  buildings = TRUE,
  force_download = FALSE
)

Arguments

aoi

A list of delineation parameters

city_boundary

A logical indicating if the city boundary should be retrieved. Default is TRUE.

network

A logical indicating if the spatial network should be retrieved. Default is TRUE.

buildings

A logical indicating if buildings should be retrieved. Default is TRUE.

force_download

Download data even if cached data is available

Value

A list with the retrieved OpenStreetMap data sets for the given location, as objects of class sf::sfc

Examples


# Set parameters
city <- "Bucharest"
river <- "Dâmbovița"

# Define AOI parameters
aoi <- define_aoi(city, river)

# Get OSM data with defaults
get_osm(aoi)

# Get OSM data without city boundary
get_osm(aoi, city_boundary = FALSE)

# Use custom network buffer to get streets and railways
aoi2 <- aoi
aoi2$network_buffer = 3500
get_osm(aoi2)

# Use custom buffer to get buildings
aoi3 <- aoi
aoi3$buildings_buffer = 150
get_osm(aoi3)

# Use custom CRS
aoi4 <- aoi
aoi4$crs <- "EPSG:31600"
get_osm(aoi4)

# Avoid getting OSM data from cache
get_osm(city_name = city, river_name = river, force_download = TRUE)


Get the bounding box of a city

Description

Get the bounding box of a city

Usage

get_osm_bb(city_name)

Arguments

city_name

A character vector of length one

Value

A bbox object with the bounding box of the city

Examples


get_osm_bb(city_name = "Bucharest")


Get OpenStreetMap buildings

Description

Get buildings from OpenStreetMap within a given buffer around a river.

Usage

get_osm_buildings(aoi, crs = NULL, force_download = FALSE)

Arguments

aoi

Area of interest as sf object or bbox

crs

Coordinate reference system as EPSG code

force_download

Download data even if cached data is available

Value

An object of class sf::sfc_POLYGON

Examples


bb <- get_osm_bb("Bucharest")
crs <- get_utm_zone(bb)
get_osm_buildings(aoi = bb, crs = crs)


Get the file path where to cache results of an Overpass API query

Description

The function returns the file path where to serialize an osdata_sf object for a given key:value pair and a bounding box. The directory used is the one returned by cache_directory().

Usage

get_osm_cache_filepath(key, value, bbox)

Arguments

key

A character string with the key to filter the data

value

A character string with the value to filter the data

bbox

A bounding box

Value

A character string representing the file path


Get the city boundary from OpenStreetMap

Description

This function retrieves the city boundary from OpenStreetMap based on a bounding box with the OSM tags "place:city" and "boundary:administrative". The result is filtered by the city name.

Usage

get_osm_city_boundary(
  bb,
  city_name,
  crs = NULL,
  multiple = FALSE,
  force_download = FALSE
)

Arguments

bb

Bounding box of class bbox

city_name

A case-sensitive character vector of length 1 with the name of the city

crs

Coordinate reference system as EPSG code

multiple

A logical indicating if multiple city boundaries should be returned. By default, only the first one is returned.

force_download

Download data even if cached data is available

Value

An object of class sf::sfc_POLYGON or sf::sfc_MULTIPOLYGON with the city boundary

Examples


bb <- get_osm_bb("Bucharest")
crs <- get_utm_zone(bb)
get_osm_city_boundary(bb = bb, city_name = "Bucharest", crs = crs)


Get example OSM data

Description

This function retrieves example OpenStreetMap (OSM) data from the Zenodo data repository, and it can be used in examples and tests. The code used to generate the example dataset is available at https://github.com/CityRiverSpaces/CRiSpExampleData. Note that the example dataset is cached locally, so that subsequent calls to the function can load the example data from disk without having to re-download the data.

Usage

get_osm_example_data(force_download = FALSE)

Arguments

force_download

Download data even if cached data is available

Value

A list of sf objects containing the OSM data as sf::sfc objects.

Examples


get_osm_example_data(force_download = TRUE)


Get file path where to cache results of an Overpass API query by OSM id

Description

The function returns the file path where to serialize an osmdata_sf object for a given OSM element type and id. The directory used is the one returned by cache_directory().

Usage

get_osm_id_cache_filepath(type, id)

Arguments

type

A character string with the OSM element type (e.g. "relation", "way", "node")

id

A character string with the OSM element id

Value

A character string representing the file path


Get OpenStreetMap railways

Description

Get OpenStreetMap railways

Usage

get_osm_railways(
  aoi,
  crs = NULL,
  railway_values = "rail",
  force_download = FALSE
)

Arguments

aoi

Area of interest as sf object or bbox

crs

A numeric vector of length one with the EPSG code of the CRS

railway_values

A case-insensitive character vector with the railway values to retrieve.

force_download

Download data even if cached data is available

Value

An object of class sf::sfc_LINESTRING

Examples


bb <- get_osm_bb("Bucharest")
crs <- get_utm_zone(bb)
get_osm_railways(aoi = bb, crs = crs)


Get the river centreline from OpenStreetMap

Description

Get the river centreline from OpenStreetMap

Usage

get_osm_river_centerline(
  bb,
  river_name,
  crs = NULL,
  buffer_distance = NULL,
  force_download = FALSE
)

Arguments

bb

Bounding box of class bbox

river_name

The name of the river as character vector of length 1, case-sensitive.

crs

Coordinate reference system as EPSG code

buffer_distance

Optional buffer distance in metres to expand the bounding box before cropping the river centreline. Useful when downstream processing (e.g. network or DEM analysis) extends beyond the original bb. Defaults to NULL (no expansion).

force_download

Download data even if cached data is available

Value

The river centreline as object of class sf::sfc_LINESTRING or sf::sfc_MULTILINESTRING.

Examples


bb <- get_osm_bb("Bucharest")
crs <- get_utm_zone(bb)
get_osm_river_centerline(bb = bb, river_name = "Dâmbovița", crs = crs,
              force_download = FALSE)


Get the river surface from OpenStreetMap

Description

Get the river surface from OpenStreetMap

Usage

get_osm_river_surface(bb, river_centerline, crs = NULL, force_download = FALSE)

Arguments

bb

Bounding box of class bbox

river_centerline

The river centerline as an object of class sf::sfc_LINESTRING or sf::sfc_MULTILINESTRING

crs

Coordinate reference system as EPSG code

force_download

Download data even if cached data is available

Value

The river surface as object of class sf::sfc_POLYGON or sf::sfc_MULTIPOLYGON.

Examples


bb <- get_osm_bb("Bucharest")
crs <- get_utm_zone(bb)
river <- get_osm_river_centerline(bb, "Dâmbovița")
get_osm_river_surface(bb = bb, river_centerline = river, crs = crs,
              force_download = FALSE)


Get OpenStreetMap streets

Description

Get OpenStreetMap streets

Usage

get_osm_streets(aoi, crs = NULL, highway_values = NULL, force_download = FALSE)

Arguments

aoi

Area of interest as sf object or bbox. Required, no default.

crs

A numeric vector of length one with the EPSG code of the CRS

highway_values

A character vector with the highway values to retrieve. If left NULL, the function retrieves the following values: "motorway", "trunk", "primary", "secondary", "tertiary"

force_download

Download data even if cached data is available

Value

An object of class sf::sfc_LINESTRING

Examples


# Set parameters
bb <- get_osm_bb("Bucharest")
crs <- 31600  # National projected CRS

# Get streets with default values
get_osm_streets(aoi = bb, crs = crs)

# Specify street categories to be retrieved
get_osm_streets(aoi = bb, crs = crs, highway_values = "primary")

# Ensure that data is not retrieved from cache
get_osm_streets(aoi = bb, crs = crs, force_download = FALSE)


Get an area of interest (AoI) around a river, cropping to the bounding box of a city

Description

Get an area of interest (AoI) around a river, cropping to the bounding box of a city

Usage

get_river_aoi(river, city_bbox, buffer_distance)

Arguments

river

A sf::sf or sf::sfc object with the river centreline and (optionally) the river surface geometry

city_bbox

Bounding box of class bbox around the city

buffer_distance

A positive number representing the buffer size around the river in meters. The upper limit is unrestricted.

Value

An sf::sfc_POLYGON object in lat/lon coordinates

Examples


bb <- get_osm_bb("Bucharest")
river_centerline <- get_osm_river_centerline(bb, "Dâmbovița")
river_surface <- get_osm_river_surface(bb, "Dâmbovița")
river <- list(centerline = river_centerline, surface = river_surface)
get_river_aoi(river = river, city_bbox = bb, buffer_distance = 100)


Draw the regions corresponding to the two river banks

Description

These are constructed as single-sided buffers around the river geometry (see river_buffer() for the implementation and refinement steps).

Usage

get_river_banks(river, width)

Arguments

river

River spatial features provided as a sfnetworks::sfnetwork or sf::sf/sf::sfc object.

width

Width of the regions

Value

A sf::sfc_POLYGON object with two polygon features


Derive slope as percentage from DEM

Description

This makes use of the terrain function of the terra package

Usage

get_slope(dem)

Arguments

dem

raster data of dem

Value

raster of derived slope over dem extent


Retrieve the URLs of all the assets intersecting a bbox from a STAC API

Description

Retrieve the URLs of all the assets intersecting a bbox from a STAC API

Usage

get_stac_asset_urls(bb, endpoint = NULL, collection = NULL)

Arguments

bb

A bounding box, provided either as a matrix (rows for "x", "y", columns for "min", "max") or as a vector ("xmin", "ymin", "xmax", "ymax"), in lat/lon coordinates (WGS84 coordinate referece system) of class bbox

endpoint

URL of the STAC API endpoint. To be provided together with stac_collection, or leave blank to use defaults (see default_stac_dem)

collection

Identifier of the STAC collection to be queried. To be provided together with stac_endpoint, or leave blank to use defaults (see default_stac_dem)

Value

A list of URLs for the assets in the collection overlapping with the specified bounding box

Examples


bb <- get_osm_bb("Bucharest")
get_stac_asset_urls(bb)

# Use non-default STAC API
get_stac_asset_urls(bb,
                    endpoint = "some endpoint",
                    collection = "some collection")


Get the UTM zone of a spatial object

Description

Get the UTM zone of a spatial object

Usage

get_utm_zone(x)

Arguments

x

Object in any class accepted by as_bbox()

Value

The EPSG code of the UTM zone

Examples

# Get EPSG code for UTM zone of Bucharest
bb <- c(xmin = 25.97, ymin = 44.33, xmax = 26.23, ymax = 44.54)
get_utm_zone(bb)

Create vector/polygon representation of valley without holes from raster mask

Description

Create vector/polygon representation of valley without holes from raster mask

Usage

get_valley_polygon(valley_mask)

Arguments

valley_mask

raster mask of valley pixels

Value

(multi)polygon representation of valley area as a simple feature geometry without holes


Remove possible holes from valley geometry

Description

Remove possible holes from valley geometry

Usage

get_valley_polygon_no_hole(valley_polygon)

Arguments

valley_polygon

Geometry of valley as object of class sf::sfc

Value

(multi)polygon geometry of valley


Create vector/polygon representation of valley raster mask

Description

Create vector/polygon representation of valley raster mask

Usage

get_valley_polygon_raw(valley_mask)

Arguments

valley_mask

raster mask of valley pixels

Value

polygon representation of valley area as object of class sf::sfc


Identify the initial edges of the river corridor

Description

These are defined by splitting the initial corridor boundary into the sub-regions that the river forms in the area of interest

Usage

initial_edges(corridor_initial, regions)

Arguments

corridor_initial

A simple feature geometry representing the area of the initial corridor

regions

A simple feature geometry representing the sub-regions formed by cutting the area of interest along the river

Value

An sf::sfc_LINESTRING or sf::sfc_MULTILINESTRING object representing the initial corridor edges


Retrieve DEM data from a list of STAC assets

Description

Load DEM data from a list of tiles, crop and merge using a given bounding box to create a raster DEM for the specified region. Results are cached, so that new queries with the same input parameters will be loaded from disk.

Usage

load_dem(bb, tile_urls, force_download = FALSE)

Arguments

bb

A bounding box, provided either as a matrix (rows for "x", "y", columns for "min", "max") or as a vector ("xmin", "ymin", "xmax", "ymax") of class bbox.

tile_urls

A list of tiles where to read the DEM data from

force_download

Download data even if cached data is available

Value

A DEM of class terra::SpatRaster, retrieved and retiled to the given bounding box

Examples


bb <- get_osm_bb("Bucharest")
tile_urls <- get_stac_asset_urls(bb)
load_dem(bb = bb, tile_urls = tile_urls, force_download = TRUE)


Load raster data from one or multiple (remote) files

Description

If a bounding box is provided, the file(s) are cropped for the given extent. The resulting rasters are then merged using terra::merge.

Usage

load_raster(urlpaths, bbox = NULL)

Arguments

urlpaths

Path or URL to the raster file(s)

bbox

A bounding box

Value

Raster data as a terra::SpatRaster object


Mask out river regions incl. a buffer in cost distance raster data

Description

Mask out river regions incl. a buffer in cost distance raster data

Usage

mask_cost_distance(cd, river, buffer = 2000)

Arguments

cd

cost distance raster

river

vector/polygon

buffer

size of buffer around river polygon to additionally mask

Value

cd raster with river+BUFFER pixels masked


Mask slope raster, setting the slope to zero for the pixels overlapping the river area.

Description

Mask slope raster, setting the slope to zero for the pixels overlapping the river area.

Usage

mask_slope(slope, river, lthresh = 0.001, target = 0)

Arguments

slope

raster data of slope

river

vector/polygon data of river

lthresh

lower numerival threshold to consider slope non-zero

target

value to set for pixels overlapping river area

Value

updated slope raster


Match OpenStreetMap data by name

Description

Match OpenStreetMap data by name

Usage

match_osm_name(osm, match)

Arguments

osm

An sf object with OpenStreetMap data

match

A character string with the name to match

Value

sf object containing only rows with filtered name


Find the node in a network that is closest to a target geometry.

Description

Find the node in a network that is closest to a target geometry.

Usage

nearest_node(network, target)

Arguments

network

A network object of class sfnetworks::sfnetwork

target

An object of class sf::sf or sf::sfc

Value

A node in the network as an object of class sf::sfc_POINT


Look up a river's OSM relation via Nominatim

Description

Look up a river's OSM relation via Nominatim

Usage

nominatim_waterway_lookup(river_name)

Arguments

river_name

A character string with the river name

Value

A data frame with Nominatim results filtered to waterway river relations, or an empty data frame if none found.


Retrieve OpenStreetMap data as sf object

Description

Query the Overpass API for a key:value pair within a given bounding box (provided as lat/lon coordiates). Results are cached, so that new queries with the same input parameters will be loaded from disk.

Usage

osmdata_as_sf(key, value, aoi, force_download = FALSE)

Arguments

key

A case-insensitive character vector of length 1 with the key to filter the data

value

A case-insensitive character vector with the value(s) to filter the data

aoi

An area of interest, provided either as as sf object or "bbox" or as a vector ("xmin", "ymin", "xmax", "ymax")

force_download

Download data even if cached data is available

Value

An osmdata::osmdata object with the retrieved OpenStreetMap data

Examples


bb <- get_osm_bb("Bucharest")
osmdata_as_sf(key = "highway",
              value = "motorway",
              aoi = bb,
              force_download = FALSE)


Retrieve OpenStreetMap data as sf object for a specific feature type and id

Description

Results are cached, so that new queries with the same type and id will be loaded from disk.

Usage

osmdata_as_sf_by_id(type, id, force_download = FALSE)

Arguments

type

A character string with the OSM element type ("relation", "way", or "node")

id

A character or numeric vector of length 1 with the OSM element id

force_download

Download data even if cached data is available

Value

An osmdata::osmdata object with the retrieved OpenStreetMap data


Query the Overpass API for a specific feature type and id

Description

Query the Overpass API for a specific feature type and id

Usage

osmdata_id_query(type, id)

Arguments

type

A character string with the OSM element type

id

A character or numeric vector of length 1 with the OSM element id

Value

An osmdata::osmdata object with the retrieved OpenStreetMap data


Query the Overpass API for a key:value pair within a bounding box

Description

Query the Overpass API for a key:value pair within a bounding box

Usage

osmdata_query(key, value, bb)

Arguments

key

A character string with the key to filter the data

value

A character string with the value to filter the data. If value = "" means that you get all features available in OSM for the specified bounding box

bb

A bounding box, in lat/lon coordinates

Value

An osmdata::osmdata object with the retrieved OpenStreetMap data


Plot a delineation object

Description

This S3 method provides a way to quickly visualise how the layers of a delineation object fit together using base R graphics. A delineation object typically includes the base layers streets, railways, river_centerline and river_surface, and the delineations of the valley, corridor, segments, and riverspace. Depending on the delineation object, some of the delineation layers may not be present and thus will not be plotted.

Usage

## S3 method for class 'delineation'
plot(x, ..., legend = TRUE)

Arguments

x

An object of class delineation, which is typically the output of the delineate() function.

...

Not used; included for compatibility with the generic.

legend

logical. If TRUE (default), a legend is added to the plot.

Value

NULL, invisibly. This function is called for its side effect of producing a plot.

See Also

geom_delineation() for a ggplot2-based alternative.

Examples


bd <- delineate_city_river("Bucharest", "Dâmbovița")
plot(bd)


Pre-process one-dimensional distance input

Description

Ensure that distance input is plain numeric in meters, regardless of whether it is provided as a units object (e.g., a distance in kilometers), a plain numeric or another vector-like object with numeric storage.mode.

Usage

preprocess_distance(x, arg_name = deparse(substitute(x)))

Arguments

x

A distance value which may be numeric, or a units::units object, or any other object for which the underlying storage.mode is numeric.

arg_name

Name of the argument, used in messages/errors.

Value

A vector of class numeric in meters.


Print a delineation object

Description

Prints a compact summary of a delineation object, showing which layers are present and their feature counts.

Usage

## S3 method for class 'delineation'
print(x, ...)

Arguments

x

An object of class delineation.

...

Not used; included for compatibility with the generic.

Value

x, invisibly.

Examples


bd <- delineate_city_river("Bucharest", "Dâmbovița")
print(bd)


Print a summary.delineation object

Description

Print a summary.delineation object

Usage

## S3 method for class 'summary.delineation'
print(x, ...)

Arguments

x

An object of class summary.delineation, as returned by summary.delineation().

...

Not used; included for compatibility with the generic.

Value

x, invisibly.

Examples


bd <- delineate_city_river("Bucharest", "Dâmbovița")
s <- summary(bd)
print(s)


Read data from the cache directory

Description

For the directory used for caching see cache_directory().

Usage

read_data_from_cache(filepath, unwrap = FALSE, quiet = FALSE)

Arguments

filepath

Path of the file to deserialize as a character string

unwrap

Whether the deserialized object should be "unpacked" (as required by terra::SpatRaster objects)

quiet

Omit message on cache file being loaded

Value

Object deserialized


Reproject a raster or vector dataset to the specified coordinate reference system (CRS)

Description

Reproject a raster or vector dataset to the specified coordinate reference system (CRS)

Usage

reproject(x, crs, ...)

Arguments

x

Raster (SpatRaster) or vector (sf) object

crs

CRS to be projected to, provided as numeric, integer or character vector of length one or sf::crs. If numeric, the value should be a positive number with unrestricted upper bound representing a valid EPSG code.

...

Optional arguments for raster or vector reproject functions

Value

sf::sf, sf::sfc, or terra::SpatRaster object reprojected to specified CRS

Examples

# Reproject a raster to EPSG:4326
r <- terra::rast(matrix(1:12, nrow = 3, ncol = 4), crs = "EPSG:32633")
reproject(r, 4326)

Draw a corridor as a fixed buffer region around a river.

Description

The river geometry may consist of multiple spatial features, these are optionally cropped using the area of interest, then merged after applying the buffer.

Usage

river_buffer(river, buffer_distance, bbox = NULL, side = NULL)

Arguments

river

A simple feature geometry representing the river

buffer_distance

Size of the buffer (in the river's CRS units)

bbox

Bounding box defining the extent of the area of interest

side

Whether to generate a single-sided buffer with a "flat" end. This is only applicable if river is a (multi)linestring geometry. Choose between NULL (double-sided), "right" and "left"

Value

An object of class sf::sfc_POLYGON


Select non-intersecting line segments

Description

Recursively drop intersecting lines, starting from the line that form most intersections with other geometries. When multilple lines form the same number of intersections with other geometries, the longest line is discarded first. Note that lines are allowed to intersect on the corridor boundary.

Usage

select_nonintersecting_lines(lines, corridor)

Arguments

lines

Candidate edge segment as a simple feature geometry

corridor

The river corridor as a simple feature geometry

Value

A set of lines of class sf::sfc_LINESTRING that do not intersect within the corridor geometry, as a simple feature geometry


Set the units of x as the units of y

Description

Set the units of x as the units of y

Usage

set_units_like(x, y)

Arguments

x

x (can be unitless)

y

y (can be unitless)

Value

Object x with units of y


Find shortest path between a pair of nodes in the network.

Description

Find shortest path between a pair of nodes in the network.

Usage

shortest_path(network, from, to, weights = "weight")

Arguments

network

A spatial network object of class sfnetworks::sfnetwork

from

Start node

to

End node

weights

Name of the column in the network edge table from where to take the weigths

Value

An sf::sfc_LINESTRING object


Simplify a spatial network by removing multiple edges and loops.

Description

Simplify the graph, removing loops and double-edge connections following this approach. When dropping multiple edges, keep the shortest ones.

Usage

simplify_network(network)

Arguments

network

A network object

Value

A simplifed network object


Spatially smooth dem by (window) filtering

Description

Spatially smooth dem by (window) filtering

Usage

smooth_dem(dem, method = "median", window = 5)

Arguments

dem

raster data of dem

method

smoothing function to be used, e.g. "median", as accepted by terra::focal()

window

size of smoothing kernel

Value

filtered dem


Split a geometry along a (multi)linestring.

Description

Split a geometry along a (multi)linestring.

Usage

split_by(geometry, line, boundary = FALSE)

Arguments

geometry

Geometry to split

line

Dividing (multi)linestring

boundary

Whether to return the split boundary instead of the regions

Value

An object of class sf::sfc


Summarise a delineation object

Description

Computes summary statistics for a delineation object and returns them as a structured list of class summary.delineation. Delineation layers are reported with their area (in km²). For segments, the number of features and mean area are also given. Base layers are reported with feature counts; river_centerline as total length (in km) and river_surface as area (in km²).

Usage

## S3 method for class 'delineation'
summary(object, ...)

Arguments

object

An object of class delineation.

...

Not used; included for compatibility with the generic.

Value

An object of class summary.delineation, which is a named list with elements city_name, river_name, crs, parameters, delineation_layers, and base_layers. parameters contains network_buffer, dem_buffer, and buildings_buffer (in metres), or NULL if no aoi was stored. Each layer entry is itself a named list of stats, or NULL if the layer is absent.

Examples


bd <- delineate_city_river("Bucharest", "Dâmbovița")
s <- summary(bd)
s$delineation_layers$corridor$area_km2


Write data to the cache directory

Description

Write object in a serialised form (RDS) to a cache directory. For the directory used for caching see cache_directory().

Usage

write_data_to_cache(x, filepath, wrap = FALSE, quiet = FALSE)

Arguments

x

Object to serialize to a file

filepath

Path where to serialize x, as a character string

wrap

Whether the object should be "packed" before serialization (as required by terra::SpatRaster objects)

quiet

Omit message on cache file being written

Value

NULL invisibly