From 701f0518667b7bb2418762c4fb156542c9288699 Mon Sep 17 00:00:00 2001 From: James McBride Date: Tue, 11 Aug 2015 10:20:00 -0700 Subject: [PATCH 1/2] Added check for z dimension in polygon; if yes, flatten before plot. Necessary because descartes does not accept polygons with a z coordinate. --- geopandas/plotting.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/geopandas/plotting.py b/geopandas/plotting.py index f7d58bc..78f9278 100644 --- a/geopandas/plotting.py +++ b/geopandas/plotting.py @@ -9,6 +9,10 @@ def plot_polygon(ax, poly, facecolor='red', edgecolor='black', alpha=0.5): """ Plot a single Polygon geometry """ from descartes.patch import PolygonPatch a = np.asarray(poly.exterior) + if poly.has_z: + from shapely.geometry import Polygon + poly = Polygon(zip(*poly.exterior.xy)) + # without Descartes, we could make a Patch of exterior ax.add_patch(PolygonPatch(poly, facecolor=facecolor, alpha=alpha)) ax.plot(a[:, 0], a[:, 1], color=edgecolor) From b3d93bd48df80501298f43ea09dab8602aa691e7 Mon Sep 17 00:00:00 2001 From: James McBride Date: Tue, 11 Aug 2015 10:49:15 -0700 Subject: [PATCH 2/2] Moved shapely import to top of file in plotting. --- geopandas/plotting.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/geopandas/plotting.py b/geopandas/plotting.py index 78f9278..e297c22 100644 --- a/geopandas/plotting.py +++ b/geopandas/plotting.py @@ -3,6 +3,7 @@ from __future__ import print_function import numpy as np from six import next from six.moves import xrange +from shapely.geometry import Polygon def plot_polygon(ax, poly, facecolor='red', edgecolor='black', alpha=0.5): @@ -10,7 +11,6 @@ def plot_polygon(ax, poly, facecolor='red', edgecolor='black', alpha=0.5): from descartes.patch import PolygonPatch a = np.asarray(poly.exterior) if poly.has_z: - from shapely.geometry import Polygon poly = Polygon(zip(*poly.exterior.xy)) # without Descartes, we could make a Patch of exterior