管道基础大数据平台系统开发-【后端】-Server
1
13693261870
2022-11-05 bfe3c6cb6e962de9e82448fea707e9c26de0a6f4
1
已添加7个文件
已修改2个文件
151 ■■■■■ 文件已修改
QGIS/data/counties.dbf 补丁 | 查看 | 原始文档 | blame | 历史
QGIS/data/counties.prj 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
QGIS/data/counties.shp 补丁 | 查看 | 原始文档 | blame | 历史
QGIS/data/counties.shp.mwsymb 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
QGIS/data/counties.shx 补丁 | 查看 | 原始文档 | blame | 历史
QGIS/main.py 25 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
QGIS/render.py 62 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
QGIS/ui.py 48 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
QGIS/说明.txt 5 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
QGIS/data/counties.dbf
Binary files differ
QGIS/data/counties.prj
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1 @@
GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]
QGIS/data/counties.shp
Binary files differ
QGIS/data/counties.shp.mwsymb
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,10 @@
<MapWinGIS OcxVersion="4.8" FileType="LayerFile" FileVersion="0" Description="">
  <Layer LayerType="Shapefile" LayerName="counties" LayerVisible="1" LayerKey="" MinVisibleScale="1.000000" MaxVisibleScale="4901750.000000" Filename="">
    <ShapefileClass>
      <DefaultDrawingOptions FillBgColor="0" FillColor="2928376" FillVisible="0" LineColor="4224439" PointShapeRatio="1.000000" />
      <ShapefileCategoriesClass />
      <LabelsClass FrameBackColor="16777215" FrameOutlineColor="1971946" FrameType="1" FrameVisible="-1" Generated="1" MaxVisibleScale="4901750.000000" MinVisibleScale="1.000000" AutoOffset="0" Positioning="1" Expression="[MWShapeID] " />
      <ChartsClass ValuesFontName="" Visible="-1" />
    </ShapefileClass>
  </Layer>
</MapWinGIS>
QGIS/data/counties.shx
Binary files differ
QGIS/main.py
@@ -1,14 +1,35 @@
from qgis.core import *
# from qgis.gui import (QgsLayerTreeMapCanvasBridge)
from qgis.gui import *
from qgis.PyQt.QtGui import (QColor)
# QgsApplication.setPrefixPath("e:/", True)
qgs = QgsApplication([], True)
qgs.initQgis()
# åˆ›å»ºå®žä¾‹
project = QgsProject.instance()
project.read(r'E:/data/1.Natural_Earth/Test.qgz')
print("FileName: " + project.fileName())
# canvas = QgsMapCanvas()
# canvas.show()
# bridge = QgsLayerTreeMapCanvasBridge(QgsProject.instance().layerTreeRoot(), canvas)
layers_list = {}
for layer in project.mapLayers().values():
    layers_list[layer.name()] = layer
print(layers_list)
openStreetMapLayer = project.mapLayersByName("OpenStreetMap")[0]
print(openStreetMapLayer)
root = project.layerTreeRoot()
print(root.findLayerIds()[0])
# ä¿å­˜ï¼Œå¦å­˜ä¸º
# project.write()
# project.write("E:/new_qgis_project.qgz")
qgs.exitQgis()
# qgs.exitQgis()
QGIS/render.py
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,62 @@
import os
from qgis.core import *
from qgis.gui import *
from qgis.PyQt.QtGui import *
from qgis.PyQt.QtCore import *
from qgis.PyQt.QtWidgets import *
from qgis.PyQt.QtXml import *
def finished():
    img = render.renderedImage()
    # QgsProject.instance().homePath()
    image_location = os.path.join("e:/", "render.png")
    # save the image; e.g. img.save("/Users/myuser/render.png","png")
    img.save(image_location, "png")
QgsApplication.setPrefixPath("C:/Program Files/QGIS 3.16/bin", True)
qgs = QgsApplication([], True)
qgs.initQgis()
# vlayer = iface.activeLayer()
project = QgsProject.instance()
project.read(r'E:/data/1.Natural_Earth/Test.qgz')
layers = project.mapLayers().values()
# root = project.layerTreeRoot()
# layout = QgsPrintLayout(project)
layout = QgsLayout(project)
# layout.initializeDefaults()
with open("E:/data/1.Natural_Earth/Layout.qpt", 'r', encoding='utf-8') as f:
    template_content = f.read()
