TORONTO - Canadian National Railway says the Ontario government's Metrolinx is paying $310.5 million to buy two segments of railway line in the Toronto area.

The rails are principally used to carry GO Transit passenger trains, which are part of the Metrolinx regional transportation system.

One of the lines runs from downtown Toronto near Rosedale Valley Road through the Don Valley to the northern edge of the city at Steeles Avenue.

The other line runs between the Etobicoke area of Toronto and a point in Oakville, Ont., just west of Fourth Line.

In total, the deal involves about 40 kilometres of track running through heavily populated areas in and around Canada's most populous city.

The Montreal-based railway will continue to have rights to run freight trains over the track.