Skip to content

Commit

Permalink
Merge branch 'main' into 43-readme-example-cf
Browse files Browse the repository at this point in the history
  • Loading branch information
cforgaci authored Dec 19, 2024
2 parents a45c4d0 + dfa958c commit 892ad2e
Show file tree
Hide file tree
Showing 31 changed files with 875 additions and 105 deletions.
126 changes: 126 additions & 0 deletions .github/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# Contributor Covenant Code of Conduct

## Our Pledge

We as members, contributors, and leaders pledge to make participation in our
community a harassment-free experience for everyone, regardless of age, body
size, visible or invisible disability, ethnicity, sex characteristics, gender
identity and expression, level of experience, education, socio-economic status,
nationality, personal appearance, race, caste, color, religion, or sexual
identity and orientation.

We pledge to act and interact in ways that contribute to an open, welcoming,
diverse, inclusive, and healthy community.

## Our Standards

Examples of behavior that contributes to a positive environment for our
community include:

* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes,
and learning from the experience
* Focusing on what is best not just for us as individuals, but for the overall
community

Examples of unacceptable behavior include:

* The use of sexualized language or imagery, and sexual attention or advances of
any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or email address,
without their explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Enforcement Responsibilities

Community leaders are responsible for clarifying and enforcing our standards of
acceptable behavior and will take appropriate and fair corrective action in
response to any behavior that they deem inappropriate, threatening, offensive,
or harmful.

Community leaders have the right and responsibility to remove, edit, or reject
comments, commits, code, wiki edits, issues, and other contributions that are
not aligned to this Code of Conduct, and will communicate reasons for moderation
decisions when appropriate.

## Scope

This Code of Conduct applies within all community spaces, and also applies when
an individual is officially representing the community in public spaces.
Examples of representing our community include using an official e-mail address,
posting via an official social media account, or acting as an appointed
representative at an online or offline event.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported to the community leaders responsible for enforcement at [email protected].
All complaints will be reviewed and investigated promptly and fairly.

All community leaders are obligated to respect the privacy and security of the
reporter of any incident.

## Enforcement Guidelines

Community leaders will follow these Community Impact Guidelines in determining
the consequences for any action they deem in violation of this Code of Conduct:

### 1. Correction

**Community Impact**: Use of inappropriate language or other behavior deemed
unprofessional or unwelcome in the community.

**Consequence**: A private, written warning from community leaders, providing
clarity around the nature of the violation and an explanation of why the
behavior was inappropriate. A public apology may be requested.

### 2. Warning

**Community Impact**: A violation through a single incident or series of
actions.

**Consequence**: A warning with consequences for continued behavior. No
interaction with the people involved, including unsolicited interaction with
those enforcing the Code of Conduct, for a specified period of time. This
includes avoiding interactions in community spaces as well as external channels
like social media. Violating these terms may lead to a temporary or permanent
ban.

### 3. Temporary Ban

**Community Impact**: A serious violation of community standards, including
sustained inappropriate behavior.

**Consequence**: A temporary ban from any sort of interaction or public
communication with the community for a specified period of time. No public or
private interaction with the people involved, including unsolicited interaction
with those enforcing the Code of Conduct, is allowed during this period.
Violating these terms may lead to a permanent ban.

### 4. Permanent Ban

**Community Impact**: Demonstrating a pattern of violation of community
standards, including sustained inappropriate behavior, harassment of an
individual, or aggression toward or disparagement of classes of individuals.

**Consequence**: A permanent ban from any sort of public interaction within the
community.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 2.1, available at
<https://www.contributor-covenant.org/version/2/1/code_of_conduct.html>.

