Skip to content

Instantly share code, notes, and snippets.

@simbamangu
simbamangu / rastertest.R
Created January 17, 2012 07:22
Test of raster formats
for (i in 1:10) {
kid.img <- system.time(dem <- raster("~/workspace/TEMP/kideporegion.img"))
kid.asc <- system.time(dem <- raster("~/workspace/TEMP/kideporegion.asc"))
kid.tiffdeflate <- system.time(dem <- raster("~/workspace/TEMP/kideporegion_deflate.tif"))
kid.tiffnone <- system.time(dem <- raster("~/workspace/TEMP/kideporegion_none.tif"))
kid.tif <- system.time(dem <- raster("~/workspace/TEMP/kideporegion.tif"))
kid.tifpack <- system.time(dem <- raster("~/workspace/TEMP/kideporegion_pack.tif"))
kid.times <- data.frame(as.list(kid.img))
kid.times[2,] <- as.list(kid.asc)
@simbamangu
simbamangu / file1.r
Created January 17, 2012 07:26
Custom median / normal
# set.seed(42)
X = 25
Y = 26
N = 100
set.sd = 5
set <- rnorm(N, Y, set.sd)
set.left <- set[set < X]
set <- c(set.left, X + (X - set.left))
@simbamangu
simbamangu / read_GDocs_tzdata.R
Created January 29, 2012 14:59
Reading mobile internet data for Tanzania from GDocs and examining in R
# RCurl needed for Google Docs access.
require(RCurl)
# The URL obtained by File|Publish to web then select csv:
u <- "https://docs.google.com/spreadsheet/pub?hl=en_GB&hl=en_GB&
key=0AmFzIcfgCzGFdHQ0eEU0MWZWV200RjgtTXVMY1NoQVE
&single=true&gid=4&output=csv"
con <- getURL(u, ssl.verifypeer=FALSE)
i <- read.csv(textConnection(con)) # Read the file.
@simbamangu
simbamangu / ExifTool geotagging and databasing.md
Last active January 31, 2022 10:49
Geotag folder with ExifTool

Geotagging with ExifTool and a tracklog

This is a brief guide to using ExifTool to geotag a folder of images.

  • On OSX: get ExifTool with Homebrew: brew install exiftool
  • Ubuntu/Mint: sudo apt install exiftool
  • On Windows: download from the ExifTool website. Replace exiftool with exiftool.exe in the examples here!

Example:

@simbamangu
simbamangu / Poly2Lines_rmdup_2Poly.model3
Created June 6, 2018 13:20
QGIS3 processing model to convert polygon to lines, break at intersections, remove duplicates and polygonize
<!DOCTYPE model>
<Option type="Map">
<Option type="Map" name="children">
<Option type="Map" name="grass7:v.clean_1">
<Option type="bool" value="true" name="active"/>
<Option name="alg_config"/>
<Option type="QString" value="grass7:v.clean" name="alg_id"/>
<Option type="QString" value="v.clean - Toolset for cleaning topology of vector map." name="component_description"/>
<Option type="double" value="157" name="component_pos_x"/>
<Option type="double" value="185" name="component_pos_y"/>
# Run in QGIS
# Save all the layouts as PNG files from the current project.
outurl = '/Users/USERNAME/' # using ~ does not work?
outformat = '.png'
outdpi = 200
manager = QgsProject.instance().layoutManager()
for layout in manager.printLayouts():
print('Saving: ' + layout.name())
layout = manager.layoutByName(layout.name())
@simbamangu
simbamangu / mvuuid.sh
Created April 27, 2020 13:06
Rename a file with UUID and extension
#!/bin/bash
# Rename a file with a UUID, preserve the extension.
# Usage:
# mvuuid.sh TEST.JPG
# Output example:
# 887D830A-AE74-4835-8990-760908125E0B.JPG
mv $FILE `uuidgen`."${FILE##*.}"
@simbamangu
simbamangu / mvuuid.sh
Last active May 11, 2020 18:10
Rename a file with UUID and extension
#!/bin/bash
# Rename a file with a UUID, preserve the extension.
# Usage:
# mvuuid.sh TEST.JPG
# Output example:
# 887D830A-AE74-4835-8990-760908125E0B.JPG
mv $1 `uuidgen`."${1##*.}"
@simbamangu
simbamangu / cpyNsubfolder.sh
Last active February 11, 2021 08:27
Copy 'n' files to subfolder
# Copy 'n' files to subfolder
# Usage:
# cpn.sh N DEST
# Copies 'N' files to destination folder DEST
ls | sort | head -n $1 | xargs cp "{}" -t $2