Skip to content

Instantly share code, notes, and snippets.

@jlehtoma
Created August 27, 2012 10:55
Show Gist options
  • Save jlehtoma/3487445 to your computer and use it in GitHub Desktop.
Save jlehtoma/3487445 to your computer and use it in GitHub Desktop.
Aggreagate with majority
library(raster)
# HUOM! Kaikissa hakemistopoluissa pitää Windows-kenoviiva korvata normikenoviivalla
# esim. C:\Kansio\tiedosto.txt -> C:/Kansio/tiedosto.txt
workspace <- "[KANSIO-JOSSA-LAHTORASTERIT]"
# Oletus: rasterit ovat yllä mainitussa kansiossa
org.raster.file <- "[ALKUPERAISEN-RASTERIN-NIMI]"
agg.raster.file <- "[AGGREGOIDUN-RASTERIN-NIMI]"
setwd(workspace)
custom.modal <- function(x, ...) {
return(modal(x, ties="highest", ...))
}
org.raster <- raster(org.raster.file)
(aggregate(org.raster, fact=3, fun=custom.modal,
filename=agg.raster.file, option=c("COMPRESS=YES")))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment