The origins of the ancient Gauja River valley go back more than 350 million years, but its current ravine-ridden terrain was moulded by the glacier meltwater at the end of the Ice Age. The Gauja, which is the longest river in Latvia (452 km), winds through the national park. The river once served as a trading route, and the Livonians built their settlements on its banks. Strong stone castles, which were enclosed by steep slopes and deep valleys, were built in the 13th century. The cities and the social and cultural life grew around these castles.