
9 Cal.Rptr.3d 672 (2004)
115 Cal.App.4th 944
Michael TREMPER et al., Plaintiffs, Cross-defendants and Appellants,
v.
Victor QUINONES, Defendant, Cross-complainant and Respondent.
No. B165218.
Court of Appeal, Second District, Division Six.
February 17, 2004.
John F. Hodges, Arroyo Grande, for Plaintiffs, Cross-defendants and Appellants.
*673 No appearance for Defendant, Cross-complainant and Respondent.
PERREN, J.
Believing in good faith that he was working on his own property, Victor Quinones planted a crop of cacti on land belonging to his neighbors, Michael and Janis Tremper. The Trempers sued to quiet title against this wrongful use of their property, a claim for which the landowner generally is not entitled to recover attorney fees and costs. In response to the complaint, however, Quinones filed a cross-complaint seeking relief as a good faith improver. To obtain such relief, the good faith improver must pay any costs and attorney fees incurred by the landowner. (Code Civ. Proc.,[1] § 871.3; Civ.Code, § 1013.5.) The trial court found that Quinones was a good faith improver and granted him the right to remove his crops and other improvements from the Trempers' property, save one, and also granted the Trempers their requested relief. The court refused, however, to award the Trempers any costs and fees after counsel indicated that it was impossible to apportion costs and fees incurred in prosecuting the complaint, for which costs and fees are not allowed, and in defending against the cross-complaint, which mandates such recovery.
The law recognizes that one may innocently and in good faith trespass upon and improve the property of a neighbor. When realized, the good faith improver may seek to recover the improvements placed upon the neighbor's land and seek the assistance of the court in doing so. In making that decision, however, the improver must weigh the cost of the loss of the improvement against his recovery, which will include "protect[ing] the owner of the land upon which the improvement was constructed against any pecuniary loss." (§ 871.5.) Here, the trial court did not protect the landowner against such loss. Pursuant to the good faith improver statutes, the trial court could not grant Quinones the right to remove improvements from the Trempers' property without also requiring him to reimburse the Trempers for all reasonable costs and fees incurred in litigating their rights to that property, without regard to whether they were incurred in litigating the causes of action raised in their complaint or the causes of action raised in Quinones's cross-complaint. Accordingly, we reverse.

FACTS AND PROCEDURAL HISTORY
In December 1996, Quinones purchased 180 acres of unimproved rural property near Santa Maria. The Trempers purchased 170 acres of unimproved property adjacent to the eastern edge of Quinones's property in May 2000. Quinones incorrectly calculated the boundary of his property as approximately 660 feet east of its actual location, on property which belonged to the Trempers. Quinones subsequently planted cacti for commercial harvest on that portion of the property, and he placed a water pump in a well on the property. He also permitted his livestock to roam and to graze upon that portion of the property, resulting in damage to some oak trees.
After the Trempers closed escrow on their property, they informed Quinones of their intention to have the property surveyed. Both parties and another adjacent landowner subsequently agreed to share the cost of approximately $15,000 for a *674 survey. The survey disclosed that Quinones's cacti encroached upon the Trempers' property. When Quinones continued planting cacti on the Trempers' property, they filed an action for quiet title, trespass, nuisance, destruction of trees, and for declaratory relief and a preliminary and permanent injunction. Quinones answered the complaint and cross-complained for quiet title based on the doctrine of agreed boundary, and for relief as a good faith improver pursuant to section 871.3.
In its statement of decision, the trial court concluded that the doctrine of agreed boundary did not apply. The court also found that the record of survey accurately described the boundaries of the parties' properties, and quieted title in favor of the Trempers with regard to that portion of their property that Quinones had utilized as his own. Quinones was found liable for trespass resulting in damage to the Trempers' trees. To offset the damage to the trees, the court awarded the Trempers the water pump that Quinones placed on the property.
The court found in favor of Quinones on his good faith improver claim. The court further found, pursuant to section 871.4, that Quinones's relief was limited to removal of his improvements from the Trempers' property, as provided by Civil Code section 1013.5. The court further recognized that a party awarded relief as a good faith improver must pay the landowner's costs of suit and attorney fees (§ 871.5; Civ.Code, § 1013.5), and retained jurisdiction to determine the amount of the award.
The Trempers thereafter submitted an application for $22,519.50 in attorney fees and $8,105.04 in costs, with documentation supporting the claimed costs and fees. Quinones opposed the application, contending that he had not been afforded any relief as contemplated by the good faith improver statutes. He further complained that an award of fees against him would amount to a penalty for seeking good faith improver relief, since the Trempers would not have been entitled to their fees had he not cross-complained for such relief.
At the hearing on the Trempers' application, the trial court determined that the Trempers were only entitled to recover those fees incurred in litigating the issue of removal, as opposed to the litigation regarding ownership of the property. The court directed the Trempers as follows: "I want you to tell me how much of the trial and how much of your preparation was spent in deciding who was going to own the property. Then when Mr. Quinones says, `If I'm not going to own it, I want to move my crop,' how much of the trial was spent on that." When the Trempers' counsel argued that any attempt at apportionment would be futile because the ownership issue was part and parcel of the removal issue, the court responded, "you will have to appeal that part. You have argued it. My intended ruling is my ruling. It will be apportioned."
The Trempers submitted supplemental briefing, in which counsel provided a detailed analysis of the legal work expended on the case. Counsel stated that it was impossible to apportion fees in the manner contemplated by the court. Counsel also asserted that the court could not grant Quinones relief as a good faith improver without also requiring him to pay all costs and attorney fees incurred by the Trempers in the action in which such relief was sought. At the hearing on the matter, the court stated, "[Quinones doesn't] have to pay you anything, because ... I can't get a percentage out and I won't guess." Accordingly, the court entered an order denying the Trempers' application for costs and fees. This appeal followed.


