Skip to content

Instantly share code, notes, and snippets.

View nvkelso's full-sized avatar

Nathaniel V. KELSO nvkelso

View GitHub Profile
@nvkelso
nvkelso / indexShapefile.py
Created November 16, 2012 21:45 — forked from williamscraigm/indexShapefile.py
Build a spatial index for all shapefiles in a directory with ArcGIS
import arcpy
from arcpy import env
import os
# Set the workspace for the ListFeatureClass function
#
env.workspace = "C:\\data\\mydata"
# Use the ListFeatureClasses function to return a list of
# all shapefiles.
@nvkelso
nvkelso / size_order.sql
Created October 24, 2012 01:54 — forked from andrewxhill/size_order.sql
Order polygons by size/height
WITH RECURSIVE dims AS (SELECT 2*sqrt(sum(ST_Area(the_geom))) as d, sqrt(sum(ST_Area(the_geom)))/20 as w, count(*) as rows FROM osm_export_polygon WHERE the_geom IS NOT NULL),
geoms AS (SELECT the_geom, ST_YMax(the_geom)-ST_YMin(the_geom) as height FROM osm_export_polygon WHERE the_geom IS NOT NULL ORDER BY ST_YMax(the_geom)-ST_YMin(the_geom) DESC),
geomval AS (SELECT the_geom, row_number() OVER (ORDER BY height DESC) as id from geoms),
positions(the_geom,x_offset,y_offset,new_row,row_offset) AS (
(SELECT the_geom, 0.0::float, 0.0::float, FALSE, 2 from geomval limit 1)
UNION ALL
(
SELECT
(SELECT the_geom FROM geomval WHERE id = p.row_offset),
CASE WHEN
@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 / 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
@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 / countTiles.py
Created March 1, 2012 22:04 — forked from andrewharvey/countTiles.py
Given a WGS84 bounding box and an OSM tile zoom range calculates a total number of tiles and how much the Amazon Cloud will cost ya.
#!/usr/bin/python
# README
#
# This script is from: https://gist.github.com/1953554
# By Nathaniel Vaughn Kelso and Mike Migurski @ Stamen
#
# Based on script by andrewharvey: https://gist.github.com/1675606
#
# This script should be considered CC0 licensed