| | |
| | | prj.addMapLayer(layer) |
| | | |
| | | |
| | | # 获取比例尺 |
| | | def get_scale(scale): |
| | | # scale = '1:' + str(math.ceil(map.scale() / 100) * 100) |
| | | if scale > 10000: |
| | | return "1:" + str(math.ceil(map.scale() / 10000)) + "万" |
| | | elif scale > 1000: |
| | | return "1:" + str(math.ceil(map.scale() / 1000)) + "千" |
| | | elif scale > 100: |
| | | return "1:" + str(math.ceil(map.scale() / 100) * 100) |
| | | elif scale > 10: |
| | | return "1:" + str(math.ceil(map.scale() / 10) * 10) |
| | | else: |
| | | return "1:" + str(math.ceil(scale)) |
| | | |
| | | |
| | | # 初始化 |
| | | # QgsApplication.setPrefixPath(r"E:/terrait/TianJin/LFServer/QGIS/", True) |
| | | qgs = QgsApplication([], False) |
| | |
| | | # map = layout.itemById(r'地图') |
| | | map = layout.referenceMap() |
| | | map.zoomToExtent(map.extent()) |
| | | scale = '1:' + str(math.ceil(map.scale() / 100) * 100) |
| | | scale = get_scale(map.scale()) |
| | | print(scale) |
| | | |
| | | # template_content = template_content.replace('1:25万', scale) |
| | | # doc.setContent(template_content) |
| | | # layout.loadFromTemplate(doc, QgsReadWriteContext(), True) |
| | | # map = layout.referenceMap() |
| | | # map.zoomToExtent(map.extent()) |
| | | |
| | | size = map.sizeWithUnits() |
| | | print('size: ' + str(size.width()) + " * " + str(size.height()) + " mm") |
| | |
| | | print('size: ' + str(map.sizeWithUnits().width()) + " * " + str(map.sizeWithUnits().height()) + " mm") |
| | | |
| | | # 设置图层 |
| | | # "阀室", "站场", "管道中心线", "矢量注记", "矢量图", "高德影像注记", "高德影像", "影像注记", "影像图" |
| | | # showLayers = ["阀室", "管道中心线", "矢量注记", "矢量图"] |
| | | # showLayers = ["阀室", "站场", "管道中心线", "矢量注记", "矢量图", "高德影像注记", "高德影像", "影像注记", "影像图"] |
| | | showLayers = layout.customProperty("layers").split(',') |
| | | root = project.layerTreeRoot() |
| | | |
| | |
| | | # add_map_layer(project, layout) |
| | | |
| | | # sm = layout.itemById(r'说明') |
| | | '''table = layout.multiFrames()[0] |
| | | table = layout.multiFrames()[0] |
| | | contents = table.tableContents() |
| | | contents[1][1] = scale |
| | | table.refreshAttributes() |
| | | table.refresh()''' |
| | | # contents[0][1] = scale |
| | | contents[1][1].setContent(scale) |
| | | table.setTableContents(contents) |
| | | table.refresh() |
| | | |
| | | # collection = layout.pageCollection() |
| | | # page = collection.page(0) |