Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?

Fix 2016-05-06

svn checkout svn://scm.r-forge.r-project.org/svnroot/rgdal/pkg mv pkg rgdal R CMD build rgdal --no-build-vignettes --no-manual sudo R CMD INSTALL rgdal_1.1-9.tar.gz

R

Geopackage "GPKG" driver is not listed for rasters.

library(rgdal)
#rgdal: version: 1.1-8, (SVN revision 616)
# Geospatial Data Abstraction Library extensions to R successfully loaded
# Loaded GDAL runtime: GDAL 2.1.0dev, released 2015/99/99
# Path to GDAL shared files: /usr/local/share/gdal
# Loaded PROJ.4 runtime: Rel. 4.9.1, 04 March 2015, [PJ_VERSION: 491]
# Path to PROJ.4 shared files: (autodetected)
# Linking to sp version: 1.2-3 
 
fmt <- "GPKG"
lfmt <- "GeoPackage"
gdrvs <- gdalDrivers()
odrvs <- ogrDrivers()
subset(gdrvs, grepl(fmt, name))

## [1] name      long_name create    copy      isVector 
## <0 rows> (or 0-length row.names)
subset(gdrvs, grepl(lfmt, long_name))

## [1] name      long_name create    copy      isVector 
## <0 rows> (or 0-length row.names)

It is for vector.

subset(odrvs, grepl(fmt, name))

##    name  long_name write copy isVector
## 23 GPKG GeoPackage  TRUE TRUE     TRUE
subset(odrvs, grepl(lfmt, long_name))

##    name  long_name write copy isVector
## 23 GPKG GeoPackage  TRUE TRUE     TRUE

Yet both work for reading and writing.

library(maptools); data(wrld_simpl)
library(raster)
vfile <- sprintf("%s.gpkg", basename(tempfile()))
writeOGR(wrld_simpl[1, ], vfile, "wrld_simpl", driver = "GPKG")
readOGR(vfile, "wrld_simpl")

## OGR data source with driver: GPKG 
## Source: "file2ad4277da429.gpkg", layer: "wrld_simpl"
## with 1 features
## It has 11 fields
## class       : SpatialPolygonsDataFrame 
## features    : 1 
## extent      : -61.88722, -61.68667, 17.02444, 17.70389  (xmin, xmax, ymin, ymax)
## coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 
## variables   : 11
## names       : FIPS, ISO2, ISO3, UN,                NAME, AREA, POP2005, REGION, SUBREGION,     LON,    LAT 
## min values  :   AC,   AG,  ATG, 28, Antigua and Barbuda,   44,   83039,     19,        29, -61.783, 17.078 
## max values  :   AC,   AG,  ATG, 28, Antigua and Barbuda,   44,   83039,     19,        29, -61.783, 17.078
rfile <- "wrld_simpl_raster.gpkg"
r <- rasterize(geometry(wrld_simpl), raster())
writeGDAL(as(r, "SpatialGridDataFrame"), rfile)
raster(rfile)

## class       : RasterLayer 
## dimensions  : 180, 360, 64800  (nrow, ncol, ncell)
## resolution  : 1, 1  (x, y)
## extent      : -180, 180, -90, 90  (xmin, xmax, ymin, ymax)
## coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 
## data source : wrld_simpl_raster.gpkg 
## names       : wrld_simpl_raster

And the system GDAL lists them both.

system("gdalinfo --formats | grep GeoPackage", intern = TRUE)
## [1] "  GPKG -raster,vector- (rw+vs): GeoPackage"

system("ogrinfo --formats | grep GeoPackage", intern = TRUE)
## [1] "  GPKG -raster,vector- (rw+vs): GeoPackage"
devtools::session_info()
## Session info --------------------------------------------------------------

##  setting  value                       
##  version  R version 3.2.5 (2016-04-14)
##  system   x86_64, linux-gnu           
##  ui       RStudio (0.99.1172)         
##  language (EN)                        
##  collate  en_US.UTF-8                 
##  tz       <NA>                        
##  date     2016-05-06

## Packages ------------------------------------------------------------------

##  package    * version date       source                           
##  bookdown     0.0.71  2016-05-06 Github (rstudio/bookdown@951aab4)
##  devtools     1.11.0  2016-04-12 CRAN (R 3.2.5)                   
##  digest       0.6.9   2016-01-08 CRAN (R 3.2.3)                   
##  evaluate     0.9     2016-04-29 CRAN (R 3.2.5)                   
##  foreign      0.8-66  2015-08-19 CRAN (R 3.2.2)                   
##  formatR      1.3     2016-03-05 CRAN (R 3.2.5)                   
##  htmltools    0.3.5   2016-03-21 CRAN (R 3.2.5)                   
##  httpuv       1.3.3   2015-08-04 CRAN (R 3.2.1)                   
##  knitr        1.12.28 2016-05-06 Github (yihui/knitr@5b3e656)     
##  lattice      0.20-33 2015-07-14 CRAN (R 3.2.1)                   
##  magrittr     1.5     2014-11-22 CRAN (R 3.2.0)                   
##  maptools   * 0.8-39  2016-01-30 CRAN (R 3.2.3)                   
##  memoise      1.0.0   2016-01-29 CRAN (R 3.2.3)                   
##  mime         0.4     2015-09-03 CRAN (R 3.2.2)                   
##  miniUI       0.1.1   2016-01-15 CRAN (R 3.2.5)                   
##  R6           2.1.2   2016-01-26 CRAN (R 3.2.3)                   
##  raster     * 2.5-2   2015-12-19 CRAN (R 3.2.3)                   
##  Rcpp         0.12.4  2016-03-26 CRAN (R 3.2.5)                   
##  rgdal      * 1.1-8   2016-04-04 CRAN (R 3.2.5)                   
##  rmarkdown    0.9.6   2016-05-01 CRAN (R 3.2.5)                   
##  rsconnect    0.4.3   2016-05-02 CRAN (R 3.2.5)                   
##  rstudioapi   0.5     2016-01-24 CRAN (R 3.2.3)                   
##  shiny        0.13.2  2016-03-28 CRAN (R 3.2.5)                   
##  sp         * 1.2-3   2016-04-14 CRAN (R 3.2.5)                   
##  stringi      1.0-1   2015-10-22 CRAN (R 3.2.2)                   
##  stringr      1.0.0   2015-04-30 CRAN (R 3.2.0)                   
##  withr        1.0.1   2016-02-04 CRAN (R 3.2.3)                   
##  xtable       1.8-2   2016-02-05 CRAN (R 3.2.3)                   
##  yaml         2.1.13  2014-06-12 CRAN (R 3.2.0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment