Skip to content

Instantly share code, notes, and snippets.

Jesse Crocker JesseCrocker

View GitHub Profile
@JesseCrocker
JesseCrocker / split-shapefile.py
Created Aug 25, 2015
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 Aug 26, 2015
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 Aug 26, 2015
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 / background.xml
Created Feb 18, 2014
Test mapnik with gdal driver using the GDAL_WMS driver with the TMS mini driver. On OS X this works correctly, on linux the background is always greyscale.
View background.xml
<GDAL_WMS>
<Service name="TMS">
<ServerUrl>http://otile1.mqcdn.com/tiles/1.0.0/sat/${z}/${x}/${y}.png</ServerUrl>
</Service>
<DataWindow>
<UpperLeftX>-20037508.34</UpperLeftX>
<UpperLeftY>20037508.34</UpperLeftY>
<LowerRightX>20037508.34</LowerRightX>
<LowerRightY>-20037508.34</LowerRightY>
<TileLevel>18</TileLevel>
@JesseCrocker
JesseCrocker / ViewController.m
Created Feb 28, 2014
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 Aug 29, 2015
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 Apr 3, 2014
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 Apr 17, 2014
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 Aug 29, 2015
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 / gdal_rounded_extent.py
Created May 7, 2014
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()
You can’t perform that action at this time.