Whenever any highway crosses a railroad at grade and the town, village or county board or the city council or city commissioners other than in a city of the first class, as the case may be, shall deem it for the best interest of the public that said highway and railroad shall cross at separate grades, and when an agreement can be made between such board and the railroad company as to the manner of