This is an automated email from the git hooks/post-receive script. johanvdw-guest pushed a commit to branch master in repository python-descartes.
commit 1ddbda5916f7dcacaaafcd5a259be693951788be Author: Johan Van de Wauw <johan.vandew...@gmail.com> Date: Thu Dec 18 07:19:52 2014 +0100 Imported Upstream version 1.0.1 --- PKG-INFO | 85 +++++++++++++++++++++++++++++++++ README.txt | 65 +++++++++++++++++++++++++ descartes.egg-info/PKG-INFO | 85 +++++++++++++++++++++++++++++++++ descartes.egg-info/SOURCES.txt | 11 +++++ descartes.egg-info/dependency_links.txt | 1 + descartes.egg-info/not-zip-safe | 1 + descartes.egg-info/top_level.txt | 1 + descartes/__init__.py | 4 ++ descartes/patch.py | 66 +++++++++++++++++++++++++ descartes/tests.py | 38 +++++++++++++++ setup.cfg | 5 ++ setup.py | 33 +++++++++++++ 12 files changed, 395 insertions(+) diff --git a/PKG-INFO b/PKG-INFO new file mode 100644 index 0000000..c1ca2fd --- /dev/null +++ b/PKG-INFO @@ -0,0 +1,85 @@ +Metadata-Version: 1.1 +Name: descartes +Version: 1.0.1 +Summary: Use geometric objects as matplotlib paths and patches +Home-page: http://bitbucket.org/sgillies/descartes/ +Author: Sean Gillies +Author-email: sean.gill...@gmail.com +License: BSD +Description: Descartes + ========= + + Use Shapely_ or GeoJSON-like geometric objects as matplotlib paths and patches + + .. image:: http://farm4.static.flickr.com/3662/4555372019_9bbed1f956_o_d.png + :width: 800 + :height: 320 + + Requires: matplotlib, numpy, and optionally Shapely 1.2+. + + Example:: + + from matplotlib import pyplot + from shapely.geometry import LineString + from descartes import PolygonPatch + + BLUE = '#6699cc' + GRAY = '#999999' + + def plot_line(ax, ob): + x, y = ob.xy + ax.plot(x, y, color=GRAY, linewidth=3, solid_capstyle='round', zorder=1) + + line = LineString([(0, 0), (1, 1), (0, 2), (2, 2), (3, 1), (1, 0)]) + + fig = pyplot.figure(1, figsize=(10, 4), dpi=180) + + # 1 + ax = fig.add_subplot(121) + + plot_line(ax, line) + + dilated = line.buffer(0.5) + patch1 = PolygonPatch(dilated, fc=BLUE, ec=BLUE, alpha=0.5, zorder=2) + ax.add_patch(patch1) + + #2 + ax = fig.add_subplot(122) + + patch2a = PolygonPatch(dilated, fc=GRAY, ec=GRAY, alpha=0.5, zorder=1) + ax.add_patch(patch2a) + + eroded = dilated.buffer(-0.3) + + # GeoJSON-like data works as well + + polygon = eroded.__geo_interface__ + # >>> geo['type'] + # 'Polygon' + # >>> geo['coordinates'][0][:2] + # ((0.50502525316941682, 0.78786796564403572), (0.5247963548222736, 0.8096820147509064)) + patch2b = PolygonPatch(polygon, fc=BLUE, ec=BLUE, alpha=0.5, zorder=2) + ax.add_patch(patch2b) + + pyplot.show() + + + See also: examples/patches.py. + + Descartes is not associated with the identically named and apparently defunct + project at http://descartes.sourceforge.net/. + + .. _Shapely: http://gispython.org/lab/wiki/Shapely + + +Keywords: matplotlib gis geojson geometry +Platform: UNKNOWN +Classifier: Development Status :: 5 - Production/Stable +Classifier: Intended Audience :: Developers +Classifier: Intended Audience :: Science/Research +Classifier: License :: OSI Approved :: BSD License +Classifier: Operating System :: OS Independent +Classifier: Programming Language :: Python +Classifier: Programming Language :: Python :: 2 +Classifier: Programming Language :: Python :: 3 +Classifier: Topic :: Scientific/Engineering :: GIS diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..5b9c10a --- /dev/null +++ b/README.txt @@ -0,0 +1,65 @@ +Descartes +========= + +Use Shapely_ or GeoJSON-like geometric objects as matplotlib paths and patches + +.. image:: http://farm4.static.flickr.com/3662/4555372019_9bbed1f956_o_d.png + :width: 800 + :height: 320 + +Requires: matplotlib, numpy, and optionally Shapely 1.2+. + +Example:: + + from matplotlib import pyplot + from shapely.geometry import LineString + from descartes import PolygonPatch + + BLUE = '#6699cc' + GRAY = '#999999' + + def plot_line(ax, ob): + x, y = ob.xy + ax.plot(x, y, color=GRAY, linewidth=3, solid_capstyle='round', zorder=1) + + line = LineString([(0, 0), (1, 1), (0, 2), (2, 2), (3, 1), (1, 0)]) + + fig = pyplot.figure(1, figsize=(10, 4), dpi=180) + + # 1 + ax = fig.add_subplot(121) + + plot_line(ax, line) + + dilated = line.buffer(0.5) + patch1 = PolygonPatch(dilated, fc=BLUE, ec=BLUE, alpha=0.5, zorder=2) + ax.add_patch(patch1) + + #2 + ax = fig.add_subplot(122) + + patch2a = PolygonPatch(dilated, fc=GRAY, ec=GRAY, alpha=0.5, zorder=1) + ax.add_patch(patch2a) + + eroded = dilated.buffer(-0.3) + + # GeoJSON-like data works as well + + polygon = eroded.__geo_interface__ + # >>> geo['type'] + # 'Polygon' + # >>> geo['coordinates'][0][:2] + # ((0.50502525316941682, 0.78786796564403572), (0.5247963548222736, 0.8096820147509064)) + patch2b = PolygonPatch(polygon, fc=BLUE, ec=BLUE, alpha=0.5, zorder=2) + ax.add_patch(patch2b) + + pyplot.show() + + +See also: examples/patches.py. + +Descartes is not associated with the identically named and apparently defunct +project at http://descartes.sourceforge.net/. + +.. _Shapely: http://gispython.org/lab/wiki/Shapely + diff --git a/descartes.egg-info/PKG-INFO b/descartes.egg-info/PKG-INFO new file mode 100644 index 0000000..c1ca2fd --- /dev/null +++ b/descartes.egg-info/PKG-INFO @@ -0,0 +1,85 @@ +Metadata-Version: 1.1 +Name: descartes +Version: 1.0.1 +Summary: Use geometric objects as matplotlib paths and patches +Home-page: http://bitbucket.org/sgillies/descartes/ +Author: Sean Gillies +Author-email: sean.gill...@gmail.com +License: BSD +Description: Descartes + ========= + + Use Shapely_ or GeoJSON-like geometric objects as matplotlib paths and patches + + .. image:: http://farm4.static.flickr.com/3662/4555372019_9bbed1f956_o_d.png + :width: 800 + :height: 320 + + Requires: matplotlib, numpy, and optionally Shapely 1.2+. + + Example:: + + from matplotlib import pyplot + from shapely.geometry import LineString + from descartes import PolygonPatch + + BLUE = '#6699cc' + GRAY = '#999999' + + def plot_line(ax, ob): + x, y = ob.xy + ax.plot(x, y, color=GRAY, linewidth=3, solid_capstyle='round', zorder=1) + + line = LineString([(0, 0), (1, 1), (0, 2), (2, 2), (3, 1), (1, 0)]) + + fig = pyplot.figure(1, figsize=(10, 4), dpi=180) + + # 1 + ax = fig.add_subplot(121) + + plot_line(ax, line) + + dilated = line.buffer(0.5) + patch1 = PolygonPatch(dilated, fc=BLUE, ec=BLUE, alpha=0.5, zorder=2) + ax.add_patch(patch1) + + #2 + ax = fig.add_subplot(122) + + patch2a = PolygonPatch(dilated, fc=GRAY, ec=GRAY, alpha=0.5, zorder=1) + ax.add_patch(patch2a) + + eroded = dilated.buffer(-0.3) + + # GeoJSON-like data works as well + + polygon = eroded.__geo_interface__ + # >>> geo['type'] + # 'Polygon' + # >>> geo['coordinates'][0][:2] + # ((0.50502525316941682, 0.78786796564403572), (0.5247963548222736, 0.8096820147509064)) + patch2b = PolygonPatch(polygon, fc=BLUE, ec=BLUE, alpha=0.5, zorder=2) + ax.add_patch(patch2b) + + pyplot.show() + + + See also: examples/patches.py. + + Descartes is not associated with the identically named and apparently defunct + project at http://descartes.sourceforge.net/. + + .. _Shapely: http://gispython.org/lab/wiki/Shapely + + +Keywords: matplotlib gis geojson geometry +Platform: UNKNOWN +Classifier: Development Status :: 5 - Production/Stable +Classifier: Intended Audience :: Developers +Classifier: Intended Audience :: Science/Research +Classifier: License :: OSI Approved :: BSD License +Classifier: Operating System :: OS Independent +Classifier: Programming Language :: Python +Classifier: Programming Language :: Python :: 2 +Classifier: Programming Language :: Python :: 3 +Classifier: Topic :: Scientific/Engineering :: GIS diff --git a/descartes.egg-info/SOURCES.txt b/descartes.egg-info/SOURCES.txt new file mode 100644 index 0000000..9ac7444 --- /dev/null +++ b/descartes.egg-info/SOURCES.txt @@ -0,0 +1,11 @@ +README.txt +setup.cfg +setup.py +descartes/__init__.py +descartes/patch.py +descartes/tests.py +descartes.egg-info/PKG-INFO +descartes.egg-info/SOURCES.txt +descartes.egg-info/dependency_links.txt +descartes.egg-info/not-zip-safe +descartes.egg-info/top_level.txt \ No newline at end of file diff --git a/descartes.egg-info/dependency_links.txt b/descartes.egg-info/dependency_links.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/descartes.egg-info/dependency_links.txt @@ -0,0 +1 @@ + diff --git a/descartes.egg-info/not-zip-safe b/descartes.egg-info/not-zip-safe new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/descartes.egg-info/not-zip-safe @@ -0,0 +1 @@ + diff --git a/descartes.egg-info/top_level.txt b/descartes.egg-info/top_level.txt new file mode 100644 index 0000000..77933de --- /dev/null +++ b/descartes.egg-info/top_level.txt @@ -0,0 +1 @@ +descartes diff --git a/descartes/__init__.py b/descartes/__init__.py new file mode 100644 index 0000000..8fd72b2 --- /dev/null +++ b/descartes/__init__.py @@ -0,0 +1,4 @@ +"""Turn geometric objects into matplotlib patches""" + +from descartes.patch import PolygonPatch + diff --git a/descartes/patch.py b/descartes/patch.py new file mode 100644 index 0000000..34686f7 --- /dev/null +++ b/descartes/patch.py @@ -0,0 +1,66 @@ +"""Paths and patches""" + +from matplotlib.patches import PathPatch +from matplotlib.path import Path +from numpy import asarray, concatenate, ones + + +class Polygon(object): + # Adapt Shapely or GeoJSON/geo_interface polygons to a common interface + def __init__(self, context): + if hasattr(context, 'interiors'): + self.context = context + else: + self.context = getattr(context, '__geo_interface__', context) + @property + def geom_type(self): + return (getattr(self.context, 'geom_type', None) + or self.context['type']) + @property + def exterior(self): + return (getattr(self.context, 'exterior', None) + or self.context['coordinates'][0]) + @property + def interiors(self): + value = getattr(self.context, 'interiors', None) + if value is None: + value = self.context['coordinates'][1:] + return value + + +def PolygonPath(polygon): + """Constructs a compound matplotlib path from a Shapely or GeoJSON-like + geometric object""" + this = Polygon(polygon) + assert this.geom_type == 'Polygon' + def coding(ob): + # The codes will be all "LINETO" commands, except for "MOVETO"s at the + # beginning of each subpath + n = len(getattr(ob, 'coords', None) or ob) + vals = ones(n, dtype=Path.code_type) * Path.LINETO + vals[0] = Path.MOVETO + return vals + vertices = concatenate( + [asarray(this.exterior)] + + [asarray(r) for r in this.interiors]) + codes = concatenate( + [coding(this.exterior)] + + [coding(r) for r in this.interiors]) + return Path(vertices, codes) + + +def PolygonPatch(polygon, **kwargs): + """Constructs a matplotlib patch from a geometric object + + The `polygon` may be a Shapely or GeoJSON-like object with or without holes. + The `kwargs` are those supported by the matplotlib.patches.Polygon class + constructor. Returns an instance of matplotlib.patches.PathPatch. + + Example (using Shapely Point and a matplotlib axes): + + >>> b = Point(0, 0).buffer(1.0) + >>> patch = PolygonPatch(b, fc='blue', ec='blue', alpha=0.5) + >>> axis.add_patch(patch) + + """ + return PathPatch(PolygonPath(polygon), **kwargs) diff --git a/descartes/tests.py b/descartes/tests.py new file mode 100644 index 0000000..8cb48b4 --- /dev/null +++ b/descartes/tests.py @@ -0,0 +1,38 @@ +from shapely.geometry import * +import unittest + +from descartes.patch import PolygonPatch + +class PolygonTestCase(unittest.TestCase): + polygon = Point(0, 0).buffer(10.0).difference( + MultiPoint([(-5, 0), (5, 0)]).buffer(3.0)) + def test_patch(self): + patch = PolygonPatch(self.polygon) + self.failUnlessEqual(str(type(patch)), + "<class 'matplotlib.patches.PathPatch'>") + path = patch.get_path() + self.failUnless(len(path.vertices) == len(path.codes) == 198) + +class JSONPolygonTestCase(unittest.TestCase): + polygon = Point(0, 0).buffer(10.0).difference( + MultiPoint([(-5, 0), (5, 0)]).buffer(3.0)) + def test_patch(self): + geo = self.polygon.__geo_interface__ + patch = PolygonPatch(geo) + self.failUnlessEqual(str(type(patch)), + "<class 'matplotlib.patches.PathPatch'>") + path = patch.get_path() + self.failUnless(len(path.vertices) == len(path.codes) == 198) + +class GeoInterfacePolygonTestCase(unittest.TestCase): + class GeoThing: + __geo_interface__ = None + thing = GeoThing() + thing.__geo_interface__ = Point(0, 0).buffer(10.0).difference( + MultiPoint([(-5, 0), (5, 0)]).buffer(3.0)).__geo_interface__ + def test_patch(self): + patch = PolygonPatch(self.thing) + self.failUnlessEqual(str(type(patch)), + "<class 'matplotlib.patches.PathPatch'>") + path = patch.get_path() + self.failUnless(len(path.vertices) == len(path.codes) == 198) diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..861a9f5 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,5 @@ +[egg_info] +tag_build = +tag_date = 0 +tag_svn_revision = 0 + diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..4d05b5a --- /dev/null +++ b/setup.py @@ -0,0 +1,33 @@ +import os +import sys +import warnings + +from setuptools import setup, find_packages + +version = '1.0.1' +description = open('README.txt', 'r').read() + +setup(name='descartes', + version=version, + description="Use geometric objects as matplotlib paths and patches", + long_description=description, + classifiers=[ + 'Development Status :: 5 - Production/Stable', + 'Intended Audience :: Developers', + 'Intended Audience :: Science/Research', + 'License :: OSI Approved :: BSD License', + 'Operating System :: OS Independent', + 'Programming Language :: Python', + 'Programming Language :: Python :: 2', + 'Programming Language :: Python :: 3', + 'Topic :: Scientific/Engineering :: GIS' + ], + keywords='matplotlib gis geojson geometry', + author='Sean Gillies', + author_email='sean.gill...@gmail.com', + url='http://bitbucket.org/sgillies/descartes/', + license='BSD', + packages=find_packages(exclude=['ez_setup', 'examples', 'tests']), + include_package_data=True, + zip_safe=False, + ) -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-grass/python-descartes.git _______________________________________________ Pkg-grass-devel mailing list Pkg-grass-devel@lists.alioth.debian.org http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-grass-devel