geojson release: newline-delimited GeoJSON and other bits

geojson
geospatial
r
Tags: #<Tag:0x00007fdab4a836d0> #<Tag:0x00007fdab4a83068> #<Tag:0x00007fdab4a82a00>

#1

There’s a new version of geojson up on CRAN, binaries available as well. Check out the release notes at https://github.com/ropensci/geojson/releases/tag/v0.3.0 Here’s some highlights of the new release:

Newline-delimited GeoJSON

Newline-delimited GeoJSON (hereafter nd-GeoJSON; another flavor is GeoJSON text sequences) are an extension of newline-delimited JSON, or JSON lines http://jsonlines.org/. See also the geojson spec: https://tools.ietf.org/html/rfc794

The TLDR is that nd-GeoJSON is a file where each line is a valid GeoJSON structure, and the line by line nature allows it to be written and read line by line, making it much easier to deal with very large GeoJSON’s.

A brief example, here reading from a file:

url <- "https://storage.googleapis.com/osm-extracts.interline.io/honolulu_hawaii.geojsonl"
f <- tempfile(fileext = ".geojsonl")
download.file(url, f)
x <- ndgeo_read(f)
x
#> <geojson>
#>   type:  FeatureCollection
#>   features (n): 65004
#>   features (geometry / length) [first 5]:
#>     Point / 2
#>     Point / 2
#>     Point / 2
#>     Point / 2
#>     Point / 2

The print method was modified. The object above in the previous version of geojson had the bounding box, but for very large objects that calculation can take some time, and can even lead to protect(): protection stack overflow errors (see ropensci/geojson#36), so we’ve removed it for now, but you can always grab the bounding box yourself by running geojson::geo_bbox() yourself. We’ve got an open issue for speeding up bounding box calculation: ropensci/geojson#37

note: there was a little slip up in the ndgeo_read fxn, install latest from github for the fix to read directly from a url

sf for as.geojson

@cpsievert added a new s3 method for the generic as.geojson. a brief example:

library(geojson)
library(sf)
nc <- st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
as.geojson(nc)
#> <geojson>
#>   type:  FeatureCollection
#>   features (n): 100
#>   features (geometry / length) [first 5]:
#>     Polygon / 1
#>     Polygon / 1
#>     Polygon / 1
#>     Polygon / 3
#>     Polygon / 1


Check out the release notes https://github.com/ropensci/geojson/releases/tag/v0.3.0 for more changes.