*675 DISCUSSION
After the Trempers sued to quiet title to a portion of property upon which their neighbor Quinones had planted cacti, Quinones cross-complained for relief as a good faith improver under section 871.3. For purposes relevant here, a good faith improver is defined as "A person who makes an improvement to land in good faith and under the erroneous belief, because of a mistake of law or fact, that he is the owner of the land." (§ 871.1, subd. (a).)
The trial court, in adjudicating an action brought under section 871.3, has equitable authority to fashion a remedy "as is consistent with substantial justice to the parties under the circumstances of the particular case." (§ 871.5.) In granting any relief to a good faith improver, the court "shall protect the owner of the land upon which the improvement was constructed against any pecuniary loss...." (Ibid.) The statutory scheme further provides that "In protecting the owner of the land against pecuniary loss, the court shall take into consideration the expenses the owner of the land has incurred in the action in which relief ... is sought, including but not limited to reasonable attorney fees." (Ibid.)
Section 871.4 provides that equitable relief will not lie where, for purposes relevant here, "exercise of the good faith improver's right ... to remove the improvement under Section 1013.5 of the Civil Code would result in substantial justice to the parties under the circumstances of the particular case." Civil Code section 1013.5, subdivision (a) gives a good faith improver the right to remove the improvements "upon payment ... to the owner of the land ... of all their damages proximately resulting from the affixing and removal of such improvements." The statute further provides that "In any action brought to enforce such right the owner of the land [who shall be named as a defendant] ... shall recover his costs of suit and a reasonable attorney's fee to be fixed by the court." (Civ.Code, § 1013.5, subd. (b).)
The trial court found that Quinones was a good faith improver, and accordingly awarded him the right to remove his cacti from the Trempers' property. The court also recognized that it could not grant such relief without also awarding the Trempers costs and attorney fees. The court concluded, however, that the Trempers were only entitled to recover those costs and fees incurred in litigating the good faith improver claim raised in Quinones's cross-complaint, as distinguished from the dispute regarding the ownership of the property that was the subject of the Trempers' complaint.
We agree with the Trempers that the court erred in so concluding. Section 871.5 plainly provides that a party granted relief as a good faith improver must protect the landowner from any pecuniary loss incurred in litigating the matter, which includes attorney fees and costs "incurred in the action in which relief" as a good faith improver is sought. The statute does not limit the landowner's recovery to those losses incurred in litigating the cross-complaint of the party seeking relief as a good faith improver. Rather, the landowner must also be reimbursed for any expenses incurred in bringing the action that precipitated the cross-complaint. Because the trial court granted Quinones relief as a good faith improver of the Trempers' property, Quinones must compensate the Trempers for their litigation expenses, without regard to whether those expenses were incurred in prosecuting their rights to the exclusive use and possession of their property, or in defending against Quinones's claim to the improvements thereon.
Raab v. Casper (1975) 51 Cal.App.3d 866, 124 Cal.Rptr. 590 is instructive. The *676 plaintiffs in that case brought an action for a mandatory injunction and damages against adjoining landowners, alleging that they had trespassed by building a family home and cabin on portions of the plaintiffs' property. The trial court found that the defendants were good faith improvers with regard to the cabin, realigned the boundary in favor of the defendants, and compensated the plaintiffs accordingly. The court also awarded the plaintiffs $750 in attorney fees, and $500 for the cost of a survey. On appeal, the plaintiffs alleged among other things that the court erred in awarding them only $500 for the survey because they had actually expended $1,757.20. The Court of Appeal agreed that the plaintiffs were entitled to recover the entire cost of the survey pursuant to section 871.5. The court reasoned that "the survey was necessitated by defendants' act of constructing their cabin on plaintiffs' land." (Id., at p. 876, 124 Cal.Rptr. 590.)
Here, the Trempers' lawsuit was necessitated by Quinones's act of planting cacti on their land. Their complaint sought nothing more than to quiet title to their property and to prevent Quinones from further trespassing on it or damaging its trees. Pursuant to section 871.4, the court could allow Quinones to remove his property from the Trempers' property only if doing so would result in substantial justice to the parties. Section 871.5 provides that substantial justice in this regard requires Quinones to protect the Trempers against any pecuniary loss incurred in litigating claims that were precipitated by Quinones's trespass. Because all of the causes of action in the Trempers' complaint were necessitated by the very act that gave rise to Quinones's status as a good faith improver, the court erred in ordering the Trempers to apportion costs and fees incurred in litigating those causes of action.
Quinones complains that he should not be held liable for the Trempers' costs and fees because the court did not grant him the equitable relief afforded by section 871.3, but rather granted him the right of removal provided by Civil Code section 1013.5. The result would be no different, however, if Quinones had brought his cross-complaint under Civil Code section 1013.5. That section provides that the good faith improver shall have the right to remove his or her improvements only "upon payment ... to the owner of the land, and any other person having any interest therein ... of all their damages proximately resulting from the affixing and removal of such improvements," and that "the owner of the land shall recover his costs of suit and a reasonable attorney's fee to be fixed by the court." (Civ.Code, § 1013.5, subds.(a), (b).) Because the costs and fees the Trempers incurred in bringing their complaint were the proximate result of Quinones's trespass on their land, Quinones would be liable for those costs and fees if he had cross-complained under Civil Code section 1013.5 instead of section 871.3.
In ordering the Trempers to apportion their fees, the court reasoned that Quinones would not have been liable for any fees had he not filed his cross-complaint seeking relief as a good faith improver. The court failed to appreciate, however, that Quinones would have lost a crop that, according to his cross-complaint, was worth $180,000. In exchange for obtaining the right to remove that crop, he must protect the landowners from any pecuniary loss incurred as a result of the trespass, which includes all costs and fees incurred in litigating their rights to the land.

DISPOSITION
The order denying the Trempers' application for attorney fees and costs is reversed. *677 The matter is remanded to the trial court to set the amount of costs and fees to be awarded, without regard to whether those costs and fees were incurred in prosecuting the complaint or defending against the cross-complaint. The Trempers are awarded costs on appeal. In addition, they are entitled to attorney fees on appeal, in an amount to be determined on noticed motion in the trial court.
We concur: YEGAN, Acting P.J., and COFFEE, J.
NOTES
[1]  All further statutory references are to the Code of Civil Procedure unless otherwise noted.
