I am trying to use GDAL in Jupyter Notebook which is running on the Docker environment, the GDAL library work fine but when it comes to set a configuration by using SetConfigOption it does not work.
I am using Use jupyter/minimal-notebook image in the Docker file and I did t install GDAL on the image as dependencies by using pip and conda but none of them seems to be responding to SetConfigOption, and when I am using the GDAL in Jupyter Notebook in Windows everything seems to be in order and nothing is wrong. Why does this happen?
(When I print the SetConfigOption it says that the configuration has been set but in reality it does not affect anything.)
This my Jupyter Notebook file:
# Activating the GDAL Driver
# Set GDAL Config Parameters
# importing the libraries "GDAL" and "OGR"
# importing the library "os" with helps with some operating system specific i/o tasks (working with paths, directories, files, ..)
try:
from osgeo import gdal, ogr
import os
except:
print ('ERROR: cannot find GDAL/OGR modules')
gdal.UseExceptions()
gdal.SetConfigOption("CPL_LOG_ERRORS","ON")
gdal.SetConfigOption("VALIDATE", "YES")
gdal.SetConfigOption("FAIL_IF_VALIDATION_ERROR","YES")
gdal.SetConfigOption('WRITE_GFS','NO')
print(gdal.GetConfigOption("WRITE_GFS"))
driverName="GMLAS"
gml_driver = ogr.GetDriverByName(driverName)
if gml_driver is None:
raise Exception('GDAL driver >"+driverName+"< not available')
else: print("GDAL driver successfully loaded: >"+gml_driver.GetName()+"<")
gdal.VectorTranslate(
'test.geojson',
'Simple_XtraServerGetFeature (3).xml',
options='-f "GeoJSON"'
)
print(gdal.GetConfigOption("WRITE_GFS"))
This my Docker file:
# Use the jupyter/minimal-notebook image as the parent image
FROM jupyter/minimal-notebook:latest
# Install required dependencies
RUN conda install -c conda-forge gdal
RUN pip install --no-cache-dir \
jupyter \
requests>=2.21.0
# Set the working directory to /src
WORKDIR /src
# Make port 8888 available to the world outside this container
EXPOSE 8888
# Define environment variable
ENV NAME World
# # Copy the current directory contents into the container at /app
# COPY . /src
# Mount the host machine directory into the container
VOLUME /src
# Run Jupyter Notebook when the container launches
CMD ["jupyter", "notebook", "--ip=0.0.0.0", "--port=8888", "--no-browser", "--allow-root"]
The issue is likely that you need to explicitly close the dataset returned by gdal.VectorTranslate():