The NYPD will now have to also rewrite the book on how it stops and frisks criminal trespassing suspects in public housing projects, under a preliminary settlement to a federal class-action lawsuit reached this week.

The tentative agreement, which still needs to be ratified by Manhattan federal Judge Shira Scheindlin, would end a five-year-old lawsuit brought on behalf of residents and visitors at New York City Housing Authority residences who challenged the NYPD’s policies for stopping and arresting people there for trespassing without probable cause. The plaintiffs claimed the alleged illegal conduct was based on racial profiling.

Among the proposed changes would be revising the NYPD’s patrol guide and training manuals that instruct cops on how to interact with Housing Authority residents and visitors.

Unlike last year’s settlement that green-lighted the de Blasio administration to move ahead with how the NYPD executes stop-and-frisk tactics based on street stops, the proposed settlement deals with stops within Housing Authority sites.

If Scheindlin — who previously ruled that stop-and-frisk illegally targeted minorities and ordered sweeping reforms — signs off on the deal as expected, the Housing Authority would also fall under the same court-ordered monitoring process outlined in the earlier stop-and-frisk cases.

“This agreement strikes the right balance between safety in NYCHA developments and the rights of residents and their guests to be free from harassment and unlawful arrests. The court monitoring process offers an opportunity for the community and the NYPD to have a meaningful discussion that is essential for constructive change, especially during this critical time in police-community relations,” said Seymour James Jr., a lawyer for the Legal Aid Society, which helped represent the plaintiffs. “We are eager to begin the process that will ensure better security, and better police services, for public housing residents.”

Judge Analisa Torres, who was assigned the earlier stop-and frisk cases in November 2013 after an appellate panel booted Scheindlin off them while also questioning her impartiality, will ultimately oversee the administration of the planned settlement.