Skip to content

ReneHeim/FUN_extract_polyclass

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Instructions

This repository contains a single function that can be sourced in your R environment. The function extract digital values from a single or multi layer raster file (e.g. geotiff) and produces a data frame containing a class column (Class: Factor) and one or multiple predictor columns (Band1: num, Band2: num, ...), depending on the number of layers that the raster file contains. The final dataframe can be used for subsequent statistical analysis in R, such as land cover classification.

NOTE: The class column is created based on the attribute table that you probably created using a GIS software. The attribute table lists e.g. polygons that define your land cover classes. You must name the columns in your attribute table id and Class for the function to work.

How to use

install.packages(c("raster"))

source("FUN_extract_polyclass.R")

  img <- brick("data/rasterfile")
  shp <- shapefile("data/shapefile.shp")

testdf <- extract_polyclass(shp, img)

Thank you

If you find the function useful, please give it a "Star" and tell others. Let me know if there is room for improvement (there always is). Cheers, René

About

A function to extract pixel values from raster images according to a user-defined polygon layer

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages