mirror of
https://github.com/sensebox/opensensmapr
synced 2025-02-21 21:53:57 +01:00
rename osem_as_sf to st_as_sf.sensebox
for consistency and better integration with sf
This commit is contained in:
parent
2092976f86
commit
2b8762d52c
9 changed files with 72 additions and 39 deletions
|
@ -20,11 +20,12 @@ export(mutate_.osem_measurements)
|
||||||
export(mutate_.sensebox)
|
export(mutate_.sensebox)
|
||||||
export(osem_as_measurements)
|
export(osem_as_measurements)
|
||||||
export(osem_as_sensebox)
|
export(osem_as_sensebox)
|
||||||
export(osem_as_sf)
|
|
||||||
export(osem_box)
|
export(osem_box)
|
||||||
export(osem_boxes)
|
export(osem_boxes)
|
||||||
export(osem_counts)
|
export(osem_counts)
|
||||||
export(osem_measurements)
|
export(osem_measurements)
|
||||||
export(osem_phenomena)
|
export(osem_phenomena)
|
||||||
|
export(st_as_sf.osem_measurements)
|
||||||
|
export(st_as_sf.sensebox)
|
||||||
importFrom(graphics,plot)
|
importFrom(graphics,plot)
|
||||||
importFrom(magrittr,"%>%")
|
importFrom(magrittr,"%>%")
|
||||||
|
|
13
R/00utils.R
13
R/00utils.R
|
@ -1,16 +1,3 @@
|
||||||
# ==============================================================================
|
|
||||||
#
|
|
||||||
#' Convert a \code{sensebox} or \code{osem_measurements} dataframe to an
|
|
||||||
#' \code{\link[sf]{st_sf}} object.
|
|
||||||
#'
|
|
||||||
#' @param x The object to convert
|
|
||||||
#' @param ... maybe more objects to convert
|
|
||||||
#' @return The object with an st_geometry column attached.
|
|
||||||
#' @export
|
|
||||||
osem_as_sf = function (x, ...) {
|
|
||||||
sf::st_as_sf(x, ..., coords = c('lon', 'lat'), crs = 4326)
|
|
||||||
}
|
|
||||||
|
|
||||||
# parses from/to params for get_measurements_ and get_boxes_
|
# parses from/to params for get_measurements_ and get_boxes_
|
||||||
parse_dateparams = function (from, to) {
|
parse_dateparams = function (from, to) {
|
||||||
from = utc_date(from)
|
from = utc_date(from)
|
||||||
|
|
|
@ -10,7 +10,7 @@ plot.sensebox = function (x, ...) {
|
||||||
}
|
}
|
||||||
|
|
||||||
geom = x %>%
|
geom = x %>%
|
||||||
osem_as_sf() %>%
|
sf::st_as_sf() %>%
|
||||||
sf::st_geometry()
|
sf::st_geometry()
|
||||||
|
|
||||||
bbox = sf::st_bbox(geom)
|
bbox = sf::st_bbox(geom)
|
||||||
|
@ -74,6 +74,8 @@ summary.sensebox = function(object, ...) {
|
||||||
invisible(object)
|
invisible(object)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# ==============================================================================
|
||||||
|
#
|
||||||
#' Converts a foreign object to an sensebox data.frame.
|
#' Converts a foreign object to an sensebox data.frame.
|
||||||
#' @param x A data.frame to attach the class to
|
#' @param x A data.frame to attach the class to
|
||||||
#' @export
|
#' @export
|
||||||
|
@ -92,6 +94,8 @@ mutate_.sensebox = dplyr_class_wrapper(osem_as_sensebox)
|
||||||
#' @export
|
#' @export
|
||||||
mutate.sensebox = dplyr_class_wrapper(osem_as_sensebox)
|
mutate.sensebox = dplyr_class_wrapper(osem_as_sensebox)
|
||||||
|
|
||||||
|
# ==============================================================================
|
||||||
|
#
|
||||||
#' maintains class / attributes after subsetting
|
#' maintains class / attributes after subsetting
|
||||||
#' @noRd
|
#' @noRd
|
||||||
#' @export
|
#' @export
|
||||||
|
@ -100,3 +104,16 @@ mutate.sensebox = dplyr_class_wrapper(osem_as_sensebox)
|
||||||
mostattributes(s) = attributes(x)
|
mostattributes(s) = attributes(x)
|
||||||
s
|
s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# ==============================================================================
|
||||||
|
#
|
||||||
|
#' Convert a \code{sensebox} dataframe to an \code{\link[sf]{st_sf}} object.
|
||||||
|
#'
|
||||||
|
#' @param x The object to convert
|
||||||
|
#' @param ... maybe more objects to convert
|
||||||
|
#' @return The object with an st_geometry column attached.
|
||||||
|
#' @export
|
||||||
|
st_as_sf.sensebox = function (x, ...) {
|
||||||
|
sf:::st_as_sf.data.frame(x, ..., coords = c('lon', 'lat'), crs = 4326)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,3 +34,15 @@ mutate.osem_measurements = dplyr_class_wrapper(osem_as_measurements)
|
||||||
s
|
s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# ==============================================================================
|
||||||
|
#
|
||||||
|
#' Convert a \code{osem_measurements} dataframe to an \code{\link[sf]{st_sf}} object.
|
||||||
|
#'
|
||||||
|
#' @param x The object to convert
|
||||||
|
#' @param ... maybe more objects to convert
|
||||||
|
#' @return The object with an st_geometry column attached.
|
||||||
|
#' @export
|
||||||
|
st_as_sf.osem_measurements = function (x, ...) {
|
||||||
|
sf:::st_as_sf.data.frame(x, ..., coords = c('lon', 'lat'), crs = 4326)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
% Generated by roxygen2: do not edit by hand
|
|
||||||
% Please edit documentation in R/00utils.R
|
|
||||||
\name{osem_as_sf}
|
|
||||||
\alias{osem_as_sf}
|
|
||||||
\title{Convert a \code{sensebox} or \code{osem_measurements} dataframe to an
|
|
||||||
\code{\link[sf]{st_sf}} object.}
|
|
||||||
\usage{
|
|
||||||
osem_as_sf(x, ...)
|
|
||||||
}
|
|
||||||
\arguments{
|
|
||||||
\item{x}{The object to convert}
|
|
||||||
|
|
||||||
\item{...}{maybe more objects to convert}
|
|
||||||
}
|
|
||||||
\value{
|
|
||||||
The object with an st_geometry column attached.
|
|
||||||
}
|
|
||||||
\description{
|
|
||||||
Convert a \code{sensebox} or \code{osem_measurements} dataframe to an
|
|
||||||
\code{\link[sf]{st_sf}} object.
|
|
||||||
}
|
|
19
man/st_as_sf.osem_measurements.Rd
Normal file
19
man/st_as_sf.osem_measurements.Rd
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
% Generated by roxygen2: do not edit by hand
|
||||||
|
% Please edit documentation in R/measurement_utils.R
|
||||||
|
\name{st_as_sf.osem_measurements}
|
||||||
|
\alias{st_as_sf.osem_measurements}
|
||||||
|
\title{Convert a \code{osem_measurements} dataframe to an \code{\link[sf]{st_sf}} object.}
|
||||||
|
\usage{
|
||||||
|
st_as_sf.osem_measurements(x, ...)
|
||||||
|
}
|
||||||
|
\arguments{
|
||||||
|
\item{x}{The object to convert}
|
||||||
|
|
||||||
|
\item{...}{maybe more objects to convert}
|
||||||
|
}
|
||||||
|
\value{
|
||||||
|
The object with an st_geometry column attached.
|
||||||
|
}
|
||||||
|
\description{
|
||||||
|
Convert a \code{osem_measurements} dataframe to an \code{\link[sf]{st_sf}} object.
|
||||||
|
}
|
19
man/st_as_sf.sensebox.Rd
Normal file
19
man/st_as_sf.sensebox.Rd
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
% Generated by roxygen2: do not edit by hand
|
||||||
|
% Please edit documentation in R/box_utils.R
|
||||||
|
\name{st_as_sf.sensebox}
|
||||||
|
\alias{st_as_sf.sensebox}
|
||||||
|
\title{Convert a \code{sensebox} dataframe to an \code{\link[sf]{st_sf}} object.}
|
||||||
|
\usage{
|
||||||
|
st_as_sf.sensebox(x, ...)
|
||||||
|
}
|
||||||
|
\arguments{
|
||||||
|
\item{x}{The object to convert}
|
||||||
|
|
||||||
|
\item{...}{maybe more objects to convert}
|
||||||
|
}
|
||||||
|
\value{
|
||||||
|
The object with an st_geometry column attached.
|
||||||
|
}
|
||||||
|
\description{
|
||||||
|
Convert a \code{sensebox} dataframe to an \code{\link[sf]{st_sf}} object.
|
||||||
|
}
|
|
@ -15,7 +15,7 @@ neverActive = b[is.na(b$lastMeasurement), ] %>% nrow()
|
||||||
b_agg = data.frame(time = Sys.time(), boxcount = nrow(b))
|
b_agg = data.frame(time = Sys.time(), boxcount = nrow(b))
|
||||||
b_agg$model = b$model %>% table() %>% as.list() %>% list()
|
b_agg$model = b$model %>% table() %>% as.list() %>% list()
|
||||||
b_agg$exposure = b$exposure %>% table() %>% as.list() %>% list()
|
b_agg$exposure = b$exposure %>% table() %>% as.list() %>% list()
|
||||||
b_agg$geometry = b %>% osem_as_sf() %>% st_geometry() %>% list()
|
b_agg$geometry = b %>% st_as_sf() %>% st_geometry() %>% list()
|
||||||
b_agg$phenomena = b %>% osem_phenomena() %>% list()
|
b_agg$phenomena = b %>% osem_phenomena() %>% list()
|
||||||
|
|
||||||
b_agg$active = list(
|
b_agg$active = list(
|
||||||
|
|
|
@ -141,8 +141,7 @@ pm25 = mutate(pm25, invalid = sensorId %in% bad_sensors)
|
||||||
Then plot the measuring locations, flagging the outliers:
|
Then plot the measuring locations, flagging the outliers:
|
||||||
|
|
||||||
```{r}
|
```{r}
|
||||||
pm25_sf = osem_as_sf(pm25)
|
st_as_sf(pm25) %>% st_geometry() %>% plot(col = factor(pm25$invalid), axes = T)
|
||||||
st_geometry(pm25_sf) %>% plot(col = factor(pm25$invalid), axes = T)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Removing these sensors yields a nicer time series plot:
|
Removing these sensors yields a nicer time series plot:
|
||||||
|
|
Loading…
Add table
Reference in a new issue