-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
1,752 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--- | ||
title: "Fast loading and saving of GeoJSON" | ||
output: | ||
html_document: | ||
df_print: paged | ||
--- | ||
|
||
** | ||
The [{yyjsonr}](https://github.com/coolbutuseless/yyjsonr) package offers fast | ||
loading and saving of GeoJSON files compared to the GDAL used by, for example, | ||
`{sf}` and `{terra}`. However, GDAL has more features like filtering based on | ||
criteria. | ||
** | ||
|
||
<details> | ||
<summary>Code</summary> | ||
|
||
```{r message=FALSE} | ||
library("sf") | ||
library("yyjsonr") | ||
options(timeout = 600) # connection timeout | ||
``` | ||
|
||
```{r message=FALSE} | ||
## download dataset | ||
url = "https://github.com/paleolimbot/geoarrow-data/releases/download/v0.0.1/nshn_land_poly.gpkg" | ||
download.file(url, "nshn_land_poly.gpkg", mode = "wb") | ||
data = read_sf("nshn_land_poly.gpkg") # 24037 polygons x 11 attributes | ||
data = st_transform(data, "EPSG:4326") # transform to WGS84 | ||
``` | ||
|
||
**Data saving** | ||
|
||
```{r} | ||
system.time( sf::write_sf(data, "test.geojson") ) | ||
system.time( yyjsonr::write_geojson_file(data, "test.geojson") ) | ||
``` | ||
|
||
**Data loading** | ||
|
||
```{r} | ||
system.time( sf::read_sf("test.geojson") ) | ||
system.time( yyjsonr::read_geojson_file("test.geojson") ) | ||
``` | ||
|
||
</details> |