Skip to content

Instantly share code, notes, and snippets.

@sgillies
Last active August 29, 2015 14:10
Show Gist options
  • Save sgillies/7960d778f32ae8971053 to your computer and use it in GitHub Desktop.
Save sgillies/7960d778f32ae8971053 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"metadata": {
"name": "",
"signature": "sha256:7731dc8f84d75ee5153e2aef351f2b07daed3fd41197c9bf40df2ad426ecb4d6"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "code",
"collapsed": false,
"input": [
"%matplotlib inline"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 1
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"from shapely.geometry import LineString, Point"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 4
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"circle = Point(0, 0).buffer(5)\n",
"circle"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 13,
"svg": [
"<svg\n",
" preserveAspectRatio=\"xMinYMin meet\"\n",
" viewBox=\"-5.99879545621 -5.99879545621 11.9987954562 11.9975909124\"\n",
" width=\"100.0\"\n",
" height=\"100.0\"\n",
" transform=\"translate(0, 100.0),scale(1, -1)\">\n",
" \n",
" <g fill-rule=\"evenodd\" fill=\"#66cc99\" stroke=\"#555555\" \n",
" stroke-width=\"0.239975909124\" opacity=\"0.6\">\n",
" <path d=\"M 5.0,0.0 L 4.97592363336,-0.490085701648 L 4.90392640202,-0.975451610081 L 4.78470167866,-1.45142338627 L 4.61939766256,-1.91341716183 L 4.40960632174,-2.35698368413 L 4.15734806151,-2.7778511651 L 3.86505226681,-3.17196642082 L 3.53553390593,-3.53553390593 L 3.17196642082,-3.86505226681 L 2.7778511651,-4.15734806151 L 2.35698368413,-4.40960632174 L 1.91341716183,-4.61939766256 L 1.45142338627,-4.78470167866 L 0.975451610081,-4.90392640202 L 0.490085701648,-4.97592363336 L 8.07772287216e-15,-5.0 L -0.490085701648,-4.97592363336 L -0.975451610081,-4.90392640202 L -1.45142338627,-4.78470167866 L -1.91341716183,-4.61939766256 L -2.35698368413,-4.40960632174 L -2.7778511651,-4.15734806151 L -3.17196642082,-3.86505226681 L -3.53553390593,-3.53553390593 L -3.86505226681,-3.17196642082 L -4.15734806151,-2.7778511651 L -4.40960632174,-2.35698368413 L -4.61939766256,-1.91341716183 L -4.78470167866,-1.45142338627 L -4.90392640202,-0.975451610081 L -4.97592363336,-0.490085701648 L -5.0,-5.05321549807e-15 L -4.97592363336,0.490085701648 L -4.90392640202,0.975451610081 L -4.78470167866,1.45142338627 L -4.61939766256,1.91341716183 L -4.40960632174,2.35698368413 L -4.15734806151,2.7778511651 L -3.86505226681,3.17196642082 L -3.53553390593,3.53553390593 L -3.17196642082,3.86505226681 L -2.7778511651,4.15734806151 L -2.35698368413,4.40960632174 L -1.91341716183,4.61939766256 L -1.45142338627,4.78470167866 L -0.975451610081,4.90392640202 L -0.490085701648,4.97592363336 L -1.42411613949e-14,5.0 L 0.490085701648,4.97592363336 L 0.975451610081,4.90392640202 L 1.45142338627,4.78470167866 L 1.91341716183,4.61939766256 L 2.35698368413,4.40960632174 L 2.7778511651,4.15734806151 L 3.17196642082,3.86505226681 L 3.53553390593,3.53553390593 L 3.86505226681,3.17196642082 L 4.15734806151,2.7778511651 L 4.40960632174,2.35698368413 L 4.61939766256,1.91341716183 L 4.78470167866,1.45142338627 L 4.90392640202,0.975451610081 L 4.97592363336,0.490085701648 L 5.0,4.11926756857e-14 L 5.0,0.0 z\" />\n",
" </g>\n",
" </svg>"
],
"text": [
"<shapely.geometry.polygon.Polygon at 0x1136c2850>"
]
}
],
"prompt_number": 13
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"line = LineString([(-10, 0), (10, 0)])\n",
"line"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 14,
"svg": [
"<svg\n",
" preserveAspectRatio=\"xMinYMin meet\"\n",
" viewBox=\"-11.0 -1.0 22.0 2.0\"\n",
" width=\"100.0\"\n",
" height=\"100.0\"\n",
" transform=\"translate(0, 100.0),scale(1, -1)\">\n",
" <polyline\n",
" fill=\"none\"\n",
" stroke=\"#66cc99\"\n",
" stroke-width=0.44\n",
" points=\"-10.0,0.0 10.0,0.0\"\n",
" opacity=\".8\"\n",
" />\n",
" </svg>"
],
"text": [
"<shapely.geometry.linestring.LineString at 0x1136b7ed0>"
]
}
],
"prompt_number": 14
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"circle.difference(line)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 16,
"svg": [
"<svg\n",
" preserveAspectRatio=\"xMinYMin meet\"\n",
" viewBox=\"-6.0 -5.99879545621 12.0 11.9975909124\"\n",
" width=\"100.0\"\n",
" height=\"100.0\"\n",
" transform=\"translate(0, 100.0),scale(1, -1)\">\n",
" \n",
" <g fill-rule=\"evenodd\" fill=\"#66cc99\" stroke=\"#555555\" \n",
" stroke-width=\"0.24\" opacity=\"0.6\">\n",
" <path d=\"M 5.0,0.0 L 4.97592363336,-0.490085701648 L 4.90392640202,-0.975451610081 L 4.78470167866,-1.45142338627 L 4.61939766256,-1.91341716183 L 4.40960632174,-2.35698368413 L 4.15734806151,-2.7778511651 L 3.86505226681,-3.17196642082 L 3.53553390593,-3.53553390593 L 3.17196642082,-3.86505226681 L 2.7778511651,-4.15734806151 L 2.35698368413,-4.40960632174 L 1.91341716183,-4.61939766256 L 1.45142338627,-4.78470167866 L 0.975451610081,-4.90392640202 L 0.490085701648,-4.97592363336 L 8.07772287216e-15,-5.0 L -0.490085701648,-4.97592363336 L -0.975451610081,-4.90392640202 L -1.45142338627,-4.78470167866 L -1.91341716183,-4.61939766256 L -2.35698368413,-4.40960632174 L -2.7778511651,-4.15734806151 L -3.17196642082,-3.86505226681 L -3.53553390593,-3.53553390593 L -3.86505226681,-3.17196642082 L -4.15734806151,-2.7778511651 L -4.40960632174,-2.35698368413 L -4.61939766256,-1.91341716183 L -4.78470167866,-1.45142338627 L -4.90392640202,-0.975451610081 L -4.97592363336,-0.490085701648 L -5.0,-5.05321549807e-15 L -5.0,0.0 L -4.97592363336,0.490085701648 L -4.90392640202,0.975451610081 L -4.78470167866,1.45142338627 L -4.61939766256,1.91341716183 L -4.40960632174,2.35698368413 L -4.15734806151,2.7778511651 L -3.86505226681,3.17196642082 L -3.53553390593,3.53553390593 L -3.17196642082,3.86505226681 L -2.7778511651,4.15734806151 L -2.35698368413,4.40960632174 L -1.91341716183,4.61939766256 L -1.45142338627,4.78470167866 L -0.975451610081,4.90392640202 L -0.490085701648,4.97592363336 L -1.42411613949e-14,5.0 L 0.490085701648,4.97592363336 L 0.975451610081,4.90392640202 L 1.45142338627,4.78470167866 L 1.91341716183,4.61939766256 L 2.35698368413,4.40960632174 L 2.7778511651,4.15734806151 L 3.17196642082,3.86505226681 L 3.53553390593,3.53553390593 L 3.86505226681,3.17196642082 L 4.15734806151,2.7778511651 L 4.40960632174,2.35698368413 L 4.61939766256,1.91341716183 L 4.78470167866,1.45142338627 L 4.90392640202,0.975451610081 L 4.97592363336,0.490085701648 L 5.0,4.11926756857e-14 L 5.0,0.0 z\" />\n",
" </g>\n",
" </svg>"
],
"text": [
"<shapely.geometry.polygon.Polygon at 0x1136c2710>"
]
}
],
"prompt_number": 16
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"line.difference(circle)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 18,
"svg": [
"<svg\n",
" preserveAspectRatio=\"xMinYMin meet\"\n",
" viewBox=\"-11.0 -1.0 22.0 2.0\"\n",
" width=\"100.0\"\n",
" height=\"100.0\"\n",
" transform=\"translate(0, 100.0),scale(1, -1)\">\n",
" <polyline\n",
" fill=\"none\"\n",
" stroke=\"#66cc99\"\n",
" stroke-width=0.44\n",
" points=\"-10.0,0.0 -5.0,0.0\"\n",
" opacity=\".8\"\n",
" />\n",
"<polyline\n",
" fill=\"none\"\n",
" stroke=\"#66cc99\"\n",
" stroke-width=0.44\n",
" points=\"5.0,0.0 10.0,0.0\"\n",
" opacity=\".8\"\n",
" />\n",
" </svg>"
],
"text": [
"<shapely.geometry.multilinestring.MultiLineString at 0x11368f890>"
]
}
],
"prompt_number": 18
}
],
"metadata": {}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment