Skip to content

Commit

Permalink
Merge pull request #94 from SanderHulst/feature/except_geos_exception
Browse files Browse the repository at this point in the history
⭐ except GEOS exception when adding contour
  • Loading branch information
SorooshMani-NOAA authored Jun 22, 2023
2 parents d0c8c60 + 8afd16a commit 3b7de23
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
4 changes: 3 additions & 1 deletion ocsmesh/raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -1425,10 +1425,12 @@ def _get_raster_contour_single_window(
plt.close(fig)
for path_collection in ax.collections:
for path in path_collection.get_paths():
# LineStrings must have at least 2 coordinate tuples
if len(path.vertices) < 2:
continue
try:
features.append(LineString(path.vertices))
except ValueError:
# LineStrings must have at least 2 coordinate tuples
pass
return ops.linemerge(features)

Expand Down
35 changes: 30 additions & 5 deletions tests/api/hfun.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
from jigsawpy import jigsaw_msh_t
import geopandas as gpd
import numpy as np
import rasterio as rio
import requests
from shapely import geometry

import ocsmesh
Expand Down Expand Up @@ -81,10 +79,9 @@ def setUp(self):
self.tdir = Path(tempfile.mkdtemp())
self.rast1 = self.tdir / 'rast_1.tif'
self.rast2 = self.tdir / 'rast_2.tif'
self.mesh1 = self.tdir / 'mesh_1.gr3'
self.mesh1 = self.tdir / 'mesh_1.grd'
topo_2rast_1mesh(self.rast1, self.rast2, self.mesh1)


def tearDown(self):
shutil.rmtree(self.tdir)

Expand Down Expand Up @@ -176,7 +173,7 @@ def test_add_topo_func_constraint_exact(self):

self.assertTrue(isinstance(hfun_msht, jigsaw_msh_t))

def test_add_contor_exact(self):
def test_add_contour_exact(self):
# TODO: Improve this test (added for upgrade to shapely2)
hfun_coll = ocsmesh.Hfun(
[self.rast1, self.rast2, self.mesh1],
Expand All @@ -194,6 +191,34 @@ def test_add_contor_exact(self):
self.assertTrue(isinstance(hfun_msht, jigsaw_msh_t))


def test_add_contour_single_vertex(self):
rast3 = self.tdir / 'rast_3.tif'
rast_xy_3 = np.mgrid[-1:0.1:0.1, -0.7:0.1:0.1]
rast_z_3 = np.ones_like(rast_xy_3[0]) * 2.0
rast_z_3[0, 0] = 1
rast_z_3[-1, -1] = 3

ocsmesh.utils.raster_from_numpy(
rast3, rast_z_3, rast_xy_3, 4326
)

# regression test for single point contours
hfun_coll = ocsmesh.Hfun(
[rast3],
hmin=500,
hmax=5000,
method='exact'
)
hfun_coll.add_contour(
level=1,
target_size=1000,
)

hfun_msht = hfun_coll.msh_t()

self.assertTrue(isinstance(hfun_msht, jigsaw_msh_t))


def test_add_channel_exact(self):
# TODO: Improve this test (added for upgrade to shapely2)
hfun_coll = ocsmesh.Hfun(
Expand Down

0 comments on commit 3b7de23

Please sign in to comment.