geojsonrewind

knitr::opts_chunk$set(
  comment = "#>",
  collapse = TRUE,
  warning = FALSE,
  message = FALSE
)

Build Status codecov.io

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]])

the value is negative if ring is oriented counterclockwise

ring_area(x = rev(x$coordinates[[1]]))

rewind

when outer = TRUE, clockwise

rewind(x)

when outer = FALSE, counterclockwise

rewind(x, outer = FALSE)

Meta

rofooter



ropenscilabs/geojsonrewind documentation built on May 18, 2022, 7:38 p.m.