diff --git a/.Rbuildignore b/.Rbuildignore
new file mode 100644
index 0000000..dc9e0af
--- /dev/null
+++ b/.Rbuildignore
@@ -0,0 +1,9 @@
+^sfdbi\.Rproj$
+^\.Rproj\.user$
+^README\.Rmd$
+^LICENSE\.md$
+^codecov\.yml$
+^_pkgdown\.yml$
+^docs$
+^pkgdown$
+^\.github$
diff --git a/.github/.gitignore b/.github/.gitignore
new file mode 100644
index 0000000..2d19fc7
--- /dev/null
+++ b/.github/.gitignore
@@ -0,0 +1 @@
+*.html
diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml
new file mode 100644
index 0000000..8bc9210
--- /dev/null
+++ b/.github/workflows/pkgdown.yaml
@@ -0,0 +1,46 @@
+on:
+ push:
+ branches: master
+
+name: pkgdown
+
+jobs:
+ pkgdown:
+ runs-on: macOS-latest
+ env:
+ GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
+ steps:
+ - uses: actions/checkout@v2
+
+ - uses: r-lib/actions/setup-r@master
+
+ - uses: r-lib/actions/setup-pandoc@master
+
+ - name: Query dependencies
+ run: |
+ install.packages('remotes')
+ saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
+ writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
+ shell: Rscript {0}
+
+ - name: Cache R packages
+ uses: actions/cache@v1
+ with:
+ path: ${{ env.R_LIBS_USER }}
+ key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
+ restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-
+
+ - name: Install dependencies
+ run: |
+ remotes::install_deps(dependencies = TRUE)
+ install.packages("pkgdown")
+ shell: Rscript {0}
+
+ - name: Install package
+ run: R CMD INSTALL .
+
+ - name: Deploy package
+ run: |
+ git config --local user.email "actions@github.com"
+ git config --local user.name "GitHub Actions"
+ Rscript -e 'pkgdown::deploy_to_branch(new_process = FALSE)'
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..234f028
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,5 @@
+.Rproj.user
+.Rhistory
+.RData
+.Ruserdata
+docs
diff --git a/DESCRIPTION b/DESCRIPTION
new file mode 100644
index 0000000..3b37139
--- /dev/null
+++ b/DESCRIPTION
@@ -0,0 +1,24 @@
+Package: sfdbi
+Title: Database interface for spatial data
+Version: 0.0.0.9000
+Authors@R:
+ c(person(given = "Etienne",
+ family = "Racine",
+ role = c("aut", "cre"),
+ email = "etiennebr@gmail.com",
+ comment = c(ORCID = "0000-0003-1109-894X")),
+ person(given = "Edzer",
+ family = "Pebesma",
+ role = c("aut"),
+ email = "edzer.pebesma@uni-muenster.de",
+ comment = c(ORCID = "0000-0001-8049-7069")))
+Description: An `sf` back end for databases that allows you to
+ work with database tables as if they are in-memory spatial data frames.
+License: MIT + file LICENSE
+Encoding: UTF-8
+LazyData: true
+Roxygen: list(markdown = TRUE)
+RoxygenNote: 7.1.0
+Suggests:
+ testthat,
+ covr
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..2a02b9e
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,2 @@
+YEAR: 2020
+COPYRIGHT HOLDER: Etienne Racine
diff --git a/LICENSE.md b/LICENSE.md
new file mode 100644
index 0000000..3fdc29b
--- /dev/null
+++ b/LICENSE.md
@@ -0,0 +1,21 @@
+# MIT License
+
+Copyright (c) 2020 Etienne Racine
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/NAMESPACE b/NAMESPACE
new file mode 100644
index 0000000..6ae9268
--- /dev/null
+++ b/NAMESPACE
@@ -0,0 +1,2 @@
+# Generated by roxygen2: do not edit by hand
+
diff --git a/R/zzz.R b/R/zzz.R
new file mode 100644
index 0000000..bf7a4c1
--- /dev/null
+++ b/R/zzz.R
@@ -0,0 +1,27 @@
+# nocov start
+
+# setup_repo
+if (FALSE) {
+ .sfdbi_setup <- function() {
+ usethis::create_package("../sfdbi", open = FALSE)
+ usethis::use_readme_rmd()
+ usethis::use_news_md()
+ usethis::use_logo("logo.svg")
+ usethis::use_testthat()
+ usethis::use_roxygen_md()
+ usethis::use_mit_license()
+ usethis::use_git()
+ #usethis::use_github()
+ usethis::use_coverage()
+ usethis::use_lifecycle_badge("experimental")
+ usethis::use_pkgdown()
+ usethis::use_github_action("pkgdown")
+ usethis::use_github_labels(
+ labels = geotidy:::.geotidy_labels(),
+ colours = geotidy:::.geotidy_labels_brewer(),
+ descriptions = geotidy:::.geotidy_labels_descriptions(),
+ delete_default = TRUE
+ )
+ }
+}
+# nocov end
diff --git a/README.Rmd b/README.Rmd
new file mode 100644
index 0000000..0bc51b4
--- /dev/null
+++ b/README.Rmd
@@ -0,0 +1,86 @@
+---
+output: github_document
+---
+
+
+
+```{r, include = FALSE}
+knitr::opts_chunk$set(
+ collapse = TRUE,
+ comment = "#>",
+ fig.path = "man/figures/README-",
+ out.width = "100%"
+)
+```
+
+# sfdbi
+
+[](https://codecov.io/gh/r-spatial/sfdbi?branch=master)
+[](https://www.tidyverse.org/lifecycle/#experimental)
+
+
+## Overview
+
+sfdbi helps you manipulate spatial data stored in a database as if it was
+in-memory with standard sf and [dplyr](https://dplyr.tidyverse.org/) functions.
+With sfdbi, you can reads and write sf objects to databases and translate sf
+operations to `SQL`. We support [`postgis`](https://postgis.net/), but feel free
+to open an issue for other backends and show you interest.
+
+## Installation
+
+You can install the development version from [GitHub](https://github.com/) with:
+
+``` r
+# install.packages("devtools")
+devtools::install_github("r-spatial/sfdbi")
+```
+
+sfdbi is not available on CRAN yet.
+
+## Example
+
+This is how you write and read spatial data to a database. Note that sfdbi works best with dplyr.
+
+```{r example}
+library(sfdbi)
+library(sf)
+library(dplyr)
+
+con <- DBI::dbConnect(
+ RPostgres::Postgres(),
+ host = "localhost",
+ port = 25432
+) %>%
+ postgis()
+
+# Create a spatial table
+pyramids <- tribble(
+ ~what, ~geom,
+ "Giza", "POINT(31.1342 29.9792)",
+ "Khafre", "POINT(31.130833 29.976111)",
+ "Menkaure", "POINT(31.128333 29.9725)",
+ "Khentkaus I", "POINT(31.135608 29.973406)",
+ "Sphynx", "POINT(31.137778 29.975278)",
+ ) %>%
+ mutate(
+ geom = st_as_sfc(geom, crs = 4326)
+ )
+
+# Copy spatial data to database
+x <- copy_to(con, pyramids)
+
+# Queue operations to the database
+y <- x %>%
+ mutate(
+ geom = geom %>%
+ st_transform(23035L) %>%
+ st_buffer(10)
+ )
+
+# View the query to be executed
+y %>% show_query()
+
+# Execute operation in the database and load it in R memory
+collect(y)
+```
diff --git a/README.md b/README.md
index 2e27543..d255b18 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,104 @@
-# sfdbi
-DBI interface to sf
+
+
+
+# sfdbi
+
+
+
+[](https://codecov.io/gh/r-spatial/sfdbi?branch=master)
+[](https://www.tidyverse.org/lifecycle/#experimental)
+
+
+## Overview
+
+sfdbi helps you manipulate spatial data stored in a database as if it
+was in-memory with standard sf and [dplyr](https://dplyr.tidyverse.org/)
+functions. With sfdbi, you can reads and write sf objects to databases
+and translate sf operations to `SQL`. We support
+[`postgis`](https://postgis.net/), but feel free to open an issue for
+other backends and show you interest.
+
+## Installation
+
+You can install the development version from
+[GitHub](https://github.com/) with:
+
+``` r
+# install.packages("devtools")
+devtools::install_github("r-spatial/sfdbi")
+```
+
+sfdbi is not available on CRAN yet.
+
+## Example
+
+This is how you write and read spatial data to a database. Note that
+sfdbi works best with dplyr.
+
+``` r
+library(sfdbi)
+library(sf)
+#> Linking to GEOS 3.8.0, GDAL 3.0.2, PROJ 6.2.1
+library(dplyr)
+#>
+#> Attaching package: 'dplyr'
+#> The following objects are masked from 'package:stats':
+#>
+#> filter, lag
+#> The following objects are masked from 'package:base':
+#>
+#> intersect, setdiff, setequal, union
+
+con <- DBI::dbConnect(
+ RPostgres::Postgres(),
+ host = "localhost",
+ port = 25432
+) %>%
+ postgis()
+
+# Create a spatial table
+pyramids <- tribble(
+ ~what, ~geom,
+ "Giza", "POINT(31.1342 29.9792)",
+ "Khafre", "POINT(31.130833 29.976111)",
+ "Menkaure", "POINT(31.128333 29.9725)",
+ "Khentkaus I", "POINT(31.135608 29.973406)",
+ "Sphynx", "POINT(31.137778 29.975278)",
+ ) %>%
+ mutate(
+ geom = st_as_sfc(geom, crs = 4326)
+ )
+
+# Copy spatial data to database
+x <- copy_to(con, pyramids)
+#> Note: method with signature 'DBIObject#sf' chosen for function 'dbDataType',
+#> target signature 'PqConnection#sf'.
+#> "PqConnection#ANY" would also be valid
+
+# Queue operations to the database
+y <- x %>%
+ mutate(
+ geom = geom %>%
+ st_transform(23035L) %>%
+ st_buffer(10)
+ )
+
+# View the query to be executed
+y %>% show_query()
+#>
+#> SELECT "what", st_buffer(st_transform("geom", 23035), 10.0) AS "geom"
+#> FROM "pyramids"
+
+# Execute operation in the database and load it in R memory
+collect(y)
+#> # A tibble: 5 x 2
+#> what geom
+#>
+#> 1 Giza ((899053.3 3323853, 899053.1 3323851, 899052.6 3323849, 899051.7 3…
+#> 2 Khafre ((898740.5 3323498, 898740.3 3323496, 898739.7 3323494, 898738.8 3…
+#> 3 Menkaure ((898513.4 3323089, 898513.2 3323087, 898512.7 3323085, 898511.7 3…
+#> 4 Khentkaus… ((899212.6 3323215, 899212.4 3323213, 899211.8 3323211, 899210.9 3…
+#> 5 Sphynx ((899414.7 3323430, 899414.5 3323428, 899413.9 3323426, 899413 332…
+```
diff --git a/_pkgdown.yml b/_pkgdown.yml
new file mode 100644
index 0000000..e69de29
diff --git a/codecov.yml b/codecov.yml
new file mode 100644
index 0000000..04c5585
--- /dev/null
+++ b/codecov.yml
@@ -0,0 +1,14 @@
+comment: false
+
+coverage:
+ status:
+ project:
+ default:
+ target: auto
+ threshold: 1%
+ informational: true
+ patch:
+ default:
+ target: auto
+ threshold: 1%
+ informational: true
diff --git a/man/figures/README-pressure-1.png b/man/figures/README-pressure-1.png
new file mode 100644
index 0000000..ba27887
Binary files /dev/null and b/man/figures/README-pressure-1.png differ
diff --git a/man/figures/logo.svg b/man/figures/logo.svg
new file mode 100644
index 0000000..8ba9c66
--- /dev/null
+++ b/man/figures/logo.svg
@@ -0,0 +1,169 @@
+
+
diff --git a/sfdbi.Rproj b/sfdbi.Rproj
new file mode 100644
index 0000000..69fafd4
--- /dev/null
+++ b/sfdbi.Rproj
@@ -0,0 +1,22 @@
+Version: 1.0
+
+RestoreWorkspace: No
+SaveWorkspace: No
+AlwaysSaveHistory: Default
+
+EnableCodeIndexing: Yes
+UseSpacesForTab: Yes
+NumSpacesForTab: 2
+Encoding: UTF-8
+
+RnwWeave: Sweave
+LaTeX: pdfLaTeX
+
+AutoAppendNewline: Yes
+StripTrailingWhitespace: Yes
+LineEndingConversion: Posix
+
+BuildType: Package
+PackageUseDevtools: Yes
+PackageInstallArgs: --no-multiarch --with-keep.source
+PackageRoxygenize: rd,collate,namespace
diff --git a/tests/testthat.R b/tests/testthat.R
new file mode 100644
index 0000000..8129edc
--- /dev/null
+++ b/tests/testthat.R
@@ -0,0 +1,4 @@
+library(testthat)
+library(sfdbi)
+
+test_check("sfdbi")