Skip to content
Prev 24813 / 29559 Next

How to read .gpkg (Geopackage) files in R

On Fri, 26 Aug 2016 at 07:18 Manuel Sp?nola <mspinola10 at gmail.com> wrote:

            
You're in luck because it's extremely easy.

library(rgdal)
layers <- ogrListLayers("parcelas.gpkg")

## you may have more than one layer
x <- readOGR("parcelas.gpkg", layers[1])

## some kind of *DataFrame
print(class(x))
plot(x)

Cheers, Mike.

Read on only  if you're interested in more details about GeoPackage.

Geopackage is also extremely extensible since it's built right on top of
SQLite.  If you are keen, you can investigate the contents with
dplyr/RSQLite - though there's no need if sp/rgdal does what you want:

library(dplyr)
library(RSQLite)
db <- src_sql("parcelas.gpkg")

print(db)  ## what tabes are in there?

tbl_df(db, "some_table_name")

The geometry is in one of the tables in WKB form, so it's not "tables all
the way down" but still pretty useful.