Hello,
I try to automate the process of publishing a set of NetCDF files, using the Rest API and some Python code. My NetCDF files have all the same structure, with 8 variables and a time dimension. I’m using Geoserver 2.28.
I already managed to publish variables as layers (coverages) for a single file using the UI, but I struggle to automate the process, at least for the layer/coverage creation.
Here are my questions/issues :
-
Though the UI displays the list of existing variables (published and unpublished) in the CoverageStore that is linked to my NetCDF, I could not find a way to get a similar list using the Rest API. I can only get the list of the published variables, aka the coverages. If I look at the * documentation I understand that there is some “feature type” concept associated to a coveragestore upon creation that seem to be related to the NetCDF variables. How can I get the list of those “features” if possible ?
-
Say I want to publish only some of the variables in the NetCDF files, or publish them one by one, how could I do it with the REST API ? Based on the related part in the *documentation I’m not sure what is the right way to create a new coverage from an existing coveragestore
Could the following Python function do the job, assuming I know the list of the variables in the NetCDF file ? If so, what should be the payload of the POST method (I didn’t find examples in the doc) ?
def publish_layers(coveragestore_name):
"""Publish every NetCDF file variable as a Layer."""
variables = NETCDF_VARIABLES_TO_PUBLISH
auth = HTTPBasicAuth(GEOSERVER_USER, GEOSERVER_PASSWORD)
for var in variables:
# 1. Create coverage layer
layer_name = var["fullname"]
url = f"{GEOSERVER_URL}/rest/workspaces/{WORKSPACE}/coveragestores/{coveragestore_name}/coverages"
headers = {"Content-Type": "application/json"}
payload = ### What should be the payload ?
response = requests.post(url, headers=headers, auth=auth, json=payload)
if response.status_code != 201:
print(f"Failed publishing layer '{layer_name}': {response.text}")
continue
print(f"Layer '{layer_name}' published with success.")