Section 58. A domestic company may apply to the board of aldermen of a city or to the selectmen of a town where it desires to take land, for an adjudication that public necessity and convenience require that certain land, or interests in land, as described in its petition, and for the specific purpose therein stated, be taken by such company, to enable it, in constructing its street railway, or extension thereof, to avoid dangerous curves or grades existing in the highways, or for other similar purposes incident to and not inconsistent with its corporate franchise of operating a railway to accommodate public travel in public ways. If the board to which such application is made finds in favor of the petitioner, after the notice and hearing required by law in the case of the grant of locations for street railways in public ways, the company may, upon complying with the provisions prescribed for railroad corporations by section eighteen of chapter one hundred and sixty, apply to the department for a certificate that public necessity and convenience require the construction of the railway between the termini and substantially upon the route fixed by the agreement of association in case of a company organized under the general laws and by the charter of a company created by special statute, or of the extension substantially on the locations already granted therefor, and for approval of the adjudication of the board of aldermen or of the selectmen as to the necessity and reasons for taking land or rights in land in every city or town where such adjudication has been made. If the department, after public notice and a hearing, at which all persons or corporations alleging that they would be injured by the construction of the railway shall be deemed to be interested parties and entitled to be heard, grants the certificate as prayed for, the petitioner may take by eminent domain under chapter seventy-nine any land or rights in land the taking of which has so been approved by the department.