Skip to content
33 changes: 33 additions & 0 deletions meshkernel/meshkernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1757,6 +1757,39 @@ def mesh2d_casulli_refinement_on_polygon(
byref(c_polygon),
)

def mesh2d_compute_netlink_contour_polygons(self) -> GeometryList:
"""Gets the netlink contour polygons from the MeshKernel.

Returns:
Mesh2d: A copy of the netlink contour polygons.
"""

c_geometry_list_dimension = c_int()

self._execute_function(
self.lib.mkernel_mesh2d_compute_netlink_contour_polygons_dimension,
self._meshkernelid,
byref(c_geometry_list_dimension),
)

n_coordinates = c_geometry_list_dimension.value
x_coordinates = np.empty(n_coordinates, dtype=np.double)
y_coordinates = np.empty(n_coordinates, dtype=np.double)

edge_polygons = GeometryList(
x_coordinates=x_coordinates, y_coordinates=y_coordinates
)

c_edge_polygons = CGeometryList.from_geometrylist(edge_polygons)

self._execute_function(
self.lib.mkernel_mesh2d_compute_netlink_contour_polygons,
self._meshkernelid,
byref(c_edge_polygons),
)

return edge_polygons

def mesh2d_compute_orthogonalization(
self,
project_to_land_boundary_option: ProjectToLandBoundaryOption,
Expand Down
11 changes: 11 additions & 0 deletions tests/test_mesh2d_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -2568,3 +2568,14 @@ def test_mesh2d_casulli_refinement_based_on_depths():
# new mesh has more nodes and edges than the starting mesh, it has been refined
assert len(mesh2d_not_refined.node_x) == 121
assert len(mesh2d_refined.node_x) == 253


def test_mesh2d_netlink_contour_polygons(meshkernel_with_mesh2d: MeshKernel):
"""Test test_mesh2d_netlink_contour_polygons"""

mk = meshkernel_with_mesh2d(2, 2)

netlink_polygons = mk.mesh2d_compute_netlink_contour_polygons()

assert len(netlink_polygons.x_coordinates) == 48
assert len(netlink_polygons.y_coordinates) == 48
Loading