extractFields: extractFields

Description Usage Arguments Details Value Examples

View source: R/extractFields.R

Description

Extracts and vectorizes clumps of pixels with equal value within a raster object.

Usage

1
extractFields(x, method = "simple", smooth.x = FALSE)

Arguments

x

Object of class RasterLayer.

method

One of "simple" or "complex".

smooth.x

A logical argument.

Details

Assuming x is a classified or segmented image, this function segments it using ccLabel and, draws polygons for each group of connected pixels. The way polygons are drawn depends on the method keyword. The function will accept one of the following options:

The "simple" approach is a faster but it can lead to poor results when dealing with very complex shapes. For example, crop fields can be rectangular in which case the "simple" method is sufficient. On the other hand, forest belts can have irregular shapes, in which case the "complex" method is more appropriate. By default, the function will use all pixels associated to a region. However, if smooth.x is set to TRUE, for each region, the function will remove samples with less than 5 neighbors efectively removing isolated pixels along the edge of a region. The final output is a SpatialPolygonsDataFrame reporting on:

Value

A SpatialPolygonsDataFrame.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
{

require(raster)

# read raster data
r <- brick(system.file("extdata", "ndvi.tif", package="fieldRS"))

# spatial change labeling
or <- ccLabel(r, method="temporal", change.threshold=-50)$regions

# convert to polygons and plot (simple)
ef <- extractFields(or[10:30,10:30, drop=FALSE])
plot(ef)

# convert to polygons and plot (complex)
ef <- extractFields(or[10:30,1:30, drop=FALSE], method="complex")
plot(ef, border="red", add=TRUE)

# convert to polygons and plot (complex and smoothed)
ef <- extractFields(or[10:30,1:30, drop=FALSE], method="complex", smooth.x=TRUE)
plot(ef, border="blue", add=TRUE)

}

RRemelgado/fieldRS documentation built on June 5, 2020, 1:48 p.m.