doc = QDomDocument()
doc.setContent(template_content)
# doc = QDomDocument("E:/data/1.Natural_Earth/Layout.qpt")
#ele = layout.writeXml(doc, QgsReadWriteContext())
#layout.readLayoutXml(ele, doc, QgsReadWriteContext())
layout.loadFromTemplate(doc, QgsReadWriteContext(), False)
map = QgsLayoutItemMap(layout)
# # map.zoomToExtent(layers[0].extent())
layout.addItem(map)
# collection = layout.pageCollection()
# page = QgsLayoutItemPage(layout)
# page.setPageSize('A4')
# collection.addPage(page)
layoutView = QgsLayoutView()
layoutView.setPreviewModeEnabled(True)
layoutView.setContentsMargins(0, 0, 0, 0)
layoutView.setCurrentLayout(layout)
# project.layoutManager().addLayout(layout)
# map = QgsLayoutItemMap(layout)
# map.zoomToExtent(iface.mapCanvas().extent())
exporter = QgsLayoutExporter(layout)
img_path = os.path.join("e:/", "render.png")
exporter.exportToImage(img_path, QgsLayoutExporter.ImageExportSettings())
qgs.exitQgis()
QGIS/ui.py
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,48 @@
import os
import sys
from qgis.gui import *
from qgis.core import *
from qgis.PyQt.QtCore import *
from qgis.PyQt.QtWidgets import *
class MapViewer(QMainWindow):
    def __init__(self, shapefile):
        QMainWindow.__init__(self)
        self.setWindowTitle("Map Viewer")
        canvas = QgsMapCanvas()
        canvas.setCanvasColor(Qt.white)
        canvas.show()
        project = QgsProject.instance()
        project.read(r'E:/data/1.Natural_Earth/Test.qgz')
        layer = QgsVectorLayer(shapefile, "layer1", "ogr")
        if not layer.isValid():
            raise IOError("Invalid shapefile")
        # project.addMapLayer(layer)
        # canvas.setExtent(layer.extent())
        # canvas.setLayers([layer])
        layers = project.mapLayers().values()
        canvas.setLayers(layers)
        layout = QVBoxLayout()
        layout.addWidget(canvas)
        contents = QWidget()
        contents.setLayout(layout)
        self.setCentralWidget(contents)
if __name__ == "__main__":
    QgsApplication.setPrefixPath("qgis", True)
    qgs = QgsApplication([], True)
    qgs.initQgis()
    viewer = MapViewer("./data/Counties.shp")
    viewer.show()
    exitCode = qgs.exec()
    qgs.exitQgis()
QGIS/˵Ã÷.txt
@@ -21,6 +21,7 @@
>>> import qgis.core
================================================================================ åº“简介
格式化:ctrl + alt + l
PyQGIS库的五个包:
qgis.core                 è¿™æ ·å¯ä»¥è®¿é—®æ•´ä¸ªQGIS中使用的核心GIS功能。
qgis.gui                  è¿™å®šä¹‰äº†ä¸€ç³»åˆ—GUI小部件,您可以在自己的程序中包含这些小部件。
@@ -28,10 +29,12 @@
qgis.networkanalysis    è¿™æä¾›äº†æž„建和分析拓扑的工具。
qgis.utils                 è¿™å®žçŽ°äº†å„ç§åŠŸèƒ½ï¼Œå…è®¸æ‚¨ä½¿ç”¨Python使用QGIS应用程序。
================================================================================ æ‰§è¡Œ
exec(open('E:/terrait/TianJin/LFServer/QGIS/main.py', encoding='utf-8').read())
exec(open('E:/terrait/TianJin/LFServer/QGIS/render.py', encoding='utf-8').read())
python E:/terrait/TianJin/LFServer/QGIS/main.py
================================================================================
https://blog.csdn.net/qq_23034515/article/details/107643428
https://vimsky.com/examples/detail/python-ex-qgis.core-QgsPrintLayout-itemByUuid-method.html # ReadWriteXml
1.搭建QGIS+Python开发环境
2.承德高新区指挥平台,将和对讲集成到主站点(http协议)下
3.qgis python二次开发