Skip to content

Instantly share code, notes, and snippets.

Matthew Perry perrygeo

View GitHub Profile
View iq-fft-experiment.rs
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;
View hexbin_population.py
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
View elevation_query.py
#!/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).
View pgextwlist.md

Installing pgextwlist

# Dockerfile
ENV PGEXTWLIST_VERSION 1.7
RUN wget -q -O pgextwlist-${PGEXTWLIST_VERSION}.tar.gz https://github.com/dimitri/pgextwlist/archive/v${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/pgextwlist.so $pkg/plugins
@perrygeo
perrygeo / output_cHOUF3.gif
Last active Sep 7, 2018
transform_geom warping bug, sensitivity to central meridian
@perrygeo
perrygeo / tiled_assert.py
Last active Jun 14, 2018
Tiled=true fails silently
View tiled_assert.py
#!/usr/bin/env python
from pprint import pprint
from functools import reduce
import operator
import numpy as np
from affine import Affine
from rasterio.crs import CRS
import rasterio
View send_message.py
import random
import time
import json
import threading
import click
def send_message(msg, async=True):
"""Logs the message to an output stream.
@perrygeo
perrygeo / log_calls.py
Created Mar 20, 2018
Decorator to log all call parameters and return values for a function
View log_calls.py
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
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
perrygeo / deprecated_kwarg.py
Last active Jan 9, 2018
Decorator for aliasing kwargs in Python functions
View deprecated_kwarg.py
#!/usr/bin/env python
import warnings
from functools import wraps
def deprecated_kwarg(old, new, version):
def decorator(func):
@wraps(func)
def func_wrapper(*args, **kwargs):
new_kwargs = kwargs.copy()
You can’t perform that action at this time.