§ 24. Change of route, grade or terminus; abandonment of line or portion thereof. Every railroad corporation, except elevated railroad corporations, may, by a vote of two-thirds of all its directors, alter or change the route or any part of the route of its road or its termini, or locate such route, or any part thereof, or its termini, in a county adjoining any county named in its certificate of incorporation, if it shall appear to them that the line can be improved thereby, upon making and filing in the clerk's office of the proper county a survey, map and certificate of such alteration or change. If the same is made after the corporation has commenced grading the original route, compensation shall be made to all persons for injury done by such grading to any lands donated to the corporation. But neither terminus can be changed, under this section, to any other county than one adjoining that in which it was previously located; nor can the route or terminus of any railroad be so changed in any town, county or municipal corporation, which has issued bonds and taken any stock or bonds in aid of the construction of such railroad, without the written consent of a majority of taxpayers appearing upon the last assessment-roll of such town, county or municipal corporation, unless such terminus, after the change, will remain in the same village or city as theretofore. No alteration of the route of any railroad after its construction shall be made, or new line or route of road laid out or established, as provided in this section, in any city or village, unless approved by a vote of two-thirds of the common council of the city or trustees of the village. Any railroad corporation may, by a vote of its directors, change the grade of any part of its road, except that in the city of Buffalo such change must conform to the general plan heretofore adopted and filed by the grade crossing commissioners of said city, or any modification thereof, within the territory covered by said general plan, in such manner as it may deem necessary to avoid accidents and facilitate the use of such road; and it may by such vote alter the grade of its road, for such distance and in such manner as it may deem necessary, on each or either side of the place where the grade of its road has been changed by direction of the commissioner of transportation, at any point where its road crosses any canal or canal feeder, except that in the city of Buffalo such change must conform to the general plan heretofore adopted and filed by the grade crossing commissioners of said city, or any modification thereof, within the territory covered by said general plan. The commissioner of transportation shall have a general and supervisory power over that part of any railroad which passes over, or approaches within ten rods of any canal or canal feeder belonging to the state so far as may be necessary to preserve the free and perfect use of such canals or feeders, or to make any repairs, improvements or alterations in the same. Any railroad corporation whose tracks cross any of the canals of the state, and the grade of which may be raised by direction of the commissioner of transportation, with the assent of such commissioner, may lay out a new line of road to cross such canal at a more favorable grade, and may extend such new line and connect the same with any other line of road owned by such corporation upon making and filing in the clerk's office of the proper county a survey, map and certificate of such new or altered line. Notwithstanding the foregoing provisions of this section or of any other provision of law, any railroad corporation may by a vote of two-thirds of all its directors, or by action of its receiver or trustee if in receivership, reorganization or bankruptcy, taken with the permission of the court having jurisdiction, abandon all or any portion of its line or lines, or the operation thereof, provided, however, that the commissioner of transportation has determined that such abandonment is in the public interest.