Title: | Automate the Delineation of Urban River Spaces |
Version: | 0.1.4 |
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. 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://doi.org/10.5281/zenodo.15793526 |
BugReports: | https://github.com/CityRiverSpaces/rcrisp/issues |
Depends: | R (≥ 4.1.0) |
Imports: | dbscan, dplyr, lwgeom, osmdata, rcoins, rlang, rstac, sf, sfheaders, sfnetworks, stringr, terra, tidygraph, units, visor |
Suggests: | ggplot2, knitr, purrr, rmarkdown, testthat (≥ 3.0.0), withr |
VignetteBuilder: | knitr |
Config/testthat/edition: | 3 |
Encoding: | UTF-8 |
LazyData: | true |
RoxygenNote: | 7.3.2 |
NeedsCompilation: | no |
Packaged: | 2025-07-04 19:30:17 UTC; claudiuforgaci |
Author: | Claudiu Forgaci |
Maintainer: | Claudiu Forgaci <c.forgaci@tudelft.nl> |
Repository: | CRAN |
Date/Publication: | 2025-07-04 21:40:09 UTC |
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 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 bounding box 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)
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)
Arguments
edges |
A data frame 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 |
Value
A spatial network 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))
)
sf::st_crs(edges) <- sf::st_crs("EPSG:4326")
as_network(edges)
rcrisp example delineation data for Bucharest
Description
Delineation generated with rcrisp example data found at https://data.4tu.nl/datasets/f5d5e118-b5bd-4dfb-987f-fe10d1b9b386
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 |
Value
Expanded sf object
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
A 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:
|
network |
A spatial network object, only required if
|
Value
A simple feature geometry representing the corridor (i.e. a polygon)
Check cache
Description
A warning is raised 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 |
sf object |
Value
sf 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 |
simplify |
Whether the network should be simplified with
|
Value
A cleaned network object
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 Date |
Value
List of file paths of removed files
Examples
clear_cache()
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 a simple feature geometry
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 sfc_LINESTRING or sfc_MULTILINESTRING |
river_surface |
River surface as sfc_POLYGON or sfc_MULTIPOLYGON |
Value
Combined river as 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
A simple feature geometry representing the edge (i.e. a linestring)
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 |
spatial_network |
A |
regions |
A simple feature geometry representing the two river sides |
Value
A simple feature 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
Format
An object of class list
of length 2.
Delineate a corridor around a river.
Description
Delineate a corridor around a river.
Usage
delineate(
city_name,
river_name,
crs = NULL,
network_buffer = NULL,
buildings_buffer = NULL,
corridor_init = "valley",
dem = NULL,
dem_buffer = 2500,
max_iterations = 10,
capping_method = "shortest-path",
angle_threshold = 100,
corridor = TRUE,
segments = FALSE,
riverspace = FALSE,
force_download = FALSE,
...
)
Arguments
city_name |
A place name as a string |
river_name |
A river name as a string |
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. |
buildings_buffer |
Add a buffer (an integer in meters) around the river to retrieve additional data (buildings). Default is 100 m. |
corridor_init |
How to estimate the initial guess of the river corridor. It can take the following values:
|
dem |
Digital elevation model (DEM) of the region (only used if
|
dem_buffer |
Size of the buffer region (in meters) around the
river to retrieve the DEM (only used if |
max_iterations |
Maximum number of iterations employed to refine the
corridor edges (see |
capping_method |
The method employed to connect the corridor edge end
points (i.e. to "cap" the corridor). See |
angle_threshold |
Only network edges forming angles above this threshold
(in degrees) are considered when forming segment edges. See
|
corridor |
Whether to carry out the corridor delineation |
segments |
Whether to carry out the corridor segmentation |
riverspace |
Whether to carry out the riverspace delineation |
force_download |
Download data even if cached data is available |
... |
Additional (optional) input arguments for retrieving the DEM
dataset (see |
Value
A list with the corridor, segments, and riverspace geometries
Examples
delineate("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 to be used for the delineation |
river |
A (MULTI)LINESTRING simple feature geometry representing the river centerline |
corridor_init |
How to estimate the initial guess of the river corridor. It can take the following values: |
max_width |
(Approximate) maximum width of the corridor. The spatial network is trimmed by a buffer region of this size around the river |
max_iterations |
Maximum number of iterations employed to refine the
corridor edges (see |
capping_method |
The method employed to connect the corridor edge end
points (i.e. to "cap" the corridor). See |
Value
A simple feature geometry representing the river corridor
Examples
bucharest_osm <- get_osm_example_data()
network <- rbind(bucharest_osm$streets, bucharest_osm$railways) |>
as_network()
delineate_corridor(network, bucharest_osm$river_centerline)
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 |
ray_length |
Length of rays in meters |
Value
Polygon geometry with the riverspace
Examples
## Not run:
bucharest_osm <- get_osm_example_data()
delineate_riverspace(bucharest_osm$river_surface, bucharest_osm$buildings)
## End(Not run)
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 |
network |
The spatial network to be used for the segmentation |
river |
The river centerline as a simple feature geometry |
angle_threshold |
Only consider angles above this threshold (in degrees)
to form continuous strokes in the network. See |
Value
Segment polygons as a simple feature geometry
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 |> sf::st_geometry()
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 |
Digital elevation model of the region |
river |
A simple feature geometry representing the river |
Value
River valley as a simple feature geometry
Examples
bucharest_osm <- get_osm_example_data()
bucharest_dem <- get_dem_example_data()
delineate_valley(bucharest_dem, bucharest_osm$river_centerline)
Write DEM to cloud optimized GeoTiff file as specified location
Description
Write DEM to cloud optimized GeoTiff file as specified location
Usage
dem_to_cog(dem, fpath, output_directory = NULL)
Arguments
dem |
to write to file |
fpath |
filepath for output. If no output directory is specified (see below) fpath is parsed to determine the output directory |
output_directory |
where file should be written. If specified fpath is treated as filename only. |
Value
The input DEM. This function is used for the side-effect of writing values to a file.
Examples
bucharest_dem <- get_dem_example_data()
dem_to_cog(bucharest_dem, "bucharest_dem.tif")
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
A simple feature geometry 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 network object |
target |
The target geometry |
elements |
The elements of the network to filter. It can be "nodes" or "edges" |
Value
A spatial network object
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
A simple feature object
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 |
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
A network 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)
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 a simple feature geometry
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(
bb,
dem_source = "STAC",
stac_endpoint = NULL,
stac_collection = NULL,
crs = NULL,
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"), in lat/lon coordinates (WGS84 coordinate referece system) |
dem_source |
Source of the DEM:
|
stac_endpoint |
URL of the STAC API endpoint (only used if |
stac_collection |
Identifier of the STAC collection to be queried (only
used if |
crs |
Coordinate reference system (CRS) which to transform the DEM to |
force_download |
Download data even if cached data is available |
Value
DEM as a terra SpatRaster object
Examples
bb <- get_osm_bb("Bucharest")
get_dem(bb)
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 a persistent URL on the 4TU.ResearchData data repository, and it can be used in examples and tests.
Usage
get_dem_example_data()
Value
A SpatRaster object containing the DEM data.
Examples
get_dem_example_data()
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 |
geometry |
A simple feature geometry |
index |
Whether to return the indices of the matchin edges or the geometries |
Value
Indices or geometries of the edges intersecting the given geometry
Get the bounding box of a city
Description
Get the bounding box of a city
Usage
get_osm_bb(city_name)
Arguments
city_name |
The name of the city |
Value
A bbox object with the bounding box of the city
Examples
get_osm_bb("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 sf object with the buildings
Examples
bb <- get_osm_bb("Bucharest")
crs <- get_utm_zone(bb)
get_osm_buildings(bb, crs)
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 |
city_name |
A character string 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 sf object with the city boundary
Examples
bb <- get_osm_bb("Bucharest")
crs <- get_utm_zone(bb)
get_osm_city_boundary(bb, "Bucharest", crs)
Get example OSM data
Description
This function retrieves example OpenStreetMap (OSM) data from a persistent URL on the 4TU.ResearchData data repository, and it can be used in examples and tests.
Usage
get_osm_example_data()
Value
A list of sf objects containing the OSM data.
Examples
get_osm_example_data()
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 |
Coordinate reference system as EPSG code |
railway_values |
A character or character vector with the railway values to retrieve. |
force_download |
Download data even if cached data is available |
Value
An sf object with the railways
Examples
bb <- get_osm_bb("Bucharest")
crs <- get_utm_zone(bb)
get_osm_railways(bb, crs)
Get the river centreline and surface from OpenStreetMap
Description
Get the river centreline and surface from OpenStreetMap
Usage
get_osm_river(bb, river_name, crs = NULL, force_download = FALSE)
Arguments
bb |
Bounding box of class |
river_name |
The name of the river |
crs |
Coordinate reference system as EPSG code |
force_download |
Download data even if cached data is available |
Value
A list with the river centreline and surface
Examples
bb <- get_osm_bb("Bucharest")
crs <- get_utm_zone(bb)
get_osm_river(bb, "Dâmbovița", crs)
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 |
crs |
Coordinate reference system as EPSG code |
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 sf object with the streets
Examples
bb <- get_osm_bb("Bucharest")
crs <- get_utm_zone(bb)
get_osm_streets(bb, crs)
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_osmdata(
city_name,
river_name,
network_buffer = NULL,
buildings_buffer = NULL,
city_boundary = TRUE,
crs = NULL,
force_download = FALSE
)
Arguments
city_name |
A character string with the name of the city. |
river_name |
A character string with the name of the river. |
network_buffer |
Buffer distance in meters around the river to get the streets and railways, default is 0 means no network data will be downloaded |
buildings_buffer |
Buffer distance in meters around the river to get the buildings, default is 0 means no buildings data will be downloaded |
city_boundary |
A logical indicating if the city boundary should be retrieved. Default is TRUE. |
crs |
An integer with the EPSG code for the projection. If no CRS is specified, the default is the UTM zone for the city. |
force_download |
Download data even if cached data is available |
Value
An list with the retrieved OpenStreetMap data sets for the given location
Examples
get_osmdata("Bucharest", "Dâmbovița")
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_osmdata_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 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 list with the river centreline and surface geometries |
city_bbox |
Bounding box around the city |
buffer_distance |
Buffer size around the river |
Value
An sf object in lat/lon coordinates
Examples
bb <- get_osm_bb("Bucharest")
river <- get_osm_river(bb, "Dâmbovița")
get_river_aoi(river, 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 |
width |
Width of the regions |
Value
A sf::sfc
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) |
endpoint |
URL of the STAC API endpoint. To be provided together with
|
collection |
Identifier of the STAC collection to be queried. To be
provided together with |
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)
Get the UTM zone of a spatial object
Description
Get the UTM zone of a spatial object
Usage
get_utm_zone(x)
Arguments
x |
Bounding box or geometry object |
Value
The EPSG code of the UTM zone
Examples
# Get EPSG code for UTM zone of Bucharest
bb <- get_osm_bb("Bucharest")
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 |
st_geometry of valley region |
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 st_geometry
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
A simple feature geometry 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") |
tile_urls |
A list of tiles where to read the DEM data from |
force_download |
Download data even if cached data is available |
Value
Raster DEM, retrieved and retiled to the given bounding box
Examples
bb <- get_osm_bb("Bucharest")
tile_urls <- get_stac_asset_urls(bb)
load_dem(bb, tile_urls)
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_data, match)
Arguments
osm_data |
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 |
target |
The target geometry |
Value
A node in the network as a simple feature geometry
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 character string with the key to filter the data |
value |
A character string with the value 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 sf object with the retrieved OpenStreetMap data
Examples
bb <- get_osm_bb("Bucharest")
osmdata_as_sf("highway", "motorway", bb)
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 sf object with the retrieved OpenStreetMap data
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 |
quiet |
Omit warning 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 or vector object |
crs |
CRS to be projected to |
... |
Optional arguments for raster or vector reproject functions |
Value
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 |
Value
A simple feature geometry
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 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 |
from |
Start node |
to |
End node |
weights |
Name of the column in the network edge table from where to take the weigths |
Value
A simple feature geometry
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 |
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
A simple feature object
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 |
quiet |
Omit message on cache file being written |
Value
NULL
invisibly