本文整理汇总了Python中qgis.core.QgsComposerPicture.setSceneRect方法的典型用法代码示例。如果您正苦于以下问题:Python QgsComposerPicture.setSceneRect方法的具体用法?Python QgsComposerPicture.setSceneRect怎么用?Python QgsComposerPicture.setSceneRect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qgis.core.QgsComposerPicture
的用法示例。
在下文中一共展示了QgsComposerPicture.setSceneRect方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestQgsComposerPicture
# 需要导入模块: from qgis.core import QgsComposerPicture [as 别名]
# 或者: from qgis.core.QgsComposerPicture import setSceneRect [as 别名]
class TestQgsComposerPicture(unittest.TestCase):
@classmethod
def setUpClass(cls):
# Bring up a simple HTTP server, for remote picture tests
os.chdir(unitTestDataPath() + "")
handler = SimpleHTTPServer.SimpleHTTPRequestHandler
cls.httpd = SocketServer.TCPServer(("localhost", 0), handler)
cls.port = cls.httpd.server_address[1]
cls.httpd_thread = threading.Thread(target=cls.httpd.serve_forever)
cls.httpd_thread.setDaemon(True)
cls.httpd_thread.start()
def __init__(self, methodName):
"""Run once on class initialization."""
unittest.TestCase.__init__(self, methodName)
TEST_DATA_DIR = unitTestDataPath()
self.pngImage = TEST_DATA_DIR + "/sample_image.png"
# create composition
self.mapSettings = QgsMapSettings()
self.composition = QgsComposition(self.mapSettings)
self.composition.setPaperSize(297, 210)
self.composerPicture = QgsComposerPicture(self.composition)
self.composerPicture.setPicturePath(self.pngImage)
self.composerPicture.setSceneRect(QRectF(70, 70, 100, 100))
self.composerPicture.setFrameEnabled(True)
self.composition.addComposerPicture(self.composerPicture)
def testResizeZoom(self):
"""Test picture resize zoom mode."""
self.composerPicture.setResizeMode(QgsComposerPicture.Zoom)
checker = QgsCompositionChecker("composerpicture_resize_zoom", self.composition)
checker.setControlPathPrefix("composer_picture")
testResult, message = checker.testComposition()
assert testResult, message
def testRemoteImage(self):
"""Test fetching remote picture."""
self.composerPicture.setPicturePath(
"http://localhost:" + str(TestQgsComposerPicture.port) + "/qgis_local_server/logo.png"
)
checker = QgsCompositionChecker("composerpicture_remote", self.composition)
checker.setControlPathPrefix("composer_picture")
testResult, message = checker.testComposition()
self.composerPicture.setPicturePath(self.pngImage)
assert testResult, message
示例2: TestQgsComposerPicture
# 需要导入模块: from qgis.core import QgsComposerPicture [as 别名]
# 或者: from qgis.core.QgsComposerPicture import setSceneRect [as 别名]
class TestQgsComposerPicture(unittest.TestCase):
@classmethod
def setUpClass(cls):
# Bring up a simple HTTP server, for remote picture tests
os.chdir(unitTestDataPath() + '')
handler = http.server.SimpleHTTPRequestHandler
cls.httpd = socketserver.TCPServer(('localhost', 0), handler)
cls.port = cls.httpd.server_address[1]
cls.httpd_thread = threading.Thread(target=cls.httpd.serve_forever)
cls.httpd_thread.setDaemon(True)
cls.httpd_thread.start()
def __init__(self, methodName):
"""Run once on class initialization."""
unittest.TestCase.__init__(self, methodName)
TEST_DATA_DIR = unitTestDataPath()
self.pngImage = TEST_DATA_DIR + "/sample_image.png"
# create composition
self.mapSettings = QgsMapSettings()
self.composition = QgsComposition(self.mapSettings, QgsProject.instance())
self.composition.setPaperSize(297, 210)
self.composerPicture = QgsComposerPicture(self.composition)
self.composerPicture.setPicturePath(self.pngImage)
self.composerPicture.setSceneRect(QRectF(70, 70, 100, 100))
self.composerPicture.setFrameEnabled(True)
self.composition.addComposerPicture(self.composerPicture)
def testResizeZoom(self):
"""Test picture resize zoom mode."""
self.composerPicture.setResizeMode(QgsComposerPicture.Zoom)
checker = QgsCompositionChecker('composerpicture_resize_zoom', self.composition)
checker.setControlPathPrefix("composer_picture")
testResult, message = checker.testComposition()
assert testResult, message
@unittest.skip('test is broken for qt5/python3 - feature works')
def testRemoteImage(self):
"""Test fetching remote picture."""
self.composerPicture.setPicturePath('http://localhost:' + str(TestQgsComposerPicture.port) + '/qgis_local_server/logo.png')
checker = QgsCompositionChecker('composerpicture_remote', self.composition)
checker.setControlPathPrefix("composer_picture")
testResult, message = checker.testComposition()
self.composerPicture.setPicturePath(self.pngImage)
assert testResult, message
def testGridNorth(self):
"""Test syncing picture to grid north"""
mapSettings = QgsMapSettings()
composition = QgsComposition(mapSettings, QgsProject.instance())
composerMap = QgsComposerMap(composition)
composerMap.setNewExtent(QgsRectangle(0, -256, 256, 0))
composition.addComposerMap(composerMap)
composerPicture = QgsComposerPicture(composition)
composition.addComposerPicture(composerPicture)
composerPicture.setRotationMap(composerMap.id())
self.assertTrue(composerPicture.rotationMap() >= 0)
composerPicture.setNorthMode(QgsComposerPicture.GridNorth)
composerMap.setMapRotation(45)
self.assertEqual(composerPicture.pictureRotation(), 45)
# add an offset
composerPicture.setNorthOffset(-10)
self.assertEqual(composerPicture.pictureRotation(), 35)
def testTrueNorth(self):
"""Test syncing picture to true north"""
mapSettings = QgsMapSettings()
composition = QgsComposition(mapSettings, QgsProject.instance())
composerMap = QgsComposerMap(composition)
composerMap.setCrs(QgsCoordinateReferenceSystem.fromEpsgId(3575))
composerMap.setNewExtent(QgsRectangle(-2126029.962, -2200807.749, -119078.102, -757031.156))
composition.addComposerMap(composerMap)
composerPicture = QgsComposerPicture(composition)
composition.addComposerPicture(composerPicture)
composerPicture.setRotationMap(composerMap.id())
self.assertTrue(composerPicture.rotationMap() >= 0)
composerPicture.setNorthMode(QgsComposerPicture.TrueNorth)
self.assertAlmostEqual(composerPicture.pictureRotation(), 37.20, 1)
# shift map
#.........这里部分代码省略.........