本文整理汇总了Python中qgis.core.QgsLayoutItemMap类的典型用法代码示例。如果您正苦于以下问题:Python QgsLayoutItemMap类的具体用法?Python QgsLayoutItemMap怎么用?Python QgsLayoutItemMap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QgsLayoutItemMap类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: testSnapRect
def testSnapRect(self):
p = QgsProject()
l = QgsLayout(p)
page = QgsLayoutItemPage(l)
page.setPageSize('A4')
l.pageCollection().addPage(page)
s = QgsLayoutSnapper(l)
guides = l.guides()
# first test snapping to grid
l.gridSettings().setResolution(QgsLayoutMeasurement(5, QgsUnitTypes.LayoutMillimeters))
s.setSnapToItems(False)
s.setSnapToGrid(True)
s.setSnapTolerance(1)
rect, snapped = s.snapRect(QRectF(1, 1, 2, 1), 1)
self.assertTrue(snapped)
self.assertEqual(rect, QRectF(0, 0, 2, 1))
rect, snapped = s.snapRect(QRectF(1, 1, 3.5, 3.5), 1)
self.assertTrue(snapped)
self.assertEqual(rect, QRectF(1.5, 1.5, 3.5, 3.5))
s.setSnapToItems(False)
s.setSnapToGrid(False)
rect, snapped = s.snapRect(QRectF(1, 1, 3.5, 3.5), 1)
self.assertFalse(snapped)
self.assertEqual(rect, QRectF(1, 1, 3.5, 3.5))
# test that guide takes precedence
s.setSnapToGrid(True)
s.setSnapToGuides(True)
guides.addGuide(QgsLayoutGuide(Qt.Horizontal, QgsLayoutMeasurement(0.5), page))
rect, snapped = s.snapRect(QRectF(1, 1, 2, 3), 1)
self.assertTrue(snapped)
self.assertEqual(rect, QRectF(0.0, 0.5, 2.0, 3.0))
# add an item
item1 = QgsLayoutItemMap(l)
item1.attemptMove(QgsLayoutPoint(121, 1.1, QgsUnitTypes.LayoutMillimeters))
l.addItem(item1)
# test that guide takes precedence over item
s.setSnapToGrid(True)
s.setSnapToGuides(True)
s.setSnapToItems(True)
rect, snapped = s.snapRect(QRectF(1, 1, 2, 3), 1)
self.assertTrue(snapped)
self.assertEqual(rect, QRectF(0.0, 0.5, 2.0, 3.0))
# but items take precedence over grid
s.setSnapToGuides(False)
rect, snapped = s.snapRect(QRectF(1, 1, 2, 3), 1)
self.assertTrue(snapped)
self.assertEqual(rect, QRectF(0.0, 1.1, 2.0, 3.0))
# ... unless item is ignored!
rect, snapped = s.snapRect(QRectF(1, 1, 2, 3), 1, None, None, [item1])
self.assertTrue(snapped)
self.assertEqual(rect, QRectF(0.0, 0.0, 2.0, 3.0))
开发者ID:elpaso,项目名称:QGIS,代码行数:58,代码来源:test_qgslayoutsnapper.py
示例2: testLegendScopeVariables
def testLegendScopeVariables(self):
layout = QgsLayout(QgsProject.instance())
layout.initializeDefaults()
legend = QgsLayoutItemLegend(layout)
legend.setTitle("Legend")
layout.addLayoutItem(legend)
legend.setColumnCount(2)
legend.setWrapString('d')
legend.setLegendFilterOutAtlas(True)
expc = legend.createExpressionContext()
exp1 = QgsExpression("@legend_title")
self.assertEqual(exp1.evaluate(expc), "Legend")
exp2 = QgsExpression("@legend_column_count")
self.assertEqual(exp2.evaluate(expc), 2)
exp3 = QgsExpression("@legend_wrap_string")
self.assertEqual(exp3.evaluate(expc), 'd')
exp4 = QgsExpression("@legend_split_layers")
self.assertEqual(exp4.evaluate(expc), False)
exp5 = QgsExpression("@legend_filter_out_atlas")
self.assertEqual(exp5.evaluate(expc), True)
map = QgsLayoutItemMap(layout)
map.attemptSetSceneRect(QRectF(20, 20, 80, 80))
map.setFrameEnabled(True)
map.setExtent(QgsRectangle(781662.375, 3339523.125, 793062.375, 3345223.125))
layout.addLayoutItem(map)
map.setScale(15000)
legend.setLinkedMap(map)
expc2 = legend.createExpressionContext()
exp6 = QgsExpression("@map_scale")
self.assertAlmostEqual(exp6.evaluate(expc2), 15000, 2)
开发者ID:alexbruy,项目名称:QGIS,代码行数:34,代码来源:test_qgslayoutlegend.py
示例3: testContainsAdvancedEffects
def testContainsAdvancedEffects(self):
map_settings = QgsMapSettings()
map_settings.setLayers([self.vector_layer])
layout = QgsLayout(QgsProject.instance())
map = QgsLayoutItemMap(layout)
self.assertFalse(map.containsAdvancedEffects())
self.vector_layer.setBlendMode(QPainter.CompositionMode_Darken)
result = map.containsAdvancedEffects()
self.vector_layer.setBlendMode(QPainter.CompositionMode_SourceOver)
self.assertTrue(result)
开发者ID:,项目名称:,代码行数:11,代码来源:
示例4: testInitialSizeSymbolMapUnits
def testInitialSizeSymbolMapUnits(self):
"""Test initial size of legend with a symbol size in map units"""
point_path = os.path.join(TEST_DATA_DIR, 'points.shp')
point_layer = QgsVectorLayer(point_path, 'points', 'ogr')
QgsProject.instance().addMapLayers([point_layer])
marker_symbol = QgsMarkerSymbol.createSimple({'color': '#ff0000', 'outline_style': 'no', 'size': '5', 'size_unit': 'MapUnit'})
point_layer.setRenderer(QgsSingleSymbolRenderer(marker_symbol))
s = QgsMapSettings()
s.setLayers([point_layer])
layout = QgsLayout(QgsProject.instance())
layout.initializeDefaults()
map = QgsLayoutItemMap(layout)
map.attemptSetSceneRect(QRectF(20, 20, 80, 80))
map.setFrameEnabled(True)
map.setLayers([point_layer])
layout.addLayoutItem(map)
map.setExtent(point_layer.extent())
legend = QgsLayoutItemLegend(layout)
legend.setTitle("Legend")
legend.attemptSetSceneRect(QRectF(120, 20, 80, 80))
legend.setFrameEnabled(True)
legend.setFrameStrokeWidth(QgsLayoutMeasurement(2))
legend.setBackgroundColor(QColor(200, 200, 200))
legend.setTitle('')
layout.addLayoutItem(legend)
legend.setLinkedMap(map)
checker = QgsLayoutChecker(
'composer_legend_mapunits', layout)
checker.setControlPathPrefix("composer_legend")
result, message = checker.testLayout()
self.assertTrue(result, message)
# resize with non-top-left reference point
legend.setResizeToContents(False)
legend.setReferencePoint(QgsLayoutItem.LowerRight)
legend.attemptMove(QgsLayoutPoint(120, 90))
legend.attemptResize(QgsLayoutSize(50, 60))
self.assertEqual(legend.positionWithUnits().x(), 120.0)
self.assertEqual(legend.positionWithUnits().y(), 90.0)
self.assertAlmostEqual(legend.pos().x(), 70, -1)
self.assertAlmostEqual(legend.pos().y(), 30, -1)
legend.setResizeToContents(True)
legend.updateLegend()
self.assertEqual(legend.positionWithUnits().x(), 120.0)
self.assertEqual(legend.positionWithUnits().y(), 90.0)
self.assertAlmostEqual(legend.pos().x(), 91, -1)
self.assertAlmostEqual(legend.pos().y(), 71, -1)
QgsProject.instance().removeMapLayers([point_layer.id()])
开发者ID:SrNetoChan,项目名称:Quantum-GIS,代码行数:58,代码来源:test_qgslayoutlegend.py
示例5: testReadWriteXml
def testReadWriteXml(self):
p = QgsProject()
l = QgsPrintLayout(p)
l.setName('my layout')
l.setUnits(QgsUnitTypes.LayoutInches)
collection = l.pageCollection()
# add a page
page = QgsLayoutItemPage(l)
page.setPageSize('A6')
collection.addPage(page)
grid = l.gridSettings()
grid.setResolution(QgsLayoutMeasurement(5, QgsUnitTypes.LayoutPoints))
g1 = QgsLayoutGuide(Qt.Horizontal, QgsLayoutMeasurement(5, QgsUnitTypes.LayoutCentimeters),
l.pageCollection().page(0))
l.guides().addGuide(g1)
snapper = l.snapper()
snapper.setSnapTolerance(7)
# add some items
item1 = QgsLayoutItemMap(l)
item1.setId('xxyyxx')
l.addItem(item1)
item2 = QgsLayoutItemMap(l)
item2.setId('zzyyzz')
l.addItem(item2)
l.setReferenceMap(item2)
doc = QDomDocument("testdoc")
elem = l.writeXml(doc, QgsReadWriteContext())
l2 = QgsPrintLayout(p)
self.assertTrue(l2.readXml(elem, doc, QgsReadWriteContext()))
self.assertEqual(l2.name(), 'my layout')
self.assertEqual(l2.units(), QgsUnitTypes.LayoutInches)
collection2 = l2.pageCollection()
self.assertEqual(collection2.pageCount(), 1)
self.assertAlmostEqual(collection2.page(0).pageSize().width(), 105, 4)
self.assertEqual(collection2.page(0).pageSize().height(), 148)
self.assertEqual(l2.gridSettings().resolution().length(), 5.0)
self.assertEqual(l2.gridSettings().resolution().units(), QgsUnitTypes.LayoutPoints)
self.assertEqual(l2.guides().guidesOnPage(0)[0].orientation(), Qt.Horizontal)
self.assertEqual(l2.guides().guidesOnPage(0)[0].position().length(), 5.0)
self.assertEqual(l2.guides().guidesOnPage(0)[0].position().units(), QgsUnitTypes.LayoutCentimeters)
self.assertEqual(l2.snapper().snapTolerance(), 7)
# check restored items
new_item1 = l2.itemByUuid(item1.uuid())
self.assertTrue(new_item1)
self.assertEqual(new_item1.id(), 'xxyyxx')
new_item2 = l2.itemByUuid(item2.uuid())
self.assertTrue(new_item2)
self.assertEqual(new_item2.id(), 'zzyyzz')
self.assertEqual(l2.referenceMap().id(), 'zzyyzz')
开发者ID:mj10777,项目名称:QGIS,代码行数:59,代码来源:test_qgslayout.py
示例6: __init__
def __init__(self, methodName):
"""Run once on class initialization."""
unittest.TestCase.__init__(self, methodName)
myPath = os.path.join(TEST_DATA_DIR, 'rgb256x256.png')
rasterFileInfo = QFileInfo(myPath)
self.raster_layer = QgsRasterLayer(rasterFileInfo.filePath(),
rasterFileInfo.completeBaseName())
rasterRenderer = QgsMultiBandColorRenderer(
self.raster_layer.dataProvider(), 1, 2, 3)
self.raster_layer.setRenderer(rasterRenderer)
myPath = os.path.join(TEST_DATA_DIR, 'points.shp')
vector_file_info = QFileInfo(myPath)
self.vector_layer = QgsVectorLayer(vector_file_info.filePath(),
vector_file_info.completeBaseName(), 'ogr')
assert self.vector_layer.isValid()
# pipe = mRasterLayer.pipe()
# assert pipe.set(rasterRenderer), 'Cannot set pipe renderer'
QgsProject.instance().addMapLayers([self.raster_layer, self.vector_layer])
# create layout with layout map
self.layout = QgsLayout(QgsProject.instance())
self.layout.initializeDefaults()
self.map = QgsLayoutItemMap(self.layout)
self.map.attemptSetSceneRect(QRectF(20, 20, 200, 100))
self.map.setFrameEnabled(True)
self.map.setLayers([self.raster_layer])
self.layout.addLayoutItem(self.map)
开发者ID:,项目名称:,代码行数:29,代码来源:
示例7: _set_up_composition
def _set_up_composition(self, width, height, dpi, engine_settings):
# set up layout and add map
self._c = QgsLayout(QgsProject.instance())
""":type: QgsLayout"""
# self._c.setUseAdvancedEffects(False)
self._c.renderContext().setDpi(dpi)
# 600 x 400 px = 211.67 x 141.11 mm @ 72 dpi
paperw = width * 25.4 / dpi
paperh = height * 25.4 / dpi
page = QgsLayoutItemPage(self._c)
page.attemptResize(QgsLayoutSize(paperw, paperh))
self._c.pageCollection().addPage(page)
# NOTE: do not use QgsLayoutItemMap(self._c, 0, 0, paperw, paperh) since
# it only takes integers as parameters and the composition will grow
# larger based upon union of item scene rectangles and a slight buffer
# see end of QgsComposition::compositionBounds()
# add map as small graphics item first, then set its scene QRectF later
self._cmap = QgsLayoutItemMap(self._c)
self._cmap.attemptSetSceneRect(QRectF(10, 10, 10, 10))
""":type: QgsLayoutItemMap"""
self._cmap.setFrameEnabled(False)
self._cmap.setLayers(self._TestMapSettings.layers())
if self._TestMapSettings.labelingEngineSettings().flags() & QgsLabelingEngineSettings.UsePartialCandidates:
self._cmap.setMapFlags(QgsLayoutItemMap.ShowPartialLabels)
self._c.addLayoutItem(self._cmap)
# now expand map to fill page and set its extent
self._cmap.attemptSetSceneRect(QRectF(0, 0, paperw, paperw))
self._cmap.setExtent(self.aoiExtent())
# self._cmap.updateCachedImage()
# composition takes labeling engine settings from project
QgsProject.instance().setLabelingEngineSettings(engine_settings)
开发者ID:yoichigmf,项目名称:QGIS,代码行数:31,代码来源:test_qgspallabeling_layout.py
示例8: testSelected
def testSelected(self):
"""
Ensure that items are selectable
"""
layout = QgsLayout(QgsProject.instance())
item = QgsLayoutItemMap(layout)
item.setSelected(True)
self.assertTrue(item.isSelected())
item.setSelected(False)
self.assertFalse(item.isSelected())
开发者ID:mj10777,项目名称:QGIS,代码行数:10,代码来源:test_qgslayoutitem.py
示例9: testGridNorth
def testGridNorth(self):
"""Test syncing picture to grid north"""
layout = QgsLayout(QgsProject.instance())
map = QgsLayoutItemMap(layout)
map.setExtent(QgsRectangle(0, -256, 256, 0))
layout.addLayoutItem(map)
picture = QgsLayoutItemPicture(layout)
layout.addLayoutItem(picture)
picture.setLinkedMap(map)
self.assertEqual(picture.linkedMap(), map)
picture.setNorthMode(QgsLayoutItemPicture.GridNorth)
map.setMapRotation(45)
self.assertEqual(picture.pictureRotation(), 45)
# add an offset
picture.setNorthOffset(-10)
self.assertEqual(picture.pictureRotation(), 35)
开发者ID:dmarteau,项目名称:QGIS,代码行数:22,代码来源:test_qgslayoutpicture.py
示例10: testExportWorldFile
def testExportWorldFile(self):
l = QgsLayout(QgsProject.instance())
l.initializeDefaults()
# add some items
map = QgsLayoutItemMap(l)
map.attemptSetSceneRect(QRectF(30, 60, 200, 100))
extent = QgsRectangle(2000, 2800, 2500, 2900)
map.setExtent(extent)
l.addLayoutItem(map)
exporter = QgsLayoutExporter(l)
# setup settings
settings = QgsLayoutExporter.ImageExportSettings()
settings.dpi = 80
settings.generateWorldFile = False
rendered_file_path = os.path.join(self.basetestpath, 'test_exportwithworldfile.png')
world_file_path = os.path.join(self.basetestpath, 'test_exportwithworldfile.pgw')
self.assertEqual(exporter.exportToImage(rendered_file_path, settings), QgsLayoutExporter.Success)
self.assertTrue(os.path.exists(rendered_file_path))
self.assertFalse(os.path.exists(world_file_path))
# with world file
settings.generateWorldFile = True
rendered_file_path = os.path.join(self.basetestpath, 'test_exportwithworldfile.png')
self.assertEqual(exporter.exportToImage(rendered_file_path, settings), QgsLayoutExporter.Success)
self.assertTrue(os.path.exists(rendered_file_path))
self.assertTrue(os.path.exists(world_file_path))
lines = tuple(open(world_file_path, 'r'))
values = [float(f) for f in lines]
self.assertAlmostEqual(values[0], 0.794117647059, 2)
self.assertAlmostEqual(values[1], 0.0, 2)
self.assertAlmostEqual(values[2], 0.0, 2)
self.assertAlmostEqual(values[3], -0.794251134644, 2)
self.assertAlmostEqual(values[4], 1925.000000000000, 2)
self.assertAlmostEqual(values[5], 3050.000000000000, 2)
开发者ID:lyhkop,项目名称:QGIS,代码行数:38,代码来源:test_qgslayoutexporter.py
示例11: testInitialSizeSymbolMapUnits
def testInitialSizeSymbolMapUnits(self):
"""Test initial size of legend with a symbol size in map units"""
point_path = os.path.join(TEST_DATA_DIR, 'points.shp')
point_layer = QgsVectorLayer(point_path, 'points', 'ogr')
QgsProject.instance().addMapLayers([point_layer])
marker_symbol = QgsMarkerSymbol.createSimple({'color': '#ff0000', 'outline_style': 'no', 'size': '5', 'size_unit': 'MapUnit'})
point_layer.setRenderer(QgsSingleSymbolRenderer(marker_symbol))
s = QgsMapSettings()
s.setLayers([point_layer])
layout = QgsLayout(QgsProject.instance())
layout.initializeDefaults()
map = QgsLayoutItemMap(layout)
map.attemptSetSceneRect(QRectF(20, 20, 80, 80))
map.setFrameEnabled(True)
map.setLayers([point_layer])
layout.addLayoutItem(map)
map.setExtent(point_layer.extent())
legend = QgsLayoutItemLegend(layout)
legend.attemptSetSceneRect(QRectF(120, 20, 80, 80))
legend.setFrameEnabled(True)
legend.setFrameStrokeWidth(QgsLayoutMeasurement(2))
legend.setBackgroundColor(QColor(200, 200, 200))
legend.setTitle('')
layout.addLayoutItem(legend)
legend.setMap(map)
checker = QgsLayoutChecker(
'composer_legend_mapunits', layout)
checker.setControlPathPrefix("composer_legend")
result, message = checker.testLayout()
self.assertTrue(result, message)
QgsProject.instance().removeMapLayers([point_layer.id()])
开发者ID:minorua,项目名称:QGIS,代码行数:39,代码来源:test_qgslayoutlegend.py
示例12: testExportToSvgTextRenderFormat
def testExportToSvgTextRenderFormat(self):
l = QgsLayout(QgsProject.instance())
l.initializeDefaults()
# add a map and scalebar
mapitem = QgsLayoutItemMap(l)
mapitem.attemptSetSceneRect(QRectF(110, 120, 200, 250))
mapitem.zoomToExtent(QgsRectangle(1, 1, 10, 10))
mapitem.setScale(666) # unlikely to appear in the SVG by accident... unless... oh no! RUN!
l.addItem(mapitem)
item1 = QgsLayoutItemScaleBar(l)
item1.attemptSetSceneRect(QRectF(10, 20, 100, 150))
item1.setLinkedMap(mapitem)
item1.setStyle('Numeric')
l.addItem(item1)
exporter = QgsLayoutExporter(l)
# setup settings
settings = QgsLayoutExporter.SvgExportSettings()
settings.dpi = 80
settings.forceVectorOutput = False
settings.exportMetadata = True
settings.textRenderFormat = QgsRenderContext.TextFormatAlwaysText
svg_file_path = os.path.join(self.basetestpath, 'test_exporttosvgtextformattext.svg')
self.assertEqual(exporter.exportToSvg(svg_file_path, settings), QgsLayoutExporter.Success)
self.assertTrue(os.path.exists(svg_file_path))
# expect svg to contain a text object with the scale
with open(svg_file_path, 'r') as f:
lines = ''.join(f.readlines())
self.assertIn('<text', lines)
self.assertIn('>1:666<', lines)
# force use of outlines
os.unlink(svg_file_path)
settings.textRenderFormat = QgsRenderContext.TextFormatAlwaysOutlines
self.assertEqual(exporter.exportToSvg(svg_file_path, settings), QgsLayoutExporter.Success)
self.assertTrue(os.path.exists(svg_file_path))
# expect svg NOT to contain a text object with the scale
with open(svg_file_path, 'r') as f:
lines = ''.join(f.readlines())
self.assertNotIn('<text', lines)
self.assertNotIn('>1:666<', lines)
开发者ID:manisandro,项目名称:QGIS,代码行数:46,代码来源:test_qgslayoutexporter.py
示例13: renderAnnotationInLayout
def renderAnnotationInLayout(self, test_name, annotation):
pr = QgsProject()
l = QgsLayout(pr)
l.initializeDefaults()
map = QgsLayoutItemMap(l)
map.attemptSetSceneRect(QRectF(20, 20, 200, 100))
map.setFrameEnabled(True)
rectangle = QgsRectangle(0, 0, 18, 8)
map.setExtent(rectangle)
l.addLayoutItem(map)
annotation.setMapPosition(QgsPointXY(1, 7))
annotation.setHasFixedMapPosition(True)
pr.annotationManager().addAnnotation(annotation)
checker = QgsLayoutChecker(
test_name, l)
checker.dots_per_meter = 2 * 96 / 25.4 * 1000
checker.size = QSize(1122 * 2, 794 * 2)
checker.setControlPathPrefix("annotations")
result, message = checker.testLayout()
self.report += checker.report()
return result
开发者ID:yoichigmf,项目名称:QGIS,代码行数:23,代码来源:test_qgsannotation.py
示例14: testRectWithFrame
def testRectWithFrame(self):
layout = QgsLayout(QgsProject.instance())
item = QgsLayoutItemMap(layout)
item.attemptMove(QgsLayoutPoint(6, 10, QgsUnitTypes.LayoutMillimeters))
item.attemptResize(QgsLayoutSize(18, 12, QgsUnitTypes.LayoutMillimeters))
item.setFrameEnabled(False)
self.assertEqual(item.rectWithFrame(), QRectF(0, 0, 18, 12))
item.setFrameStrokeWidth(QgsLayoutMeasurement(10, QgsUnitTypes.LayoutMillimeters))
item.setFrameEnabled(False)
self.assertEqual(item.rectWithFrame(), QRectF(0, 0, 18, 12))
item.setFrameEnabled(True)
self.assertEqual(item.rectWithFrame(), QRectF(-5.0, -5.0, 28.0, 22.0))
item.setFrameStrokeWidth(QgsLayoutMeasurement(10, QgsUnitTypes.LayoutCentimeters))
self.assertEqual(item.rectWithFrame(), QRectF(-50.0, -50.0, 118.0, 112.0))
开发者ID:mj10777,项目名称:QGIS,代码行数:15,代码来源:test_qgslayoutitem.py
示例15: testMapCrs
def testMapCrs(self):
# create layout with layout map
map_settings = QgsMapSettings()
map_settings.setLayers([self.vector_layer])
layout = QgsLayout(QgsProject.instance())
layout.initializeDefaults()
# check that new maps inherit project CRS
QgsProject.instance().setCrs(QgsCoordinateReferenceSystem('EPSG:4326'))
map = QgsLayoutItemMap(layout)
map.attemptSetSceneRect(QRectF(20, 20, 200, 100))
map.setFrameEnabled(True)
rectangle = QgsRectangle(-13838977, 2369660, -8672298, 6250909)
map.setExtent(rectangle)
map.setLayers([self.vector_layer])
layout.addLayoutItem(map)
self.assertEqual(map.crs().authid(), 'EPSG:4326')
self.assertFalse(map.presetCrs().isValid())
# overwrite CRS
map.setCrs(QgsCoordinateReferenceSystem('EPSG:3857'))
self.assertEqual(map.crs().authid(), 'EPSG:3857')
self.assertEqual(map.presetCrs().authid(), 'EPSG:3857')
checker = QgsLayoutChecker('composermap_crs3857', layout)
checker.setControlPathPrefix("composer_map")
result, message = checker.testLayout()
self.report += checker.report()
self.assertTrue(result, message)
# overwrite CRS
map.setCrs(QgsCoordinateReferenceSystem('EPSG:4326'))
self.assertEqual(map.presetCrs().authid(), 'EPSG:4326')
self.assertEqual(map.crs().authid(), 'EPSG:4326')
rectangle = QgsRectangle(-124, 17, -78, 52)
map.zoomToExtent(rectangle)
checker = QgsLayoutChecker('composermap_crs4326', layout)
checker.setControlPathPrefix("composer_map")
result, message = checker.testLayout()
self.report += checker.report()
self.assertTrue(result, message)
# change back to project CRS
map.setCrs(QgsCoordinateReferenceSystem())
self.assertEqual(map.crs().authid(), 'EPSG:4326')
self.assertFalse(map.presetCrs().isValid())
开发者ID:,项目名称:,代码行数:47,代码来源:
示例16: testSnapPointsToItems
def testSnapPointsToItems(self):
p = QgsProject()
l = QgsLayout(p)
page = QgsLayoutItemPage(l)
page.setPageSize('A4')
#l.pageCollection().addPage(page)
s = QgsLayoutSnapper(l)
guides = l.guides()
s.setSnapToItems(True)
s.setSnapTolerance(1)
# no items
point, snapped = s.snapPointsToItems([0.5], Qt.Horizontal, 1, [])
self.assertFalse(snapped)
line = QGraphicsLineItem()
line.setVisible(True)
point, snapped = s.snapPointsToItems([0.5], Qt.Horizontal, 1, [], line)
self.assertFalse(line.isVisible())
guides.addGuide(QgsLayoutGuide(Qt.Vertical, QgsLayoutMeasurement(1), page))
# add an item
item1 = QgsLayoutItemMap(l)
item1.attemptMove(QgsLayoutPoint(4, 8, QgsUnitTypes.LayoutMillimeters))
item1.attemptResize(QgsLayoutSize(18, 12, QgsUnitTypes.LayoutMillimeters))
l.addItem(item1)
point, snapped = s.snapPointsToItems([3.5], Qt.Horizontal, 1, [], line)
self.assertTrue(snapped)
self.assertEqual(point, 0.5)
self.assertTrue(line.isVisible())
point, snapped = s.snapPointsToItems([4.5], Qt.Horizontal, 1, [])
self.assertTrue(snapped)
self.assertEqual(point, -0.5)
point, snapped = s.snapPointsToItems([4.6, 4.5], Qt.Horizontal, 1, [])
self.assertTrue(snapped)
self.assertEqual(point, -0.5)
point, snapped = s.snapPointsToItems([4.6, 4.5, 3.7], Qt.Horizontal, 1, [])
self.assertTrue(snapped)
self.assertAlmostEqual(point, 0.3, 5)
# ignoring item
point, snapped = s.snapPointsToItems([4.5], Qt.Horizontal, 1, [item1])
self.assertFalse(snapped)
# outside tolerance
point, snapped = s.snapPointsToItems([5.5], Qt.Horizontal, 1, [], line)
self.assertFalse(snapped)
self.assertFalse(line.isVisible())
# snap to center
point, snapped = s.snapPointsToItems([12.5], Qt.Horizontal, 1, [])
self.assertTrue(snapped)
self.assertEqual(point, 0.5)
# snap to right
point, snapped = s.snapPointsToItems([22.5], Qt.Horizontal, 1, [])
self.assertTrue(snapped)
self.assertEqual(point, -0.5)
#snap to top
point, snapped = s.snapPointsToItems([7.5], Qt.Vertical, 1, [], line)
self.assertTrue(snapped)
self.assertEqual(point, 0.5)
self.assertTrue(line.isVisible())
point, snapped = s.snapPointsToItems([8.5], Qt.Vertical, 1, [])
self.assertTrue(snapped)
self.assertEqual(point, -0.5)
# outside tolerance
point, snapped = s.snapPointsToItems([5.5], Qt.Vertical, 1, [], line)
self.assertFalse(snapped)
self.assertFalse(line.isVisible())
# snap to center
point, snapped = s.snapPointsToItems([13.5], Qt.Vertical, 1, [])
self.assertTrue(snapped)
self.assertEqual(point, 0.5)
# snap to bottom
point, snapped = s.snapPointsToItems([20.5], Qt.Vertical, 1, [])
self.assertTrue(snapped)
self.assertEqual(point, -0.5)
# snapping off
s.setSnapToItems(False)
line.setVisible(True)
point, snapped = s.snapPointsToItems([20.5], Qt.Vertical, 1, [], line)
self.assertFalse(snapped)
self.assertFalse(line.isVisible())
# with different pixel scale
s.setSnapToItems(True)
point, snapped = s.snapPointsToItems([20.5], Qt.Vertical, 3, [])
self.assertFalse(snapped)
开发者ID:elpaso,项目名称:QGIS,代码行数:97,代码来源:test_qgslayoutsnapper.py
示例17: testCrossGrid
def testCrossGrid(self):
layout = QgsLayout(QgsProject.instance())
layout.initializeDefaults()
map = QgsLayoutItemMap(layout)
map.attemptSetSceneRect(QRectF(20, 20, 200, 100))
map.setFrameEnabled(True)
map.setBackgroundColor(QColor(150, 100, 100))
layout.addLayoutItem(map)
myRectangle = QgsRectangle(781662.375, 3339523.125, 793062.375, 3345223.125)
map.setExtent(myRectangle)
map.grid().setEnabled(True)
map.grid().setStyle(QgsLayoutItemMapGrid.Cross)
map.grid().setCrossLength(2.0)
map.grid().setIntervalX(2000)
map.grid().setIntervalY(2000)
map.grid().setAnnotationEnabled(False)
map.grid().setGridLineColor(QColor(0, 255, 0))
map.grid().setGridLineWidth(0.5)
map.grid().setBlendMode(QPainter.CompositionMode_SourceOver)
map.updateBoundingRect()
checker = QgsLayoutChecker('composermap_crossgrid', layout)
checker.setControlPathPrefix("composer_mapgrid")
myTestResult, myMessage = checker.testLayout()
map.grid().setStyle(QgsLayoutItemMapGrid.Solid)
map.grid().setEnabled(False)
map.grid().setAnnotationEnabled(False)
assert myTestResult, myMessage
开发者ID:yoichigmf,项目名称:QGIS,代码行数:31,代码来源:test_qgslayoutmapgrid.py
示例18: testGrid
def testGrid(self):
layout = QgsLayout(QgsProject.instance())
layout.initializeDefaults()
map = QgsLayoutItemMap(layout)
map.attemptSetSceneRect(QRectF(20, 20, 200, 100))
map.setFrameEnabled(True)
map.setBackgroundColor(QColor(150, 100, 100))
layout.addLayoutItem(map)
"""Test that we can create a grid for a map."""
myRectangle = QgsRectangle(781662.375, 3339523.125,
793062.375, 3345223.125)
map.setExtent(myRectangle)
map.grid().setEnabled(True)
map.grid().setIntervalX(2000)
map.grid().setIntervalY(2000)
map.grid().setAnnotationEnabled(True)
map.grid().setGridLineColor(QColor(0, 255, 0))
map.grid().setGridLineWidth(0.5)
map.grid().setAnnotationFont(QgsFontUtils.getStandardTestFont())
map.grid().setAnnotationPrecision(0)
map.grid().setAnnotationDisplay(QgsLayoutItemMapGrid.HideAll, QgsLayoutItemMapGrid.Left)
map.grid().setAnnotationPosition(QgsLayoutItemMapGrid.OutsideMapFrame, QgsLayoutItemMapGrid.Right)
map.grid().setAnnotationDisplay(QgsLayoutItemMapGrid.HideAll, QgsLayoutItemMapGrid.Top)
map.grid().setAnnotationPosition(QgsLayoutItemMapGrid.OutsideMapFrame, QgsLayoutItemMapGrid.Bottom)
map.grid().setAnnotationDirection(QgsLayoutItemMapGrid.Horizontal, QgsLayoutItemMapGrid.Right)
map.grid().setAnnotationDirection(QgsLayoutItemMapGrid.Horizontal, QgsLayoutItemMapGrid.Bottom)
map.grid().setAnnotationFontColor(QColor(255, 0, 0, 150))
map.grid().setBlendMode(QPainter.CompositionMode_Overlay)
map.updateBoundingRect()
checker = QgsLayoutChecker('composermap_grid', layout)
checker.setControlPathPrefix("composer_mapgrid")
myTestResult, myMessage = checker.testLayout()
map.grid().setEnabled(False)
map.grid().setAnnotationEnabled(False)
assert myTestResult, myMessage
开发者ID:yoichigmf,项目名称:QGIS,代码行数:38,代码来源:test_qgslayoutmapgrid.py
示例19: testInteriorTicks
def testInteriorTicks(self):
layout = QgsLayout(QgsProject.instance())
layout.initializeDefaults()
map = QgsLayoutItemMap(layout)
map.attemptSetSceneRect(QRectF(20, 20, 200, 100))
map.setFrameEnabled(True)
map.setBackgroundColor(QColor(150, 100, 100))
layout.addLayoutItem(map)
map.grid().setFrameStyle(QgsLayoutItemMapGrid.Zebra)
myRectangle = QgsRectangle(781662.375, 3339523.125, 793062.375, 3345223.125)
map.setExtent(myRectangle)
map.grid().setIntervalX(2000)
map.grid().setIntervalY(2000)
map.grid().setAnnotationFontColor(QColor(0, 0, 0))
map.grid().setBlendMode(QPainter.CompositionMode_SourceOver)
map.grid().setFrameStyle(QgsLayoutItemMapGrid.InteriorTicks)
map.grid().setFrameWidth(10)
map.grid().setFramePenSize(1)
map.grid().setFramePenColor(QColor(0, 0, 0))
map.grid().setEnabled(True)
map.grid().setStyle(QgsLayoutItemMapGrid.FrameAnnotationsOnly)
map.updateBoundingRect()
checker = QgsLayoutChecker('composermap_interiorticks', layout)
checker.setControlPathPrefix("composer_mapgrid")
myTestResult, myMessage = checker.testLayout(0, 100)
assert myTestResult, myMessage
开发者ID:yoichigmf,项目名称:QGIS,代码行数:28,代码来源:test_qgslayoutmapgrid.py
示例20: testZebraStyleSides
def testZebraStyleSides(self):
layout = QgsLayout(QgsProject.instance())
layout.initializeDefaults()
map = QgsLayoutItemMap(layout)
map.attemptSetSceneRect(QRectF(20, 20, 200, 100))
map.setFrameEnabled(True)
map.setBackgroundColor(QColor(150, 100, 100))
layout.addLayoutItem(map)
map.grid().setFrameStyle(QgsLayoutItemMapGrid.Zebra)
myRectangle = QgsRectangle(781662.375, 3339523.125, 793062.375, 3345223.125)
map.setExtent(myRectangle)
map.grid().setIntervalX(2000)
map.grid().setIntervalY(2000)
map.grid().setGridLineColor(QColor(0, 0, 0))
map.grid().setAnnotationFontColor(QColor(0, 0, 0))
map.grid().setBlendMode(QPainter.CompositionMode_SourceOver)
map.grid().setFrameStyle(QgsLayoutItemMapGrid.Zebra)
map.grid().setFrameWidth(10)
map.grid().setFramePenSize(1)
map.grid().setGridLineWidth(0.5)
map.grid().setFramePenColor(QColor(0, 0, 0))
map.grid().setFrameFillColor1(QColor(0, 0, 0))
map.grid().setFrameFillColor2(QColor(255, 255, 255))
map.grid().setEnabled(True)
map.grid().setFrameSideFlag(QgsLayoutItemMapGrid.FrameLeft, True)
map.grid().setFrameSideFlag(QgsLayoutItemMapGrid.FrameRight, False)
map.grid().setFrameSideFlag(QgsLayoutItemMapGrid.FrameTop, False)
map.grid().setFrameSideFlag(QgsLayoutItemMapGrid.FrameBottom, False)
map.updateBoundingRect()
checker = QgsLayoutChecker('composermap_zebrastyle_left', layout)
checker.setControlPathPrefix("composer_mapgrid")
myTestResult, myMessage = checker.testLayout(0, 100)
assert myTestResult, myMessage
map.grid().setFrameSideFlag(QgsLayoutItemMapGrid.FrameTop, True)
map.updateBoundingRect()
checker = QgsLayoutChecker('composermap_zebrastyle_lefttop', layout)
checker.setControlPathPrefix("composer_mapgrid")
myTestResult, myMessage = checker.testLayout(0, 100)
assert myTestResult, myMessage
map.grid().setFrameSideFlag(QgsLayoutItemMapGrid.FrameRight, True)
map.updateBoundingRect()
checker = QgsLayoutChecker('composermap_zebrastyle_lefttopright', layout)
checker.setControlPathPrefix("composer_mapgrid")
myTestResult, myMessage = checker.testLayout(0, 100)
assert myTestResult, myMessage
map.grid().setFrameSideFlag(QgsLayoutItemMapGrid.FrameBottom, True)
map.grid().setFrameStyle(QgsLayoutItemMapGrid.NoFrame)
开发者ID:yoichigmf,项目名称:QGIS,代码行数:53,代码来源:test_qgslayoutmapgrid.py
注:本文中的qgis.core.QgsLayoutItemMap类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论