Skip to content

Commit

Permalink
only add the default catalogs once
Browse files Browse the repository at this point in the history
  • Loading branch information
Samweli committed Dec 1, 2021
1 parent e3f2968 commit b2d8037
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 62 deletions.
10 changes: 10 additions & 0 deletions src/qgis_stac/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,16 @@ def is_current_connection(self, identifier: uuid.UUID):
current = self.get_current_connection()
return False if current is None else current.id == identifier

def is_connection(self, identifier: uuid.UUID):
"""Checks if the connection with the identifier exists
:param identifier: Connection settings identifier.
:type identifier: uuid.UUID
"""
connections = self.list_connections()
exists = any([connection.id == identifier for connection in connections])
return exists

def _get_connection_settings_base(
self,
identifier: typing.Union[str, uuid.UUID]):
Expand Down
55 changes: 16 additions & 39 deletions src/qgis_stac/definitions/catalog.py
Original file line number Diff line number Diff line change
@@ -1,55 +1,32 @@
CATALOGS = [
{
"id": "07e3e9dd-cbad-4cf6-8336-424b88abf8f3",
"name": "Microsoft Planetary Computer STAC API",
"url": "https://planetarycomputer.microsoft.com/api/stac/v1"
"url": "https://planetarycomputer.microsoft.com/api/stac/v1",
"selected": True,
},
{
"id": "d74817bf-da1f-44d7-a464-b87d4009c8a3",
"name": "Earth Search",
"url": "https://earth-search.aws.element84.com/v0"
"url": "https://earth-search.aws.element84.com/v0",
"selected": False,
},
{
"id": "aff201e0-58aa-483d-9e87-090c8baecd3c",
"name": "Digital Earth Africa",
"url": "https://explorer.digitalearth.africa/stac/"
},
{
"name": "Sentinel Hub STAC catalog",
"url": "https://services.sentinel-hub.com/api/v1/catalog/"
},
{
"name": "Sentinel-2 and Landsat-8 catalog",
"url": "https://tamn.snapplanet.io/"
},
{
"name": "openEO Platform",
"url": "https://openeocloud.vito.be/openeo/1.0.0/"
"url": "https://explorer.digitalearth.africa/stac/",
"selected": False,
},
{
"id": "98c95473-9f32-4947-83b2-acc8bbf71f36",
"name": "Radiant MLHub",
"url": "https://api.radiant.earth/mlhub/v1/"
"url": "https://api.radiant.earth/mlhub/v1/",
"selected": False,
},
{
"id": "17a79ce2-9a61-457d-926f-03d37c0606b6",
"name": "NASA CMR STAC",
"url": "https://cmr.earthdata.nasa.gov/stac"
},
{
"name": "NASA AVIRIS catalog",
"url": "https://franklin.nasa-hsi.azavea.com/"
},
{
"name": "data.geo.admin.ch",
"url": "https://data.geo.admin.ch/api/stac/v0.9/"
},
{
"name": "Digital Earth Australia",
"url": "https://explorer.sandbox.dea.ga.gov.au/stac/"
},
{
"name": "CBERS",
"url": "https://stac.amskepler.com/v100"
},
{
"name": "Astraea Earth OnDemand",
"url": "https://eod-catalog-svc-prod.astraea.earth/"
},

"url": "https://cmr.earthdata.nasa.gov/stac",
"selected": False,
}
]
34 changes: 11 additions & 23 deletions src/qgis_stac/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import re
import os.path

import uuid
from qgis.core import QgsSettings
from qgis.PyQt.QtCore import QSettings, QTranslator, QCoreApplication
from qgis.PyQt.QtGui import QIcon
Expand All @@ -21,13 +20,9 @@
# Initialize Qt resources from file resources.py
from .resources import *

from qgis_stac.gui.main import QgisStacWidget
from qgis_stac.definitions.catalog import CATALOGS

from qgis_stac.conf import (
ConnectionSettings,
settings_manager
)
from .gui.main import QgisStacWidget
from .conf import settings_manager
from .utils import config_defaults_catalogs


class QgisStac:
Expand All @@ -54,21 +49,14 @@ def __init__(self, iface):
self.toolbar = self.iface.addToolBar("STAC API Browser")
self.toolbar.setObjectName("QGISStac")

# Add catalog
duplicate_names = []
for catalog in CATALOGS:
connection_settings = ConnectionSettings(
id=uuid.uuid4(),
name=catalog['name'],
url=catalog['url'],
page_size=5,
auth_config=None,
)
name_pattern = re.compile(
f"^{connection_settings.name}$|^{connection_settings.name}(\(\d+\))$"
)
if len(settings_manager.list_connections()) <= len(CATALOGS):
settings_manager.save_connection_settings(connection_settings)
# Add default catalogs, first check if they have already
# been set.
if not settings_manager.get_value(
"default_catalogs_set",
default=False,
setting_type=bool
):
config_defaults_catalogs()

# noinspection PyMethodMayBeStatic
def tr(self, message):
Expand Down
37 changes: 37 additions & 0 deletions src/qgis_stac/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# -*- coding: utf-8 -*-
"""
Plugin utilities
"""
import uuid

from .conf import (
ConnectionSettings,
settings_manager
)

from .definitions.catalog import CATALOGS


def config_defaults_catalogs():
""" Initialize the plugin connections settings with the default
catalogs and set the current connection active.
"""

for catalog in CATALOGS:
connection_id = uuid.UUID(catalog['id'])
if not settings_manager.is_connection(
connection_id
):
connection_settings = ConnectionSettings(
id=connection_id,
name=catalog['name'],
url=catalog['url'],
page_size=5,
auth_config=None,
)
settings_manager.save_connection_settings(connection_settings)

if catalog['selected']:
settings_manager.set_current_connection(connection_id)

settings_manager.set_value("default_catalogs_set", True)

0 comments on commit b2d8037

Please sign in to comment.