I am writing a standalone QGIS python application to run some unittests. I am getting an error when I try to use the QgsCoordinateReferenceSystem
library.
ERROR 4: Unable to open EPSG support file gcs.csv. Try setting the GDAL_DATA
environment variable to point to the directory containing EPSG csv files.
I am running QGIS 3.0.3 on Windows 7.
I have made sure my GDAL_DATA
path points to the gdal folder containing the gcs.csv
. I have even placed a print statement above and below the call to QgsCoordinateReferenceSystem
to print the environment variable which is correct as C:\Program Files\QGIS 3.0\share\gdal
.
Any insight into this would be most helpful.
my full code is:
import os
from qgis.core import QgsApplication, QgsCoordinateReferenceSystem
app = QgsApplication([], True)
app.setPrefixPath(r"C:\Program Files\QGIS 3.0\apps\qgis", True)
app.initQgis()
app.setPluginPath(app.pluginPath().replace("\n", ""))
app.setPkgDataPath(app.pkgDataPath().replace("\n", ""))
print(os.environ["GDAL_DATA"])
c = QgsCoordinateReferenceSystem(4326)
print(os.environ["GDAL_DATA"])
This Python script is called from the following batch file:
@ECHO OFF
call "C:\Program Files\QGIS 3.0\bin\o4w_env.bat"
call "C:\Program Files\QGIS 3.0\bin\qt5_env.bat"
call "C:\Program Files\QGIS 3.0\bin\py3_env.bat"
set PYTHONPATH=%OSGEO4W_ROOT%\apps\qgis\python;%OSGEO4W_ROOT%\apps\qgis\python\plugins;%USERPROFILE%\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins%PYTHONPATH%
python test.py
C:\Program Files\QGIS3.0\share\gdal\epsg_csv
. The GDAL_DATA variable is set when runningo4w_env.bat
. My qgis-bin.exe works fine, no problems, it is only when i run it as a standalone application that it has a problem, so i believe my gdal installation is fine. – Kezah May 31 '18 at 4:38app.initQgis()
all the paths are appended with a line break (\n
). By forcefully settingos.environ["GDAL_DATA"] = os.environ["GDAL_PATH"].replace("\n", "")
it removes the error. I dont know whyinitQgis()
is adding line breaks. – Kezah May 31 '18 at 4:51