本文整理汇总了Python中qgis.core.QgsReferencedRectangle.width方法的典型用法代码示例。如果您正苦于以下问题:Python QgsReferencedRectangle.width方法的具体用法?Python QgsReferencedRectangle.width怎么用?Python QgsReferencedRectangle.width使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qgis.core.QgsReferencedRectangle
的用法示例。
在下文中一共展示了QgsReferencedRectangle.width方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PixelSizeWidget
# 需要导入模块: from qgis.core import QgsReferencedRectangle [as 别名]
# 或者: from qgis.core.QgsReferencedRectangle import width [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)
#.........这里部分代码省略.........