chop: Split polygon into many

View source: R/chop.R

chopR Documentation

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

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)

ropenscilabs/geoaxe documentation built on May 18, 2022, 7:38 p.m.