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
davidheyman / get_tile_size.py
Created Nov 12, 2018
Get tile sizes from style-optimised vector tiles on Mapbox
View get_tile_size.py
import mercantile
import requests
import settings
def getStyle():
r = requests.get('https://api.mapbox.com/styles/v1/axismaps/' + 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
davidheyman / get_tiles.py
Created Nov 12, 2018 — forked from perrygeo/get_tiles.py
Get all map tiles for a geographic extent and zoom level(s)
View get_tiles.py
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
davidheyman / prep_rasters.py
Created Sep 24, 2018
A script to clumsily deal with GeoTIFF transparency and data types and convert to MBTiles
View prep_rasters.py
"""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/'
View chunk_contours.py
"""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."""
View shapefiles-to-vector-tiles.sh
# 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;
do
@davidheyman
davidheyman / mapshaper.sh
Last active Feb 1, 2017
MapMaster Data Processing Commands
View mapshaper.sh
# 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
View process-raster.sh
# create transparency band
for f in *tif;
do
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;
gdal_calc.py -A no.tif --outfile=mask.tif --calc="(A<=255)*255";
gdal_merge.py -separate -o ../ToCompress/$f red.tif green.tif blue.tif mask.tif;
sudo rm red.tif;
View cognita-setup.sh
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 https://github.com/axismaps/cognita.git
cp ~rails/rails_project/config/database.yml ~rails/cognita/config/
View bivariate-aal.sql
DROP VIEW IF EXISTS bivariate;
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
INNER JOIN (
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
INNER JOIN (
View keybase.md

Keybase proof

I hereby claim:

  • I am davidheyman on github.
  • I am davidheyman (https://keybase.io/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.