Created
March 29, 2015 04:02
-
-
Save sgillies/31ef3ac89c12ec4aee85 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"metadata": { | |
"name": "", | |
"signature": "sha256:f0975ccd63d3129612a25e2233b7ce2d4942897ca49e553c8ab84038019cc446" | |
}, | |
"nbformat": 3, | |
"nbformat_minor": 0, | |
"worksheets": [ | |
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"import glob\n", | |
"import os.path\n", | |
"import urllib\n", | |
"import zipfile\n", | |
"\n", | |
"import fiona\n", | |
"from shapely.geometry import shape\n", | |
"from shapely.ops import unary_union" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 3 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"if not os.path.exists('vectors.zip'):\n", | |
" urllib.urlretrieve(\n", | |
" \"http://ncp-yamato.stanford.edu/~jdouglass/shapely_sample_vectors.zip\",\n", | |
" \"vectors.zip\")\n", | |
" with zipfile.ZipFile('vectors.zip') as archive:\n", | |
" archive.extractall()\n", | |
"\n", | |
"in_vectors = glob.glob('sample_vectors/*.shp')" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 4 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"geoms = []\n", | |
"for filename in in_vectors:\n", | |
" with fiona.open(filename) as src:\n", | |
" geoms.extend([shape(f['geometry']) for f in src])\n", | |
"cumulative_union = unary_union(geoms)" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 9 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"cumulative_union" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 10, | |
"svg": [ | |
"<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"300\" height=\"300\" viewBox=\"1001341.31677 1050138.2758 207659.353731 259823.311178\" preserveAspectRatio=\"xMinYMin meet\"><g transform=\"matrix(1,0,0,-1,0,2360099.86278)\"><path fill-rule=\"evenodd\" fill=\"#66cc99\" stroke=\"#555555\" stroke-width=\"1732.15540785\" opacity=\"0.6\" d=\"M 1199244.40237,1300331.3614 L 1199287.5849,1300331.3614 L 1199377.5849,1300331.3614 L 1199377.5849,1059761.3614 L 1199287.5849,1059761.3614 L 1011007.5849,1059761.3614 L 1011007.5849,1059768.50138 L 1010964.40237,1059768.50138 L 1010964.40237,1300338.50138 L 1199244.40237,1300338.50138 L 1199244.40237,1300331.3614 z\" /></g></svg>" | |
], | |
"text": [ | |
"<shapely.geometry.polygon.Polygon at 0x106129f90>" | |
] | |
} | |
], | |
"prompt_number": 10 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [] | |
} | |
], | |
"metadata": {} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment