Skip to content

Instantly share code, notes, and snippets.

View sgillies's full-sized avatar

Sean Gillies sgillies

View GitHub Profile
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
{"features": [{"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.
@sgillies
sgillies / nb.ipynb
Created February 15, 2015 22:37
Descartes polygon holes -- orientation is important
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@sgillies
sgillies / union.py
Created February 4, 2015 21:38
unary union
>>> from shapely.ops import unary_union
>>> from shapely.geometry import shape
>>> unary_union([shape(g) for g, v in shapes(red, mask=(red < 250))])
<shapely.geometry.multipolygon.MultiPolygon object at 0x107c1b5d0>
>>> unary_union([shape(g) for g, v in shapes(red, mask=(red < 10))])
<shapely.geometry.multipolygon.MultiPolygon object at 0x105844310>
>>> import shapely
>>> print shapely.geos.geos_version
(3, 4, 2)
@sgillies
sgillies / features.py
Created February 4, 2015 21:20
Extracting characters from a PNG
$ rio insp ~/Desktop/logo.png Rasterio 0.17.1 Interactive Inspector (Python 2.7.9)
Type "src.meta", "src.read_band(1)", or "help(src)" for more information.
>>> red = src.read(1)
>>> red
array([[255, 255, 255, ..., 255, 255, 255],
[255, 255, 255, ..., 255, 255, 255],
[255, 255, 255, ..., 255, 255, 255],
...,
[255, 255, 255, ..., 255, 255, 255],
[255, 255, 255, ..., 255, 255, 255],
@sgillies
sgillies / repro.py
Last active August 29, 2015 14:14
reprojection
import numpy
import rasterio
from rasterio import Affine as A
from rasterio.warp import reproject, RESAMPLING
with rasterio.open('rasterio/tests/data/RGB.byte.tif') as src:
src_transform = src.affine
# Zoom out by a factor of 2 from the center of the source
# dataset. The destination transform is the product of the
@sgillies
sgillies / install.sh
Created January 22, 2015 18:16
Pip installing Rasterio in a Linux Conda environment
# Rasterio is a C extension, need to apt-get gcc and g++.
sudo apt-get update
sudo apt-get install curl gcc g++
# Download miniconda.
curl "http://mapbox-cloudless-testing.s3.amazonaws.com/landsat8/setup/Miniconda-3.7.0-Linux-x86_64.sh" -o "Miniconda-3.7.0-Linux-x86_64.sh"
chmod +x Miniconda-3.7.0-Linux-x86_64.sh
./Miniconda-3.7.0-Linux-x86_64.sh -b
# Put conda on path.
@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.

@sgillies
sgillies / check.py
Created January 13, 2015 17:24
Testing '-'
import fiona
with fiona.open('-') as src:
print src.bounds
@sgillies
sgillies / installation.md
Last active August 29, 2015 14:13
Pre-release testing of Rasterio binaries

Rasterio binaries for OS X

Requirements

OS X 10.7+ Python 2.7 (2.7.9 would be best because it includes pip, a package installer)

Get pip if you don't have it

  1. Download https://bootstrap.pypa.io/get-pip.py