SOUTH PORTLAND, Maine—A federal judge has handed a win to South Portland, Maine over a pipeline company that wants to send tar sands oil through the city, a proposal seen as opening a path for Canada's crude to reach the East Coast for export.

But the fight is not over. A federal district court judge dismissed on Dec. 29 all but one of the company's claims against the city. The ruling still leaves open a key question: whether the city is violating the U.S. Constitution by blocking the project.

At the heart of the lawsuit is the question of local control and what—if anything—a community can do to block an unwanted energy project.

The outcome could influence similar lawsuits elsewhere. When the Portland Pipe Line Corporation (PPLC) sued this small coastal city in 2015, it had some powerful allies, including the American Petroleum Institute, whose members include most major oil and gas companies.

The industry argued that a local ordinance prohibiting the export of heavy crude from South Portland's harbor is unconstitutional. That ordinance essentially stopped in its tracks PPLC's plans to reverse an existing pipeline and start piping tar sands oil from Canada to Maine, where it could be shipped to international markets.

"It's a great decision," said Sean Mahoney, of the Conservation Law Foundation, who has advised the city. "They won on 8 out of 9 counts—but they've got a big kahuna count left."

What's left to decide is whether the ordinance violates the federal commerce clause—an authority granted by the Constitution, which allows Congress to regulate interstate commerce. The company's argument is that local authorities do not have the ability to regulate interstate trade.

That issue will likely be taken up in a trial later this year.

Portland Pipe Line Corporation has been developing plans to reverse the flow direction of its Portland-Montreal Pipeline for nearly a decade. The pipeline currently brings conventional oil from South Portland to Montreal, but since production of tar sands oil in Canada ramped up, the need for oil to be delivered from Maine to Quebec has all but disappeared, along with PPLC's business model.

Since getting wind of the company's plans 2013, a local grassroots effort led by the group Protect South Portland has fought the reversal, arguing it would increase air pollution. The reversal would call for the construction of a pair of 70-foot high smokestacks that would burn off volatile organic compounds from the oil before loading it into tankers.

After a ballot initiative to block the project failed— a measure that API and oil companies spent hundreds of thousands of dollars to defeat—the City Council passed an ordinance in 2014. Called the Clear Skies Ordinance, it zeroed in on air pollution concerns from the project.

The lawsuit swiftly followed the ordinance's passage, and a lengthy—and expensive—legal process ensued. As of August 2017, the city had spent $1.1 million dollars to defend the ordinance. South Portland's operating budget is $32.6 million.

Following earlier decisions that were not in the city's favor, the judge's ruling came as a surprise to supporters of the ordinance. The decision dismissed claims by the company that several federal laws preempt local law.

"Immediately I felt some relief," said Rachel Burger, the co-founder and president of Protect South Portland. "Suddenly it's like, oh, we might prevail."

The company said it will continue its fight against the ordinance.

"While we are disappointed with aspects of the judge's decision, our claim under the Commerce Clause remains to be decided," attorney Jim Merrill, who represents PPLC, said in a statement. "Portland Montreal Pipe Line will vigorously continue its challenge of the ordinance."

South Portland City Manager Scott Morelli said the city was pleased with the judge's rulings and will continue to defend the ordinance. "The city looks forward to the opportunity to resolve the remaining issues in its favor," he said.

It could be a long haul. No matter the outcome of the trial, both sides are expected to appeal, and the case could wind up in the U.S. Supreme Court.