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

Initial readme #1

Merged
merged 3 commits into from
Aug 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
^sfdbi\.Rproj$
^\.Rproj\.user$
^README\.Rmd$
^LICENSE\.md$
^codecov\.yml$
^_pkgdown\.yml$
^docs$
^pkgdown$
^\.github$
1 change: 1 addition & 0 deletions .github/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.html
46 changes: 46 additions & 0 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
@@ -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 "[email protected]"
git config --local user.name "GitHub Actions"
Rscript -e 'pkgdown::deploy_to_branch(new_process = FALSE)'
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.Rproj.user
.Rhistory
.RData
.Ruserdata
docs
24 changes: 24 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]",
comment = c(ORCID = "0000-0003-1109-894X")),
person(given = "Edzer",
family = "Pebesma",
role = c("aut"),
email = "[email protected]",
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
2 changes: 2 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
YEAR: 2020
COPYRIGHT HOLDER: Etienne Racine
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Generated by roxygen2: do not edit by hand

27 changes: 27 additions & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
@@ -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
86 changes: 86 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
---
output: github_document
---

<!-- README.md is generated from README.Rmd. Please edit that file -->

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```

# sfdbi <img src='man/figures/logo.svg' align="right" height="139" />
<!-- badges: start -->
[![Codecov test coverage](https://codecov.io/gh/r-spatial/sfdbi/branch/master/graph/badge.svg)](https://codecov.io/gh/r-spatial/sfdbi?branch=master)
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)
<!-- badges: end -->

## 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)
```
106 changes: 104 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,104 @@
# sfdbi
DBI interface to sf

<!-- README.md is generated from README.Rmd. Please edit that file -->

# sfdbi <img src='man/figures/logo.svg' align="right" height="139" />

<!-- badges: start -->

[![Codecov test
coverage](https://codecov.io/gh/r-spatial/sfdbi/branch/master/graph/badge.svg)](https://codecov.io/gh/r-spatial/sfdbi?branch=master)
[![Lifecycle:
experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)
<!-- badges: end -->

## 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()
#> <SQL>
#> 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
#> <chr> <POLYGON [m]>
#> 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…
```
Empty file added _pkgdown.yml
Empty file.
14 changes: 14 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
comment: false

coverage:
status:
project:
default:
target: auto
threshold: 1%
informational: true
patch:
default:
target: auto
threshold: 1%
informational: true
Binary file added man/figures/README-pressure-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading