Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

legacy converter #2

Open
2 tasks
mdsumner opened this issue Dec 2, 2016 · 0 comments
Open
2 tasks

legacy converter #2

mdsumner opened this issue Dec 2, 2016 · 0 comments

Comments

@mdsumner
Copy link
Member

mdsumner commented Dec 2, 2016

Here's a brute force tidyfication of SGAT output

library(SGAT)

library(rworldmap)
library(rgdal)
library(rgeos)
prj <- "+proj=omerc +lonc=165 +lat_0=-22 +alpha=23 +k=0.99984 +x_0=0 +y_0=0 +no_uoff +gamma=23 +ellps=WGS84 +units=m +no_defs"
llprj <-  "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs +towgs84=0,0,0"

dp <- "."
fs <- list.files(dp, full.names = TRUE, pattern = "RData", ignore.case = TRUE)
library(tibble)
library(dplyr)
## 
as_table_raster <- function(x) {
  tibble(value = values(x), cell = seq(ncell(x))) %>% dplyr::filter(!is.na(value) & value > 0)
}
as_table_Pimage <- function(x) {
  dplyr::bind_rows(lapply(seq_along(x), function(i) as_table_raster(x[i]) %>% mutate(gmt = as.POSIXct(x)[i])))
}
master <- raster(extent(-16800000, 12500000, -20300000, 19200000), res = 50000, crs = prj)

## loop over all files and save as table
for (j in seq_along(fs)) {
  load(fs[j]); 
  label <- gsub(".rdata", "", tolower(basename(fs[j]))
                tab <-   as_table_Pimage(Pimage(fit, grid = master)) %>% mutate(id = label)
                writeRDStab, file.path(".", sprintf("%s.rds", label)), compress = "xz")
})

allcells <- as_table_Pimage(im)

It needs

  • add to SQLite database rather than a list
  • remove wasted pixels in as_table_raster by resurrecting the sparse cell stuff in tripEstimation (or SGAT?)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant