geojson-package: geojson

geojson-packageR Documentation

geojson

Description

Classes for GeoJSON to make working with GeoJSON easier

Package API

GeoJSON objects:

  • feature - Feature

  • featurecollection - FeatureCollection

  • geometrycollection - GeometryCollection

  • linestring - LineString

  • multilinestring - MultiLineString

  • multipoint - MultiPoint

  • multipolygon - MultiPolygon

  • point - Point

  • polygon - Polygon

The above are assigned two classes. All of them are class geojson, but also have a class name that is geo plus the name of the geometry, e.g., geopolygon for polygon.

GeoJSON properties:

  • properties_add, properties_get - Add or get properties

  • crs_add, crs_get - Add or get CRS

  • bbox_add, bbox_get - Add or get bounding box

GeoJSON operations:

  • geo_bbox - calculate a bounding box for any GeoJSON object

  • geo_pretty - pretty print any GeoJSON object

  • geo_type - get the object type for any GeoJSON object

  • geo_write - easily write any GeoJSON to a file

  • More complete GeoJSON operations are provdied in the package geoops

GeoJSON/Geobuf serialization:

Coordinate Reference System

According to RFC 7946 (https://datatracker.ietf.org/doc/html/rfc7946#page-12) the CRS for all GeoJSON objects must be WGS-84, equivalent to urn:ogc:def:crs:OGC::CRS84. And lat/long must be in decimal degrees.

Given the above, but considering that GeoJSON blobs exist that have CRS attributes in them, we provide CRS helpers in this package. But moving forward these are not likely to be used much.

Coordinate precision

According to RFC 7946 (https://datatracker.ietf.org/doc/html/rfc7946#section-11.2) consider that 6 decimal places amoutns to ~10 centimeters, a precision well within that of current GPS sytems. Further, A GeoJSON text containing many detailed Polygons can be inflated almost by a factor of two by increasing coordinate precision from 6 to 15 decimal places - so consider whether it is worth it to have more decimal places.

Author(s)

Scott Chamberlain, Jeroen Ooms


geojson documentation built on Aug. 8, 2023, 5:11 p.m.