How to create a coverage store using the geoserver-restconfig python package?

Question:

My os is Ubuntu 22.04.2 LTS and my python versions is 3.10.6. I am trying to create a coverage store in geoserver using the geoserver-restconfig python package. Here is my code:

from geoserver.catalog import Catalog
cat = Catalog(service_url='http://localhost:8080/geoserver/rest',
              username='FAKE_USERNAME',
              password='FAKE_PASSWORD')

# Create working space
cat.create_workspace(name='demo', uri='http://demo')

# Create coverage store
path = 'indicators/coolingdd/rcp_2_6/ensemble/coolingdd_rcp26_multi-model-mean_-_-_20210101-20301230.tiff'
cat.create_coveragestore(name='NAME',
                         workspace='demo',
                         path=path,
                         type='GeoTIFF',
                         create_layer=True,
                         layer_name='TITLE',
                         upload_data=False)

The indicators directory is inside the directory where I am running my python script from. Unfortunately I am getting the following error:

Traceback (most recent call last):
  File "/home/iliamous/PycharmProjects/winbank-esg-risk-gis-platform/scratch_work.py", line 767, in <module>
    cat.create_coveragestore(name='NAME',
  File "/home/iliamous/.local/lib/python3.10/site-packages/geoserver/catalog.py", line 617, in create_coveragestore
    raise FailedRequestError('Failed to create coverage/layer {} for : {}, {}'.format(layer_name, name,
geoserver.catalog.FailedRequestError: Failed to create coverage/layer TITLE for : NAME, 500

Why is this happening?


—————————-Update———————————

I have changed the logging level to developer from the global settings but I still receive the same error. This is what my global settings look like:
enter image description here


——————————–Update——————————-

Here is the relevant part of the log files:

06 Mar 11:25:48 WARN   [gce.geotiff] - File /var/lib/tomcat9/webapps/geoserver/data/indicators/coolingdd/rcp_2_6/ensemble/coolingdd_rcp26_multi-model-mean_-_-_20210101-20301230.tiff does not exist.
org.geotools.data.DataSourceException: File /var/lib/tomcat9/webapps/geoserver/data/indicators/coolingdd/rcp_2_6/ensemble/coolingdd_rcp26_multi-model-mean_-_-_20210101-20301230.tiff does not exist.

My understanding was that the create_coveragestore function also uploaded the tiff file to the geoserver. Apparently, I have to upload the files inside the data directory and then use the function with the correct path from the data directory of geoserver to create the coverage store.

Asked By: CoolMathematician

||

Answers:

After uploading the indicators directory to /var/lib/tomcat9/webapps/geoserver/data directory everything works fine. Apparently, create_coveragestory root directory for the path parameter is the data directory.

Answered By: CoolMathematician
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.