本文整理汇总了Python中processing.gui.RectangleMapTool.RectangleMapTool.reset方法的典型用法代码示例。如果您正苦于以下问题:Python RectangleMapTool.reset方法的具体用法?Python RectangleMapTool.reset怎么用?Python RectangleMapTool.reset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类processing.gui.RectangleMapTool.RectangleMapTool
的用法示例。
在下文中一共展示了RectangleMapTool.reset方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ExtentSelectionPanel
# 需要导入模块: from processing.gui.RectangleMapTool import RectangleMapTool [as 别名]
# 或者: from processing.gui.RectangleMapTool.RectangleMapTool import reset [as 别名]
#.........这里部分代码省略.........
popupmenu.addAction(useLayerExtentAction)
popupmenu.addAction(selectOnCanvasAction)
selectOnCanvasAction.triggered.connect(self.selectOnCanvas)
useLayerExtentAction.triggered.connect(self.useLayerExtent)
if self.canUseAutoExtent():
useMincoveringExtentAction = QAction(self.tr("Use min covering extent from input layers"), self.btnSelect)
useMincoveringExtentAction.triggered.connect(self.useMinCoveringExtent)
popupmenu.addAction(useMincoveringExtentAction)
popupmenu.exec_(QCursor.pos())
def useMinCoveringExtent(self):
self.leText.setText("")
def getMinCoveringExtent(self):
first = True
found = False
for param in self.params:
if param.value:
if isinstance(param, (ParameterRaster, ParameterVector)):
if isinstance(param.value, (QgsRasterLayer, QgsVectorLayer)):
layer = param.value
else:
layer = dataobjects.getObjectFromUri(param.value)
if layer:
found = True
self.addToRegion(layer, first)
first = False
elif isinstance(param, ParameterMultipleInput):
layers = param.value.split(";")
for layername in layers:
layer = dataobjects.getObjectFromUri(layername, first)
if layer:
found = True
self.addToRegion(layer, first)
first = False
if found:
return "{},{},{},{}".format(self.xmin, self.xmax, self.ymin, self.ymax)
else:
return None
def useNewAlg(self, alg):
self.params = alg.parameters
def addToRegion(self, layer, first):
if first:
self.xmin = layer.extent().xMinimum()
self.xmax = layer.extent().xMaximum()
self.ymin = layer.extent().yMinimum()
self.ymax = layer.extent().yMaximum()
else:
self.xmin = min(self.xmin, layer.extent().xMinimum())
self.xmax = max(self.xmax, layer.extent().xMaximum())
self.ymin = min(self.ymin, layer.extent().yMinimum())
self.ymax = max(self.ymax, layer.extent().yMaximum())
def useLayerExtent(self):
CANVAS_KEY = "Use canvas extent"
extentsDict = {}
extentsDict[CANVAS_KEY] = iface.mapCanvas().extent()
extents = [CANVAS_KEY]
layers = dataobjects.getAllLayers()
for layer in layers:
extents.append(layer.name())
extentsDict[layer.name()] = layer.extent()
(item, ok) = QInputDialog.getItem(self, self.tr("Select extent"), self.tr("Use extent from"), extents, False)
if ok:
self.setValueFromRect(extentsDict[item])
def selectOnCanvas(self):
canvas = iface.mapCanvas()
canvas.setMapTool(self.tool)
self.dialog.showMinimized()
def updateExtent(self):
r = self.tool.rectangle()
self.setValueFromRect(r)
def setValueFromRect(self, r):
s = "{},{},{},{}".format(r.xMinimum(), r.xMaximum(), r.yMinimum(), r.yMaximum())
self.leText.setText(s)
self.tool.reset()
canvas = iface.mapCanvas()
canvas.setMapTool(self.prevMapTool)
self.dialog.showNormal()
self.dialog.raise_()
self.dialog.activateWindow()
def getValue(self):
if str(self.leText.text()).strip() != "":
return unicode(self.leText.text())
else:
return self.getMinCoveringExtent()
def setExtentFromString(self, s):
self.leText.setText(s)
示例2: ExtentSelectionPanel
# 需要导入模块: from processing.gui.RectangleMapTool import RectangleMapTool [as 别名]
# 或者: from processing.gui.RectangleMapTool.RectangleMapTool import reset [as 别名]
#.........这里部分代码省略.........
self.tool = RectangleMapTool(canvas)
self.tool.rectangleCreated.connect(self.updateExtent)
else:
self.prevMapTool = None
self.tool = None
if param.defaultValue() is not None:
context = createContext()
rect = QgsProcessingParameters.parameterAsExtent(param, {param.name(): param.defaultValue()}, context)
crs = QgsProcessingParameters.parameterAsExtentCrs(param, {param.name(): param.defaultValue()}, context)
if not rect.isNull():
try:
s = '{},{},{},{}'.format(
rect.xMinimum(), rect.xMaximum(), rect.yMinimum(), rect.yMaximum())
if crs.isValid():
s += ' [' + crs.authid() + ']'
self.crs = crs
self.leText.setText(s)
except:
pass
def selectExtent(self):
popupmenu = QMenu()
useCanvasExtentAction = QAction(
QCoreApplication.translate("ExtentSelectionPanel", 'Use Canvas Extent'),
self.btnSelect)
useLayerExtentAction = QAction(
QCoreApplication.translate("ExtentSelectionPanel", 'Use Layer Extent…'),
self.btnSelect)
selectOnCanvasAction = QAction(
self.tr('Select Extent on Canvas'), self.btnSelect)
popupmenu.addAction(useCanvasExtentAction)
popupmenu.addAction(selectOnCanvasAction)
popupmenu.addSeparator()
popupmenu.addAction(useLayerExtentAction)
selectOnCanvasAction.triggered.connect(self.selectOnCanvas)
useLayerExtentAction.triggered.connect(self.useLayerExtent)
useCanvasExtentAction.triggered.connect(self.useCanvasExtent)
if self.param.flags() & QgsProcessingParameterDefinition.FlagOptional:
useMincoveringExtentAction = QAction(
self.tr('Use Min Covering Extent from Input Layers'),
self.btnSelect)
useMincoveringExtentAction.triggered.connect(
self.useMinCoveringExtent)
popupmenu.addAction(useMincoveringExtentAction)
popupmenu.exec_(QCursor.pos())
def useMinCoveringExtent(self):
self.leText.setText('')
def useLayerExtent(self):
dlg = LayerSelectionDialog(self)
if dlg.exec_():
layer = dlg.selected_layer()
self.setValueFromRect(QgsReferencedRectangle(layer.extent(), layer.crs()))
def useCanvasExtent(self):
self.setValueFromRect(QgsReferencedRectangle(iface.mapCanvas().extent(),
iface.mapCanvas().mapSettings().destinationCrs()))
def selectOnCanvas(self):
canvas = iface.mapCanvas()
canvas.setMapTool(self.tool)
self.dialog.showMinimized()
def updateExtent(self):
r = self.tool.rectangle()
self.setValueFromRect(r)
def setValueFromRect(self, r):
s = '{},{},{},{}'.format(
r.xMinimum(), r.xMaximum(), r.yMinimum(), r.yMaximum())
try:
self.crs = r.crs()
except:
self.crs = QgsProject.instance().crs()
if self.crs.isValid():
s += ' [' + self.crs.authid() + ']'
self.leText.setText(s)
self.tool.reset()
canvas = iface.mapCanvas()
canvas.setMapTool(self.prevMapTool)
self.dialog.showNormal()
self.dialog.raise_()
self.dialog.activateWindow()
def getValue(self):
if str(self.leText.text()).strip() != '':
return str(self.leText.text())
else:
return None
def setExtentFromString(self, s):
self.leText.setText(s)
示例3: ExtentSelectionPanel
# 需要导入模块: from processing.gui.RectangleMapTool import RectangleMapTool [as 别名]
# 或者: from processing.gui.RectangleMapTool.RectangleMapTool import reset [as 别名]
#.........这里部分代码省略.........
self.tool = None
if param.defaultValue() is not None:
context = createContext()
rect = QgsProcessingParameters.parameterAsExtent(param, {param.name(): param.defaultValue()}, context)
crs = QgsProcessingParameters.parameterAsExtentCrs(param, {param.name(): param.defaultValue()}, context)
if not rect.isNull():
try:
s = '{},{},{},{}'.format(
rect.xMinimum(), rect.xMaximum(), rect.yMinimum(), rect.yMaximum())
if crs.isValid():
s += ' [' + crs.authid() + ']'
self.crs = crs
self.leText.setText(s)
except:
pass
def selectExtent(self):
popupmenu = QMenu()
useLayerExtentAction = QAction(
self.tr('Use layer/canvas extent'), self.btnSelect)
selectOnCanvasAction = QAction(
self.tr('Select extent on canvas'), self.btnSelect)
popupmenu.addAction(useLayerExtentAction)
popupmenu.addAction(selectOnCanvasAction)
selectOnCanvasAction.triggered.connect(self.selectOnCanvas)
useLayerExtentAction.triggered.connect(self.useLayerExtent)
if self.param.flags() & QgsProcessingParameterDefinition.FlagOptional:
useMincoveringExtentAction = QAction(
self.tr('Use min covering extent from input layers'),
self.btnSelect)
useMincoveringExtentAction.triggered.connect(
self.useMinCoveringExtent)
popupmenu.addAction(useMincoveringExtentAction)
popupmenu.exec_(QCursor.pos())
def useMinCoveringExtent(self):
self.leText.setText('')
def useLayerExtent(self):
CANVAS_KEY = 'Use canvas extent'
extentsDict = {}
extentsDict[CANVAS_KEY] = {"extent": iface.mapCanvas().extent(),
"authid": iface.mapCanvas().mapSettings().destinationCrs().authid()}
extents = [CANVAS_KEY]
layers = QgsProcessingUtils.compatibleLayers(QgsProject.instance())
for layer in layers:
authid = layer.crs().authid()
if ProcessingConfig.getSetting(ProcessingConfig.SHOW_CRS_DEF) \
and authid is not None:
layerName = u'{} [{}]'.format(layer.name(), authid)
else:
layerName = layer.name()
extents.append(layerName)
extentsDict[layerName] = {"extent": layer.extent(), "authid": authid}
(item, ok) = QInputDialog.getItem(self, self.tr('Select extent'),
self.tr('Use extent from'), extents, False)
if ok:
self.setValueFromRect(QgsReferencedRectangle(extentsDict[item]["extent"], QgsCoordinateReferenceSystem(extentsDict[item]["authid"])))
def selectOnCanvas(self):
canvas = iface.mapCanvas()
canvas.setMapTool(self.tool)
self.dialog.showMinimized()
def updateExtent(self):
r = self.tool.rectangle()
self.setValueFromRect(r)
def setValueFromRect(self, r):
s = '{},{},{},{}'.format(
r.xMinimum(), r.xMaximum(), r.yMinimum(), r.yMaximum())
try:
self.crs = r.crs()
except:
self.crs = QgsProject.instance().crs()
if self.crs.isValid():
s += ' [' + self.crs.authid() + ']'
self.leText.setText(s)
self.tool.reset()
canvas = iface.mapCanvas()
canvas.setMapTool(self.prevMapTool)
self.dialog.showNormal()
self.dialog.raise_()
self.dialog.activateWindow()
def getValue(self):
if str(self.leText.text()).strip() != '':
return str(self.leText.text())
else:
return None
def setExtentFromString(self, s):
self.leText.setText(s)
示例4: ExtentSelectionPanel
# 需要导入模块: from processing.gui.RectangleMapTool import RectangleMapTool [as 别名]
# 或者: from processing.gui.RectangleMapTool.RectangleMapTool import reset [as 别名]
#.........这里部分代码省略.........
def getMinCoveringExtent(self):
first = True
found = False
for param in self.params:
if param.value:
if isinstance(param, (ParameterRaster, ParameterVector)):
if isinstance(param.value, (QgsRasterLayer, QgsVectorLayer)):
layer = param.value
else:
layer = dataobjects.getObject(param.value)
if layer:
found = True
self.addToRegion(layer, first)
first = False
elif isinstance(param, ParameterMultipleInput):
layers = param.value.split(";")
for layername in layers:
layer = dataobjects.getObject(layername)
if layer:
found = True
self.addToRegion(layer, first)
first = False
if found:
return "{},{},{},{}".format(self.xmin, self.xmax, self.ymin, self.ymax)
else:
return None
def useNewAlg(self, alg):
self.params = alg.parameters
def addToRegion(self, layer, first):
if first:
self.xmin = layer.extent().xMinimum()
self.xmax = layer.extent().xMaximum()
self.ymin = layer.extent().yMinimum()
self.ymax = layer.extent().yMaximum()
else:
self.xmin = min(self.xmin, layer.extent().xMinimum())
self.xmax = max(self.xmax, layer.extent().xMaximum())
self.ymin = min(self.ymin, layer.extent().yMinimum())
self.ymax = max(self.ymax, layer.extent().yMaximum())
def useLayerExtent(self):
CANVAS_KEY = "Use canvas extent"
extentsDict = {}
extentsDict[CANVAS_KEY] = {
"extent": iface.mapCanvas().extent(),
"authid": iface.mapCanvas().mapSettings().destinationCrs().authid(),
}
extents = [CANVAS_KEY]
layers = dataobjects.getAllLayers()
for layer in layers:
authid = layer.crs().authid()
if ProcessingConfig.getSetting(ProcessingConfig.SHOW_CRS_DEF) and authid is not None:
layerName = u"{} [{}]".format(layer.name(), authid)
else:
layerName = layer.name()
extents.append(layerName)
extentsDict[layerName] = {"extent": layer.extent(), "authid": authid}
(item, ok) = QInputDialog.getItem(self, self.tr("Select extent"), self.tr("Use extent from"), extents, False)
if ok:
self.setValueFromRect(extentsDict[item]["extent"])
if extentsDict[item]["authid"] != iface.mapCanvas().mapSettings().destinationCrs().authid():
iface.messageBar().pushMessage(
self.tr("Warning"),
self.tr(
"The projection of the chosen layer is not the same as canvas projection! The selected extent might not be what was intended."
),
QgsMessageBar.WARNING,
8,
)
def selectOnCanvas(self):
canvas = iface.mapCanvas()
canvas.setMapTool(self.tool)
self.dialog.showMinimized()
def updateExtent(self):
r = self.tool.rectangle()
self.setValueFromRect(r)
def setValueFromRect(self, r):
s = "{},{},{},{}".format(r.xMinimum(), r.xMaximum(), r.yMinimum(), r.yMaximum())
self.leText.setText(s)
self.tool.reset()
canvas = iface.mapCanvas()
canvas.setMapTool(self.prevMapTool)
self.dialog.showNormal()
self.dialog.raise_()
self.dialog.activateWindow()
def getValue(self):
if unicode(self.leText.text()).strip() != "":
return unicode(self.leText.text())
else:
return self.getMinCoveringExtent()
def setExtentFromString(self, s):
self.leText.setText(s)
示例5: ExtentSelectionPanel
# 需要导入模块: from processing.gui.RectangleMapTool import RectangleMapTool [as 别名]
# 或者: from processing.gui.RectangleMapTool.RectangleMapTool import reset [as 别名]
#.........这里部分代码省略.........
selectOnCanvasAction = QtGui.QAction(self.tr('Select extent on canvas'),
self.pushButton)
selectOnCanvasAction.triggered.connect(self.selectOnCanvas)
popupmenu.addAction(selectOnCanvasAction)
if self.canUseAutoExtent():
useMincoveringExtentAction = \
QtGui.QAction(self.tr('Use min covering extent from input layers'),
self.pushButton)
useMincoveringExtentAction.triggered.connect(
self.useMinCoveringExtent)
popupmenu.addAction(useMincoveringExtentAction)
popupmenu.exec_(QtGui.QCursor.pos())
def useMinCoveringExtent(self):
self.text.setText('')
def getMinCoveringExtent(self):
first = True
found = False
for param in self.params:
if param.value:
if isinstance(param, (ParameterRaster, ParameterVector)):
if isinstance(param.value, (QgsRasterLayer,
QgsVectorLayer)):
layer = param.value
else:
layer = dataobjects.getObjectFromUri(param.value)
if layer:
found = True
self.addToRegion(layer, first)
first = False
elif isinstance(param, ParameterMultipleInput):
layers = param.value.split(';')
for layername in layers:
layer = dataobjects.getObjectFromUri(layername, first)
if layer:
found = True
self.addToRegion(layer, first)
first = False
if found:
return str(self.xmin) + ',' + str(self.xmax) + ',' \
+ str(self.ymin) + ',' + str(self.ymax)
else:
return None
def useNewAlg(self, alg):
self.params = alg.parameters
def addToRegion(self, layer, first):
if first:
self.xmin = layer.extent().xMinimum()
self.xmax = layer.extent().xMaximum()
self.ymin = layer.extent().yMinimum()
self.ymax = layer.extent().yMaximum()
else:
self.xmin = min(self.xmin, layer.extent().xMinimum())
self.xmax = max(self.xmax, layer.extent().xMaximum())
self.ymin = min(self.ymin, layer.extent().yMinimum())
self.ymax = max(self.ymax, layer.extent().yMaximum())
def useLayerExtent(self):
CANVAS_KEY = 'Use canvas extent'
extentsDict = {}
extentsDict[CANVAS_KEY] = iface.mapCanvas().extent()
extents = [CANVAS_KEY]
layers = dataobjects.getAllLayers()
for layer in layers:
extents.append(layer.name())
extentsDict[layer.name()] = layer.extent()
(item, ok) = QtGui.QInputDialog.getItem(self, 'Select extent',
'Use extent from', extents, False)
if ok:
self.setValueFromRect(extentsDict[item])
def selectOnCanvas(self):
canvas = iface.mapCanvas()
canvas.setMapTool(self.tool)
self.dialog.showMinimized()
def fillCoords(self):
r = self.tool.rectangle()
self.setValueFromRect(r)
def setValueFromRect(self, r):
s = str(r.xMinimum()) + ',' + str(r.xMaximum()) + ',' \
+ str(r.yMinimum()) + ',' + str(r.yMaximum())
self.text.setText(s)
self.tool.reset()
canvas = iface.mapCanvas()
canvas.setMapTool(self.prevMapTool)
self.dialog.showNormal()
self.dialog.raise_()
self.dialog.activateWindow()
def getValue(self):
if str(self.text.text()).strip() != '':
return str(self.text.text())
else:
return self.getMinCoveringExtent()
示例6: BboxWidget
# 需要导入模块: from processing.gui.RectangleMapTool import RectangleMapTool [as 别名]
# 或者: from processing.gui.RectangleMapTool.RectangleMapTool import reset [as 别名]
class BboxWidget(BASE, WIDGET):
def __init__(self, parent=None):
super(BboxWidget, self).__init__(parent)
self.setupUi(self)
self.dialog = None
self.btnSelect.clicked.connect(self.selectExtent)
canvas = iface.mapCanvas()
self.prevMapTool = canvas.mapTool()
self.tool = RectangleMapTool(canvas)
self.tool.rectangleCreated.connect(self.updateExtent)
def setDialog(self):
self._dialog = Dialog
def selectExtent(self):
popupmenu = QMenu()
useLayerExtentAction = QAction(
self.tr('Use layer/canvas extent'), self.btnSelect)
selectOnCanvasAction = QAction(
self.tr('Select extent on canvas'), self.btnSelect)
popupmenu.addAction(useLayerExtentAction)
popupmenu.addAction(selectOnCanvasAction)
selectOnCanvasAction.triggered.connect(self.selectOnCanvas)
useLayerExtentAction.triggered.connect(self.useLayerExtent)
popupmenu.exec_(QCursor.pos())
def useLayerExtent(self):
CANVAS_KEY = 'Use canvas extent'
extentsDict = {}
extentsDict[CANVAS_KEY] = {"extent": iface.mapCanvas().extent(),
"authid": iface.mapCanvas().mapSettings().destinationCrs().authid()}
extents = [CANVAS_KEY]
for layer in QgsProject.instance().mapLayers().values():
authid = layer.crs().authid()
layerName = layer.name()
extents.append(layerName)
extentsDict[layerName] = {"extent": layer.extent(), "authid": authid}
(item, ok) = QInputDialog.getItem(self, self.tr('Select extent'),
self.tr('Use extent from'), extents, False)
if ok:
self.setValue(extentsDict[item]["extent"], extentsDict[item]['authid'])
def selectOnCanvas(self):
canvas = iface.mapCanvas()
canvas.setMapTool(self.tool)
if self.dialog:
self.dialog.showMinimized()
def updateExtent(self):
self.setValue(self.tool.rectangle(),
iface.mapCanvas().mapSettings().destinationCrs().authid())
self.tool.reset()
canvas = iface.mapCanvas()
canvas.setMapTool(self.prevMapTool)
if self.dialog:
self.dialog.showNormal()
self.dialog.raise_()
self.dialog.activateWindow()
def setValue(self, value, crs_authid):
if isinstance(value, QgsRectangle):
s = '{},{},{},{}'.format(value.xMinimum(),
value.yMinimum(),
value.xMaximum(),
value.yMaximum())
elif isinstance(value, str):
s = value
else:
s = ",".join([str(v) for v in value])
s = '{},{}'.format(s, crs_authid)
self.leText.setText(s)
return True
def value(self):
return self.leText.text()
def rectangle(self):
if self.value() == '':
return None
xmin, ymin, xmax, ymax = [float(x) for x in self.value().split(',')[0:4]]
return QgsRectangle(xmin, ymin, xmax, ymax)
def crs(self):
if self.value() == '':
return None
return QgsCoordinateReferenceSystem(self.value().split(',')[4])
def isValid(self):
try:
rect = self.rectangle()
#.........这里部分代码省略.........