The territories of the Viceroyalty - New Granada ( Colombia ) , Venezuela , and Quito - gained their independence between 1819 and 1822 and formed a federation known as Gran Colombia .