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

Update on the AOI text input #123

Open
wants to merge 2 commits into
base: master
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
2 changes: 1 addition & 1 deletion planet_explorer/gui/pe_basemaps_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ def next_order_method_page_clicked(self):
def find_quads_clicked(self):
self.labelWarningQuads.setText("")
selected = self.mosaicsList.selected_mosaics()
if not self.aoi_filter.leAOI.text():
if not self.aoi_filter.leAOI.toPlainText():
self.labelWarningQuads.setText("⚠️ No area of interest (AOI) defined")
return
geom = self.aoi_filter.aoi_as_4326_geom()
Expand Down
6 changes: 3 additions & 3 deletions planet_explorer/gui/pe_dailyimages_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def perform_search(self, clicked=True):

send_analytics_for_search(self._sources)

if not self._aoi_filter.leAOI.text():
if not self._aoi_filter.leAOI.toPlainText():
id_filters = filters_from_request(self._filters, "id")
if len(id_filters) == 0:
self.lblWarning.setHidden(False)
Expand Down Expand Up @@ -351,8 +351,8 @@ def order_checked(self):
return

tool_resources = {}
if self._aoi_filter.leAOI.text():
tool_resources["aoi"] = self._aoi_filter.leAOI.text()
if self._aoi_filter.leAOI.toPlainText():
tool_resources["aoi"] = self._aoi_filter.leAOI.toPlainText()
else:
tool_resources["aoi"] = None

