-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #113 from pedro-andrade-inpe/master
new functionality and small updates
- Loading branch information
Showing
13 changed files
with
132 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#' @title Add a column with height to GPS data | ||
#' @description Add a column named height to GPS data using a tif data as reference. | ||
#' @param gps A GPS data created from gtfs2gps(). | ||
#' @param heightfile The pathname of a tif file with height data. | ||
#' @return The GPS data with a new column named height. | ||
#' @export | ||
#' @examples | ||
#' library(dplyr) | ||
#' | ||
#' fortaleza <- system.file("extdata/fortaleza.zip", package = "gtfs2gps") | ||
#' srtmfile <- system.file("extdata/fortaleza-srtm.tif", package = "gtfs2gps") | ||
#' | ||
#' gtfs <- read_gtfs(fortaleza) %>% | ||
#' filter_week_days() %>% | ||
#' filter_single_trip() | ||
#' | ||
#' fortaleza_gps <- gtfs2gps(gtfs, progress = FALSE) %>% append_height(srtmfile) | ||
append_height <- function(gps, heightfile){ | ||
f_gps <- gps | ||
|
||
sp::coordinates(f_gps) <- ~shape_pt_lon + shape_pt_lat | ||
|
||
myraster <- raster::raster(heightfile) | ||
gps$height <- raster::extract(myraster, f_gps) | ||
|
||
return(gps) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
prep_data/fortaleza-srtm/generate-fortaleza-srtm-simplified.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# SRTM data downloaded from | ||
# http://www.dsr.inpe.br/topodata/acesso.php | ||
|
||
require(raster) | ||
require(gtfs2gps) | ||
|
||
inputDir <- "prep_data/fortaleza-srtm/" | ||
|
||
myraster <- paste0(inputDir, "03S39_ZN.tif") %>% raster::raster() | ||
|
||
fortaleza <- read_gtfs(system.file("extdata/fortaleza.zip", package="gtfs2gps")) | ||
|
||
fortaleza_sf <- gtfs_shapes_as_sf(fortaleza) %>% sf::st_buffer(0.001) %>% sf::as_Spatial() | ||
|
||
mm.sub <- raster::crop(myraster, fortaleza_sf) | ||
|
||
raster::writeRaster(mm.sub, "inst/extdata/fortaleza-srtm.tif", overwrite = TRUE) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
test_that("append_height", { | ||
fortaleza <- system.file("extdata/fortaleza.zip", package="gtfs2gps") | ||
srtmfile <- system.file("extdata/fortaleza-srtm.tif", package="gtfs2gps") | ||
|
||
gtfs <- read_gtfs(fortaleza) %>% | ||
filter_week_days() %>% | ||
filter_single_trip() | ||
|
||
fortaleza_gps <- gtfs2gps(gtfs, progress = FALSE) %>% append_height(srtmfile) | ||
|
||
expect_equal(sum(fortaleza_gps$height), 72932, 0.05) | ||
|
||
fort <- fortaleza_gps[which(is.na(fortaleza_gps$height)),] | ||
|
||
#fott <- gps_as_sf(fort) | ||
#sf::write_sf(fott, "fort-na.shp") | ||
}) |