https://github.com/mdsumner/basf
Load sf but with sp-like plot
https://github.com/mdsumner/basf
Last synced: 7 months ago
JSON representation
Load sf but with sp-like plot
- Host: GitHub
- URL: https://github.com/mdsumner/basf
- Owner: mdsumner
- Created: 2018-06-02T09:44:59.000Z (about 8 years ago)
- Default Branch: main
- Last Pushed: 2022-09-02T01:27:35.000Z (almost 4 years ago)
- Last Synced: 2025-01-28T14:51:44.923Z (over 1 year ago)
- Language: R
- Homepage: https://mdsumner.github.io/basf/.
- Size: 858 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.Rmd
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
---
output: github_document
editor_options:
chunk_output_type: console
---
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
library(basf)
```
# basf
The goal of basf is to smooth over some of the peculiarities of the sf package, with a very short list of features.
- plot simple features in a base graphics way that sp did.
- read vector data with a straightforward extent filter
## Installation
From CRAN in the usual way.
```{r cran, eval=FALSE}
install.packages("basf")
```
From Github:
```{r install, eval=FALSE}
#install.packages("remotes")
remotes::install_github("mdsumner/basf")
```
Use `library(basf)` instead of `library(sf)` if you want these features.
## Plotting
There will be a warning when basf starts up because this is what it does.
```R
Registered S3 method overwritten by 'basf':
method from
plot.sf sf
```
This example shows the impact of basf on plotting.
```{r example}
library(basf)
## all the stuff is available
x <- read_sf(system.file("shape/nc.shp", package="sf"))
## all we've changed is the plot command
plot(x)
plot(x[sample(1:nrow(x), 10), ], col = rainbow(10), add = TRUE)
## overplotting works
axis(1); axis(2)
abline(v = -80, h = -34)
```
Without basf, we would have to do extra format-aware workarounds when setting up
the plot. I find this incredibly disruptive, perhaps because I've used R and sp
for so long - I use plotting every day to verify my work. It makes no sense to
me to make things format-specific so I'm kind of mystified as to why it's gone
this way.
```R
library(sf)
x <- read_sf(system.file("shape/nc.shp", package="sf"))
plot(x[1], reset = FALSE, col = NA, main = "")
plot(x[sample(1:nrow(x), 10), ], col = rainbow(10), add = TRUE)
axis(1); axis(2)
abline(v = -80, h = -34)
```
## Reading
This example shows the impact of basf on reading. We would otherwise obtain 32 polygons from this file.
The second optional argument `ext` can be an extent, either a raw vector xmin,xmax,ymin,ymax as here or a spatial object.
```R
library(basf)
read_ext("../measoshapes/inst/extdata/measo_regions_ll.gpkg", c(100, 120, -80, -10))
Simple feature collection with 8 features and 3 fields
geometry type: POLYGON
dimension: XY
bbox: xmin: 30 ymin: -80 xmax: 170 ymax: -30
geographic CRS: WGS 84
```
---
Please note that this project is released with a [Contributor Code of Conduct](https://github.com/mdsumner/basf/blob/master/CODE_OF_CONDUCT.md).
By participating in this project you agree to abide by its terms.