管道基础大数据平台系统开发-【CS】-ExportMap
13693261870
2023-11-16 839871788f5cfde328a7049a174f809c4b9c0b7e
ExportMap/Sources/MoonExp.py
@@ -97,6 +97,21 @@
        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)
@@ -124,14 +139,8 @@
# 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")
@@ -140,8 +149,7 @@
    print('size: ' + str(map.sizeWithUnits().width()) + " * " + str(map.sizeWithUnits().height()) + " mm")
# 设置图层
# "阀室", "站场", "管道中心线", "矢量注记", "矢量图", "高德影像注记", "高德影像", "影像注记", "影像图"
# showLayers = ["阀室", "管道中心线", "矢量注记", "矢量图"]
# showLayers = ["阀室", "站场", "管道中心线", "矢量注记", "矢量图", "高德影像注记", "高德影像", "影像注记", "影像图"]
showLayers = layout.customProperty("layers").split(',')
root = project.layerTreeRoot()
@@ -150,11 +158,12 @@
# 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)