CHEYENNE, Wyo. (AP) — Two Wyoming laws that prohibit trespassing to collect environmental data violate the U.S. Constitution's free-speech protections, a judge ruled in siding with two environmental groups and a news photographer association.

Wyoming officials moreover failed to demonstrate the laws are necessary to discourage environmentalists from documenting damage to streams and grasslands because of livestock grazing, U.S. District Judge Scott Skavdahl ruled Monday.

"There is simply no plausible reason for the specific curtailment of speech in the statutes beyond a clear attempt to punish individuals for engaging in protected speech that at least some find unpleasant," Skavdahl wrote in his ruling.

The laws prohibit not only trespassing to collect resource data on private land but trespassing on private land to collect data on public land.

Skavdahl ordered Wyoming to not enforce the statutes.

The two similar laws are an example of so-called "ag-gag" statutes states have enacted to shield the agriculture industry from monitoring by environmentalists and animal-welfare activists. Federal judges have struck down laws in Utah and Idaho that made it a crime to make undercover recordings at farms and slaughterhouses.

Violating one of the two similar Wyoming laws is punishable by up to a year in jail, double the possible jail time for simple trespassing. The other Wyoming law provides for civil penalties.

Two environmental groups, the Natural Resources Defense Council and Western Watersheds Project, and the National Press Photographers Association sued to contest the laws.

Skavdahl earlier sided with Wyoming officials in the case. The 10th U.S. Circuit Court of Appeals in 2017 sent the case back for him to decide if the laws violated free-speech rights.

It doesn't appear that anybody has been prosecuted under the laws because they were enacted in 2015 and revised in 2016, said Erik Molvar with Western Watersheds Project.

"But it's certainly had its intended effect of suppressing the gathering of data on public lands in parts of the state where public and private lands are intermingled with poorly marked boundaries," Molvar said Tuesday.

Wyoming Gov. Matt Mead and Attorney General Peter Michael didn't immediately respond to requests for comment on the ruling.