The federal government and the Westlands Water District apparently settled a long and bitter dispute yesterday over how much federal water the giant irrigation district is entitled to and at what cost.

The Interior Department's Bureau of Reclamation and Westlands officials formally agreed to a new 28-year water contract during negotiations at bureau offices in Sacrament, Calif.

The contract, subject to ratification by the Westlands board of directors on Aug. 20, would guarantee the district more than 1 million acre feet of water a year at a new, higher price.

Perhaps more importantly, the agreement settles a tangled legal dispute over the district's rights to some of the water - a dispute that was bound to wind up in the courts unless it was successfully negotiated as part of the contract.

Westlands, covering an estimated 600,000 acres of rich farmland on the west side of California's San Joaquin Valley, is the largest project of its kind in the federal water reclamation system. The reclamation bureau and Interior recognized Westlands as the most heavily subsidized and controversial district in the system, partly because many of its members are large corporate farms that have been receiving water at bargain-basement rates since the mid-1960s.

Interior considered resolution of the Westlands dispute to be the key to moving ahead with further water development projects in the reclamation Bureau's huge Central Valley Project in California. One of those projects involves construction of the San Joaquin Drain, which would siphon off salty used irrigation water that now threatens to rob millions of acres of their rich productivity.

In essence, the contract would:

Give the government a new higher price of $9.09 an acre foot for Westland's basic annual allotment of 900,000-acre feet of water now sold for $7.50 an acre foot.

Grant Westlands legal rights to another 250,000 acre feet that it has been using under cloudy legal circumstances. The price for this water, now also $7.50 an acre foot, will go to $11.80, which is what the Bureau of Reclamation calculates to be its cost of delivering the water to Westlands.

Give the bureau the right to cut off as much as 103,000 acre feet of Westlands water a year if it is needed to protect water quality in the Sacramento-San Joaquin River Delta in drought years. In the past, valley farmers challenged the right of the bureau to use federal project water for such environmental enhancement. In fact, the bureau had resisted state efforts to force it to use Central Valley Project water for delta water quality.

Opinions varied widely as to the effect of the agreement, which followed long months of deadlock between the Interior Deparment and Westlands.