Skip to content

Commit

Permalink
Merge pull request #29 from MIERUNE/feat/get-catalog-online
Browse files Browse the repository at this point in the history
Feat/get catalog online
  • Loading branch information
nbayashi authored May 30, 2024
2 parents 7b540b4 + 9a72ea1 commit 7c1caf2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 14 deletions.
10 changes: 6 additions & 4 deletions catalog/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ def get_catalog() -> dict:
unused in plugin
this method needs too long time to run everytime on launch plugin
run when build this plugin and make dictionary with output of this script
UPDATE 2024-05-30 : catalog can be retrieved through following URL:
https://data.earth.jaxa.jp/app/qgis/catalog.json
This script to be used only when above URL does not work.
"""
catalog = {}

res = requests.get(STAC_CATALOG_URL)
res_json = res.json()

children = list(
filter(lambda d: d["rel"] == "child", res_json.get("links", [])))
children = list(filter(lambda d: d["rel"] == "child", res_json.get("links", [])))
for child in children:
res_child = requests.get(child["href"])
res_child_json = res_child.json()
Expand All @@ -33,12 +35,12 @@ def get_catalog() -> dict:
"bands": dataset_bands,
"keywords": dataset_keywords,
"bbox": dataset_bbox,
"temporal": dataset_temporal
"temporal": dataset_temporal,
}
return catalog


if __name__ == "__main__":
catalog = get_catalog()
with open('./catalog.json', mode='w') as f:
with open("./catalog.json", mode="w") as f:
json.dump(catalog, f, ensure_ascii=False)
38 changes: 34 additions & 4 deletions jaxaEarthApiDialog.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""
/***************************************************************************
Sample
JAXA Earth API Plugin
A QGIS plugin
QGIS Sample Plugin
QGIS Plugin for JAXA Earth API, easily get satellite datasets.
-------------------
begin : 2021-06-30
git sha : $Format:%H$
Expand All @@ -16,6 +16,7 @@
import json
import datetime
import webbrowser
import requests

# QGIS-API
from qgis.PyQt import uic
Expand All @@ -29,8 +30,37 @@
# Load module
from .jaxa.earth import je

with open(os.path.join(os.path.dirname(__file__), "catalog.json")) as f:
CATALOG = json.load(f)
# Load jaxa dataset catalog
CATALOG_URL = "https://data.earth.jaxa.jp/app/qgis/catalog.json"

try:
response = requests.get(CATALOG_URL, timeout=60)
if response.status_code == 200:
CATALOG = response.json()
print(response)
else:
message = "Could not load catalog.json\n"
message += f"Response {response.status_code} \nLoad local catalog"
QMessageBox.information(
None,
"JAXA Earth API Plugin - Warning",
message,
)
# Fallback load local catalog
with open(os.path.join(os.path.dirname(__file__), "catalog.json")) as f:
CATALOG = json.load(f)
except Exception as e:
message = "Could not load catalog.json\n"
message += f"{str(e)} \nLoad local catalog"
QMessageBox.information(
None,
"JAXA Earth API Plugin - Warning",
message,
)
print(e)
# Fallback load local catalog
with open(os.path.join(os.path.dirname(__file__), "catalog.json")) as f:
CATALOG = json.load(f)


def parse_jaxa_dateid(date_id: str, year=None) -> (int, int, int):
Expand Down
11 changes: 5 additions & 6 deletions jaxaEarthApiPlugin.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""
/***************************************************************************
Sample
JAXA Earth API Plugin
A QGIS plugin
QGIS Sample Plugin
QGIS Plugin for JAXA Earth API, easily get satellite datasets.
-------------------
begin : 2021-06-30
git sha : $Format:%H$
Expand Down Expand Up @@ -39,11 +39,10 @@ def __init__(self, iface):
self.dialog = None
self.action = None
# initialize locale
locale = QSettings().value('locale/userLocale')[0:2]
locale = QSettings().value("locale/userLocale")[0:2]
locale_path = os.path.join(
self.plugin_dir,
'i18n',
'jaxaEarthApi_{}.qm'.format(locale))
self.plugin_dir, "i18n", "jaxaEarthApi_{}.qm".format(locale)
)

if os.path.exists(locale_path):
self.translator = QTranslator()
Expand Down

0 comments on commit 7c1caf2

Please sign in to comment.