Skip to content

Commit

Permalink
fix record_batch_reader package
Browse files Browse the repository at this point in the history
  • Loading branch information
denironyx committed Jun 17, 2024
1 parent f95c680 commit 5871107
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 13 deletions.
1 change: 1 addition & 0 deletions .Rhistory
Original file line number Diff line number Diff line change
Expand Up @@ -448,3 +448,4 @@ check()
use_readme_rmd()
renv::status()
?renv::status()
library
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.Rproj.user
renv.lock
renv/
20 changes: 10 additions & 10 deletions R/core.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ dataset_path <- function(overture_type) {
#'
#' @param overture_type Character. Required. The type of feature to select. Examples include 'building', 'place', etc.
#' To learn more, run \code{get_all_overture_types()}.
#' @param bbox Numeric vector. Optional. A bounding box specified as c(xmin, ymin, xmax, ymax).
#' @param bbox_ Numeric vector. Optional. A bounding box specified as c(xmin, ymin, xmax, ymax).
#' It is recommended to use a bounding box to limit the dataset size and processing time.
#' Without a bounding box, processing the entire dataset (e.g., buildings over 2 billion) can be time-consuming.
#'
Expand All @@ -66,25 +66,25 @@ dataset_path <- function(overture_type) {
#' \dontrun{
#' # Example usage with a bounding box
#' sf_bbox <- c(-122.5, 37.7, -122.3, 37.8)
#' result <- record_batch_reader(overture_type = 'place', bbox = sf_bbox)
#' result <- record_batch_reader(overture_type = 'place', bbox_ = sf_bbox)
#' print(result)
#' }
#'
#' @importFrom arrow open_dataset
#' @importFrom sf st_as_sf
#' @importFrom dplyr %>% filter collect
record_batch_reader <- function(overture_type, bbox = NULL){
record_batch_reader <- function(overture_type, bbox_ = NULL){

# Open the dataset based on the overture_type
dataset <- open_dataset(dataset_path(overture_type))

# based on kyle walker code - https://walker-data.com/posts/overture-buildings/
if(!is.null(bbox)){
filtered_df <- open_dataset(dataset_path(overture_type)) %>%
filter(bbox$xmin > bbox[1],
bbox$ymin > bbox[2],
bbox$xmax < bbox[3],
bbox$ymax < bbox[4]) %>%
if(!is.null(bbox_)){
filtered_df <- dataset %>%
filter(bbox$xmin > bbox_[1],
bbox$ymin > bbox_[2],
bbox$xmax < bbox_[3],
bbox$ymax < bbox_[4]) %>%
collect() %>%
st_as_sf(crs = 4326)
} else {
Expand All @@ -98,5 +98,5 @@ record_batch_reader <- function(overture_type, bbox = NULL){

# Example usage (uncomment to test)
# sf_bbox <- c(-122.5, 37.7, -122.3, 37.8)
# result <- record_batch_reader(overture_type = 'place', bbox = sf_bbox)
# result <- record_batch_reader(overture_type = 'place', bbox_ = sf_bbox)
# print(result)
9 changes: 9 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ You'll still need to render `README.Rmd` regularly, to keep `README.md` up-to-da

In that case, don't forget to commit and push the resulting figure files, so they display on GitHub and CRAN.

## Try it out

Example lisbon building
```{r }
library(overturemapsr)
```

## Functions

- `get_all_overture_types`: This function returns all available OvertureMaps theme types.
Expand Down
6 changes: 3 additions & 3 deletions man/record_batch_reader.Rd

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

0 comments on commit 5871107

Please sign in to comment.