[QGIS-Developer] How do I add a QgsLayoutItemMapGrid to a QgsLayoutItemMap with PyQGIS 3.x?
Damián Ortega Terol
dortegat at gmail.com
Mon May 13 08:12:54 PDT 2019
I'm trying to add a grid to a map but I don't get any results. My code:
def add_map_layout_item(self,
list_maplayers,
qgs_rectangle,
origin_x_mm,
origin_y_mm,
width_mm,
height_mm,
grid_interval):
map = QgsLayoutItemMap(self.layout)
map.updateBoundingRect()
map.setRect(QRectF(origin_x_mm, origin_y_mm, width_mm, height_mm))
map.setPos(origin_x_mm, origin_y_mm)
map.setFrameEnabled(True)
map.setLayers(list_maplayers)
map.setKeepLayerSet(True)
map.setExtent(qgs_rectangle)
self.iface.mapCanvas().freeze(True)
map.attemptMove(QgsLayoutPoint(origin_x_mm, origin_y_mm))
map.attemptResize(QgsLayoutSize(width_mm, height_mm))
map.zoomToExtent(qgs_rectangle)
qgs_layout_item_map_grid = QgsLayoutItemMapGrid("New grid",
map)
qgs_layout_item_map_grid.setAnnotationPrecision(0)
qgs_layout_item_map_grid.setAnnotationFrameDistance(1)
qgs_layout_item_map_grid.setAnnotationFontColor(QColor(0, 0, 0))
qgs_layout_item_map_grid.setCrossLength(1.0)
qgs_layout_item_map_grid.setIntervalX(grid_interval)
qgs_layout_item_map_grid.setIntervalY(grid_interval)
self.layout.addLayoutItem(map)
What am I missing?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20190513/1130eb2c/attachment.html>
More information about the QGIS-Developer
mailing list