Community Impact Guidelines were inspired by
[Mozilla's code of conduct enforcement ladder][https://github.com/mozilla/inclusion].

For answers to common questions about this code of conduct, see the FAQ at
<https://www.contributor-covenant.org/faq>. Translations are available at <https://www.contributor-covenant.org/translations>.

[homepage]: https://www.contributor-covenant.org
16 changes: 16 additions & 0 deletions .github/ISSUE_TEMPLATE/issue_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
name: Bug report or feature request
about: Describe a bug you've seen or make a case for a new feature
---

Please briefly describe your problem and what output you expect. If you have a question, please don't use this form. Instead, ask on <https://stackoverflow.com/> or <https://community.rstudio.com/>.

Please include a minimal reproducible example (AKA a reprex). If you've never heard of a [reprex](http://reprex.tidyverse.org/) before, start by reading <https://www.tidyverse.org/help/#reprex>.

For more advice on how to write a great issue, see <https://code-review.tidyverse.org/issues/>.

Brief description of the problem

```r
# insert reprex here
```
40 changes: 40 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!--
For Work In Progress Pull Requests, please use the Draft PR feature,
see https://github.blog/2019-02-14-introducing-draft-pull-requests/ for further details.
Before submitting a Pull Request, please ensure you've read the CRiSp
[Contributing Guide](https://cityriverspaces.github.io/CRiSp/CONTRIBUTING.html)
and [Code of Conduct](https://cityriverspaces.github.io/CRiSp/CODE_OF_CONDUCT.html)
-->

## What type of PR is this? (check all applicable)

- [ ] Refactor
- [ ] Feature
- [ ] Bug Fix
- [ ] Optimization
- [ ] Documentation Update

## Description

## Related Issues

<!--
See [Github's guidance on linking issues to pull requests](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue).
-->

- Related Issue #
- Closes #

## Added/updated tests?
_We encourage you to keep the code coverage percentage at 75% and above._

- [ ] Yes
- [ ] No, and this is why: _please replace this line with details on why tests
have not been included_
- [ ] I need help with writing tests

## Added entry in changelog?
_For user-facing changes, add a line describing the changes in [NEWS.md](/NEWS.md)_

- [ ] Yes
12 changes: 8 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ Description: CRiSp (City River Spaces) provides tools to automate the
License: Apache License (>= 2)
URL: https://cityriverspaces.github.io/CRiSp/
BugReports: https://github.com/CityRiverSpaces/crisp/issues
Depends:
Depends:
R (>= 2.10)
Imports:
Imports:
dbscan,
dplyr,
lwgeom,
osmdata,
rcoins,
rlang,
rstac,
sf,
Expand All @@ -29,17 +31,19 @@ Imports:
tibble,
tidygraph,
units
Suggests:
Suggests:
ggplot2,
gridExtra,
knitr,
purrr,
rmarkdown,
testthat (>= 3.0.0)
VignetteBuilder:
VignetteBuilder:
knitr
Config/testthat/edition: 3
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2
Remotes:
github::CityRiverSpaces/rcoins
4 changes: 2 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ export(add_weights)
export(as_bbox)
export(as_network)
export(clean_network)
export(corridor)
export(delineate_corridor)
export(delineate_riverspace)
export(delineate_segments)
export(dem_to_cog)
export(flatten_network)
export(get_cd_char)
export(get_corridor)
export(get_cost_distance)
export(get_dem)
export(get_osm_bb)
Expand All @@ -19,6 +18,7 @@ export(get_osm_railways)
export(get_osm_river)
export(get_osm_streets)
export(get_osmdata)
export(get_segments)
export(get_slope)
export(get_stac_asset_urls)
export(get_utm_zone)
Expand Down
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

# [Unreleased]

- Add developer guidelines
25 changes: 1 addition & 24 deletions R/corridor.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#'
#' @return A simple feature geometry representing the river corridor
#' @export
corridor <- function(
get_corridor <- function(
network, river_centerline, river_surface, bbox, initial_method = "buffer",
capping_method = "direct"
) {
Expand Down Expand Up @@ -129,17 +129,6 @@ split_aoi <- function(bbox, river) {
}
}

#' Split a geometry along a (multi)linestring.
#'
#' @param geometry Geometry to split
#' @param line Dividing (multi)linestring
#'
#' @return A simple feature object
split <- function(geometry, line) {
lwgeom::st_split(geometry, line) |>
sf::st_collection_extract()
}

#' Identify the initial edges of the river corridor
#'
#' These are defined by splitting the initial corridor boundary into the
Expand Down Expand Up @@ -208,15 +197,3 @@ cap_corridor <- function(edges, method = "direct", network = NULL) {
}
as_polygon(c(edges, cap_edge_1, cap_edge_2))
}

as_linestring <- function(points) {
points_union <- sf::st_union(points)
sf::st_cast(points_union, "LINESTRING")
}

as_polygon <- function(lines) {
lines_union <- sf::st_union(lines)
sf::st_line_merge(lines_union) |>
sf::st_polygonize() |>
sf::st_collection_extract()
}
28 changes: 15 additions & 13 deletions R/delineate.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@
#' @param capping_method The method employed to connect the corridor edge end
#' points (i.e. to "cap" the corridor). See [cap_corridor()] for
#' the available methods
#' @param angle_threshold Only network edges forming angles above this threshold
#' (in degrees) are considered when forming segment edges. See
#' [get_segments()] and [rcoins::stroke()]. Only used if `segments` is TRUE.
#' @param segments Whether to carry out the corridor segmentation
#' @param riverspace Whether to carry out the riverspace delineation
#'
#' @return A simple feature geometry
#' @export
delineate_corridor <- function(
city_name, river_name, crs = NULL, bbox_buffer = NULL,
initial_method = "buffer", capping_method = "direct", segments = FALSE,
riverspace = FALSE
initial_method = "buffer", capping_method = "direct", angle_threshold = 90,
segments = FALSE, riverspace = FALSE
) {
# Retrieve all relevant OSM datasets using the extended bounding box
osm_data <- get_osmdata(city_name, river_name, crs, bbox_buffer)
Expand All @@ -32,25 +35,24 @@ delineate_corridor <- function(
network <- as_network(network_edges)

# Run the corridor delineation on the spatial network
corridor <- corridor(
corridor <- get_corridor(
network, osm_data$river_centerline, osm_data$river_surface, bbox,
initial_method, capping_method
)

if (segments) delineate_segments()
if (segments) {
# Select the relevant part of the network
buffer_corridor <- 100 # TODO should this be an additional input parameter?
corridor_buffer <- sf::st_buffer(corridor, buffer_corridor)
network_filtered <- filter_network(network, corridor_buffer)

corridor <- get_segments(corridor, network_filtered,
osm_data$river_centerline, angle_threshold)
}
if (riverspace) delineate_riverspace()
return(corridor)
}


#' Delineate segments of a river corridor.
#'
#' @return A simple feature geometry
#' @export
delineate_segments <- function() {
stop("Segmentation not yet implemented.")
}

#' Delinate the riverspace.
#'
#' @return A simple feature geometry
Expand Down
18 changes: 16 additions & 2 deletions R/network.R
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,20 @@ filter_network <- function(network, target) {
tidygraph::filter(sfnetworks::node_intersects(target))
}

strokes <- function() {
stop("`strokes` not yet implemented.")
#' Identify network edges that are intersecting a geometry
#'
#' @param network A spatial network object
#' @param geometry A simple feature geometry
#' @param index Whether to return the indices of the matchin edges or the
#' geometries
#'
#' @return Indices or geometries of the edges intersecting the given geometry
get_intersecting_edges <- function(network, geometry, index = FALSE) {
edges <- sf::st_as_sf(network, "edges")
intersects <- sf::st_intersects(edges, geometry, sparse = FALSE)
if (index) {
return(which(intersects))
} else {
return(edges[intersects, ])
}
}
Loading

0 comments on commit 892ad2e

Please sign in to comment.