Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for loading item footprints when they are available #70

Merged
merged 1 commit into from
Dec 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/qgis_stac/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ def handle_items(
assets=assets

)
if item.geometry:
item_result.geometry = item.geometry
items.append(item_result)

self.items_received.emit(items, pagination)
Expand Down
2 changes: 1 addition & 1 deletion src/qgis_stac/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ class Item:
type: ResourceType = None
stac_version: str = None
stac_extensions: typing.List[str] = None
geometry: ResourceGeometry = None
geometry: typing.Optional[dict] = None
bbox: typing.List[float] = None
properties: ResourceProperties = None
links: typing.List[ResourceLink] = None
Expand Down
40 changes: 39 additions & 1 deletion src/qgis_stac/gui/result_item_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

import os

import json
import tempfile

from functools import partial

from qgis.PyQt import (
Expand Down Expand Up @@ -114,6 +117,42 @@ def initialize_ui(self):
'selection-color: white;'
)

self.footprint_box.setEnabled(self.item.geometry is not None)
self.footprint_box.clicked.connect(self.add_footprint)

def add_footprint(self):
""" Adds the item footprint inside QGIS as a map layer"""
layer_file = tempfile.NamedTemporaryFile(
mode="w+",
suffix='.geojson',
delete=False
)
layer_name = f"{self.item.id}_footprint"
json.dump(self.item.geometry, layer_file)

layer_file.flush()

layer = QgsVectorLayer(
layer_file.name,
layer_name,
AssetLayerType.VECTOR.value
)
if layer.isValid():
QgsProject.instance().addMapLayer(layer)
self.main_widget.show_message(
tr("Successfully loaded footprint layer."),
level=Qgis.Info
)

else:
self.main_widget.show_message(
tr(
"Couldn't load footprint into QGIS,"
" its layer is not valid."
),
level=Qgis.Critical
)

def update_inputs(self, enabled):
""" Updates the inputs widgets state in the main search item widget.

Expand Down Expand Up @@ -156,7 +195,6 @@ def download_asset(self, index):
except Exception as e:
self.main_widget.show_message("Error in downloading file")


def load_asset(self, index):
""" Loads asset into QGIS.
Checks if the asset type is a loadable layer inside QGIS.
Expand Down
2 changes: 1 addition & 1 deletion src/qgis_stac/ui/qgis_stac_widget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
</sizepolicy>
</property>
<property name="currentIndex">
<number>2</number>
<number>0</number>
</property>
<widget class="QWidget" name="search">
<attribute name="title">
Expand Down
10 changes: 8 additions & 2 deletions src/qgis_stac/ui/result_item_widget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
<item>
<widget class="QToolButton" name="footprint_box">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Open resource in Browser&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>Add item footprint as a layer</string>
</property>
<property name="text">
<string>Add footprint</string>
Expand All @@ -155,6 +155,9 @@
</item>
<item>
<widget class="QComboBox" name="assets_load_box">
<property name="toolTip">
<string>Add item assets as layers</string>
</property>
<item>
<property name="text">
<string>Add assets as layers</string>
Expand All @@ -164,6 +167,9 @@
</item>
<item>
<widget class="QComboBox" name="assets_download_box">
<property name="toolTip">
<string>Download item assets</string>
</property>
<item>
<property name="text">
<string>Download assets</string>
Expand Down Expand Up @@ -195,7 +201,7 @@
<enum>QFrame::StyledPanel</enum>
</property>
<property name="text">
<string>Thumbnail</string>
<string>No Thumbnail</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
Expand Down