Skip to content

Instantly share code, notes, and snippets.

Avatar

Jesse Crocker JesseCrocker

View GitHub Profile
@JesseCrocker
JesseCrocker / split-shapefile.py
Created August 25, 2015 23:24
Split a shapefile into many spatialite files based on TMS tiling
View split-shapefile.py
#!/usr/bin/env python
import logging
from optparse import OptionParser
import os
import mercantile
import subprocess
def split_file(source_path, dest_dir, zoom, mercator=False):
for x in range(0, pow(2, zoom)):
@JesseCrocker
JesseCrocker / contour_workflow.md
Last active August 26, 2015 02:32
Workflow for generating contour lines, in progress
View contour_workflow.md

This document is a work in progress, and outlines my new workflow for generating contour lines.

Prep:

Load metadata for all available DEMs into into postgis. More on this later.

Prepare coastline data

Goal of this step is to get a series of polygons that can be used for intersection queries to determine if a contour is adjacent to the coastline.

Download OSM coastlines wget http://data.openstreetmapdata.com/coastlines-split-3857.zip

@JesseCrocker
JesseCrocker / macSetup.sh
Created August 26, 2015 21:29
Setup virtual env and install packages
View macSetup.sh
#!/bin/bash
[ $SHLVL = 2 ] && echo "Usage: . ${0##*/}" && exit
VIRTUALENVNAME=contours
if [ ! -d ~/python/$VIRTUALENVNAME ]
then
test -e ~/python || mkdir ~/python
pushd .
cd ~/python
@JesseCrocker
JesseCrocker / ViewController.m
Created February 28, 2014 00:26
Which is faster [[NSFileManager defaultManager] fileExistsAtPath:file] or access([file UTF8String], R_OK), access() wins by 10%
View ViewController.m
//
// file existance test
//
// Created by Jesse Crocker on 2/27/14.
//
#import "ViewController.h"
@interface ViewController ()
@JesseCrocker
JesseCrocker / mvt-tile-info.py
Last active August 29, 2015 13:57
Convert mapnik vector tiles to GeoJSON. This code has been updated and moved to https://github.com/mapbox/vector-tile-py/blob/master/tile-info.py
View mvt-tile-info.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# By Jesse Crocker
# Convert mapnik vector tiles to geojson
# Based on https://github.com/mapbox/mapnik-vector-tile/blob/master/python/renderer.py
from __future__ import print_function
import sys
@JesseCrocker
JesseCrocker / S3DownloadStatus.java
Created April 3, 2014 17:02
Downloading files from S3 on android using the AmazonS3Client. This code is not complete, and references a bunch of private classes, but you should be able to adapt it easy enough. The SntpClient refereced is from http://stackoverflow.com/questions/9466342/get-data-from-the-internet-android
View S3DownloadStatus.java
package com.trailbehind.downloads;
import android.util.Log;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.model.GetObjectMetadataRequest;
import com.amazonaws.services.s3.model.GetObjectRequest;
import com.amazonaws.services.s3.model.ObjectMetadata;
import com.amazonaws.services.s3.model.S3Object;
import com.crashlytics.android.Crashlytics;
@JesseCrocker
JesseCrocker / RMProjection.h
Created April 17, 2014 23:51
Objective-C wrapper for proj-4, it doesn't do a lot, just forward and inverse projection for 2d coordinates. This code originated in Route-Me, but has been fixed so it actually works.
View RMProjection.h
//
// RMProjection.h
//
// Copyright (c) 2008-2009, Route-Me Contributors
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this
@JesseCrocker
JesseCrocker / average-file-size
Last active August 29, 2015 14:01
Count and find average size of files in a dir
View average-file-size
#!/bin/bash
if [ $# -eq 0 ]
then
DIR=`pwd`
else
DIR=$1
fi
echo Directory $DIR
find -x $DIR -type f -exec sh -c 'stat -f '%z' "${@}"' _ '{}' + |
@JesseCrocker
JesseCrocker / buildContours.sh
Created May 7, 2014 00:14
Script for processing NED 1/3 arc second DEMs into contour lines
View buildContours.sh
#!/bin/bash
FEET=true
DELETE_CONVERTED=true
DROP_INTERMEDIATE_TABLE=true
CLIP=true
DB=gis
USER=jesse
HOST=localhost
@JesseCrocker
JesseCrocker / gdal_rounded_extent.py
Created May 7, 2014 00:10
Get extent of a raster rounded to nearest degree. Usefull in shell scripts for clipping DEMs with overlap pixels
View gdal_rounded_extent.py
#!/usr/bin/env python
from osgeo import gdal, ogr, osr
import sys
import logging
from optparse import OptionParser
import os
gdal.UseExceptions()