本文整理汇总了Python中qgis.core.QgsRectangle.toString方法的典型用法代码示例。如果您正苦于以下问题:Python QgsRectangle.toString方法的具体用法?Python QgsRectangle.toString怎么用?Python QgsRectangle.toString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qgis.core.QgsRectangle
的用法示例。
在下文中一共展示了QgsRectangle.toString方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testUnion
# 需要导入模块: from qgis.core import QgsRectangle [as 别名]
# 或者: from qgis.core.QgsRectangle import toString [as 别名]
def testUnion(self):
rect1 = QgsRectangle( 0.0, 0.0, 5.0, 5.0)
rect2 = QgsRectangle( 2.0, 2.0, 7.0, 7.0)
pnt1 = QgsPoint(6.0, 2.0)
rect1.combineExtentWith(rect2)
myMessage = ('Expected: %s\nGot: %s\n' %
(True, rect1.contains(rect2)))
assert rect1.contains(rect2), myMessage
print rect1.toString()
assert rect1 == QgsRectangle(0.0, 0.0, 7.0, 7.0), "Wrong combine with rectangle result"
rect1 = QgsRectangle( 0.0, 0.0, 5.0, 5.0)
rect1.combineExtentWith(6.0, 2.0)
myMessage = ('Expected: %s\nGot: %s\n' %
(True, rect1.contains(pnt1)))
assert rect1.contains(pnt1), myMessage
myExpectedResult = QgsRectangle(0.0, 0.0, 6.0, 5.0).toString()
myResult = rect1.toString()
myMessage = ('Expected: %s\nGot: %s\n' %
(myExpectedResult, myResult))
self.assertEquals(myResult, myExpectedResult, myMessage)
rect1 = QgsRectangle( 0.0, 0.0, 5.0, 5.0)
rect1.unionRect(rect2)
myMessage = ('Expected: %s\nGot: %s\n' %
(True, rect1.contains(rect2)))
assert rect1.contains(rect2), myMessage
assert rect1 == QgsRectangle(0.0, 0.0, 7.0, 7.0), "Wrong union result"
示例2: bounds
# 需要导入模块: from qgis.core import QgsRectangle [as 别名]
# 或者: from qgis.core.QgsRectangle import toString [as 别名]
def bounds(self):
"""
Function for recalculating the bounded extents of the
layers as they are processed. Under construction
:return:
"""
# Requires refinement for raster manipulation of bounds
selected_extent = unicode(self.getParameterValue(self.MAP_EXTENT)).split(',')
xMin = float(selected_extent[0])
xMax = float(selected_extent[1])
yMin = float(selected_extent[2])
yMax = float(selected_extent[3])
extent = QgsRectangle(xMin, yMin, xMax, yMax)
mapCRS = iface.mapCanvas().mapSettings().destinationCrs()
transform = QgsCoordinateTransform(
mapCRS,
QgsCoordinateReferenceSystem('EPSG:4326') # WGS84
# QgsCoordinateReferenceSystem('EPSG:3785') # Popular vis mercator
)
try:
layer_extent = transform.transform(extent)
except QgsCsException:
ProcessingLog.addToLog(ProcessingLog.LOG_WARNING,
"exception in transform layer srs")
layer_extent = QgsRectangle(-180, -90, 180, 90)
ProcessingLog.addToLog(ProcessingLog.LOG_INFO, layer_extent.toString())
return layer_extent
示例3: test_mouse_drag
# 需要导入模块: from qgis.core import QgsRectangle [as 别名]
# 或者: from qgis.core.QgsRectangle import toString [as 别名]
def test_mouse_drag(self):
"""Test setting extents by dragging works.
This currently fails as QTest does not properly do the mouse
interactions with the canvas.
"""
# Imported here because it is not available in OSX QGIS bundle
# pylint: disable=redefined-outer-name
from PyQt4.QtTest import QTest
# Click the capture button
QTest.mouseClick(self.dialog.capture_button, Qt.LeftButton)
# drag a rect on the canvas
QTest.mousePress(CANVAS, Qt.LeftButton, pos=QPoint(0, 0), delay=500)
QTest.mouseRelease(
CANVAS, Qt.LeftButton,
pos=QPoint(300, 300),
delay=-1)
# on drag the extents selector windows should appear again
QTest.qWaitForWindowShown(self.dialog)
# Click ok to dispose of the window again
ok = self.dialog.button_box.button(QtGui.QDialogButtonBox.Ok)
QTest.mouseClick(ok, Qt.LeftButton)
# Check the extent emitted on closing teh dialog is correct
expected_extent = QgsRectangle(10.0, 10.0, 30.0, 20.0)
self.assertEqual(self.extent.toString(), expected_extent.toString())
示例4: test_point_to_rectangle
# 需要导入模块: from qgis.core import QgsRectangle [as 别名]
# 或者: from qgis.core.QgsRectangle import toString [as 别名]
def test_point_to_rectangle(self):
"""Test for point to rectangle."""
point = QgsPoint(1.0, 1.0)
rectangle = point_to_rectangle(point)
expected_rectangle = QgsRectangle(
0.9999999999900000,
0.9999999999900000,
1.0000000000100000,
1.0000000000100000)
self.assertEqual(rectangle.toString(), expected_rectangle.toString())
示例5: test_spinboxes
# 需要导入模块: from qgis.core import QgsRectangle [as 别名]
# 或者: from qgis.core.QgsRectangle import toString [as 别名]
def test_spinboxes(self):
"""Test validate extent method."""
self.dialog.x_maximum.clear()
self.dialog.extent_defined.connect(self.extent_defined)
QTest.mouseClick(self.dialog.x_maximum, Qt.LeftButton)
QTest.keyClick(self.dialog.x_maximum, '3')
QTest.keyClick(self.dialog.x_maximum, '0')
ok = self.dialog.button_box.button(QtGui.QDialogButtonBox.Ok)
QTest.mouseClick(ok, Qt.LeftButton)
expected_extent = QgsRectangle(10.0, 10.0, 30.0, 20.0)
self.assertEqual(self.extent.toString(), expected_extent.toString())
示例6: testToString
# 需要导入模块: from qgis.core import QgsRectangle [as 别名]
# 或者: from qgis.core.QgsRectangle import toString [as 别名]
def testToString(self):
"""Test the different string representations"""
self.assertEqual(QgsRectangle().toString(), 'Empty')
rect = QgsRectangle(0, 0.1, 0.2, 0.3)
myExpectedString = '0.0000000000000000,0.1000000000000000 : 0.2000000000000000,0.3000000000000000'
myString = rect.toString()
myMessage = ('Expected: %s\nGot: %s\n' %
(myExpectedString, myString))
assert myString == myExpectedString, myMessage
# can't test the actual result here, because floating point inaccuracies mean the result is unpredictable
# at this precision
self.assertEqual(len(rect.toString(20)), 93)
myMessage = ('Expected: %s\nGot: %s\n' %
(myExpectedString, myString))
assert myString == myExpectedString, myMessage
myExpectedString = '0,0 : 0,0'
myString = rect.toString(0)
myMessage = ('Expected: %s\nGot: %s\n' %
(myExpectedString, myString))
assert myString == myExpectedString, myMessage
myExpectedString = '0.00,0.10 : 0.20,0.30'
myString = rect.toString(2)
myMessage = ('Expected: %s\nGot: %s\n' %
(myExpectedString, myString))
assert myString == myExpectedString, myMessage
myExpectedString = '0.0,0.1 : 0.2,0.3'
myString = rect.toString(1)
myMessage = ('Expected: %s\nGot: %s\n' %
(myExpectedString, myString))
assert myString == myExpectedString, myMessage
myExpectedString = '0.00,0.10 : 0.20,0.30'
myString = rect.toString(-1)
myMessage = ('Expected: %s\nGot: %s\n' %
(myExpectedString, myString))
assert myString == myExpectedString, myMessage
rect = QgsRectangle(5000000.01111, -0.3, 5000000.44111, 99.8)
myExpectedString = '5000000.01,-0.30 : 5000000.44,99.80'
myString = rect.toString(-1)
myMessage = ('Expected: %s\nGot: %s\n' %
(myExpectedString, myString))
assert myString == myExpectedString, myMessage
示例7: testToString
# 需要导入模块: from qgis.core import QgsRectangle [as 别名]
# 或者: from qgis.core.QgsRectangle import toString [as 别名]
def testToString(self):
"""Test the different string representations"""
rect = QgsRectangle(0, 0.1, 0.2, 0.3)
myExpectedString = '0.0000000000000000,0.1000000000000000 : 0.2000000000000000,0.3000000000000000'
myString = rect.toString()
myMessage = ('Expected: %s\nGot: %s\n' %
(myExpectedString, myString))
assert myString == myExpectedString, myMessage
myExpectedString = '0,0 : 0,0'
myString = rect.toString(0)
myMessage = ('Expected: %s\nGot: %s\n' %
(myExpectedString, myString))
assert myString == myExpectedString, myMessage
myExpectedString = '0.00,0.10 : 0.20,0.30'
myString = rect.toString(2)
myMessage = ('Expected: %s\nGot: %s\n' %
(myExpectedString, myString))
assert myString == myExpectedString, myMessage
myExpectedString = '0.0,0.1 : 0.2,0.3'
myString = rect.toString(1)
myMessage = ('Expected: %s\nGot: %s\n' %
(myExpectedString, myString))
assert myString == myExpectedString, myMessage
myExpectedString = '0.00,0.10 : 0.20,0.30'
myString = rect.toString(-1)
myMessage = ('Expected: %s\nGot: %s\n' %
(myExpectedString, myString))
assert myString == myExpectedString, myMessage
rect = QgsRectangle(5000000.01111, -0.3, 5000000.44111, 99.8)
myExpectedString = '5000000.01,-0.30 : 5000000.44,99.80'
myString = rect.toString(-1)
myMessage = ('Expected: %s\nGot: %s\n' %
(myExpectedString, myString))
assert myString == myExpectedString, myMessage
示例8: drawDebugInformation
# 需要导入模块: from qgis.core import QgsRectangle [as 别名]
# 或者: from qgis.core.QgsRectangle import toString [as 别名]
def drawDebugInformation(layer, renderContext, zoom, xmin, ymin, xmax, ymax):
self = layer
mapSettings = self.iface.mapCanvas().mapSettings()
lines = []
lines.append("TileLayer")
lines.append(" zoom: %d, tile matrix extent: (%d, %d) - (%d, %d), tile count: %d * %d" % (zoom, xmin, ymin, xmax, ymax, xmax - xmin, ymax - ymin))
extent = renderContext.extent()
lines.append(" map extent (renderContext): %s" % extent.toString())
lines.append(" map center (renderContext): %lf, %lf" % (extent.center().x(), extent.center().y()))
lines.append(" map size: %f, %f" % (extent.width(), extent.height()))
lines.append(" map extent (map canvas): %s" % self.iface.mapCanvas().extent().toString())
map2pixel = renderContext.mapToPixel()
painter = renderContext.painter()
viewport = painter.viewport()
mapExtent = QgsRectangle(map2pixel.toMapCoordinatesF(0, 0), map2pixel.toMapCoordinatesF(viewport.width(), viewport.height()))
lines.append(" map extent (calculated): %s" % mapExtent.toString())
lines.append(" map center (calc rect): %lf, %lf" % (mapExtent.center().x(), mapExtent.center().y()))
center = map2pixel.toMapCoordinatesF(0.5 * viewport.width(), 0.5 * viewport.height())
lines.append(" map center (calc pt): %lf, %lf" % (center.x(), center.y()))
lines.append(" viewport size (pixel): %d, %d" % (viewport.width(), viewport.height()))
lines.append(" window size (pixel): %d, %d" % (painter.window().width(), painter.window().height()))
lines.append(" outputSize (pixel): %d, %d" % (mapSettings.outputSize().width(), mapSettings.outputSize().height()))
device = painter.device()
lines.append(" deviceSize (pixel): %f, %f" % (device.width(), device.height()))
lines.append(" logicalDpi: %f, %f" % (device.logicalDpiX(), device.logicalDpiY()))
lines.append(" outputDpi: %f" % mapSettings.outputDpi())
lines.append(" mapToPixel: %s" % map2pixel.showParameters())
mupp = map2pixel.mapUnitsPerPixel()
lines.append(" map units per pixel: %f" % mupp)
lines.append(" meters per pixel (renderContext): %f" % (extent.width() / viewport.width()))
transform = renderContext.coordinateTransform()
if transform:
mpp = mupp * {QGis.Feet: 0.3048, QGis.Degrees: self.layerDef.TSIZE1 / 180}.get(transform.destCRS().mapUnits(), 1)
lines.append(" meters per pixel (calc 1): %f" % mpp)
cx, cy = 0.5 * viewport.width(), 0.5 * viewport.height()
geometry = QgsGeometry.fromPolyline([map2pixel.toMapCoordinatesF(cx - 0.5, cy), map2pixel.toMapCoordinatesF(cx + 0.5, cy)])
geometry.transform(QgsCoordinateTransform(transform.destCRS(), transform.sourceCrs())) # project CRS to layer CRS (EPSG:3857)
mpp = geometry.length()
lines.append(" meters per pixel (calc center pixel): %f" % mpp)
lines.append(" scaleFactor: %f" % renderContext.scaleFactor())
lines.append(" rendererScale: %f" % renderContext.rendererScale())
scaleX, scaleY = self.getScaleToVisibleExtent(renderContext)
lines.append(" scale: %f, %f" % (scaleX, scaleY))
# draw information
textRect = painter.boundingRect(QRect(QPoint(0, 0), viewport.size()), Qt.AlignLeft, "Q")
for i, line in enumerate(lines):
painter.drawText(10, (i + 1) * textRect.height(), line)
self.log(line)
# diagonal
painter.drawLine(QPointF(0, 0), QPointF(painter.viewport().width(), painter.viewport().height()))
painter.drawLine(QPointF(painter.viewport().width(), 0), QPointF(0, painter.viewport().height()))
# credit label
margin, paddingH, paddingV = (3, 4, 3)
credit = "This is credit"
rect = QRect(0, 0, painter.viewport().width() - margin, painter.viewport().height() - margin)
textRect = painter.boundingRect(rect, Qt.AlignBottom | Qt.AlignRight, credit)
bgRect = QRect(textRect.left() - paddingH, textRect.top() - paddingV, textRect.width() + 2 * paddingH, textRect.height() + 2 * paddingV)
painter.drawRect(bgRect)
painter.drawText(rect, Qt.AlignBottom | Qt.AlignRight, credit)
示例9: ExtentSelectorTest
# 需要导入模块: from qgis.core import QgsRectangle [as 别名]
# 或者: from qgis.core.QgsRectangle import toString [as 别名]
class ExtentSelectorTest(unittest.TestCase):
"""Test Import Dialog widget
"""
# noinspection PyPep8Naming
def setUp(self):
"""Runs before each test."""
self.extent = QgsRectangle(10.0, 10.0, 20.0, 20.0)
self.crs = QgsCoordinateReferenceSystem('EPSG:4326')
CANVAS.setExtent(self.extent)
self.dialog = ExtentSelectorDialog(
IFACE,
PARENT,
self.extent,
self.crs)
self.signal_received = False
self.dialog.extent_defined.connect(self.extent_defined)
self.widget = QtGui.QWidget()
self.widget.setGeometry(0, 0, 500, 500)
layout = QtGui.QVBoxLayout(self.widget)
layout.addWidget(CANVAS)
self.widget.show()
QTest.qWaitForWindowShown(self.widget)
self.dialog.show()
QTest.qWaitForWindowShown(self.dialog)
def tearDown(self):
"""Runs after each test."""
self.dialog.reject()
self.dialog = None
self.extent = None
self.crs = None
def extent_defined(self, extent, crs):
"""Slot for when extents are changed in dialog.
:param extent: Rectangle that was created.
:type extent: QgsRectangle
:param crs: Coordiate reference system.
:type crs: QgsCoordinateReferenceSystem
"""
self.extent = extent
self.crs = crs
self.signal_received = True
def canvas_mouse_moved(self, point):
"""Slot for when the mouse moves on the canvas."""
print point.toString()
def test_spinboxes(self):
"""Test validate extent method."""
self.dialog.x_maximum.clear()
self.dialog.extent_defined.connect(self.extent_defined)
QTest.mouseClick(self.dialog.x_maximum, Qt.LeftButton)
QTest.keyClick(self.dialog.x_maximum, '3')
QTest.keyClick(self.dialog.x_maximum, '0')
ok = self.dialog.button_box.button(QtGui.QDialogButtonBox.Ok)
QTest.mouseClick(ok, Qt.LeftButton)
expected_extent = QgsRectangle(10.0, 10.0, 30.0, 20.0)
self.assertEqual(self.extent.toString(), expected_extent.toString())
@unittest.expectedFailure
@unittest.skip
def test_mouse_drag(self):
"""Test setting extents by dragging works.
This currently fails as QTest does not properly do the mouse
interactions with the canvas.
"""
# Imported here because it is not available in OSX QGIS bundle
# pylint: disable=redefined-outer-name
from PyQt4.QtTest import QTest
# Click the capture button
QTest.mouseClick(self.dialog.capture_button, Qt.LeftButton)
# drag a rect on the canvas
QTest.mousePress(CANVAS, Qt.LeftButton, pos=QPoint(0, 0), delay=500)
QTest.mouseRelease(
CANVAS, Qt.LeftButton,
pos=QPoint(300, 300),
delay=-1)
# on drag the extents selector windows should appear again
QTest.qWaitForWindowShown(self.dialog)
# Click ok to dispose of the window again
ok = self.dialog.button_box.button(QtGui.QDialogButtonBox.Ok)
QTest.mouseClick(ok, Qt.LeftButton)
# Check the extent emitted on closing teh dialog is correct
expected_extent = QgsRectangle(10.0, 10.0, 30.0, 20.0)
self.assertEqual(self.extent.toString(), expected_extent.toString())
示例10: testBoundingBox
# 需要导入模块: from qgis.core import QgsRectangle [as 别名]
# 或者: from qgis.core.QgsRectangle import toString [as 别名]
def testBoundingBox(self):
# 2-+-+-+-+-3
# | |
# + 6-+-+-7 +
# | | | |
# + + 9-+-8 +
# | | |
# ! 5-+-+-+-4 !
# |
# 1-+-+-+-+-0 !
points = [ QgsPoint(5,0), QgsPoint(0,0), QgsPoint(0,4), QgsPoint(5,4), QgsPoint(5,1), QgsPoint(1,1), QgsPoint(1,3), QgsPoint(4,3), QgsPoint(4,2), QgsPoint(2,2) ]
polyline = QgsGeometry.fromPolyline(points)
expbb = QgsRectangle(0,0,5,4)
bb = polyline.boundingBox()
assert expbb == bb, "Expected:\n%s\nGot:\n%s\n" % (expbb.toString(), bb.toString())
# 2-3 6-+-7
# | | | |
# 0-1 4 5 8-9
points = [
[ QgsPoint(0,0), QgsPoint(1,0), QgsPoint(1,1), QgsPoint(2,1), QgsPoint(2,0), ],
[ QgsPoint(3,0), QgsPoint(3,1), QgsPoint(5,1), QgsPoint(5,0), QgsPoint(6,0), ]
]
polyline = QgsGeometry.fromMultiPolyline(points)
expbb = QgsRectangle(0,0,6,1)
bb = polyline.boundingBox()
assert expbb == bb, "Expected:\n%s\nGot:\n%s\n" % (expbb.toString(), bb.toString())
# 5---4
# | |
# | 2-3
# | |
# 0-1
points = [[
QgsPoint(0,0), QgsPoint(1,0), QgsPoint(1,1), QgsPoint(2,1), QgsPoint(2,2), QgsPoint(0,2), QgsPoint(0,0),
]]
polygon = QgsGeometry.fromPolygon(points)
expbb = QgsRectangle(0,0,2,2)
bb = polygon.boundingBox()
assert expbb == bb, "Expected:\n%s\nGot:\n%s\n" % (expbb.toString(), bb.toString())
# 3-+-+-2
# | |
# + 8-7 +
# | | | |
# + 5-6 +
# | |
# 0-+-+-1
points = [
[ QgsPoint(0,0), QgsPoint(3,0), QgsPoint(3,3), QgsPoint(0,3), QgsPoint(0,0) ],
[ QgsPoint(1,1), QgsPoint(2,1), QgsPoint(2,2), QgsPoint(1,2), QgsPoint(1,1) ],
]
polygon = QgsGeometry.fromPolygon(points)
expbb = QgsRectangle(0,0,3,3)
bb = polygon.boundingBox()
assert expbb == bb, "Expected:\n%s\nGot:\n%s\n" % (expbb.toString(), bb.toString())
# 5-+-4 0-+-9
# | | | |
# | 2-3 1-2 |
# | | | |
# 0-1 7-8
points = [
[ [ QgsPoint(0,0), QgsPoint(1,0), QgsPoint(1,1), QgsPoint(2,1), QgsPoint(2,2), QgsPoint(0,2), QgsPoint(0,0), ] ],
[ [ QgsPoint(4,0), QgsPoint(5,0), QgsPoint(5,2), QgsPoint(3,2), QgsPoint(3,1), QgsPoint(4,1), QgsPoint(4,0), ] ]
]
polygon = QgsGeometry.fromMultiPolygon(points)
expbb = QgsRectangle(0,0,5,2)
bb = polygon.boundingBox()
assert expbb == bb, "Expected:\n%s\nGot:\n%s\n" % (expbb.toString(), bb.toString())