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

FIX: Handle invalid geometries for rectangular projections #2262

Merged
merged 1 commit into from
Oct 17, 2023
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
9 changes: 9 additions & 0 deletions lib/cartopy/tests/test_line_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,15 @@ def test_nan_end(self):
assert not any(np.isnan(coord)), \
'Unexpected NaN in projected coords.'

def test_nan_rectangular(self):
# Make sure rectangular projections can handle invalid geometries
projection = ccrs.Robinson()
line_string = sgeom.LineString([(0, 0), (1, 1), (np.nan, np.nan),
(2, 2), (3, 3)])
multi_line_string = projection.project_geometry(line_string,
ccrs.PlateCarree())
assert len(multi_line_string.geoms) == 2


class TestMisc:
def test_misc(self):
Expand Down
5 changes: 4 additions & 1 deletion lib/cartopy/trace.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,10 @@ def project_linear(geometry not None, src_crs not None,
cdef bool geom_fully_inside = False
if isinstance(dest_projection, (ccrs._RectangularProjection, ccrs._WarpedRectangularProjection)):
dest_line = sgeom.LineString([(x[0], x[1]) for x in dest_coords])
geom_fully_inside = gp_domain.covers(dest_line)
if dest_line.is_valid:
# We can only check for covers with valid geometries
# some have nans/infs at this point still
geom_fully_inside = gp_domain.covers(dest_line)

lines = LineAccumulator()
for src_idx in range(1, src_size):
Expand Down