geobuf {geojson} | R Documentation |
Geobuf serialization
Description
Geobuf serialization
Usage
from_geobuf(x, pretty = FALSE)
to_geobuf(x, file = NULL, decimals = 6)
Arguments
x |
(character) a file or raw object for |
pretty |
(logical) pretty print JSON. Default: |
file |
(character) file to write protobuf to. if NULL, geobuf raw binary returned |
decimals |
(integer) how many decimals (digits behind the dot) to store for numbers |
Details
from_geobuf
uses protolite::geobuf2json()
,
while to_geobuf
uses protolite::json2geobuf()
Note that protolite expects either a Feature,
FeatureCollection, or Geometry class geojson
object, Thus, for to_geobuf
we check the geojson class, and
convert to a Feature if the class is something other than
the acceptable set.
Value
for from_geobuf
JSON as a character string, and for
to_geobuf
raw or file written to disk
References
Geobuf is a compact binary encoding for geographic data using protocol buffers https://github.com/mapbox/geobuf
Examples
file <- system.file("examples/test.pb", package = "geojson")
(json <- from_geobuf(file))
from_geobuf(file, pretty = TRUE)
pb <- to_geobuf(json)
f <- tempfile(fileext = ".pb")
to_geobuf(json, f)
from_geobuf(f)
object.size(json)
object.size(pb)
file.info(file)$size
file.info(f)$size
file <- system.file("examples/featurecollection1.geojson",
package = "geojson")
json <- paste0(readLines(file), collapse = "")
to_geobuf(json)
# other geojson class objects
x <- '{ "type": "Polygon",
"coordinates": [
[ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ]
]
}'
(y <- polygon(x))
to_geobuf(y)
x <- '{"type": "MultiPoint", "coordinates": [ [100.0, 0.0], [101.0, 1.0] ] }'
(y <- multipoint(x))
to_geobuf(y)