Skip to content

Instantly share code, notes, and snippets.

# Converting coordinates from DMS or DdM formats to decimal
# DMS = "degrees minutes seconds"; DdM = "degrees decimal minutes"
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dg2dec <- function(varb, Dg=NA, Min=NA, Sec=NA, SW.Hemisphere="S|W") {
# Dg=decimal, Min=minutes and Sec=seconds;
# NOTE 1 - if the format is "degrees decimal minutes - DdM" (e.g. 40° 26.767′ N) and not
# "degrees minutes seconds - DMS" (e.g. 40° 26′ 46″ N), then call the function only with
# Dg and Min arguments, like dg2dec(varb, Dg="°", Min="′N").
# Same applies when there is no seconds symbol (e.g. 45°12'7.38).
# Note that one should not use blank spaces in Dg, Min or Sec arguments (will return NA).
@adamkc
adamkc / PunchCulverts.r
Last active October 22, 2024 17:59
Punch culverts through roads in LiDAR or DEMs using R
#Load Packages and data files:
library(sf)
library(terra)
library(tidyverse)
#Function:
PunchCulverts <- function(
rasterFile = "raster/DEM.tif",
culvertFile = "vector/culverts.shp",
newRasterFile = "raster/DEM_punched.tif"
@adamkc
adamkc / textExtraction.r
Last active November 4, 2022 16:35
Extract Reconyx text (temperature, date, timelapse/motion) from images.
library(magick)
library(tesseract)
library(tidyverse)
white <- image_read("C:/Users/adamcummings/Box/01. adam.cummings Workspace/Childs Camera Traps/white.png")
get_temperature <- function(image){
#crop:
crop <- image_crop(image, "75x32+1880") %>%
@adamkc
adamkc / allTauDEM
Last active May 8, 2024 18:53
Run All TauDEM functions at once
library(terra)
library(shapefiles)
allTaudem <- function(rasterDir="dir/dir2",
rasterName="raster.tif",
shortName = "auto",
threshold = .01, # either <1 it calculates as a percent of the max accum cell or >1 as the accum threshold
saveHillshade=FALSE,
quiet=TRUE){
oldWD <- getwd()