port of the JS library geojson-rewind, with ports of parts of the JS libraries geojson-area and wgs84 included

Installation

install.packages("devtools")
devtools::install_github("ropenscilabs/geojsonrewind")
library("geojsonrewind")

Get ring area

x <- '{
 "type":"Polygon",
 "coordinates":[
   [[100.0,0.0],[100.0,1.0],[101.0,1.0],[101.0,0.0],[100.0,0.0]]
 ]
}'

the value is positive if ring is oriented clockwise

x <- jsonlite::fromJSON(x, FALSE)
ring_area(x = x$coordinates[[1]])
#> [1] 12391399902

the value is negative if ring is oriented counterclockwise

ring_area(x = rev(x$coordinates[[1]]))
#> [1] -12391399902

rewind

when outer = TRUE, counterclockwise

rewind(x)
#> {"type":"Polygon","coordinates":[[[100,0],[101,0],[101,1],[100,1],[100,0]]]}

when outer = FALSE, clockwise

rewind(x, outer = FALSE)
#> {"type":"Polygon","coordinates":[[[100,0],[100,1],[101,1],[101,0],[100,0]]]}

Meta