Skip to content

Instantly share code, notes, and snippets.

View nvkelso's full-sized avatar

Nathaniel V. KELSO nvkelso

View GitHub Profile
@nvkelso
nvkelso / polygonize.py
Created September 27, 2012 04:34 — forked from migurski/polygonize.py
Polygonize a bag of lines
from sys import argv
from shapely.ops import polygonize
from shapely.geometry import asShape, LineString
import json
if __name__ == '__main__':
input = argv[1]
input = json.load(open(input))
@nvkelso
nvkelso / ogr_postgis.py
Created September 24, 2012 20:51
OGR in Python with PostGIS
from glob import glob
from os.path import dirname, basename, join
print 'psql -U username -c "TRUNCATE roads_skeletron"'
all_filenames = glob('tmp/*/???????-roads-z12.shp')
for (overall_index, filename) in enumerate(sorted(all_filenames)):
quad = basename(filename)[:7]
#!/bin/bash
# loop through all of the shapefiles in the directory and act on them
# http://trac.osgeo.org/gdal/wiki/FAQVector#HowcanImergehundredsofShapefiles
# http://stackoverflow.com/questions/965053/extract-filename-and-extension-in-bash
#USAGE:
# sh list_dir_of_shps.sh in_dir_path out_dir_path
#Capture the shell arguments
@nvkelso
nvkelso / gist:2898674
Created June 8, 2012 23:29
sqlite db for natural earth
zips/packages/natural_earth_vector.sqlite.zip:
#SQL-Lite
for shp in 10m_cultural/*.shp 10m_physical/*.shp 50m_cultural/*.shp 50m_physical/*.shp 110m_cultural/*.shp 110m_physical/*.shp; \
do \
ogr2ogr -f SQLite -append zips/packages/natural_earth_vector.sqlite $$shp; \
done
zip zips/packages/natural_earth_vector.sqlite.zip zips/packages/natural_earth_vector.sqlite VERSION README.md CHANGELOG
@nvkelso
nvkelso / ne_1d4_utf8_web_merc_900913
Created June 5, 2012 23:33
Natural Earth 1.4 UTF-8 + spherical mercator ZIPS
UTF-8 + spherical mercator.
http://cascadenik.teczno.com/data/ne-1.4/900913/admin_0_boundary_breakaway_disputed_areas_10m.zip
http://cascadenik.teczno.com/data/ne-1.4/900913/admin_0_boundary_breakaway_disputed_areas_50m.zip
http://cascadenik.teczno.com/data/ne-1.4/900913/admin_0_boundary_lines_land_10m.zip
http://cascadenik.teczno.com/data/ne-1.4/900913/admin_0_boundary_lines_land_50m.zip
http://cascadenik.teczno.com/data/ne-1.4/900913/admin_0_boundary_lines_land_110m.zip
http://cascadenik.teczno.com/data/ne-1.4/900913/admin_0_boundary_lines_map_units_10m.zip
http://cascadenik.teczno.com/data/ne-1.4/900913/admin_0_boundary_lines_maritime_indicator_10m.zip
http://cascadenik.teczno.com/data/ne-1.4/900913/admin_0_boundary_lines_maritime_indicator_50m.zip
@nvkelso
nvkelso / true-distance-to-shore.py
Created May 30, 2012 22:02 — forked from scw/true-distance-to-shore.py
Example using OGR and Shapely to compute true distances between geometries and points.
#!/usr/bin/env python
# distance_from_shore.py: compute true distance between points
# and closest geometry.
# shaun walbridge, 2012.05.15
# TODO: no indexing used currently, could stand if performance needs
# improving (currently runs in ~1.5hr for 13k points)
from geopy import distance
legend: #PctHomesInNegEquityOfMortgage
<span style="color: #e73a43">▉</span> 0.4 – 1.0 <br />
<span style="color: #ff7265">▉</span> 0.3 – 0.4 <br />
<span style="color: #ffac8f">▉</span> 0.2 – 0.3 <br />
<span style="color: #ffd8b0">▉</span> 0.1 – 0.2 <br />
<span style="color: #fff4e5">▉</span> 0.0 – 0.1 <br />
<span style="color: #cad8e5">▉</span> No data
@nvkelso
nvkelso / fieldpapers-bookmarklet.js
Created April 20, 2012 00:26 — forked from mapmeld/fieldpapers-bookmarklet.js
FieldPapers: experimental marker editor and tile inspector via bookmarklet
/*
Turns red dots on the Field Papers tiles into markers automatically
Write a description to save the marker
I don't understand the server-side installation or the QR-scanning, so I'm using a bookmarklet
Client-side HTML5 Canvas for tile inspection
*/
// collect the most zoomed-in tiles from the scan
var zoomimgs = document.getElementsByTagName("img");
var maxzoom = 0;
@nvkelso
nvkelso / GoogleMaps.js
Created March 6, 2012 00:52
Use Stamen's map tiles in your favorite mapping library, Google Maps version
// replace "toner" here with "terrain" or "watercolor"
var layer = "toner";
var map = new google.maps.Map(document.getElementById("element_id"), {
center: new google.maps.LatLng(37.7, -122.4),
zoom: 12,
mapTypeId: layer,
mapTypeControlOptions: {
mapTypeIds: [layer]
}
});
@nvkelso
nvkelso / OpenLayers.js
Created March 6, 2012 00:52
Use Stamen's map tiles in your favorite mapping library, OpenLayers version
// replace "toner" here with "terrain" or "watercolor"
var layer = new OpenLayers.Layer.Stamen("toner");
var map = new OpenLayers.Map("element_id");
map.addLayer(layer);