-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix shapely deprecation warnings and remove descartes dependency (#210)
- Loading branch information
Showing
14 changed files
with
105 additions
and
28 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,5 +13,5 @@ dependencies: | |
- xarray | ||
- pip | ||
- pip: | ||
- coveralls | ||
- coveralls==3.2.0 | ||
- pytest-cov |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,5 +14,5 @@ dependencies: | |
- dask | ||
- pip | ||
- pip: | ||
- coveralls | ||
- coveralls==3.2.0 | ||
- pytest-cov |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,6 @@ dependencies: | |
- joblib | ||
- geopandas | ||
- xarray | ||
- descartes | ||
- sphinx-gallery | ||
- scikit-image | ||
- motionless |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
"""Paths and patches | ||
This file is part of the package "descartes" by sgilles, | ||
apparently discontinued today. | ||
https://pypi.org/project/descartes | ||
License: BSD License (BSD) | ||
""" | ||
|
||
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.coords)[:, :2]] | ||
+ [asarray(r.coords)[:, :2] 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) |
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
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
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