通过独立的python脚本在地图集导出中未出现QGIS3.14资源共享符号

我创建了一个独立的python脚本来导出我的地图集布局。一切工作都很好,除了我在Resource Sharing插件中使用的SVG符号只是问号(假定找不到它们)。但是,如果我通过QGIS3文件夹中的startup.py运行脚本,那么一切都会按预期进行。我真的想避免使用此方法,因为它会阻止您在脚本完成之前使用QGIS,这大约需要2个小时。我希望只需要向.bat文件中添加一个简单的环境变量,以便它可以找到Resource Sharing插件。预先感谢您的帮助!

.bat文件

@ECHO off

set OSGEO4W_ROOT=C:\OSGeo4W64

call "%OSGEO4W_ROOT%\bin\o4w_env.bat"
call "%OSGEO4W_ROOT%\bin\qt5_env.bat"
call "%OSGEO4W_ROOT%\bin\py3_env.bat"

path %OSGEO4W_ROOT%\apps\qgis\bin;%PATH%
set QGIS_PREFIX_PATH=%OSGEO4W_ROOT%\apps\qgis

set GDAL_FILENAME_IS_UTF8=YES

set VSI_CACHE=TRUE
set VSI_CACHE_SIZE=1000000
set QT_PLUGIN_PATH=%OSGEO4W_ROOT%\apps\qgis\qtplugins;%OSGEO4W_ROOT%\apps\qt5\plugins

SET PYCHARM="C:\Program Files\JetBrains\PyCharm 2019.2.3\bin\pycharm64.exe"

set PYTHONPATH=%OSGEO4W_ROOT%\apps\qgis\python
set PYTHONHOME=%OSGEO4W_ROOT%\apps\Python37
set PYTHONPATH=%OSGEO4W_ROOT%\apps\Python37\lib\site-packages;%PYTHONPATH%

set QT_QPA_PLATFORM_PLUGIN_PATH=%OSGEO4W_ROOT%\apps\Qt5\plugins\platforms
set QGIS_PREFIX_PATH=%OSGEO4W_ROOT%\apps\qgis

start "PyCharm aware of QGIS" /B %PYCHARM% %*

Python脚本

from qgis.core import  QgsApplication,QgsProject,QgsLayoutExporter
import os
import sys

def export_atlas(qgs_project_path,layout_name,outputs_folder):

    # Open existing project
    project = QgsProject.instance()
    project.read(qgs_project_path)

    print(f'Project in "{project.fileName()} loaded successfully')

    # Open prepared layout that as atlas enabled and set
    layout = project.layoutManager().layoutByName(layout_name)

    # Export atlas
    exporter = QgsLayoutExporter(layout)
    settings = QgsLayoutExporter.PdfExportSettings()
    exporter.exportToPdfs(layout.atlas(),outputs_folder,settings)


def run():
    # Start a QGIS application without GUI
    QgsApplication.setPrefixPath(r"C:\\OSGeo4W64\\apps\\qgis",True)
    qgs = QgsApplication([],False)
    qgs.initQgis()
    sys.path.append(r'C:\OSGeo4W64\apps\qgis\python\plugins')

    project_path = [project_path]
    output_folder = [export_location]
    layout_name_portrait = [portrait layout name]
    layout_name_landscape = [landscape laytout name]

    export_atlas(project_path,layout_name_portrait,output_folder)
    export_atlas(project_path,layout_name_landscape,output_folder)

    # Close the QGIS application
    qgs.exitQgis()

run()
iCMS 回答:通过独立的python脚本在地图集导出中未出现QGIS3.14资源共享符号

我想可能与设置svg/searchPathsForSVG有关。

QgsSettings().setValue('svg/searchPathsForSVG',<your path>)
本文链接:https://www.f2er.com/2058440.html

大家都在问