Expand Down
48 changes: 34 additions & 14 deletions planet_explorer/gui/pe_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,8 @@ def __init__(
# This may later be a nullptr, if no active tool when queried
self._cur_maptool = None

self.leAOI.textChanged["QString"].connect(self.filters_changed)
self.leAOI.textEdited["QString"].connect(self.validate_edited_aoi)
self.leAOI.textChanged.connect(self.filters_changed)
self.leAOI.textChanged.connect(self.validate_edited_aoi)

self._setup_tool_buttons()

Expand All @@ -335,15 +335,17 @@ def __init__(
self.p_client = PlanetClient.getInstance()

def reset_aoi_box(self):
self.leAOI.blockSignals(True)
self.leAOI.setText("")
self.leAOI.blockSignals(False)
if self._aoi_box:
self._aoi_box.reset(QgsWkbTypes.PolygonGeometry)

def filters(self):
filters = []
if self.leAOI.text():
if self.leAOI.toPlainText():
try:
qgsgeom = qgsgeometry_from_geojson(self.leAOI.text())
qgsgeom = qgsgeometry_from_geojson(self.leAOI.toPlainText())
if not qgsgeom.isEmpty():
geom_json = json.loads(qgsgeom.asJson())
filters.append(geom_filter(geom_json))
Expand All @@ -360,24 +362,26 @@ def filters(self):

def filters_as_json(self):
filters = []
if self.leAOI.text():
filters.append(self.leAOI.text())
if self.leAOI.toPlainText():
filters.append(self.leAOI.toPlainText())

return filters

def set_from_request(self, request):
self.emitFiltersChanged = False
filters = filters_from_request(request, "geometry")
self.leAOI.blockSignals(True)
if filters:
geom = filters[0]["config"]
txt = json.dumps(geom)
self.leAOI.setText(txt)
else:
self.leAOI.setText("")
self.leAOI.blockSignals(False)
self.emitFiltersChanged = True

@pyqtSlot("QString")
def filters_changed(self, value):
@pyqtSlot()
def filters_changed(self, value=None):
if self.emitFiltersChanged:
self.filtersChanged.emit()

Expand Down Expand Up @@ -645,7 +649,9 @@ def aoi_from_layer(self, layers):
# Sets the features to the canvas
geom_json = multipart_polygon.asJson(precision=6)
self._aoi_box.setToGeometry(multipart_polygon)
self.leAOI.blockSignals(True)
self.leAOI.setText(geom_json)
self.leAOI.blockSignals(False)

log.debug("AOI set to layer")

Expand Down Expand Up @@ -707,7 +713,9 @@ def aoi_bb_from_layer(self, layers):

self._aoi_box.setToGeometry(geom_bb)

self.leAOI.blockSignals(True)
self.leAOI.setText(geom_json)
self.leAOI.blockSignals(False)

log.debug("AOI set to layer")

Expand Down Expand Up @@ -760,7 +768,9 @@ def aoi_from_current_extent(self):

self._aoi_box.setToGeometry(QgsGeometry.fromRect(canvas.extent()))

self.leAOI.blockSignals(True)
self.leAOI.setText(extent_json)
self.leAOI.blockSignals(False)

log.debug("AOI set to canvas extent")

Expand Down Expand Up @@ -796,7 +806,9 @@ def aoi_from_active_layer_extent(self):
geom_extent = QgsGeometry.fromRect(transform_extent)
extent_json = geom_extent.asJson(precision=6)

self.leAOI.blockSignals(True)
self.leAOI.setText(extent_json)
self.leAOI.blockSignals(False)

log.debug("AOI set to active layer extent")

Expand Down Expand Up @@ -828,7 +840,9 @@ def aoi_from_full_extent(self):
extent_json = geom_extent.asJson(precision=6)
self._aoi_box.setToGeometry(QgsGeometry.fromRect(canvas_extent))

self.leAOI.blockSignals(True)
self.leAOI.setText(extent_json)
self.leAOI.blockSignals(False)

log.debug("AOI set to full data extent")

Expand Down Expand Up @@ -882,7 +896,9 @@ def set_draw_aoi(self, aoi):
aoi_json = aoi.asJson(precision=6)

if aoi_json:
self.leAOI.blockSignals(True)
self.leAOI.setText(aoi_json)
self.leAOI.blockSignals(False)

self._show_message("AOI set to drawn figure")
self.zoom_to_aoi()
Expand Down Expand Up @@ -952,7 +968,9 @@ def aoi_from_multiple_polygons(self):
# Sets the features to the canvas
geom_json = multipart_polygon.asJson(precision=6)
self._aoi_box.setToGeometry(multipart_polygon)
self.leAOI.blockSignals(True)
self.leAOI.setText(geom_json)
self.leAOI.blockSignals(False)

log.debug("AOI set to layer")

Expand Down Expand Up @@ -996,7 +1014,9 @@ def aoi_from_bound(self):
geom_bbox = QgsGeometry.fromRect(transform_bbox)
bbox_json = geom_bbox.asJson(precision=6)

self.leAOI.blockSignals(True)
self.leAOI.setText(bbox_json)
self.leAOI.blockSignals(False)

bbox_canvas = trans_canvas.transformBoundingBox(transform_bbox)
self._aoi_box.setToGeometry(QgsGeometry.fromRect(bbox_canvas))
Expand Down Expand Up @@ -1033,11 +1053,11 @@ def aoi_as_4326_geom(self):

@pyqtSlot()
def zoom_to_aoi(self):
if not self.leAOI.text():
if not self.leAOI.toPlainText():
log.debug("No AOI defined, skipping zoom to AOI")
return

geom: QgsGeometry = qgsgeometry_from_geojson(self.leAOI.text())
geom: QgsGeometry = qgsgeometry_from_geojson(self.leAOI.toPlainText())
if geom.isEmpty():
self._show_message(
"AOI GeoJSON geometry invalid", level=Qgis.Warning, duration=10
Expand All @@ -1048,18 +1068,18 @@ def zoom_to_aoi(self):

self.show_aoi()

zoom_canvas_to_aoi(self.leAOI.text())
zoom_canvas_to_aoi(self.leAOI.toPlainText())

self.zoomToAOIRequested.emit()

@pyqtSlot()
def copy_aoi_to_clipboard(self):
if not self.leAOI.text():
if not self.leAOI.toPlainText():
log.debug("No AOI defined, skipping zoom to AOI")
return

try:
json_obj = json.loads(self.leAOI.text())
json_obj = json.loads(self.leAOI.toPlainText())
except ValueError:
return

Expand All @@ -1072,7 +1092,7 @@ def copy_aoi_to_clipboard(self):

@pyqtSlot()
def validate_edited_aoi(self):
json_txt = self.leAOI.text()
json_txt = self.leAOI.toPlainText()
if not json_txt:
self.reset_aoi_box()
self.show_aoi_area_size()
Expand Down
8 changes: 4 additions & 4 deletions planet_explorer/tests/test_daily_imagery.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ def test_aoi_from_layer(name, layer_dir, expected_coordinates):
# Determines the extent
aoi_filter.aoi_from_layer([layer])

extent = aoi_filter.leAOI.text()
extent = aoi_filter.leAOI.toPlainText()
extent_json = json.loads(extent)
geom_type = extent_json.get("type")
coords = extent_json.get("coordinates")
Expand Down Expand Up @@ -569,7 +569,7 @@ def test_aoi_bb_from_layer(layer_dir, expected_coordinates):
# Determines the extent
aoi_filter.aoi_bb_from_layer([layer])

extent = aoi_filter.leAOI.text()
extent = aoi_filter.leAOI.toPlainText()
extent_json = json.loads(extent)
geom_type = extent_json.get("type")
coords = extent_json.get("coordinates")
Expand Down Expand Up @@ -753,7 +753,7 @@ def test_aoi_from_multiple_polygons(qtbot, pe_qgis_iface, layer_dir, expected_co
# Determines the extent
aoi_filter.aoi_from_multiple_polygons()

extent = aoi_filter.leAOI.text()
extent = aoi_filter.leAOI.toPlainText()
extent_json = json.loads(extent)
geom_type = extent_json.get("type")
coords = extent_json.get("coordinates")
Expand Down Expand Up @@ -808,7 +808,7 @@ def test_bb_aoi_from_multiple_polygons(qtbot, pe_qgis_iface, layer_dir, expected
# Determines the extent
aoi_filter.aoi_from_bound()

extent = aoi_filter.leAOI.text()
extent = aoi_filter.leAOI.toPlainText()
extent_json = json.loads(extent)
geom_type = extent_json.get("type")
coords = extent_json.get("coordinates")
Expand Down
4 changes: 2 additions & 2 deletions planet_explorer/tests/test_orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def get_order_dialog(qtbot, daily_images_widget):
images = daily_images_widget.searchResultsWidget.selected_images()

tool_resources = {}
if daily_images_widget._aoi_filter.leAOI.text(): # noqa
tool_resources["aoi"] = daily_images_widget._aoi_filter.leAOI.text() # noqa
if daily_images_widget._aoi_filter.leAOI.toPlainText(): # noqa
tool_resources["aoi"] = daily_images_widget._aoi_filter.leAOI.toPlainText() # noqa
else:
tool_resources["aoi"] = None

Expand Down
2 changes: 1 addition & 1 deletion planet_explorer/tests/test_saved_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def _dlg_interact():

# make sure the proper AOI from the saved search is loaded by checking the filter
qgis_debug_wait(qtbot, qgis_debug_enabled)
assert daily_images_widget._aoi_filter.leAOI.text() == sample_aoi
assert daily_images_widget._aoi_filter.leAOI.toPlainText() == sample_aoi


def test_create(qtbot, logged_in_explorer_dock_widget, qgis_debug_enabled, sample_aoi):
Expand Down
14 changes: 10 additions & 4 deletions planet_explorer/ui/pe_aoi_filter_base.ui
Original file line number Diff line number Diff line change
Expand Up @@ -198,20 +198,26 @@
<number>0</number>
</property>
<item>
<widget class="QLineEdit" name="leAOI">
<widget class="QTextEdit" name="leAOI">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>30</height>
</size>
</property>
<property name="toolTip">
<string>GeoJSON feature required:
- only polygon type supported
- use WGS 84 long, lat coordinates
- limited to 500 vertices
</string>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="placeholderText">
<string>Active coordinates (GeoJSON)</string>
</property>
<property name="clearButtonEnabled">
<bool>true</bool>
</property>
</widget>
</item>
<item>
Expand Down