[python-descartes] 01/04: Imported Upstream version 1.1.0
Johan Van de Wauw
johanvdw-guest at moszumanska.debian.org
Thu Jan 19 21:34:14 UTC 2017
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 0fe3eb355cec554ebb4b10e20b089f75ad133bbd
Author: Johan Van de Wauw <johan.vandewauw at gmail.com>
Date: Thu Jan 19 18:00:34 2017 +0100
Imported Upstream version 1.1.0
---
PKG-INFO | 2 +-
descartes.egg-info/PKG-INFO | 2 +-
descartes.egg-info/SOURCES.txt | 1 +
descartes.egg-info/requires.txt | 1 +
descartes/patch.py | 59 +++++++++++++++++++++----------
descartes/tests.py | 77 +++++++++++++++++++++++++++++++++++------
setup.py | 27 +++++++--------
7 files changed, 124 insertions(+), 45 deletions(-)
diff --git a/PKG-INFO b/PKG-INFO
index c1279c9..c638898 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: descartes
-Version: 1.0.2
+Version: 1.1.0
Summary: Use geometric objects as matplotlib paths and patches
Home-page: http://bitbucket.org/sgillies/descartes/
Author: Sean Gillies
diff --git a/descartes.egg-info/PKG-INFO b/descartes.egg-info/PKG-INFO
index c1279c9..c638898 100644
--- a/descartes.egg-info/PKG-INFO
+++ b/descartes.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: descartes
-Version: 1.0.2
+Version: 1.1.0
Summary: Use geometric objects as matplotlib paths and patches
Home-page: http://bitbucket.org/sgillies/descartes/
Author: Sean Gillies
diff --git a/descartes.egg-info/SOURCES.txt b/descartes.egg-info/SOURCES.txt
index 9ac7444..e06089e 100644
--- a/descartes.egg-info/SOURCES.txt
+++ b/descartes.egg-info/SOURCES.txt
@@ -8,4 +8,5 @@ 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/requires.txt
descartes.egg-info/top_level.txt
\ No newline at end of file
diff --git a/descartes.egg-info/requires.txt b/descartes.egg-info/requires.txt
new file mode 100644
index 0000000..6ccafc3
--- /dev/null
+++ b/descartes.egg-info/requires.txt
@@ -0,0 +1 @@
+matplotlib
diff --git a/descartes/patch.py b/descartes/patch.py
index 480b137..9b0de27 100644
--- a/descartes/patch.py
+++ b/descartes/patch.py
@@ -8,31 +8,28 @@ 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
+ if isinstance(context, dict):
+ self.context = context['coordinates']
else:
- self.context = getattr(context, '__geo_interface__', context)
- @property
- def geom_type(self):
- return (getattr(self.context, 'geom_type', None)
- or self.context['type'])
+ self.context = context
+
@property
def exterior(self):
- return (getattr(self.context, 'exterior', None)
- or self.context['coordinates'][0])
+ return (getattr(self.context, 'exterior', None)
+ or self.context[0])
+
@property
def interiors(self):
value = getattr(self.context, 'interiors', None)
if value is None:
- value = self.context['coordinates'][1:]
+ value = self.context[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
@@ -40,18 +37,42 @@ def PolygonPath(polygon):
vals = ones(n, dtype=Path.code_type) * Path.LINETO
vals[0] = Path.MOVETO
return vals
- vertices = concatenate(
- [asarray(this.exterior)[:, :2]]
- + [asarray(r)[:, :2] for r in this.interiors])
- codes = concatenate(
- [coding(this.exterior)]
- + [coding(r) for r in this.interiors])
+
+ if hasattr(polygon, 'geom_type'): # Shapely
+ ptype = polygon.geom_type
+ if ptype == 'Polygon':
+ polygon = [Polygon(polygon)]
+ elif ptype == 'MultiPolygon':
+ polygon = [Polygon(p) for p in polygon]
+ else:
+ raise ValueError(
+ "A polygon or multi-polygon representation is required")
+
+ else: # GeoJSON
+ polygon = getattr(polygon, '__geo_interface__', polygon)
+ ptype = polygon["type"]
+ if ptype == 'Polygon':
+ polygon = [Polygon(polygon)]
+ elif ptype == 'MultiPolygon':
+ polygon = [Polygon(p) for p in polygon['coordinates']]
+ else:
+ raise ValueError(
+ "A polygon or multi-polygon representation is required")
+
+ vertices = concatenate([
+ concatenate([asarray(t.exterior)[:, :2]] +
+ [asarray(r)[:, :2] for r in t.interiors])
+ for t in polygon])
+ codes = concatenate([
+ concatenate([coding(t.exterior)] +
+ [coding(r) for r in t.interiors]) for t in polygon])
+
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.
diff --git a/descartes/tests.py b/descartes/tests.py
index 8cb48b4..c3acaab 100644
--- a/descartes/tests.py
+++ b/descartes/tests.py
@@ -1,38 +1,95 @@
-from shapely.geometry import *
+from shapely.geometry import Point, MultiPoint
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))
+ 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'>")
+ 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))
+ 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'>")
+ 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__
+ 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'>")
+ self.failUnlessEqual(
+ str(type(patch)), "<class 'matplotlib.patches.PathPatch'>")
path = patch.get_path()
self.failUnless(len(path.vertices) == len(path.codes) == 198)
+
+
+class MultiPolygonTestCase(unittest.TestCase):
+
+ polygon = Point(0, 0).buffer(10.0) .difference(
+ MultiPoint([(-5, 0), (5, 0)]).buffer(3.0)).union(
+ MultiPoint([(-10, 10), (10, -10)]).buffer(2.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) == 330)
+
+
+class JSONMultiPolygonTestCase(unittest.TestCase):
+
+ polygon = Point(0, 0).buffer(10.0).difference(
+ MultiPoint([(-5, 0), (5, 0)]).buffer(3.0)).union(
+ MultiPoint([(-10, 10), (10, -10)]).buffer(2.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) == 330)
+
+
+class GeoInterfaceMultiPolygonTestCase(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)).union(
+ MultiPoint([(-10, 10), (10, -10)]).buffer(2.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) == 330)
diff --git a/setup.py b/setup.py
index 891893e..7af8170 100644
--- a/setup.py
+++ b/setup.py
@@ -4,24 +4,23 @@ import warnings
from setuptools import setup, find_packages
-version = '1.0.2'
+version = '1.1.0'
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'
- ],
+ 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.gillies at gmail.com',
@@ -29,5 +28,5 @@ setup(name='descartes',
license='BSD',
packages=find_packages(exclude=['ez_setup', 'examples', 'tests']),
include_package_data=True,
- zip_safe=False,
- )
+ install_requires=['matplotlib'],
+ zip_safe=False)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-grass/python-descartes.git
More information about the Pkg-grass-devel
mailing list