diff --git a/meshkernel/meshkernel.py b/meshkernel/meshkernel.py index e89bee75..1217592b 100644 --- a/meshkernel/meshkernel.py +++ b/meshkernel/meshkernel.py @@ -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, diff --git a/tests/test_mesh2d_basics.py b/tests/test_mesh2d_basics.py index ea48b41d..fc7515eb 100644 --- a/tests/test_mesh2d_basics.py +++ b/tests/test_mesh2d_basics.py @@ -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