Skip to content

Instantly share code, notes, and snippets.

View sgillies's full-sized avatar

Sean Gillies sgillies

View GitHub Profile
@sgillies
sgillies / even-more-functional.py
Created February 22, 2012 19:27
Functional style geoprocessing with Fiona, pyproj, Shapely
# Example of using Fiona, pyproj, and Shapely together in a functional
# style.
import functools
import itertools
import logging
import sys
import fiona
from pyproj import Proj, transform
@sgillies
sgillies / fiona-translate.py
Created March 6, 2012 04:03
Translating features with Fiona
# Translation of Shapefile record geometries in a functional style.
from fiona import collection
from functools import partial
from itertools import imap
import logging
log = logging.getLogger()
# To begin: a few functions to translate geometry coordinates. They call each
@sgillies
sgillies / with-descartes-reduce.py
Created March 11, 2012 06:17
Mapping and reducing
# Making maps with reduce()
from matplotlib import pyplot
from descartes import PolygonPatch
from fiona import collection
BLUE = '#6699cc'
def render(axes, rec):
"""Given matplotlib axes and a record, adds the record as a patch
@sgillies
sgillies / swap-coords.py
Created March 12, 2012 16:29
Swapping coordinates with Fiona
# Swapping x, y coords.
from descartes import PolygonPatch
from fiona import collection
from itertools import imap
import logging
from matplotlib import pyplot
log = logging.getLogger()
@sgillies
sgillies / geo_interface.rst
Last active April 10, 2024 00:26
A Python Protocol for Geospatial Data

Author: Sean Gillies Version: 1.0

Abstract

This document describes a GeoJSON-like protocol for geo-spatial (GIS) vector data.

Introduction

@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": [
{
@sgillies
sgillies / gist:3516360
Created August 29, 2012 18:05
union-benchmark.py
from itertools import islice
import timeit
from shapely.geometry import Point
from shapely.ops import unary_union
def halton(base):
"""Returns an iterator over an infinite Halton sequence"""
def value(index):
result = 0.0
from descartes import PolygonPatch
from functools import reduce
import json
import urllib
data = urllib.urlopen("https://raw.github.com/gist/3634233/4de4c6de1cd0edbea410cc32bfcc7cbe90a78b44/tlv.json").read()
f = json.loads(data)
g = f.copy()
g['geometry']['coordinates'] = [f['geometry']['coordinates']]
@sgillies
sgillies / 1.py
Created September 5, 2012 18:57
Putting it all together
from descartes import PolygonPatch
import fiona
from functools import partial, reduce
from math import sqrt
from itertools import imap
import pylab
from pyproj import Proj, transform
fiona.open = fiona.collection
@sgillies
sgillies / geojson-profile.rst
Created October 8, 2012 17:02
A GeoJSON profile of the application/json media type

A GeoJSON profile of the application/json media type (Strawman)

Motivation

There are at least two different dialects of geospatial JSON data on the internet today and we're doing very little to explain to clients or servers which one is being used in a particular interaction. A web API may return data using the application/json media type if given a f=json parameter (or not) but a client doesn't necessarily know whether it is getting GeoJSON or ArcGIS JSON, two different ways of structuring information about the same kinds of entities.

Profiles