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 spatial extent filtering in API v2 #169

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
19 changes: 12 additions & 7 deletions src/qgis_geonode/apiclient/apiv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class GeonodeApiV2Client(base.BaseGeonodeClient):
models.ApiClientCapability.FILTER_BY_RESOURCE_TYPES,
models.ApiClientCapability.FILTER_BY_TEMPORAL_EXTENT,
models.ApiClientCapability.FILTER_BY_PUBLICATION_DATE,
models.ApiClientCapability.FILTER_BY_SPATIAL_EXTENT,
]

@property
Expand Down Expand Up @@ -96,13 +97,17 @@ def _build_search_query(
"filter{date.lte}",
search_params.publication_date_end.toString(QtCore.Qt.ISODate),
)
# TODO revisit once the support for spatial extent is available on
# GeoNode API V2
if (
search_params.spatial_extent is not None
and not search_params.spatial_extent.isNull()
):
pass

if search_params.spatial_extent is not None:
spatial_extent_value = (
f"{search_params.spatial_extent.xMinimum()},"
f"{search_params.spatial_extent.yMinimum()},"
f"{search_params.spatial_extent.xMaximum()},"
f"{search_params.spatial_extent.yMaximum()}"
)

query.addQueryItem("extent", spatial_extent_value)

if search_params.layer_types is None:
types = [
models.GeonodeResourceType.VECTOR_LAYER,
Expand Down
5 changes: 4 additions & 1 deletion src/qgis_geonode/gui/geonode_source_select_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ def __init__(self, parent, fl, widgetMode):
# ATTENTION: the order of initialization of the self.spatial_extent_box widget
# is crucial here. Only call self.spatial_extent_box.setMapCanvas() after
# having called self.spatial_extent_box.setOutputExtentFromCurrent()
self.spatial_extent_box.setTitleBase(tr("Spatial Extent"))
epsg_4326 = qgis.core.QgsCoordinateReferenceSystem("EPSG:4326")
self.spatial_extent_box.setOutputCrs(epsg_4326)
map_canvas = iface.mapCanvas()
Expand Down Expand Up @@ -431,7 +432,9 @@ def search_geonode(self, reset_pagination: bool = False):
if not pub_start.isNull()
else None,
publication_date_end=pub_end if not pub_end.isNull() else None,
spatial_extent=spatial_extent_epsg4326,
spatial_extent=spatial_extent_epsg4326
if self.spatial_extent_box.isChecked()
else None,
)
)

Expand Down
13 changes: 11 additions & 2 deletions src/qgis_geonode/ui/geonode_datasource_widget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,18 @@
<item row="7" column="0" colspan="2">
<widget class="QgsExtentGroupBox" name="spatial_extent_box">
<property name="title">
<string>Spatial Extent</string>
<string>Extent (current: none)</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<property name="collapsed">
<bool>false</bool>
</property>
<property name="saveCheckedState">
<bool>true</bool>
</property>
</widget>
Expand Down Expand Up @@ -606,7 +615,7 @@
<x>0</x>
<y>0</y>
<width>708</width>
<height>366</height>
<height>226</height>
</rect>
</property>
</widget>
Expand Down