Skip to content

Instantly share code, notes, and snippets.

@dwtkns
dwtkns / google-earth-perspective-to-geojson.js
Last active October 1, 2017 20:20
OSAscript to output the footprint of what's visible in the current Google Earth Pro window as a geojson file
#!/usr/bin/env osascript -l JavaScript
// usage: google-earth-perspective-to-geojson.js xSamples ySamples > currentPerspective.geojson
function run(argv) {
var xSamples = argv[0] || 50;
var ySamples = argv[1] || 50;
var ge = Application('Google Earth Pro');
@dwtkns
dwtkns / copygeo.py
Last active November 12, 2015 03:35
Copies georeferencing information from one file to another via PAM .aux.xml files
#!/usr/bin/env python
# This script copies georeferencing information from one file to another that has none,
# via the creation of an .aux.xml file (so it should work with any image format).
# This is useful if, for example, you've edited a GeoTIFF in Photoshop,
# and saved the result as a JPG that you'd still like to be geo-aware for use
# with GDAL or QGIS.
# Requires GDAL command line tools, because re-making gdalbuildvrt in python
@dwtkns
dwtkns / closest_point_on_perimeter_of_rectangle.js
Created November 10, 2015 03:14
Finds the location on the perimeter of a given rectangle that is closest to a given point.
// translated from http://stackoverflow.com/questions/20453545/how-to-find-the-nearest-point-in-the-perimeter-of-a-rectangle-to-a-given-point
function clamp(n,lower,upper) {
return Math.max(lower, Math.min(upper, n));
}
function getNearestPointInPerimeter(l,t,w,h,x,y) {
var r = l+w,
b = t+h;
#docs-editor-container .kix-page-compact::before {
border-top: none;
}
@dwtkns
dwtkns / lockView.js
Created October 6, 2014 19:32
Lock viewport onto an element during resize
// Looks an element up by CSS selector and keeps it centered in the viewport on window resize
// Useful for testing responsive versions of specific DOM elements
// if jquery isn't loaded on the page, paste this code into the console first to load it:
var jqURL = 'http://code.jquery.com/jquery-latest.min.js';
var jqscript = document.createElement('script');
jqscript.type= 'text/javascript';
jqscript.src = jqURL;
document.head.appendChild(jqscript);
@dwtkns
dwtkns / README.md
Last active May 28, 2019 06:59
Sun and Earth

Experiments faking 3d rotation of a globe and sun in SVG. Illusion is helped by dynamic gradients, two nested orthographic projections, scaling the sun circle's radius based on distance from the 'camera', and toggling a clipping mask that makes the sun appear to move "behind" the earth.

Based on Mike Bostock's Solar Terminator and this past experiment.

This example stems from drafts of maps for Norway the Slow Way. Also see Mike's Pencil Sketch example.

@dwtkns
dwtkns / gist:2a6fb6f57850ef6e2829
Created August 7, 2014 13:41
Introductory D3 links
http://chimera.labs.oreilly.com/books/1230000000345/ (full book online)
https://www.dashingd3js.com/table-of-contents
http://vadim.ogievetsky.com/IntroD3/#1
http://www.jeromecukier.net/blog/2012/09/04/getting-to-hello-world-with-d3/
http://www.jeromecukier.net/blog/2013/03/05/d3-tutorial-at-strata-redux/
http://www.jeromecukier.net/blog/2012/05/28/manipulating-data-like-a-boss-with-d3/
http://www.jeromecukier.net/blog/2011/08/11/d3-scales-and-color/
http://blog.visual.ly/creating-animations-and-transitions-with-d3-js/
http://code.hazzens.com/d3tut/lesson_1.html
http://bost.ocks.org/mike/map/
@dwtkns
dwtkns / index.html
Created August 7, 2014 11:33
Simple D3 US Map
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.counties {
fill: none;
stroke: black;
opacity:0.2;
}
@dwtkns
dwtkns / l8_pansharp.sh
Created July 30, 2014 18:26
l8_pansharp
# These are shell functions to quickly create pansharpened RGB images ready for color correction
# from a set of raw Landsat 8 TIF files in a given directory.
# For example:
# l8_pansharp LC81690352014169LGN00
# Creates:
# LC81690352014169LGN00_rgb_pansharp.tif
# l8_rush_pansharp downloads a L8 tile from Google Storage (if they have it), extracts the relevant bands, then creates the pansharpened output.
@dwtkns
dwtkns / l8get
Last active October 1, 2017 20:19
A shell function to quickly grab the data for a given Landsat 8 tile ID from Google's servers
# This is a shell function to quickly grab the data for a given Landsat 8 tile ID from Google's servers
# For example:
# l8get LC81690352014169LGN00
# The echo at the end is to remind myself of the syntax for extracting bands 8, 4, 3, and 2. (Pansharp, Red, Green, Blue)
# On OSX this would go into your ~/.bash_profile file.
# Requires gsutil from https://developers.google.com/storage/docs/gsutil_install
# Most useful in conjunction with USGS' Earth Explorer: http://earthexplorer.usgs.gov/