Skip to content

Commit

Permalink
removed dependency descartes and added support for shapely>=1.8.5, <3
Browse files Browse the repository at this point in the history
  • Loading branch information
lausdahl committed Dec 5, 2023
1 parent cf0ca92 commit ad04eb9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
# For a discussion on single-sourcing the version across setup.py and the
# project code, see
# https://packaging.python.org/en/latest/single_source_version.html
version='1.2.6', # Required
version='1.3.0', # Required

# This is a one-line description or tagline of what your project does. This
# corresponds to the "Summary" metadata field:
Expand Down Expand Up @@ -142,7 +142,7 @@
#
# For an analysis of "install_requires" vs pip's requirements files see:
# https://packaging.python.org/en/latest/requirements.html
install_requires=['matplotlib', 'pymap3d>=3.0.1, <4', 'shapely<=1.8.5', 'descartes','folium'], # Optional
install_requires=['matplotlib', 'pymap3d>=3.0.1, <4', "shapely>=1.8.5, <3", 'folium'], # Optional

# List additional groups of dependencies here (e.g. development
# dependencies). Users will be able to install these using the "extras"
Expand Down
26 changes: 24 additions & 2 deletions src/isoxmlviz/visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,36 @@
import sys
import pymap3d
import shapely.geometry as SHP
from descartes.patch import PolygonPatch

from matplotlib import pyplot as plt
from matplotlib.collections import PatchCollection, LineCollection
from shapely.geometry import LineString, JOIN_STYLE, MultiLineString, MultiPoint
import math
from isoxmlviz.LineStringUtil import extract_lines_within
from isoxmlviz.webmap import WebMap

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)
"""

# from descartes but no longer maintained so inspired by https://github.com/geopandas/geopandas/issues/1039
from matplotlib.path import Path
from matplotlib.patches import Polygon
import numpy as np
return Polygon(Path.make_compound_path(Path(np.asarray(polygon.exterior.coords)[:, :2]),
*[Path(np.asarray(ring.coords)[:, :2]) for ring in polygon.interiors]).vertices, **kwargs)

ell_wgs84 = pymap3d.Ellipsoid.from_name('wgs84')

default_propagation_num = 100
Expand Down Expand Up @@ -512,7 +534,7 @@ def plot_all_lsg(ax, parent_map, web_map, ref, root, line_type_groups, gpn_filte
ax.plot([p[0] for p in points], [p[1] for p in points], label=designator, color=color)
else:
ax.plot([p[0] for p in points], [p[1] for p in points], color=color)
web_map.add([p[0] for p in points], [p[1] for p in points], tooltip=designator, style={'lineColor': color})
web_map.add(LineString([(p[0], p[1]) for p in points]), tooltip=designator, style={'color': color})


if __name__ == '__main__':
Expand Down
12 changes: 6 additions & 6 deletions src/isoxmlviz/webmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,25 @@ def transform(shape, func):
from shapely.geometry import Point, LineString, Polygon, GeometryCollection
construct = shape.__class__

if shape.type.startswith('Multi'):
if shape.geom_type.startswith('Multi'):
parts = [transform(geom, func) for geom in shape.geoms]
return construct(parts)

if shape.type in ( 'LineString'):
if shape.geom_type in ( 'LineString'):
return construct(map(func, shape.coords))
if shape.type in ('Point'):
if shape.geom_type in ('Point'):
return construct(flatten(map(func, shape.coords)))


if shape.type == 'Polygon':
if shape.geom_type == 'Polygon':
exterior = map(func, shape.exterior.coords)
rings = [list(map(func, ring.coords)) for ring in shape.interiors]
return construct(exterior, rings)

if shape.type == 'GeometryCollection':
if shape.geom_type == 'GeometryCollection':
return construct()

raise ValueError('Unknown geometry type, "%s"' % shape.type)
raise ValueError('Unknown geometry type, "%s"' % shape.geom_type)


class WebMap:
Expand Down

0 comments on commit ad04eb9

Please sign in to comment.