Except to the extent required to implement section 335.27, no ordinance adopted under this chapter applies to land, farm houses, farm barns, farm outbuildings or other buildings or structures which are primarily adapted, by reason of nature and area, for use for agricultural purposes, while so used. However, the ordinances may apply to any structure, building, dam, obstruction, deposit or excavation in or on the flood plains of any river or stream.