Skip to content

Commit

Permalink
Merge pull request #26 from Fanevanjanahary/stac_api_list
Browse files Browse the repository at this point in the history
add list of populate stac api
  • Loading branch information
Samweli authored Dec 1, 2021
2 parents 12b9835 + ad4f8ad commit 058227c
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 14 deletions.
10 changes: 10 additions & 0 deletions src/qgis_stac/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,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
Empty file.
32 changes: 32 additions & 0 deletions src/qgis_stac/definitions/catalog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
CATALOGS = [
{
"id": "07e3e9dd-cbad-4cf6-8336-424b88abf8f3",
"name": "Microsoft Planetary Computer STAC API",
"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",
"selected": False,
},
{
"id": "aff201e0-58aa-483d-9e87-090c8baecd3c",
"name": "Digital Earth Africa",
"url": "https://explorer.digitalearth.africa/stac/",
"selected": False,
},
{
"id": "98c95473-9f32-4947-83b2-acc8bbf71f36",
"name": "Radiant MLHub",
"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",
"selected": False,
}
]
3 changes: 1 addition & 2 deletions src/qgis_stac/gui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from qgis.PyQt import QtCore, QtGui, QtNetwork, QtWidgets, QtXml
from qgis.PyQt.uic import loadUiType

from ..conf import settings_manager
from ..resources import *
from ..gui.connection_dialog import ConnectionDialog

Expand Down Expand Up @@ -121,5 +122,3 @@ def display_results(self):

def display_search_error(self):
raise NotImplementedError


36 changes: 24 additions & 12 deletions src/qgis_stac/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
***************************************************************************/
"""

import re
import os.path

from qgis.core import QgsSettings
Expand All @@ -19,7 +20,9 @@
# Initialize Qt resources from file resources.py
from .resources import *

from qgis_stac.gui.main import QgisStacWidget
from .gui.main import QgisStacWidget
from .conf import settings_manager
from .utils import config_defaults_catalogs


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

# 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):
"""Get the translation for a string using Qt translation API.
Expand All @@ -59,16 +71,16 @@ def tr(self, message):
return QCoreApplication.translate("QgisStac", message)

def add_action(
self,
icon_path,
text,
callback,
enabled_flag=True,
add_to_menu=True,
add_to_toolbar=True,
status_tip=None,
whats_this=None,
parent=None,
self,
icon_path,
text,
callback,
enabled_flag=True,
add_to_menu=True,
add_to_toolbar=True,
status_tip=None,
whats_this=None,
parent=None,
):
"""Add a toolbar icon to the toolbar.
:param icon_path: Path to the icon for this action. Can be a resource
Expand Down Expand Up @@ -142,4 +154,4 @@ def unload(self):
def run(self):
self.main_widget.show()
if not self.pluginIsActive:
self.pluginIsActive = True
self.pluginIsActive = True
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 058227c

Please sign in to comment.