Split polygon into many

Share:

Description

Split polygon into many

Usage

1
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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)

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.