New York state’s highest court ruled Monday that towns can use land-use ordinances to ban hydraulic fracturing, the method of natural gas extraction also called fracking, ending a three-year battle over whether the state or local governments can control where and if shale gas development can occur.

For six years, the state had a moratorium on fracking and has been studying the potential health effects, the New York Times reported. Concerned that the state may eventually allow fracking, more than 170 communities have banned fracking or passed moratoriums.

However, those communities are some of the least attractive for shale gas extraction, according to Shale Gas Review. In southern communities sitting atop the Marcellus Shale, a booming gas field, many local governments support fracking. XTO Energy, a subsidiary of Exxon Mobil, has paid farmers across the Pennsylvania border $110 million to test drill on their land.

The case before the court concerned two towns, Dryden and Middlefield, which amended zoning laws to ban fracking in 2011, citing residents’ health, environment and the community’s character as reasons. Before the ban, an energy company in Dryden had bought oil and gas leases there, and a dairy farm in Middlefield had leased land to a gas drilling company. The two parties filed legal complaints, arguing that state oil-and-gas law preempted the towns’ new zoning laws.

The State Court of Appeals ruled 5-2 rejecting that argument and finding that the towns do have the authority to ban fracking through land-use regulations. The decision supports a plan proposed by New York Gov. Andrew Cuomo in summer 2012 that began issuing permits to areas where communities and industry want to develop natural gas resources.

The future of fracking in New York rests on whether the state legislature clarifies the state’s role in gas drilling operations, or if it bans fracking altogether, though fracking bans have so far failed in the state Senate. Cuomo could also decide at any time to withdraw the fracking study, but he is not likely to do that until after election day, Nov. 4, when he is expected to run for a second term.