Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify Import #22

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ This would be an example output:

See the full example source code in [examples/random_points_across_italy.py](examples/random_points_across_italy.py). See also the other examples in the [examples/](examples) directory that show how to calculate the area of the Voronoi regions, handle duplicate points or interact with the GeoPandas or Fiona packages.

```python
from geopandas import __version__ as version_geopandas
if version_geopandas < "0.13.0":
from geopandas.plotting import _flatten_multi_geoms
else:
from geopandas.plotting import _sanitize_geoms
```
In geopandas v0.13.0 and later, function _flatten_multi_geoms becomes function _sanitize_geoms. Prior to this version (< v0.13.0), the old function name was still used.

## Dependencies

*geovoronoi* requires **Python 3.6 or newer** (the package is tested for up to Python 3.10). The following packages need to be installed (if not, they will be automatically installed if you use a Python package manager like *pip*):
Expand Down
14 changes: 12 additions & 2 deletions geovoronoi/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@
import matplotlib.pyplot as plt
from matplotlib.collections import PatchCollection
from descartes.patch import PolygonPatch
from geopandas.plotting import _flatten_multi_geoms

from geopandas import __version__ as version_geopandas
if version_geopandas < "0.13.0":
from geopandas.plotting import _flatten_multi_geoms
else:
from geopandas.plotting import _sanitize_geoms

from geopandas import GeoSeries

from ._voronoi import points_to_coords, points_to_region
Expand Down Expand Up @@ -342,7 +348,11 @@ def plot_polygon_collection_with_color(ax, geoms, color=None, **kwargs):
color_values = color
color_indices = np.arange(len(color))

geoms, multi_indices = _flatten_multi_geoms(geoms)
if version_geopandas < "0.13.0":
geoms, multi_indices = _flatten_multi_geoms(geoms)
else:
geoms, multi_indices = _sanitize_geoms(geoms)


if color_indices is not None: # retain correct color indices
color_values = color_values[np.nonzero(geoms_indices[multi_indices][..., np.newaxis] == color_indices)[1]]
Expand Down