ropensci/randgeo

Name: randgeo

Owner: rOpenSci

Description: random WKT or GeoJSON

Created: 2017-01-19 18:12:39.0

Updated: 2018-01-09 20:05:59.0

Pushed: 2018-01-05 19:47:27.0

Homepage: https://ropensci.github.io/randgeo/

Size: 574

Language: R

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

randgeo: random WKT and GeoJSON

Build Status codecov.io rstudio mirror downloads cran version

randgeo generates random points and shapes in GeoJSON and WKT formats for use in examples, teaching, or statistical applications.

Points and shapes are generated in the long/lat coordinate system and with appropriate spherical geometry; random points are distributed evenly across the globe, and random shapes are sized according to a maximum great-circle distance from the center of the shape.

randgeo was adapted from https://github.com/tmcw/geojson-random to have a pure R implementation without any dependencies as well as appropriate geometry. Data generated by randgeo may be processed or displayed of with packages such as sf, wicket, geojson, wellknown, geojsonio, or lawn.

Package API:

Docs

https://ropensci.github.io/randgeo/

Install

Stabler CRAN version

all.packages("randgeo")

Development version

ools::install_github("ropensci/randgeo")

ary("randgeo")
Generate a random position
osition()
[1]]
1] 149.33018 -60.94463
Generate random GeoJSON

Random point - evenly distributed across the sphere. The bbox option allows you to limit points to within long/lat bounds.

point()
type
1] "FeatureCollection"

features
features[[1]]
features[[1]]$type
1] "Feature"

features[[1]]$geometry
features[[1]]$geometry$type
1] "Point"

features[[1]]$geometry$coordinates
1] -76.98977 -41.36819


features[[1]]$properties
ULL



ttr(,"class")
1] "geo_list"

Random linestring - starting from a random point, with default maximum segment length and maximum rotation between two segments.

linestring()
type
1] "FeatureCollection"

features
features[[1]]
features[[1]]$type
1] "Feature"

features[[1]]$geometry
features[[1]]$geometry$type
1] "LineString"

features[[1]]$geometry$coordinates
features[[1]]$geometry$coordinates[[1]]
features[[1]]$geometry$coordinates[[1]][[1]]
1] 51.028387 -2.188767

features[[1]]$geometry$coordinates[[1]][[2]]
1] 51.027774 -2.189005

features[[1]]$geometry$coordinates[[1]][[3]]
1] 51.028109 -2.189318

features[[1]]$geometry$coordinates[[1]][[4]]
1] 51.027487 -2.190017

features[[1]]$geometry$coordinates[[1]][[5]]
1] 51.027774 -2.190379

features[[1]]$geometry$coordinates[[1]][[6]]
1] 51.027088 -2.191078

features[[1]]$geometry$coordinates[[1]][[7]]
1] 51.027435 -2.191403

features[[1]]$geometry$coordinates[[1]][[8]]
1] 51.026922 -2.192147

features[[1]]$geometry$coordinates[[1]][[9]]
1] 51.027533 -2.192925

features[[1]]$geometry$coordinates[[1]][[10]]
1] 51.027475 -2.192984




features[[1]]$properties
ULL



ttr(,"class")
1] "geo_list"

Random polygon - centered on a random point, with default maximum size

polygon()
type
1] "FeatureCollection"

features
features[[1]]
features[[1]]$type
1] "Feature"

features[[1]]$geometry
features[[1]]$geometry$type
1] "Polygon"

features[[1]]$geometry$coordinates
features[[1]]$geometry$coordinates[[1]]
features[[1]]$geometry$coordinates[[1]][[1]]
1]  7.375542 21.481953

features[[1]]$geometry$coordinates[[1]][[2]]
1]  9.557249 13.822460

features[[1]]$geometry$coordinates[[1]][[3]]
1] 10.882944  6.553386

features[[1]]$geometry$coordinates[[1]][[4]]
1] 8.192794 5.962077

features[[1]]$geometry$coordinates[[1]][[5]]
1] 8.305398 5.210405

features[[1]]$geometry$coordinates[[1]][[6]]
1] 2.573744 9.711262

features[[1]]$geometry$coordinates[[1]][[7]]
1]  0.4559409 17.8573283

features[[1]]$geometry$coordinates[[1]][[8]]
1]  5.093829 12.718010

features[[1]]$geometry$coordinates[[1]][[9]]
1]  2.778335 20.708271

features[[1]]$geometry$coordinates[[1]][[10]]
1]  5.103798 12.757463

features[[1]]$geometry$coordinates[[1]][[11]]
1]  7.375542 21.481953




features[[1]]$properties
ULL



ttr(,"class")
1] "geo_list"

Visualize your shapes with lawn.

::view(jsonlite::toJSON(geo_polygon(count = 4), auto_unbox = TRUE))

map

Generate random WKT

Random point

point()
1] "POINT (50.3923570 -70.3787919)"

Random linestring

linestring()
1] "LINESTRING (42.7817546 19.4598109, 42.7818265 19.4597713, 42.7819039 19.4597543, 42.7819206 19.4597476, 42.7819732 19.4597341, 42.7820674 19.4596920, 42.7821133 19.4596554, 42.7821233 19.4596390, 42.7821761 19.4595728, 42.7821867 19.4595509)"

Random polygon

polygon()
1] "POLYGON ((-164.5191674 48.1392788, -160.7019535 50.0321237, -162.9547961 47.6318361, -154.1477728 46.2428280, -164.4173904 45.9485672, -160.5131717 43.5274697, -167.1833639 41.2046996, -164.5419419 45.9658491, -171.4209181 42.8764619, -166.7761058 46.2084577, -164.5191674 48.1392788))"
Contributors
Meta

rofooter


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.