turf.js R client
R JavaScript TeX
Latest commit 6eb3672 Feb 4, 2017 @jhollist jhollist committed on GitHub Merge pull request #58 from jhollist/doc_grammar.
First pass through on making documentation consistent  closes #56
Permalink
Failed to load latest commit information.
R Merge pull request #58 from jhollist/doc_grammar. Feb 3, 2017
data added trunc_mat for pretty printing, and print methods for classes #26 May 21, 2015
inst udpated a few js libraries, added missing license files for js libraries Oct 17, 2016
man-roxygen updated man files for math fxns May 12, 2015
man bump license year, library jsonlite for an eg that needs minify() Jan 13, 2017
tests fixed link to my repo, and fixed issue with single point on buffer (t… Oct 19, 2016
vignettes using rmarkdown now for the vignette Oct 18, 2016
.Rbuildignore addded paper.md Dec 22, 2016
.gitignore draft of materials for JOSS submission. Dec 16, 2016
.travis.yml do release and devel builds on travis May 13, 2016
CONDUCT.md add contributor code of conduct, removed install leaflet from github … Aug 24, 2015
CONTRIBUTING.md bumped date and added contributing file Mar 8, 2015
DESCRIPTION fix to lawn_circle, and more egs for intersect, bumpd dev version, #50 Nov 23, 2016
LICENSE bump license year, library jsonlite for an eg that needs minify() Jan 13, 2017
NAMESPACE added view.feature Feb 3, 2017
NEWS.md updated news and cran comments, reran readme, bumped to v0.3 Oct 24, 2016
README.Rmd added EPA requested disclaimers for JWH contributions. Dec 16, 2016
README.md added EPA requested disclaimers for JWH contributions. Dec 16, 2016
appveyor.yml try removing v8 install from github see if appveyor does v8 install c… Mar 9, 2016
codemeta.json went verbose on Turf in the title Dec 22, 2016
cran-comments.md update cran comments Oct 24, 2016
lawn.Rproj fixed link to my repo, and fixed issue with single point on buffer (t… Oct 19, 2016
paper.bib draft of materials for JOSS submission. Dec 16, 2016
paper.md Title Case on title... Jan 3, 2017

README.md

lawn

Build Status Build status codecov.io rstudio mirror downloads cran version

lawn is an R wrapper for the Javascript library turf.js. In addition, we have a few functions to interface with the geojson-random and geojsonhint Javascript libraries, for generating random GeoJSON objects and linting GeoJSON, respectively.

Install

The latest release of lawn is available from CRAN. To install:

install.packages("lawn")

To install the development version:

install.packages("devtools")
devtools::install_github("ropensci/lawn")
library("lawn")

count

Count number of points within polygons

lawn_count(lawn_data$polygons_count, lawn_data$points_count, 'population')
#> <FeatureCollection>
#>   Bounding box: -112.1 46.6 -112.0 46.6
#>   No. features: 2
#>   No. points: 20
#>   Properties: 
#>     values count
#> 1 200, 600     2
#> 2              0

average

Average value of a field for a set of points within a set of polygons

lawn_average(polygons = lawn_data$polygons_average, points = lawn_data$points_average, 'population')
#> <FeatureCollection>
#>   Bounding box: 10.7 59.9 10.9 59.9
#>   No. features: 2
#>   No. points: 20
#>   Properties: 
#>          values average
#> 1 200, 600, 100     300
#> 2      200, 300     250

distance

Define two points

from <- '{
 "type": "Feature",
 "properties": {},
 "geometry": {
   "type": "Point",
   "coordinates": [-75.343, 39.984]
 }
}'
to <- '{
  "type": "Feature",
  "properties": {},
  "geometry": {
    "type": "Point",
    "coordinates": [-75.534, 39.123]
  }
}'

Calculate distance, default units is kilometers (km)

lawn_distance(from, to)
#> [1] 97.15958

random set of points

lawn_random(n = 2)
#> <FeatureCollection>
#>   Bounding box: -179.0 -64.9 175.4 -1.9
#>   No. features: 2
#>   No. points: 4
#>   Properties: NULL
lawn_random(n = 5)
#> <FeatureCollection>
#>   Bounding box: -91.1 3.7 140.0 54.0
#>   No. features: 5
#>   No. points: 10
#>   Properties: NULL

random features with geojson-random

Points

gr_point(2)
#> <FeatureCollection>
#>   Bounding box: 26.9 -29.1 82.8 44.9
#>   No. features: 2
#>   No. points: 4
#>   Properties: NULL

Positions

gr_position()
#> [1] 147.16514 -10.64865

Polygons

gr_polygon(n = 1, vertices = 5, max_radial_length = 5)
#> <FeatureCollection>
#>   Bounding box: -59.5 51.8 -52.7 54.3
#>   No. features: 1
#>   No. points: 12
#>   Properties: NULL

sample from a FeatureCollection

dat <- lawn_data$points_average
lawn_sample(dat, 1)
#> <FeatureCollection>
#>   Bounding box: 10.7 59.9 10.7 59.9
#>   No. features: 1
#>   No. points: 2
#>   Properties: 
#>   population
#> 1        200
lawn_sample(dat, 2)
#> <FeatureCollection>
#>   Bounding box: 10.7 59.9 10.8 59.9
#>   No. features: 2
#>   No. points: 4
#>   Properties: 
#>   population
#> 1        600
#> 2        300
lawn_sample(dat, 3)
#> <FeatureCollection>
#>   Bounding box: 10.7 59.9 10.8 59.9
#>   No. features: 3
#>   No. points: 6
#>   Properties: 
#>   population
#> 1        300
#> 2        600
#> 3        200

extent

lawn_extent(lawn_data$points_average)
#> [1] 10.71579 59.90478 10.80643 59.93162

within

lawn_within(lawn_data$points_within, lawn_data$polygons_within)
#> <FeatureCollection>
#>   Bounding box: -46.6 -23.6 -46.6 -23.6
#>   No. features: 2
#>   No. points: 4
#>   Properties: NULL

buffer

dat <- '{
 "type": "Feature",
 "properties": {},
 "geometry": {
     "type": "Polygon",
     "coordinates": [[
       [-112.072391,46.586591],
       [-112.072391,46.61761],
       [-112.028102,46.61761],
       [-112.028102,46.586591],
       [-112.072391,46.586591]
     ]]
   }
}'
lawn_buffer(dat, 1, "miles")
#> <Feature>
#>   Type: Polygon
#>   Bounding box: -112.1 46.6 -112.0 46.6
#>   No. points: 74
#>   Properties: NULL

view

lawn includes a tiny helper function for visualizing geojson.

view(lawn_data$points_average)

map1

Or during process of manipulating geojson, view at mostly any time.

Here, we sample at random two points from the same dataset just viewed.

lawn_sample(lawn_data$points_average, 2) %>% view()

map1

Contributors

Meta

  • Please report any issues or bugs.
  • License: MIT
  • Get citation information for lawn in R doing citation(package = 'lawn')
  • Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

Additional disclaimer

Portions of this code have been contributed by Jeff Hollister, US EPA. As such, that code is subjec to the following disclaimer: https://www.epa.gov/home/github-contribution-disclaimer

rofooter