管道基础大数据平台系统开发-【CS】-ExportMap
13693261870
2024-09-07 8d7a67ab1d635cb954337d8a767878ae526dd3dc
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,24 +139,17 @@
# 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")
if size.width() > 280 or size.height() > 174:
    map.attemptResize(QgsLayoutSize(280, 174, QgsUnitTypes.LayoutMillimeters))
if size.width() > 233 or size.height() > 174:
    map.attemptResize(QgsLayoutSize(233, 174, QgsUnitTypes.LayoutMillimeters))
    print('size: ' + str(map.sizeWithUnits().width()) + " * " + str(map.sizeWithUnits().height()) + " mm")
# 设置图层
# "阀室", "站场", "管道中心线", "矢量注记", "矢量图", "高德影像注记", "高德影像", "影像注记", "影像图"
# showLayers = ["阀室", "管道中心线", "矢量注记", "矢量图"]
# showLayers = ["阀室", "站场", "管道中心线", "矢量注记", "矢量图", "高德影像注记", "高德影像", "影像注记", "影像图"]
showLayers = layout.customProperty("layers").split(',')
root = project.layerTreeRoot()
@@ -152,8 +160,9 @@
# sm = layout.itemById(r'说明')
'''table = layout.multiFrames()[0]
contents = table.tableContents()
contents[1][1] = scale
table.refreshAttributes()
# contents[0][1] = scale
contents[1][1].setContent(scale)
table.setTableContents(contents)
table.refresh()'''
# collection = layout.pageCollection()