Skip to content

Instantly share code, notes, and snippets.

View sgillies's full-sized avatar

Sean Gillies sgillies

View GitHub Profile
@sgillies
sgillies / about.md
Last active April 24, 2021 21:57
Rasterio example

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@sgillies
sgillies / README.md
Last active April 6, 2020 12:53
Get raster value at a point using a tiny window

A Rasterio dataset's index() method gives you the row, col index of the pixel containing the point x, y (in the dataset's CRS units).

Define a 1x1 pixel read window starting at that index (see the tiny_window() function below) and use it to read an ndarray. The one in this case has shape (3, 1, 1): 3 bands, 1 row, and 1 column. The values of the 3 bands at the point x, y for this case are 28, 29, and 27.

# 15 statement in this Fiona script, 12 after I move the prop_type function to Fiona.
# Compare to 31 statements for the ogr.py script at
# http://pcjericks.github.io/py-gdalogr-cookbook/layers.html#create-a-new-shapefile-and-add-data.
# The difference is that Fiona's schema and feature definition are declarative (using dict
# literals and comprehensions, not imperative (CreateField, SetField, etc) and that Fiona
# is designed to allow concise code.
from csv import DictReader
import fiona
from fiona.crs import from_epsg
@sgillies
sgillies / latency.txt
Created October 19, 2016 11:54 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@sgillies
sgillies / benchmark.py
Last active February 7, 2019 01:02
GeoJSON: json vs msgpack vs shapely.wkb vs geobuf
# Comparing serialization of complex GeoJSON geometries using:
#
# - standard lib json, marshal, pickle, cPickle
# - umsgpack
# - shapely.wkb
# - geobuf (protobuf)
#
# The test case is a nearly circular polygon with 128 vertices.
#
# Python 2.7 because geobuf isn't possible on Python 3 (because
@sgillies
sgillies / gist:3503994
Created August 28, 2012 20:38
unary_union.ipynb
{
"metadata": {
"name": "Unary union example"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
{"geometry": {"coordinates": [[[-111.73527526855469, 41.995094299316406], [-111.65931701660156, 41.99627685546875], [-111.6587142944336, 41.9921875], [-111.65888977050781, 41.95676803588867], [-111.67082977294922, 41.91230010986328], [-111.67332458496094, 41.905494689941406], [-111.67088317871094, 41.90049362182617], [-111.66474914550781, 41.893211364746094], [-111.6506576538086, 41.875465393066406], [-111.64759826660156, 41.87091827392578], [-111.64640808105469, 41.86273956298828], [-111.64334869384766, 41.858192443847656], [-111.63720703125, 41.85499572753906], [-111.633544921875, 41.847267150878906], [-111.63053894042969, 41.83409118652344], [-111.6330337524414, 41.82728576660156], [-111.63983154296875, 41.8227653503418], [-111.6484603881836, 41.82188034057617], [-111.66077423095703, 41.82327651977539], [-111.6712417602539, 41.82330322265625], [-111.67618560791016, 41.82013702392578], [-111.68803405761719, 41.78792953491211], [-111.69361114501953, 41.77931594848633], [-111.70162200927734, 41.77797317504883
@sgillies
sgillies / GNU parallel vs concurrent.futures console
Last active March 30, 2017 20:41
Python concurrency benchmarks
vas-y:parallelz seang$ time parallel wc ::: `find ~/writing/blog/2013 -name *.rst`
18 128 791 /Users/seang/writing/blog/2013/10/07/downgrading-my-blog.rst
106 567 4011 /Users/seang/writing/blog/2013/10/08/linking-geojson.rst
34 249 1586 /Users/seang/writing/blog/2013/10/24/joining-mapbox.rst
70 373 2910 /Users/seang/writing/blog/2013/11/24/introducing-rasterio.rst
14 45 395 /Users/seang/writing/blog/2013/12/02/geojson-website-refreshed.rst
25 158 1256 /Users/seang/writing/blog/2013/12/03/atom-extension-for-tinkerer.rst
16 74 627 /Users/seang/writing/blog/2013/11/27/new-home-on-github-for-geojson.rst
143 685 6211 /Users/seang/writing/blog/2013/12/04/json-diff-and-patch-for-geojson.rst
26 202 1237 /Users/seang/writing/blog/2013/12/05/first-blog-post-at-mapbox.rst
@sgillies
sgillies / build.sh
Last active March 7, 2017 01:45
Building GDAL and friends for inclusion in Rasterio binary wheels
#!/bin/bash
export MACOSX_DEPLOYMENT_TARGET=10.6
export ARCHFLAGS="-arch i386 -arch x86_64"
# GEOS from source.
cd ~/work/geos-3.4.2
./configure CFLAGS="-Os -arch i386 -arch x86_64" CXXFLAGS="-Os -arch i386 -arch x86_64" LDFLAGS="-arch i386 -arch x86_64"
make clean
make