geoaxe
helps you split geospatial objects into pieces. It includes support for
spatial object inputs (e.g., SpatialPolygons
), Well-Known Text (WKT), and GeoJSON
(character and list).
But, Why?
The use case we have at rOpenSci is that often web APIs accept WKT, but the WKT string can only be so long. If the string is longer than allowed by a web API, then one option is to split up the WKT string into many, and do a request on each one of those.
Surely there are other use cases for splitting up geospatial objects :)
Install from CRAN
install.packages("geoaxe")
Or install the development version from GitHub
devtools::install_github("ropenscilabs/geoaxe")
Load geoaxe
(as well as sp
and rgeos
)
library("geoaxe") library("sp") library("rgeos")
Works for SpatialPolygons
and SpatialPolygonsDataFrame
for now, may include other classes later
wkt <- "POLYGON((-180 -20, -140 55, 10 0, -140 -60, -180 -20))" poly <- rgeos::readWKT(wkt) polys <- chop(x = poly)
Plot original polygon
plot(poly, lwd = 6)
Add chopped up polygon bits
plot(polys, add = TRUE)
wkt <- "POLYGON((-180 -20, -140 55, 10 0, -140 -60, -180 -20))" plot(chop(wkt))
plots go left to right, then down, and repeat
layout(matrix(c(1,2,3,4), 2, 2, byrow = TRUE)) par(mar = c(1, 0, 1, 0)) plot(chop(wkt, n = 10)) plot(chop(wkt, n = 15)) plot(chop(wkt, n = 20)) plot(chop(wkt, n = 50))
plots go left to right, then down, and repeat
layout(matrix(1:8, 4, 2, byrow = TRUE)) par(mar = c(1, 0, 1, 0)) plot(chop(wkt, size = 2)) plot(chop(wkt, size = 4)) plot(chop(wkt, size = 8)) plot(chop(wkt, size = 15)) plot(chop(wkt, size = 25)) plot(chop(wkt, size = 50)) plot(chop(wkt, size = 100)) plot(chop(wkt, size = 200))
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.