Skip to content

Instantly share code, notes, and snippets.

View geotheory's full-sized avatar

Robin Edwards geotheory

View GitHub Profile
@geotheory
geotheory / gist:1869673
Created February 20, 2012 15:28
Simplifying spatial polygons in R {rgeos}
library(rgeos)
data(wrld_simpl)
plot(wrld_simpl, col='white', bg='grey9', border=NA)
limx <- c(-6,1)
limy <- c(49,60)
plot(wrld_simpl, xlim=limx, ylim=limy, col='white', bg='grey9', border=NA)
# Apply RDP algorithm with distance variable = 0.4 degrees
@geotheory
geotheory / galaxy
Created March 17, 2012 13:22
Colliding galaxies in Processing
// Galaxy collisions
Star[] Stars;
PVector[] galp;
PVector[] galv;
color[] galcol, galcol2;
boolean paused = false;
int side = 100; // border around Stars' initial positions
int Startot = 300; // number of Stars
int obsize = 10; // size of Stars
@geotheory
geotheory / gist:2770618
Created May 22, 2012 18:03
Rotation problem
// Processing script to resolve a frame rotation problem
float zoom;
PVector a, b, pvec;
void setup()
{
size(800, 600, P3D);
a = new PVector(0.0, 0.0, 0.0);
b = new PVector(200.0, 400.0, -600.0);
@geotheory
geotheory / trees
Created May 26, 2012 13:05
3D trees
Branch[] trees;
int N = 5;
int Norig = N;
int ntrees = 10;
int area = 600;
boolean HD = false;
boolean HDswitch = false;
boolean levelswitch = false;
boolean levelup;
boolean spin = true;
@geotheory
geotheory / gist:4086735
Created November 16, 2012 11:57
Twitter data visualisation in Processing
// Data for this is available at https://dl.dropbox.com/u/46043231/data/twit.csv
String[][] allData;
int[][] grid;
int[][][] agGrid;
float[] count;
int[][] boxHeight;
int res = 35; // range from 20-50
float latmin = 51.2;
@geotheory
geotheory / index.html
Created March 26, 2013 16:15
Circles and text
<!DOCTYPE html>
<meta charset="utf-8">
<head>
<script src="http://d3js.org/d3.v3.min.js"></script>
<body>
<div id="viz"></div>
<div id="status" style="position:fixed; bottom:0; left:0;
color:white; background-color:darkgreen; font-size:small"></div>
<script type="text/javascript">
@geotheory
geotheory / stickman.pde
Created April 12, 2013 15:47
Processing stickman
// Code for a walking stickman
// by geotheory.co.uk (2013)
Stickman Stanley;
int grnd;
void setup() {
size(200, 200);
grnd = height-20;
frameRate(30);
smooth();
@geotheory
geotheory / 3d_mapping
Last active July 1, 2021 18:01
Plotting 3D maps using OpenStreetMap and RGL.
# Plotting 3D maps using OpenStreetMap and RGL. For info see:
# http://geotheory.co.uk/blog/2013/04/26/plotting-3d-maps-with-rgl/
map3d <- function(map, ...){
if(length(map$tiles)!=1){stop("multiple tiles not implemented") }
nx = map$tiles[[1]]$xres
ny = map$tiles[[1]]$yres
xmin = map$tiles[[1]]$bbox$p1[1]
xmax = map$tiles[[1]]$bbox$p2[1]
ymin = map$tiles[[1]]$bbox$p1[2]
@geotheory
geotheory / ggplot_hex.R
Last active January 28, 2021 17:16
ggplot2 functionality for mapping to hexagon size and colour aesthetics
#' GGPLOT2 FUNCTIONALITY FOR MAPPING TO HEXAGON SIZE AND COLOUR AESTHETICS
#' by Robin Edwards, 2013 (geotheory.co.uk, @geotheory)
#' This has been adapted from the ggplot bin_hex.R script that underpins geom_hex, etc
#' (see https://github.com/hadley/densityvis/blob/master/R/bin-hex.r).
#'
#' These functions implement aesthetic mapping to hexagon size (area), in addition to the existing
#' colour-mapping functionality. The key change is the addition of a new fourth variable (var4)
#' to hex_bin(), which complements the inbuilt hexagon binning functionality. The 'frequency.to.area'
#' argument enables the default mappings of binned data to colour and var4 to size to be interchanged.
#' The hmin/hmax arguments [0,1] set area mapping constraints (hmax can exceed 1).
@geotheory
geotheory / index.html
Last active December 26, 2015 05:29
Calibration-check points using Leaflet and D3
<!DOCTYPE html>
<html>
<head>
<title>Calibration-check points using Leaflet and D3</title>
<!-- Points are London O2 Arena, Washington Monument, Cape Town Stadium and the Sydney Opera House -->
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">