Skip to content

Instantly share code, notes, and snippets.

David Heyman davidheyman

Block or report user

Report or block davidheyman

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
davidheyman /
Created Nov 12, 2018
Get tile sizes from style-optimised vector tiles on Mapbox
import mercantile
import requests
import settings
def getStyle():
r = requests.get('' + settings.MAPBOX_STYLE + '?access_token=' + settings.MAPBOX_TOKEN)
return r.json()['modified']
def download_tile(tileurl, tile, modified):
url = tileurl + '/{z}/{x}/{y}.mvt'.format(**tile.__dict__)
davidheyman /
Created Nov 12, 2018 — forked from perrygeo/
Get all map tiles for a geographic extent and zoom level(s)
from __future__ import print_function
import mercantile
import urllib
import time
import os
def download_tile(tileurl, tile, output_dir, pause=1):
url = tileurl + '/{z}/{x}/{y}.png'.format(**tile.__dict__)
local_path = url.replace(tileurl, output_dir)
davidheyman /
Created Sep 24, 2018
A script to clumsily deal with GeoTIFF transparency and data types and convert to MBTiles
"""Deal with raster transparency and convert to MBTiles"""
import os
import re
from string import Template
from shutil import copyfile
from osgeo import gdal
import rasterio
PATH = 'data/geotiff/'
"""Splits rasters into chunks and creates contours"""
import os
import argparse
import uuid
import re
from osgeo import gdal
def chunk():
"""Splits rasters into 5000 x 5000 chunks."""
# Install Mapshaper
npm install -g mapshaper
# Install Tippecanoe
brew install tippecanoe
# Make a directory for your geojson files and convert all the shapefiles in a directory to geojson
mkdir ../geojson
for f in *.shp;
davidheyman /
Last active Feb 1, 2017
MapMaster Data Processing Commands
# Convert shp to topjson and simplify
mapshaper -i /Volumes/Storage/Box\ Sync/MapMaster\ data/World/Physical\ Environment/Vector/005_Water_Resources_Vulnerability/005_Water_Resources_Vulnerability.shp -simplify 5% -o data/world/005_water_resources.json format=topojson
# Load shapefiles in subdirectories into PostGIS
for f in *; do cd $f; for g in *.shp; do shp2pgsql -I -s 4326 $g `basename $g .shp` | psql -d mapmaster; cd ../; done; done
# create transparency band
for f in *tif;
gdal_translate -b 1 -ot Byte $f red.tif;
gdal_translate -b 2 -ot Byte $f green.tif;
gdal_translate -b 3 -ot Byte $f blue.tif;
gdal_translate -a_nodata none $f no.tif; -A no.tif --outfile=mask.tif --calc="(A<=255)*255"; -separate -o ../ToCompress/$f red.tif green.tif blue.tif mask.tif;
sudo rm red.tif;
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install -y postgis postgresql-9.3-postgis-2.1 imagemagick
cd ~rails
git clone
cp ~rails/rails_project/config/database.yml ~rails/cognita/config/
View bivariate-aal.sql
CREATE VIEW bivariate AS
SELECT gid, gdp, pop, aal_gdp, aal_pop, aal_gdp / gdp AS gdp_pct, aal_pop / pop AS pop_pct, geom
FROM admin1
SELECT aal AS aal_gdp, wb_adm1_co
FROM flood
WHERE analysis_sector = 'GDP' AND year = 2010
) AS fl ON admin1.adm1_code = fl.wb_adm1_co

Keybase proof

I hereby claim:

  • I am davidheyman on github.
  • I am davidheyman ( on keybase.
  • I have a public key whose fingerprint is E39B FE40 D15B 962B 189E 8C5C F0F2 DE54 5DED 409D

To claim this, I am signing this object:

You can’t perform that action at this time.