Hello everyone. I was trying to layout with pyQGIS, and I already have the map frame with the layers, but now I need to add a grid, I tried with the code written down, but the grid didn't work. I'm new pyQGIS and maybe there are errors in the code.
project = QgsProject().instance() layer_name = "Curvas de nivel" layout_name = "MyLayout" layout_page = ["Letter", 0] layers = QgsProject.instance().mapLayersByName(layer_name)[0] for layout in project.layoutManager().printLayouts(): if layout.name() == layout_name: project.layoutManager().removeLayout(layout) layout = QgsPrintLayout(project) page = QgsLayoutItemPage(layout) page.setPageSize(layout_page[0], layout_page[1]) layout.pageCollection().addPage(page) map = QgsLayoutItemMap(layout) map.attemptMove(QgsLayoutPoint(5,5,0)) map.attemptResize(QgsLayoutSize(200,200,0)) map.setExtent(layers.extent()) map_grid = QgsLayoutItemMapGrid("Grid", map) map_grid.setEnabled(True) map_grid.setIntervalX(layers.extent().width() / 3) map_grid.setIntervalY(layers.extent().width() / 3) map_grids = QgsLayoutItemMapGridStack(map).addGrid(map_grid) layout.addLayoutItem(map) layout.setName(layout_name) project.layoutManager().addLayout(layout)
_______________________________________________ Qgis-user mailing list Qgis-user@lists.osgeo.org List info: https://lists.osgeo.org/mailman/listinfo/qgis-user Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user