Learn R Programming

⚠️There's a newer version (0.6.0) of this package.Take me there.

lawn

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(polygons = lawn_data$polygons_count, points = lawn_data$points_count)
#> <FeatureCollection>
#>   Bounding box: -112.1 46.6 -112.0 46.6
#>   No. features: 2
#>   No. points: 20
#>   Properties: NULL

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: NULL

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: -60.9 43.4 59.9 57.9
#>   No. features: 2
#>   No. points: 4
#>   Properties: NULL
lawn_random(n = 5)
#> <FeatureCollection>
#>   Bounding box: -137.6 -77.2 167.4 85.8
#>   No. features: 5
#>   No. points: 10
#>   Properties: NULL

random features with geojson-random

Points

gr_point(2)
#> <FeatureCollection>
#>   Bounding box: -80.6 71.6 -60.2 88.1
#>   No. features: 2
#>   No. points: 4
#>   Properties: NULL

Positions

gr_position()
#> [1] 24.779369  6.632737

Polygons

gr_polygon(n = 1, vertices = 5, max_radial_length = 5)
#> <FeatureCollection>
#>   Bounding box: 129.8 55.9 136.0 59.8
#>   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.8 59.9 10.8 59.9
#>   No. features: 1
#>   No. points: 2
#>   Properties: NULL
lawn_sample(dat, 2)
#> <FeatureCollection>
#>   Bounding box: 10.7 59.9 10.8 59.9
#>   No. features: 2
#>   No. points: 4
#>   Properties: NULL
lawn_sample(dat, 3)
#> <FeatureCollection>
#>   Bounding box: 10.7 59.9 10.8 59.9
#>   No. features: 3
#>   No. points: 6
#>   Properties: NULL

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")
#> <FeatureCollection>
#>   Bounding box: -112.1 46.6 -112.0 46.6
#>   No. features: 1
#>   No. points: 74
#>   Properties: NULL

view

lawn includes a tiny helper function for visualizing geojson.

view(lawn_data$points_average)

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

Meta

Copy Link

Version

Install

install.packages('lawn')

Monthly Downloads

31

Version

0.1.7

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Scott Chamberlain

Last Published

May 2nd, 2016

Functions in lawn (0.1.7)

lawn-package

R client for turf.js for geospatial analysis
as.turf

Coerce to turf.js javascript function call
georandom

Return a FeatureCollection with N number of features with random coordinates
lawn_buffer

Buffer a feature
lawn_featurecollection

Create a FeatureCollection
lawn_filter

Filter a FeatureCollection by a given property and value
lawn_merge

Merge polygons
lawn_point_on_surface

Get a point on the surface of a feature
lawn_size

Expand a bounding box
lawn_tin

Create a Triangulated Irregular Network
lawn_within

Return points that fall within polygons
lawn_bezier

Curve a linestring
lawn_random

Generate random data
lawn_sample

Return features from FeatureCollection at random
lawn_simplify

Simplify GeoJSON data
lawn_sum

Sum of a field among points within polygons
lawn_area

Calculate the area of a polygon or group of polygons
lawn_median

Median value of a field among points within polygons
lawn_bearing

Get geographic bearing between two points
lawn_concave

Concave hull polygon
lawn_point_grid

Create a PointGrid
lawn_planepoint

Calculate a Planepoint
lawn_square_grid

Create a SquareGrid
lawn_center

Get center point
lawn_flip

Flip x,y to y,x, and vice versa
lawn_min

Minimum value of a field among points within polygons
%>%

Pipe operator
type_sum

Type summary
lawn_distance

Distance between two points
lawn_midpoint

Get a point midway between two points
view

Visualize geojson
lawn_bbox_polygon

Make a polygon from a bounding box
lawn_along

Get a point at a distance along a line
lawn_convex

Convex hull polygon
lawn_count

Count number of points within polygons
lawn_deviation

Standard deviation of a field among points within polygons
lawn_destination

Calculate destination point
lawn_data

Data for use in examples
lawn_explode

Explode vertices to points
lawn_jenks

Get Jenks breaks
lawn_kinks

Get points at all self-intersections of a polygon
lawn_max

Maximum value of a field among points within polygons
lawn_quantile

Calculate quantiles
lawn_reclass

Reclassify properties data
lawn_square

Calculate a square bounding box
lawn_tag

Spatial join of points and polygons
print-methods

Lawn print methods to provide summary view
as_feature

Convert a FeatureCollection to a Feature
lawn_combine

Combine singular features into plural versions
lawn_envelope

Calculate envelope around features
lawn_extent

Get a bounding box
lawn_polygon

Create a polygon
lawn_aggregate

Calculate a series of aggregations for a set of points within polygons
lawn_average

Average of a field among points within polygons
lawn_isolines

Generate Isolines
lawn_linestring

Create a linestring
lawn_line_distance

Measure a linestring
lawn_line_slice

Slice a line given two points
lawn_intersect

Intersection
lawn_inside

Does a point reside inside a polygon
lawn_point

Create a point
lawn_hex_grid

Create a HexGrid
lawn_erase

Erase one polygon from another
lawn_union

Merge polygons
lawn_variance

Variance of a field among points within polygons
lawn_point_on_line

Get closest point on linestring to reference point
lawn_nearest

Get nearest point
lawn_remove

Remove things from a FeatureCollection
data-types

Description of GeoJSON data types
lawn_centroid

Centroid
lawn_triangle_grid

Create a TriangleGrid