Edinburgh Castle is a fortress which dominates the skyline of the city of Edinburgh, Scotland, from its position atop the volcanic Castle Rock. Human habitation of the site is dated back as far as the 9th century BC, although the nature of early settlement is unclear. There has been a royal castle here since at least the reign of David I in the 12th century, and the site continued to be a royal residence until the Union of the Crowns in 1603. From the 15th century the castle’s residential role declined, and by the 17th century its principal role was as a military base with a large garrison. Its importance as a historic monument was recognised from the 19th century, and various restoration programmes have been carried out since. As one of the most important fortresses in the Kingdom of Scotland, Edinburgh Castle was involved in many historical conflicts, from the Wars of Scottish Independence in the 14th century, up to the Jacobite Rising of 1745, and has been besieged, both successfully and unsuccessfully, on several occasions.