MyNixOS website logo
Description

Generate Random 'WKT' or 'GeoJSON'.

Generate random positions (latitude/longitude), Well-known text ('WKT') points or polygons, or 'GeoJSON' points or polygons.

randgeo: random WKT and GeoJSON

Project Status: Active – The project has reached a stable, usable state and is being actively developed. cran checks 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:

  • rg_position - random position (lon, lat)
  • geo_point - random GeoJSON point
  • geo_linestring - random GeoJSON linestring
  • geo_polygon - random GeoJSON polygon
  • wkt_point - random WKT point
  • wkt_linestring - random WKT linestring
  • wkt_polygon - random WKT polygon

Docs

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

Install

Stabler CRAN version

install.packages("randgeo")

Development version

devtools::install_github("ropensci/randgeo")
library("randgeo")

Generate a random position

rg_position()
#> [[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.

geo_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
#> NULL
#> 
#> 
#> 
#> attr(,"class")
#> [1] "geo_list"

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

geo_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
#> NULL
#> 
#> 
#> 
#> attr(,"class")
#> [1] "geo_list"

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

geo_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
#> NULL
#> 
#> 
#> 
#> attr(,"class")
#> [1] "geo_list"

Visualize your shapes with lawn.

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

map

Generate random WKT

Random point

wkt_point()
#> [1] "POINT (50.3923570 -70.3787919)"

Random linestring

wkt_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

wkt_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

  • Scott Chamberlain
  • Noam Ross
  • Samuel Bosch

Meta

  • Please report any issues or bugs.
  • License: MIT
  • Get citation information for randgeo in R doing citation(package = 'randgeo')
  • 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.

rofooter

Metadata

Version

0.3.0

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows