This repository has been archived by the owner on Nov 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from kbgg/dev
Version 1.1.0 Release
- Loading branch information
Showing
18 changed files
with
721 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[flake8] | ||
exclude = help/,venv/,resources.py | ||
per-file-ignores = stac_browser.py:F401,F403 | ||
max-line-length = 119 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# Contributor Covenant Code of Conduct | ||
|
||
## Our Pledge | ||
|
||
In the interest of fostering an open and welcoming environment, we as | ||
contributors and maintainers pledge to making participation in our project and | ||
our community a harassment-free experience for everyone, regardless of age, body | ||
size, disability, ethnicity, sex characteristics, gender identity and expression, | ||
level of experience, education, socio-economic status, nationality, personal | ||
appearance, race, religion, or sexual identity and orientation. | ||
|
||
## Our Standards | ||
|
||
Examples of behavior that contributes to creating a positive environment | ||
include: | ||
|
||
* Using welcoming and inclusive language | ||
* Being respectful of differing viewpoints and experiences | ||
* Gracefully accepting constructive criticism | ||
* Focusing on what is best for the community | ||
* Showing empathy towards other community members | ||
|
||
Examples of unacceptable behavior by participants include: | ||
|
||
* The use of sexualized language or imagery and unwelcome sexual attention or | ||
advances | ||
* Trolling, insulting/derogatory comments, and personal or political attacks | ||
* Public or private harassment | ||
* Publishing others' private information, such as a physical or electronic | ||
address, without explicit permission | ||
* Other conduct which could reasonably be considered inappropriate in a | ||
professional setting | ||
|
||
## Our Responsibilities | ||
|
||
Project maintainers are responsible for clarifying the standards of acceptable | ||
behavior and are expected to take appropriate and fair corrective action in | ||
response to any instances of unacceptable behavior. | ||
|
||
Project maintainers have the right and responsibility to remove, edit, or | ||
reject comments, commits, code, wiki edits, issues, and other contributions | ||
that are not aligned to this Code of Conduct, or to ban temporarily or | ||
permanently any contributor for other behaviors that they deem inappropriate, | ||
threatening, offensive, or harmful. | ||
|
||
## Scope | ||
|
||
This Code of Conduct applies both within project spaces and in public spaces | ||
when an individual is representing the project or its community. Examples of | ||
representing a project or community include using an official project e-mail | ||
address, posting via an official social media account, or acting as an appointed | ||
representative at an online or offline event. Representation of a project may be | ||
further defined and clarified by project maintainers. | ||
|
||
## Enforcement | ||
|
||
Instances of abusive, harassing, or otherwise unacceptable behavior may be | ||
reported by contacting the project team at [email protected]. All | ||
complaints will be reviewed and investigated and will result in a response that | ||
is deemed necessary and appropriate to the circumstances. The project team is | ||
obligated to maintain confidentiality with regard to the reporter of an incident. | ||
Further details of specific enforcement policies may be posted separately. | ||
|
||
Project maintainers who do not follow or enforce the Code of Conduct in good | ||
faith may face temporary or permanent repercussions as determined by other | ||
members of the project's leadership. | ||
|
||
## Attribution | ||
|
||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, | ||
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html | ||
|
||
[homepage]: https://www.contributor-covenant.org | ||
|
||
For answers to common questions about this code of conduct, see | ||
https://www.contributor-covenant.org/faq |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
build: | ||
pb_tool deploy -y | ||
pb_tool zip --quick | ||
|
||
lint: | ||
flake8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
import re | ||
|
||
from PyQt5 import uic | ||
from PyQt5.QtWidgets import ( | ||
QWidget, QAction, QMenu, QVBoxLayout, QDialog, QDialogButtonBox) | ||
|
||
import qgis.utils | ||
|
||
from qgis.core import ( | ||
QgsProject, QgsMapLayerProxyModel, QgsRectangle, QgsReferencedRectangle, | ||
QgsPointXY, QgsCoordinateReferenceSystem) | ||
from qgis.gui import QgsMapLayerComboBox | ||
from processing.gui.RectangleMapTool import RectangleMapTool | ||
|
||
from ..utils import ui | ||
|
||
|
||
FORM_CLASS, _ = uic.loadUiType(ui.path('extent_selector.ui')) | ||
|
||
|
||
class ExtentSelector(QWidget, FORM_CLASS): | ||
"""Helper widget to provide extent selection functionality. | ||
Mimics the UI behaviour of the qgis.processing.gui.ExtentSelectionPanel | ||
""" | ||
|
||
EXTRACT_REGEX = r'(-?\d+(\.\d+)?) (-?\d+(\.\d+)?), (-?\d+(\.\d+)?) (-?\d+(\.\d+)?) \[(EPSG:(\d{2,}))\]' | ||
|
||
def __init__(self, parent=None, iface=None, filters=None): | ||
"""Constructor.""" | ||
super(ExtentSelector, self).__init__(parent) | ||
|
||
self.setupUi(self) | ||
|
||
# self.dialog is used by RectangleMapTool!!! | ||
self.dialog = parent | ||
self.iface = iface if iface else qgis.utils.iface | ||
self.canvas = iface.mapCanvas() | ||
self.prev_map_tool = self.canvas.mapTool() | ||
self.tool = RectangleMapTool(self.canvas) | ||
|
||
self.tool.rectangleCreated.connect(self.on_tool_update_extent) | ||
|
||
self.actionCanvas = QAction('Use canvas extent', self.menuButton) | ||
self.actionLayer = QAction('Use layer extent', self.menuButton) | ||
self.actionSelection = QAction('Draw extent...', self.menuButton) | ||
|
||
self.actionCanvas.setToolTip('') | ||
self.actionLayer.setToolTip('') | ||
self.actionSelection.setToolTip('') | ||
|
||
self.menu = QMenu() | ||
self.menu.addAction(self.actionCanvas) | ||
self.menu.addAction(self.actionLayer) | ||
self.menu.addSeparator() | ||
self.menu.addAction(self.actionSelection) | ||
|
||
self.menuButton.setMenu(self.menu) | ||
|
||
self.extent_layer_dialog = self._init_extent_layer_dialog() | ||
|
||
self.actionCanvas.triggered.connect(self.on_action_canvas_triggered) | ||
self.actionLayer.triggered.connect(self.on_action_layer_triggered) | ||
self.actionSelection.triggered.connect( | ||
self.on_action_selection_triggered) | ||
self.extent_layer_dialog.accepted.connect( | ||
self.on_extent_layer_dialog_accepted) | ||
self.lineEdit.textChanged.connect(self.on_line_textchanged) | ||
|
||
def _init_extent_layer_dialog(self, filters=QgsMapLayerProxyModel.All): | ||
dialog = QDialog() | ||
layout = QVBoxLayout() | ||
buttons = QDialogButtonBox( | ||
QDialogButtonBox.Ok | QDialogButtonBox.Cancel, dialog) | ||
layer_combobox = QgsMapLayerComboBox() | ||
|
||
layout.addWidget(layer_combobox) | ||
layout.addWidget(buttons) | ||
|
||
layer_combobox.setFilters(filters) | ||
layer_combobox.setAccessibleName('') | ||
dialog.setModal(True) | ||
dialog.setLayout(layout) | ||
|
||
buttons.accepted.connect(dialog.accept) | ||
buttons.rejected.connect(dialog.reject) | ||
|
||
# ugly, but better to keep the function as pure as possible pure. | ||
# I guess it begs for it's own class | ||
dialog.layer_combobox = layer_combobox | ||
|
||
return dialog | ||
|
||
def is_valid(self, value=None): | ||
"""Check if input string is valid.""" | ||
if value is None: | ||
value = self.lineEdit.text() | ||
|
||
if re.match(self.EXTRACT_REGEX, value): | ||
return True | ||
else: | ||
return False | ||
|
||
def value(self): | ||
"""Mimic the QT API to get the value.""" | ||
# Even though it is more work, everytime we should convert the | ||
# rectangle to string and then parse the string back to a rectangle. | ||
# This way there is only single source of | ||
# truth and will keep away a lot of tricky bugs | ||
|
||
value = self.lineEdit.text().strip() | ||
|
||
if not self.is_valid(value): | ||
return None | ||
|
||
[x1, _, y1, _, x2, _, y2, _, epsg, crs_code] = re.findall( | ||
self.EXTRACT_REGEX, value)[0] | ||
|
||
p1 = QgsPointXY(float(x1), float(y1)) | ||
p2 = QgsPointXY(float(x2), float(y2)) | ||
rect = QgsReferencedRectangle( | ||
QgsRectangle(p1, p2), | ||
QgsCoordinateReferenceSystem(int(crs_code))) | ||
|
||
return rect | ||
|
||
def toggle_line_validity(self, is_valid=None): | ||
"""Set the input with red class if not valid.""" | ||
if is_valid is None: | ||
is_valid = self.is_valid() | ||
|
||
if is_valid: | ||
self.lineEdit.setStyleSheet('color: inherit;') | ||
else: | ||
self.lineEdit.setStyleSheet('color: red;') | ||
|
||
def on_line_textchanged(self, value): | ||
"""Triggered when the input changes, even programatically.""" | ||
self.toggle_line_validity() | ||
|
||
def on_extent_layer_dialog_accepted(self): | ||
"""Triggered when a layer is selected and dialog accepted.""" | ||
layer = self.extent_layer_dialog.layer_combobox.currentLayer() | ||
self.set_value_from_layer(layer) | ||
|
||
def on_action_canvas_triggered(self): | ||
"""Triggered when menu action "canvas" is clicked.""" | ||
self.set_value_from_rect(self.canvas.extent()) | ||
|
||
def on_action_layer_triggered(self, filters): | ||
"""Triggered when menu action "layer" is clicked.""" | ||
self.extent_layer_dialog.show() | ||
|
||
def on_action_selection_triggered(self): | ||
"""Triggered when menu action "selection" is clicked.""" | ||
self.prev_map_tool = self.canvas.mapTool() | ||
self.canvas.setMapTool(self.tool) | ||
self.dialog.showMinimized() | ||
|
||
def on_tool_update_extent(self): | ||
"""Triggered when the map tool finishes drawing a rectangle.""" | ||
rect = self.tool.rectangle() | ||
self.set_value_from_rect(rect) | ||
|
||
self.tool.reset() | ||
|
||
self.canvas.setMapTool(self.prev_map_tool) | ||
self.dialog.showNormal() | ||
self.dialog.raise_() | ||
self.dialog.activateWindow() | ||
|
||
def set_value_from_str(self, value, crs=None): | ||
"""Set the coordinates from the coordinates string. | ||
If no CRS provided, gets the one from the project. | ||
There should be no CRS in the string! | ||
""" | ||
# don't cache current project, as it may be changed | ||
crs = QgsProject.instance().crs() if not crs else crs | ||
|
||
if crs.isValid(): | ||
value += ' [' + crs.authid() + ']' | ||
|
||
self.toggle_line_validity() | ||
self.lineEdit.setText(value) | ||
|
||
def set_value_from_layer(self, layer): | ||
"""Set the coordinates to the passed layer extent.""" | ||
self.set_value_from_rect(layer.extent(), layer.crs()) | ||
|
||
def set_value_from_rect(self, rect, crs=None): | ||
"""Set the coordinates from the passed rectangle extent. | ||
If no CRS provided, tries to obtain it from the rectangle. | ||
""" | ||
value = rect.asWktCoordinates() | ||
crs = rect.crs() if isinstance(rect, QgsReferencedRectangle) else crs | ||
|
||
self.set_value_from_str(value, crs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.