geoaxe (version 0.1.0)

chop: Split polygon into many

Description

Split polygon into many

Usage

chop(x, size = 10, n = 20)

Arguments

x
Spatial object
size
size of each side of each cell, which makes a square cell
n
number of cells to make in each dimension, same number used for each dimension

Details

Works on spatial classes of type SpatialPolygons, Well-Known Text character strings, and GeoJSON character strings and lists

Examples

Run this code
library("rgeos")
wkt <- "POLYGON((-180 -20, -140 55, 10 0, -140 -60, -180 -20))"

# SpatialPolygons input
poly <- readWKT(wkt)
plot(poly)
polys <- chop(x = poly)
to_wkt(polys)
to_wkt(polys)[[2]]
plot(polys)
plot(poly, add = TRUE, lwd = 6)

# SpatialPolygonsDataFrame input
class(poly)
polydf <- as(poly, "SpatialPolygonsDataFrame")
class(polydf)
chop(polydf)

# WKT character input
chop(wkt)

# geojson character input
file <- system.file("examples", "sample1.geojson", package = "geoaxe")
x <- readLines(file)
chop(x)

# geojson json input
x <- structure(x, class = "json")
chop(x)

Run the code above in your browser using DataCamp Workspace