本文整理汇总了Python中qgis.core.QgsLayoutItemMap.setAtlasScalingMode方法的典型用法代码示例。如果您正苦于以下问题:Python QgsLayoutItemMap.setAtlasScalingMode方法的具体用法?Python QgsLayoutItemMap.setAtlasScalingMode怎么用?Python QgsLayoutItemMap.setAtlasScalingMode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qgis.core.QgsLayoutItemMap
的用法示例。
在下文中一共展示了QgsLayoutItemMap.setAtlasScalingMode方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: rotation_test
# 需要导入模块: from qgis.core import QgsLayoutItemMap [as 别名]
# 或者: from qgis.core.QgsLayoutItemMap import setAtlasScalingMode [as 别名]
def rotation_test(self):
# We will create a polygon layer with a rotated rectangle.
# Then we will make it the object layer for the atlas,
# rotate the map and test that the bounding rectangle
# is smaller than the bounds without rotation.
polygonLayer = QgsVectorLayer('Polygon', 'test_polygon', 'memory')
poly = QgsFeature(polygonLayer.fields())
points = [(10, 15), (15, 10), (45, 40), (40, 45)]
poly.setGeometry(QgsGeometry.fromPolygonXY([[QgsPointXY(x[0], x[1]) for x in points]]))
polygonLayer.dataProvider().addFeatures([poly])
QgsProject.instance().addMapLayer(polygonLayer)
# Recreating the layout locally
composition = QgsPrintLayout(QgsProject.instance())
composition.initializeDefaults()
# the atlas map
atlasMap = QgsLayoutItemMap(composition)
atlasMap.attemptSetSceneRect(QRectF(20, 20, 130, 130))
atlasMap.setFrameEnabled(True)
atlasMap.setLayers([polygonLayer])
atlasMap.setExtent(QgsRectangle(0, 0, 100, 50))
composition.addLayoutItem(atlasMap)
# the atlas
atlas = composition.atlas()
atlas.setCoverageLayer(polygonLayer)
atlas.setEnabled(True)
atlasMap.setAtlasDriven(True)
atlasMap.setAtlasScalingMode(QgsLayoutItemMap.Auto)
atlasMap.setAtlasMargin(0.0)
# Testing
atlasMap.setMapRotation(0.0)
atlas.beginRender()
atlas.first()
nonRotatedExtent = QgsRectangle(atlasMap.extent())
atlasMap.setMapRotation(45.0)
atlas.first()
rotatedExtent = QgsRectangle(atlasMap.extent())
self.assertLess(rotatedExtent.width(), nonRotatedExtent.width() * 0.9)
self.assertLess(rotatedExtent.height(), nonRotatedExtent.height() * 0.9)
QgsProject.instance().removeMapLayer(polygonLayer)
示例2: test_datadefined_margin
# 需要导入模块: from qgis.core import QgsLayoutItemMap [as 别名]
# 或者: from qgis.core.QgsLayoutItemMap import setAtlasScalingMode [as 别名]
def test_datadefined_margin(self):
polygonLayer = QgsVectorLayer('Polygon?field=margin:int', 'test_polygon', 'memory')
poly = QgsFeature(polygonLayer.fields())
poly.setAttributes([0])
poly.setGeometry(QgsGeometry.fromWkt('Polygon((30 30, 40 30, 40 40, 30 40, 30 30))'))
polygonLayer.dataProvider().addFeatures([poly])
poly = QgsFeature(polygonLayer.fields())
poly.setAttributes([10])
poly.setGeometry(QgsGeometry.fromWkt('Polygon((10 10, 20 10, 20 20, 10 20, 10 10))'))
polygonLayer.dataProvider().addFeatures([poly])
poly = QgsFeature(polygonLayer.fields())
poly.setAttributes([20])
poly.setGeometry(QgsGeometry.fromWkt('Polygon((50 50, 60 50, 60 60, 50 60, 50 50))'))
polygonLayer.dataProvider().addFeatures([poly])
QgsProject.instance().addMapLayer(polygonLayer)
layout = QgsPrintLayout(QgsProject.instance())
map = QgsLayoutItemMap(layout)
map.setCrs(polygonLayer.crs())
map.attemptSetSceneRect(QRectF(20, 20, 130, 130))
map.setFrameEnabled(True)
map.setLayers([polygonLayer])
map.setExtent(QgsRectangle(0, 0, 100, 50))
layout.addLayoutItem(map)
atlas = layout.atlas()
atlas.setCoverageLayer(polygonLayer)
atlas.setEnabled(True)
map.setAtlasDriven(True)
map.setAtlasScalingMode(QgsLayoutItemMap.Auto)
map.setAtlasMargin(77.0)
map.dataDefinedProperties().setProperty(QgsLayoutObject.MapAtlasMargin, QgsProperty.fromExpression('margin/2'))
atlas.beginRender()
atlas.first()
self.assertEqual(map.extent(), QgsRectangle(25, 30, 45, 40))
self.assertTrue(atlas.next())
self.assertEqual(map.extent(), QgsRectangle(4.5, 9.75, 25.5, 20.25))
self.assertTrue(atlas.next())
self.assertEqual(map.extent(), QgsRectangle(44, 49.5, 66, 60.5))
QgsProject.instance().removeMapLayer(polygonLayer)
示例3: prepareIteratorLayout
# 需要导入模块: from qgis.core import QgsLayoutItemMap [as 别名]
# 或者: from qgis.core.QgsLayoutItemMap import setAtlasScalingMode [as 别名]
def prepareIteratorLayout(self):
layer_path = os.path.join(TEST_DATA_DIR, 'france_parts.shp')
layer = QgsVectorLayer(layer_path, 'test', "ogr")
project = QgsProject()
project.addMapLayers([layer])
# select epsg:2154
crs = QgsCoordinateReferenceSystem()
crs.createFromSrid(2154)
project.setCrs(crs)
layout = QgsPrintLayout(project)
layout.initializeDefaults()
# fix the renderer, fill with green
props = {"color": "0,127,0", "outline_width": "4", "outline_color": '255,255,255'}
fillSymbol = QgsFillSymbol.createSimple(props)
renderer = QgsSingleSymbolRenderer(fillSymbol)
layer.setRenderer(renderer)
# the atlas map
atlas_map = QgsLayoutItemMap(layout)
atlas_map.attemptSetSceneRect(QRectF(20, 20, 130, 130))
atlas_map.setFrameEnabled(True)
atlas_map.setLayers([layer])
layout.addLayoutItem(atlas_map)
# the atlas
atlas = layout.atlas()
atlas.setCoverageLayer(layer)
atlas.setEnabled(True)
atlas_map.setExtent(
QgsRectangle(332719.06221504929, 6765214.5887386119, 560957.85090677091, 6993453.3774303338))
atlas_map.setAtlasDriven(True)
atlas_map.setAtlasScalingMode(QgsLayoutItemMap.Auto)
atlas_map.setAtlasMargin(0.10)
return project, layout
示例4: TestQgsLayoutAtlas
# 需要导入模块: from qgis.core import QgsLayoutItemMap [as 别名]
# 或者: from qgis.core.QgsLayoutItemMap import setAtlasScalingMode [as 别名]
#.........这里部分代码省略.........
def testNameForPage(self):
p = QgsProject()
vectorFileInfo = QFileInfo(unitTestDataPath() + "/france_parts.shp")
vector_layer = QgsVectorLayer(vectorFileInfo.filePath(), vectorFileInfo.completeBaseName(), "ogr")
self.assertTrue(vector_layer.isValid())
p.addMapLayer(vector_layer)
l = QgsPrintLayout(p)
atlas = l.atlas()
atlas.setEnabled(True)
atlas.setCoverageLayer(vector_layer)
atlas.setPageNameExpression("\"NAME_1\"")
self.assertTrue(atlas.beginRender())
self.assertEqual(atlas.nameForPage(0), 'Basse-Normandie')
self.assertEqual(atlas.nameForPage(1), 'Bretagne')
self.assertEqual(atlas.nameForPage(2), 'Pays de la Loire')
self.assertEqual(atlas.nameForPage(3), 'Centre')
def filename_test(self):
self.atlas.setFilenameExpression("'output_' || @atlas_featurenumber")
self.atlas.beginRender()
for i in range(0, self.atlas.count()):
self.atlas.seekTo(i)
expected = "output_%d" % (i + 1)
self.assertEqual(self.atlas.currentFilename(), expected)
self.atlas.endRender()
def autoscale_render_test(self):
self.atlas_map.setExtent(
QgsRectangle(332719.06221504929, 6765214.5887386119, 560957.85090677091, 6993453.3774303338))
self.atlas_map.setAtlasDriven(True)
self.atlas_map.setAtlasScalingMode(QgsLayoutItemMap.Auto)
self.atlas_map.setAtlasMargin(0.10)
self.atlas.beginRender()
for i in range(0, 2):
self.atlas.seekTo(i)
self.mLabel1.adjustSizeToText()
checker = QgsLayoutChecker('atlas_autoscale%d' % (i + 1), self.layout)
checker.setControlPathPrefix("atlas")
myTestResult, myMessage = checker.testLayout(0, 200)
self.report += checker.report()
self.assertTrue(myTestResult, myMessage)
self.atlas.endRender()
self.atlas_map.setAtlasDriven(False)
self.atlas_map.setAtlasScalingMode(QgsLayoutItemMap.Fixed)
self.atlas_map.setAtlasMargin(0)
def fixedscale_render_test(self):
self.atlas_map.setExtent(QgsRectangle(209838.166, 6528781.020, 610491.166, 6920530.620))
self.atlas_map.setAtlasDriven(True)
self.atlas_map.setAtlasScalingMode(QgsLayoutItemMap.Fixed)
self.atlas.beginRender()
for i in range(0, 2):
self.atlas.seekTo(i)
self.mLabel1.adjustSizeToText()
checker = QgsLayoutChecker('atlas_fixedscale%d' % (i + 1), self.layout)