1

I am building a headless PyQGIS application that will need to be integrated into a bigger system.

Everything works, but when reading a layer from a GML file, the output keeps printing:

Cannot import http://spatialreference.org/ref/epsg/3812/ due to ALLOW_NETWORK_ACCESS=NO

It still all works fine, but the logging is annoying since it prints it about 8 times per layer and I have multiple layers. And it swamps our log management application.

qgis_app = QgsApplication([], False)
qgis_app.initQgis()
os.environ["ALLOW_NETWORK_ACCESS"] = "YES"

project = QgsProject.instance()
QgsSettings().setValue("qgis/networkAndProxy/networkAccessAllowed", True)
crs = QgsCoordinateReferenceSystem("EPSG:3812")
for layer_name in self.layer_names:
    layer = QgsVectorLayer(f"{file}|layername={layer_name}", layer_name, "ogr", crs=crs)

As you can see, I've tried setting the environment variable and manually setting the CRS, but neither works.

It works from a Docker container using QGIS 3.34.

Any ideas?

4
  • 2
    It's probably not an environment variable: gdal.org/en/latest/doxygen/classOGRSpatialReference.html Commented Nov 20 at 8:19
  • 3
    There should be no need to read the definitions of EPSG:3812 from the web at all if the Proj database "proj.db" is available. So I would study how to prevent the network query instead of studying how to make it success.
    – user30184
    Commented Nov 20 at 8:41
  • @user30184 agreed. I start from the basic docker image: qgis/qgis:3.34-bookworm Any idea where and how to include proj.db? Commented Nov 21 at 12:41
  • Proj looks for the proj.db wherever on the path set in the PROJ_DATA environment variable, which in my anaconda environment is set to $CONDA_PREFIX/share/proj. See proj.org/en/stable/usage/environmentvars.html. Depending on where/how you installed QGIS and what platform you're on, you may need to look for it in other places.
    – couteau
    Commented Nov 21 at 22:33

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.