A CKAN extension that provides a client for interacting with GeoServer natively from CKAN. It handles tasks such as workspace creation, uploading shapefiles, styling layers, and synchronizing GeoServer data automatically.
System dependency (required):
ogr2ogr must be installed on the CKAN server. It is used to convert GeoJSON to Shapefile before uploading to GeoServer:
# Debian/Ubuntu
apt-get install gdal-bin
# macOS
brew install gdal
# Alpine Linux
apk add gdal-binPython dependency (optional):
If you are using S3/MinIO for CKAN file storage (via ckanext-s3filestore), boto3 is required for the extension to fetch resource files directly from S3:
pip install boto3==1.35.77If ckanext-s3filestore is already installed, boto3 will already be present. Note: newer versions of boto3 may cause compatibility issues with ckanext-s3filestore.
-
Activate your CKAN virtual environment:
. /usr/lib/ckan/default/bin/activate -
Install the extension:
pip install -e git+https://github.com/datopian/ckanext-geoserver-client.git#egg=ckanext-geoserver-client
-
Add
geoserver_clienttockan.pluginsin your CKAN config file. -
Restart CKAN.
Set the following in your CKAN config file (production.ini) or via environment variables:
# The REST API URL of your GeoServer instance.
# Default: http://localhost:8080/geoserver/rest
ckanext.geoserver_client.rest_url = http://geoserver:8080/geoserver/rest
# The admin username for GeoServer
# Default: admin
ckanext.geoserver_client.user = admin
# The admin password for GeoServer
# Default: geoserver
ckanext.geoserver_client.password = my_secret_password
# The target workspace in GeoServer where CKAN will publish layers
# Default: ckan
ckanext.geoserver_client.workspace = ckan
# The public-facing GeoServer URL used to build WMS/WFS links on resources
# Default: http://localhost:8080/geoserver
ckanext.geoserver_client.public_url = http://geoserver:8080/geoserverEnvironment variable equivalents (for use with ckanext-envvars):
CKANEXT__GEOSERVER_CLIENT__REST_URL=http://geoserver:8080/geoserver/rest
CKANEXT__GEOSERVER_CLIENT__USER=admin
CKANEXT__GEOSERVER_CLIENT__PASSWORD=my_secret_password
CKANEXT__GEOSERVER_CLIENT__WORKSPACE=ckan
CKANEXT__GEOSERVER_CLIENT__PUBLIC_URL=http://geoserver:8080/geoserverWhen a resource is created or updated, the plugin checks whether it is a GeoJSON resource. A resource is considered GeoJSON if either:
- Its format field is set to
GeoJSON(case-insensitive), or - Its URL ends with
.geojson
If either condition is met, a background job is enqueued that:
- Fetches the file (from local CKAN storage, S3/MinIO, or HTTP fallback)
- Validates the content is valid GeoJSON
- Converts it to a Shapefile using
ogr2ogr - Uploads the Shapefile to GeoServer and publishes it as a layer
- Optionally applies an SLD style if an
SLDresource exists on the same dataset - Updates the resource with
wms_url,wfs_url, andgeoserver_layerfields
When a GeoJSON resource is deleted, the corresponding GeoServer layer is also removed.
Publishing only happens via the background worker. Make sure it is running:
ckan -c /etc/ckan/default/production.ini jobs workerInitialize GeoServer workspace:
ckan -c /etc/ckan/default/production.ini geoserver initPublish a single resource:
ckan -c /etc/ckan/default/production.ini geoserver publish <resource_id>Bulk publish all existing GeoJSON resources:
ckan -c /etc/ckan/default/production.ini geoserver publish-allgit clone https://github.com/datopian/ckanext-geoserver-client.git
cd ckanext-geoserver-client
python setup.py develop # or: pip install -e .
pip install -r dev-requirements.txtpytest --ckan-ini=test.ini
# With coverage:
pytest --ckan-ini=test.ini --cov=ckanext.geoserver_client --disable-warnings ckanext/geoserver_client/tests