Skip to content

Instantly share code, notes, and snippets.

View ForrestStevens's full-sized avatar

Forrest R. Stevens ForrestStevens

View GitHub Profile
@ashenkin
ashenkin / make_elevation_profile_swaths.r
Last active March 18, 2016 15:31
You have a digital elevation model (DEM), and you want to make an elevation profile between two or more points. You want that elevation profile to reflect an average elevation across a swath, and not just a single point from a line. Here's one way to do it in R. Thanks to Forrest Stevens and other folks from the R-sig-geo list.
# Thanks to Forrest Stevens. Some of the code here borrowed from him here: https://github.com/ForrestStevens/Scratch/blob/master/swath_slices.R
library(raster)
library(rgdal)
library(sp)
library(rgeos)
library(gtools)
library(ggplot2)
library(plyr)
library(zoo)
@etiennebr
etiennebr / as.data.table.r
Last active November 13, 2023 11:24
Transform raster or terra object to data.table
#' Transform raster to data.table
#'
#' @param x Raster* object
#' @param row.names `NULL` or a character vector giving the row names for the data frame. Missing values are not allowed
#' @param optional logical. If `TRUE`, setting row names and converting column names (to syntactic names: see make.names) is optional
#' @param xy logical. If `TRUE`, also return the spatial coordinates
#' @param centroids logical. If TRUE return the centroids instead of all spatial coordinates (only relevant if xy=TRUE)
#' @param sepNA logical. If TRUE the parts of the spatial objects are separated by lines that are NA (only if xy=TRUE and, for polygons, if centroids=FALSE
#' @param ... Additional arguments (none) passed to `raster::as.data.frame`
#'