Publish your Collection using the EDC / BC Geoservice

Publish you collections as WMS service. The BC geoservice provides access to publishing your collection as a WMS service using the geoDB Python client. Please refer to the geoserver documentation for configuring the rest API call to your WMS/geojson service.

You will have access to this service if you have purchased a large management account. This service is in beta mode. If you find any issues, please report them on our GitHub Issues page.

Init the GeoDB client

[7]:
from xcube_geodb.core.geodb import GeoDBClient
geodb = GeoDBClient(raise_it=False, server_url='https://xcube-geodb.brockmann-consult.de', gs_server_url='https://xcube-geodb.brockmann-consult.de')
geodb._gs_server_url
[7]:
'https://xcube-geodb.brockmann-consult.de'

Create a Database and Copy some Public Data Across

[8]:
my_database_name = 'my-urban-eea-subset-db13'

In case your database does not exist, you need to uncomment the following line and create the database. Please note, that database names must be unique, which means if another user has already used a database name you cannot create a database with the same name.

[9]:
geodb.create_database(my_database_name)
[9]:
<xcube_geodb.core.message.Message at 0x7f47d17014c0>

Here we copy a collection from a public database, so we can publish as a geoservice.

[10]:
geodb.copy_collection(collection='SI001L2_LJUBLJANA_UA2018', new_collection='SI001L2_LJUBLJANA_UA2018', database='eea-urban-atlas', new_database=my_database_name)
[10]:
<xcube_geodb.core.message.Message at 0x7f47cfa4e100>

You can check if the colleciton was successfully added to your database:

[11]:
geodb.get_my_collections(database=my_database_name)
[11]:
owner database collection table_name
0 geodb_965a53df-6c09-4de2-b9ec-1052a2a9534a my-urban-eea-subset-db13 SI001L2_LJUBLJANA_UA2018 SI001L2_LJUBLJANA_UA2018
[12]:
## List Collections Published on the BC WMS Service

#geodb.get_published_gs(database=my_database_name)

Publish your Collection to the BC WMS Service

[13]:
geodb.publish_gs(collection='SI001L2_LJUBLJANA_UA2018', database=my_database_name)
[13]:
<xcube_geodb.core.message.Message at 0x7f47d0983670>

You can now click on the preview link which will give you an unstyled view of your WMS output.

[14]:
## List Collections Published on the BC WMS Service

geodb.get_published_gs(database=my_database_name)
[14]:
<xcube_geodb.core.message.Message at 0x7f47d09912b0>

View the Data

Once you have published you collection, you can use the WMS service to visualise your collection. For this using ipyleaflet. In this example we have used a pre-defined style. You can always provide a custom style using the parameter sld. We have provided a class that will pass that parameter to the WMS service. Just replace WMSLayer with SldWMSLayer. The sldparameter is given as a URL to an SLD file.

[15]:
url = f"http://xcube-geodb.brockmann-consult.de/geoserver/{my_database_name}/wms?"

[16]:
from ipyleaflet import Map, WMSLayer, basemaps
[17]:
from traitlets import Unicode

class SldWMSLayer(WMSLayer):

    sld = Unicode('').tag(sync=True, o=True)

[17]:
wmsn = WMSLayer(
    url=url,
    layers=f'{my_database_name}:{my_database_name}_SI001L2_LJUBLJANA_UA2018',
    format='image/png',
    opacity=0.5,
    attribution='Copernicus',
    styles='ljubilana'
#     sld='https://raw.githubusercontent.com/dzelge/test-gha/main/ljubilana.sld'
)
[18]:
m = Map(basemap=basemaps.CartoDB.Positron, center=(46.0, 14.5), zoom=13)
m.add_layer(wmsn)

m
[19]:
geodb.unpublish_gs(collection='SI001L2_LJUBLJANA_UA2018', database=my_database_name)
[19]:
True
[ ]:
geodb.drop_collection('SI001L2_LJUBLJANA_UA2018', database=my_database_name)