[processing] Use standard QGIS projection selection widget for CRS params

This commit is contained in:
Nyall Dawson 2016-11-11 19:46:42 +10:00
parent fbc12a8a81
commit 3ef7b3b7eb
5 changed files with 36 additions and 92 deletions

View File

@ -75,11 +75,12 @@ class warp(GdalAlgorithm):
def defineCharacteristics(self):
self.name, self.i18n_name = self.trAlgorithm('Warp (reproject)')
self.group, self.i18n_group = self.trAlgorithm('[GDAL] Projections')
self.tags = self.tr('transform,reproject,crs,srs')
self.addParameter(ParameterRaster(self.INPUT, self.tr('Input layer'), False))
self.addParameter(ParameterCrs(self.SOURCE_SRS,
self.tr('Source SRS'), '', optional=True))
self.addParameter(ParameterCrs(self.DEST_SRS,
self.tr('Destination SRS'), ''))
self.tr('Destination SRS'), 'EPSG:4326'))
self.addParameter(ParameterString(self.NO_DATA,
self.tr("Nodata value, leave blank to take the nodata value from input"),
'', optional=True))

View File

@ -25,12 +25,17 @@ __copyright__ = '(C) 2012, Alexander Bruy'
__revision__ = '$Format:%H$'
import os
from qgis.core import QgsCoordinateReferenceSystem, QgsCoordinateTransform, QgsFeature
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.parameters import ParameterVector
from processing.core.parameters import ParameterCrs
from processing.core.outputs import OutputVector
from processing.tools import dataobjects, vector
from qgis.PyQt.QtGui import QIcon
pluginPath = os.path.split(os.path.split(os.path.dirname(__file__))[0])[0]
class ReprojectLayer(GeoAlgorithm):
@ -39,9 +44,13 @@ class ReprojectLayer(GeoAlgorithm):
TARGET_CRS = 'TARGET_CRS'
OUTPUT = 'OUTPUT'
def getIcon(self):
return QIcon(os.path.join(pluginPath, 'images', 'gdaltools', 'warp.png'))
def defineCharacteristics(self):
self.name, self.i18n_name = self.trAlgorithm('Reproject layer')
self.group, self.i18n_group = self.trAlgorithm('Vector general tools')
self.tags = self.tr('transform,reproject,crs,srs,warp')
self.addParameter(ParameterVector(self.INPUT,
self.tr('Input layer')))

View File

@ -1,76 +0,0 @@
# -*- coding: utf-8 -*-
"""
***************************************************************************
CrsSelectionPanel.py
---------------------
Date : August 2012
Copyright : (C) 2012 by Victor Olaya
Email : volayaf at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************
"""
__author__ = 'Victor Olaya'
__date__ = 'August 2012'
__copyright__ = '(C) 2012, Victor Olaya'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'
import os
from qgis.PyQt import uic
from qgis.core import QgsCoordinateReferenceSystem
from qgis.gui import QgsGenericProjectionSelector
pluginPath = os.path.split(os.path.dirname(__file__))[0]
WIDGET, BASE = uic.loadUiType(
os.path.join(pluginPath, 'ui', 'widgetBaseSelector.ui'))
class CrsSelectionPanel(BASE, WIDGET):
def __init__(self, default='EPSG:4326'):
super(CrsSelectionPanel, self).__init__(None)
self.setupUi(self)
self.leText.setEnabled(False)
self.btnSelect.clicked.connect(self.browseCRS)
# TODO: Default should be removed
self.crs = default
self.updateText()
def setAuthId(self, authid):
self.crs = authid
self.updateText()
def browseCRS(self):
selector = QgsGenericProjectionSelector()
selector.setSelectedAuthId(self.crs)
if selector.exec_():
authId = selector.selectedAuthId()
if authId.upper().startswith("EPSG:"):
self.crs = authId
else:
proj = QgsCoordinateReferenceSystem()
proj.createFromSrsId(selector.selectedCrsId())
self.crs = proj.toProj4()
self.updateText()
def updateText(self):
if self.crs is not None:
self.leText.setText(self.crs)
def getValue(self):
return self.crs

