Skip to content

Instantly share code, notes, and snippets.

Matthew Perry perrygeo

View GitHub Profile
extern crate byteorder;
extern crate itertools;
extern crate rustfft;
use byteorder::{LittleEndian, ReadBytesExt};
use num_complex::Complex;
use rustfft::num_traits::Zero;
use rustfft::FFTplanner;
use std::fs::File;
use std::io::Seek;
from h3 import h3
import json
from rasterstats import gen_zonal_stats
def hexbin_features(bounding_polygon, zoom=8):
"""Takes a GeoJSON-like geometry dictionary with type Polygon
and yields GeoJSON-like Features representing the hexbins
that cover the polygon at a given zoom level
#!/usr/bin/env python
from fiona.transform import transform_geom
from rasterstats import point_query
import mercantile
def make_dem_url(lon: float, lat: float, z: int = 14) -> str:
"""Returns a URL referencing the GeoTiff Digitial Elevation Model (DEM)
for the given point at a zoom level (default, max is 14).

Installing pgextwlist

# Dockerfile
RUN wget -q -O pgextwlist-${PGEXTWLIST_VERSION}.tar.gz${PGEXTWLIST_VERSION}.tar.gz
RUN tar -xzf pgextwlist-${PGEXTWLIST_VERSION}.tar.gz && \
    cd pgextwlist-${PGEXTWLIST_VERSION} && \
    make -j${CPUS} && make install && \
    export pkg=$(pg_config --pkglibdir) && mkdir $pkg/plugins && cp $pkg/ $pkg/plugins
perrygeo / output_cHOUF3.gif
Last active Sep 7, 2018
transform_geom warping bug, sensitivity to central meridian
perrygeo /
Last active Jun 14, 2018
Tiled=true fails silently
#!/usr/bin/env python
from pprint import pprint
from functools import reduce
import operator
import numpy as np
from affine import Affine
from import CRS
import rasterio
import random
import time
import json
import threading
import click
def send_message(msg, async=True):
"""Logs the message to an output stream.
perrygeo /
Created Mar 20, 2018
Decorator to log all call parameters and return values for a function
import sys
def log_calls(fh=sys.stderr):
"""Logs the function, args, kwargs and return value to a file handle
def decorator(func):
def wrapper(*args, **kwargs):
retval = func(*args, **kwargs)
print(func, args, kwargs, retval, file=fh)
perrygeo / Dockerfile
Last active Apr 8, 2020
Minimal debian image with Python 3.6 and geo python tools
View Dockerfile
FROM python:3.6-slim-stretch
ADD requirements.txt /tmp/requirements.txt
RUN apt-get update && \
apt-get install -y \
build-essential \
make \
gcc \
locales \
perrygeo /
Last active Jan 9, 2018
Decorator for aliasing kwargs in Python functions
#!/usr/bin/env python
import warnings
from functools import wraps
def deprecated_kwarg(old, new, version):
def decorator(func):
def func_wrapper(*args, **kwargs):
new_kwargs = kwargs.copy()
You can’t perform that action at this time.