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

🐛 Ensure masking polygon lines are CCW #957

Merged
merged 1 commit into from
Sep 12, 2024
Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ All notable changes to this library are documented in this file.

### Bug Fixes

- Ensure geometries going into masking helper are CCW, to mask outside of.

## **1.21.0** (6 Sep 2024)

### API Changes
Expand Down
4 changes: 3 additions & 1 deletion src/pyiem/plot/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,9 @@ def mask_outside_geom(gp, geom):
geom = MultiPolygon([geom])
trans = Transformer.from_crs(LATLON, gp.crs, always_xy=True)
for geo in geom.geoms:
ccw = np.asarray(geo.exterior.coords)[::-1]
ccw = np.asarray(geo.exterior.coords)
if not geo.exterior.is_ccw:
ccw = ccw[::-1]
points = trans.transform(ccw[:, 0], ccw[:, 1])
# pylint: disable=unsubscriptable-object
ar = np.column_stack([*points])[:-1]
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions tests/plot/test_geoplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,28 @@ def test_fema_region6():
return mp.fig


@pytest.mark.mpl_image_compare(tolerance=PAIN)
def test_fema_region_pcolormesh():
"""Test problem found in production."""
mp = MapPlot(
figsize=(8, 6),
nocaption=True,
fema_region=7,
sector="fema_region",
title="FEMA Region 7",
nostates=True,
)
lons = np.arange(-100, -80, 0.25)
lats = np.arange(40, 50, 0.25)
vals = np.linspace(0, 1, lats.shape[0] * lons.shape[0]).reshape(
[lats.shape[0], lons.shape[0]]
)
lons, lats = np.meshgrid(lons, lats)
res = mp.pcolormesh(lons, lats, vals, np.arange(0, 1, 0.1))
res.set_rasterized(True)
return mp.fig


@pytest.mark.mpl_image_compare(tolerance=PAIN)
def test_nashville():
"""Test that Benton County, TNC005 does not show for OHX."""
Expand Down
Loading