View File

@ -36,13 +36,12 @@ from functools import cmp_to_key
from qgis.core import QgsCoordinateReferenceSystem, QgsVectorLayer
from qgis.PyQt.QtWidgets import QCheckBox, QComboBox, QLineEdit, QPlainTextEdit
from qgis.gui import QgsFieldExpressionWidget, QgsExpressionLineEdit
from qgis.gui import QgsFieldExpressionWidget, QgsExpressionLineEdit, QgsProjectionSelectionWidget
from qgis.PyQt.QtCore import pyqtSignal, QObject, QVariant
from processing.gui.NumberInputPanel import NumberInputPanel
from processing.gui.InputLayerSelectorPanel import InputLayerSelectorPanel
from processing.modeler.MultilineTextPanel import MultilineTextPanel
from processing.gui.CrsSelectionPanel import CrsSelectionPanel
from processing.gui.PointSelectionPanel import PointSelectionPanel
from processing.core.parameters import (ParameterBoolean,
ParameterPoint,
@ -222,23 +221,32 @@ class CrsWidgetWrapper(WidgetWrapper):
widget.setEditText(self.param.default)
return widget
else:
return CrsSelectionPanel()
widget = QgsProjectionSelectionWidget()
if self.param.optional:
widget.setOptionVisible(QgsProjectionSelectionWidget.CrsNotSet, True)
if self.param.default:
crs = QgsCoordinateReferenceSystem(self.param.default)
widget.setCrs(crs)
return widget
def setValue(self, value):
if self.dialogType == DIALOG_MODELER:
self.setComboValue(value)
else:
if isinstance(value, str): # authId
self.widget.crs = value
else:
self.widget.crs = QgsCoordinateReferenceSystem(value).authid()
self.widget.updateText()
self.widget.setCrs(QgsCoordinateReferenceSystem(value))
def value(self):
if self.dialogType == DIALOG_MODELER:
return self.comboValue()
else:
return self.widget.getValue()
crs = self.widget.crs()
if crs.isValid():
return self.widget.crs().authid()
else:
return None
class ExtentWidgetWrapper(WidgetWrapper):

View File

@ -28,7 +28,8 @@ __revision__ = '$Format:%H$'
import math
from qgis.gui import QgsExpressionLineEdit
from qgis.gui import QgsExpressionLineEdit, QgsProjectionSelectionWidget
from qgis.core import QgsCoordinateReferenceSystem
from qgis.PyQt.QtCore import Qt
from qgis.PyQt.QtWidgets import (QDialog,
QVBoxLayout,
@ -54,7 +55,6 @@ from processing.core.parameters import (Parameter,
ParameterFile,
ParameterPoint,
ParameterCrs)
from processing.gui.CrsSelectionPanel import CrsSelectionPanel
class ModelerParameterDefinitionDialog(QDialog):
@ -247,10 +247,12 @@ class ModelerParameterDefinitionDialog(QDialog):
elif (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_CRS or
isinstance(self.param, ParameterCrs)):
self.verticalLayout.addWidget(QLabel(self.tr('Default value')))
self.defaultTextBox = CrsSelectionPanel('EPSG:4326')
self.selector = QgsProjectionSelectionWidget()
if self.param is not None:
self.defaultTextBox.setAuthId(self.param.default)
self.verticalLayout.addWidget(self.defaultTextBox)
self.selector.setCrs(QgsCoordinateReferenceSystem(self.param.default))
else:
self.selector.setCrs(QgsCoordinateReferenceSystem('EPSG:4326'))
self.verticalLayout.addWidget(self.selector)
self.verticalLayout.addSpacing(20)
self.requiredCheck = QCheckBox()
@ -361,7 +363,7 @@ class ModelerParameterDefinitionDialog(QDialog):
str(self.defaultTextBox.text()))
elif (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_CRS or
isinstance(self.param, ParameterCrs)):
self.param = ParameterCrs(name, description, self.defaultTextBox.getValue())
self.param = ParameterCrs(name, description, default=self.selector.crs().authid())
self.param.optional = not self.requiredCheck.isChecked()
self.close()