当前位置: 首页>>代码示例>>Python>>正文


Python QgsReferencedRectangle.combineExtentWith方法代码示例

本文整理汇总了Python中qgis.core.QgsReferencedRectangle.combineExtentWith方法的典型用法代码示例。如果您正苦于以下问题:Python QgsReferencedRectangle.combineExtentWith方法的具体用法?Python QgsReferencedRectangle.combineExtentWith怎么用?Python QgsReferencedRectangle.combineExtentWith使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在qgis.core.QgsReferencedRectangle的用法示例。


在下文中一共展示了QgsReferencedRectangle.combineExtentWith方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: PixelSizeWidget

# 需要导入模块: from qgis.core import QgsReferencedRectangle [as 别名]
# 或者: from qgis.core.QgsReferencedRectangle import combineExtentWith [as 别名]
class PixelSizeWidget(BASE, WIDGET):

    def __init__(self):
        super(PixelSizeWidget, self).__init__(None)
        self.setupUi(self)
        self.context = dataobjects.createContext()

        self.extent = QgsRectangle()
        self.layers = []

        self.mCellXSpinBox.setShowClearButton(False)
        self.mCellYSpinBox.setShowClearButton(False)
        self.mRowsSpinBox.setShowClearButton(False)
        self.mColumnsSpinBox.setShowClearButton(False)

        self.mCellYSpinBox.valueChanged.connect(self.mCellXSpinBox.setValue)
        self.mCellXSpinBox.valueChanged.connect(self.pixelSizeChanged)
        self.mRowsSpinBox.valueChanged.connect(self.rowsChanged)
        self.mColumnsSpinBox.valueChanged.connect(self.columnsChanged)

    def setLayers(self, layersData):
        self.extent = QgsRectangle()
        self.layers = []
        for row in layersData.split(';'):
            v = row.split('::~::')
            # need to keep a reference until interpolation is complete
            layer = QgsProcessingUtils.variantToSource(v[0], self.context)
            if layer:
                self.layers.append(layer)
                bbox = layer.sourceExtent()
                if self.extent.isEmpty():
                    self.extent = bbox
                else:
                    self.extent.combineExtentWith(bbox)

        self.pixelSizeChanged()

    def setExtent(self, extent):
        if extent is not None:
            tokens = extent.split(' ')[0].split(',')
            ext = QgsRectangle(float(tokens[0]), float(tokens[2]), float(tokens[1]), float(tokens[3]))
            if len(tokens) > 1:
                self.extent = QgsReferencedRectangle(ext, QgsCoordinateReferenceSystem(tokens[1][1:-1]))
            else:
                self.extent = ext
        self.pixelSizeChanged()

    def pixelSizeChanged(self):
        cell_size = self.mCellXSpinBox.value()
        if cell_size <= 0:
            return

        self.mCellYSpinBox.blockSignals(True)
        self.mCellYSpinBox.setValue(cell_size)
        self.mCellYSpinBox.blockSignals(False)
        rows = max(round(self.extent.height() / cell_size) + 1, 1)
        cols = max(round(self.extent.width() / cell_size) + 1, 1)
        self.mRowsSpinBox.blockSignals(True)
        self.mRowsSpinBox.setValue(rows)
        self.mRowsSpinBox.blockSignals(False)
        self.mColumnsSpinBox.blockSignals(True)
        self.mColumnsSpinBox.setValue(cols)
        self.mColumnsSpinBox.blockSignals(False)

    def rowsChanged(self):
        rows = self.mRowsSpinBox.value()
        if rows <= 0:
            return
        cell_size = self.extent.height() / rows
        cols = max(round(self.extent.width() / cell_size) + 1, 1)
        self.mColumnsSpinBox.blockSignals(True)
        self.mColumnsSpinBox.setValue(cols)
        self.mColumnsSpinBox.blockSignals(False)
        for w in [self.mCellXSpinBox, self.mCellYSpinBox]:
            w.blockSignals(True)
            w.setValue(cell_size)
            w.blockSignals(False)

    def columnsChanged(self):
        cols = self.mColumnsSpinBox.value()
        if cols < 2:
            return
        cell_size = self.extent.width() / (cols - 1)
        rows = max(round(self.extent.height() / cell_size), 1)
        self.mRowsSpinBox.blockSignals(True)
        self.mRowsSpinBox.setValue(rows)
        self.mRowsSpinBox.blockSignals(False)
        for w in [self.mCellXSpinBox, self.mCellYSpinBox]:
            w.blockSignals(True)
            w.setValue(cell_size)
            w.blockSignals(False)

    def setValue(self, value):
        try:
            numeric_value = float(value)
        except:
            return False

        self.mCellXSpinBox.setValue(numeric_value)
        self.mCellYSpinBox.setValue(numeric_value)
#.........这里部分代码省略.........
开发者ID:dmarteau,项目名称:QGIS,代码行数:103,代码来源:InterpolationWidgets.py


注:本文中的qgis.core.QgsReferencedRectangle.combineExtentWith方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。