src.eddie.geoserver

Functions and utilities for loading and serving data with geoserver. Imports here are accessible directly by from eddie import geoserver.

Submodules

Classes

Workspaces

Enum to label and access geoserver workspaces initialized within data_to_db.py.

Functions

create_datastore_layer(→ None)

Create a GeoServer layer for a given data store if it does not currently exist.

create_db_store_if_not_exists(→ None)

Create PostGIS database store in a GeoServer workspace for a given database.

create_main_db_store(→ str)

Create PostGIS database store in a GeoServer workspace for the main PostGIS database.

create_workspace_if_not_exists(→ None)

Create a GeoServer workspace if it does not currently exist.

get_geoserver_url(→ str)

Retrieve full GeoServer URL from environment variables.

add_gtiff_to_geoserver(→ None)

Upload a GeoTiff file to GeoServer, ready for serving to clients.

add_style(→ None)

Create a GeoServer style in the default workspace for rasters using a SLD style definition file.

style_exists(→ bool)

Check if a GeoServer style definition already exists for a given style_name.

get_terria_catalog(→ Catalog)

Query geoserver for available layers from key workspaces, and return a terria catalog to serve the data.

Package Contents

src.eddie.geoserver.create_datastore_layer(workspace_name: str, data_store_name: str, layer_name: str, metadata_elem: str = '') None

Create a GeoServer layer for a given data store if it does not currently exist. Can be used to create layers for a database table, or to create a database view for a custom dynamic query.

Parameters:
  • workspace_name (str) – The name of the workspace the data store is associated to

  • data_store_name (str) – The name of the data store the layer is being created from.

  • layer_name (str) – The name of the new layer. This is the same as the name of the database table if creating a layer from a table.

  • metadata_elem (str = "") – An optional XML str that contains the metadata element used to configure custom SQL queries.

Raises:

HTTPError – If geoserver responds with an error, raises it as an exception since it is unexpected.

src.eddie.geoserver.create_db_store_if_not_exists(db_name: str, workspace_name: str, new_data_store_name: str) None

Create PostGIS database store in a GeoServer workspace for a given database. If it already exists, do not do anything.

Parameters:
  • db_name (str) – The name of the connected database, to connect datastore to

  • workspace_name (str) – The name of the workspace to create views for

  • new_data_store_name (str) – The name of the new datastore to create

Raises:

HTTPError – If geoserver responds with an error, raises it as an exception since it is unexpected.

src.eddie.geoserver.create_main_db_store(workspace_name: str) str

Create PostGIS database store in a GeoServer workspace for the main PostGIS database. If it already exists, do not do anything.

Parameters:

workspace_name (str) – The name of the workspace to create views for

Returns:

The name of the new datastore created.

Return type:

str

Raises:

HTTPError – If geoserver responds with an error, raises it as an exception since it is unexpected.

src.eddie.geoserver.create_workspace_if_not_exists(workspace_name: str) None

Create a GeoServer workspace if it does not currently exist.

Parameters:

workspace_name (str) – The name of the workspace to create if it does not exists.

Raises:

HTTPError – If geoserver responds with an error, raises it as an exception since it is unexpected.

src.eddie.geoserver.get_geoserver_url() str

Retrieve full GeoServer URL from environment variables.

Returns:

The full GeoServer URL

Return type:

str

src.eddie.geoserver.add_gtiff_to_geoserver(gtiff_filepath: pathlib.Path, workspace_name: str, layer_name: str) None

Upload a GeoTiff file to GeoServer, ready for serving to clients.

Parameters:
  • gtiff_filepath (pathlib.Path) – The filepath to the GeoTiff file to be served.

  • workspace_name (str) – The name of the existing GeoServer workspace that the store is to be added to.

  • layer_name (str) – The name of the layer being added must be unique within the workspace. #todo check uniqueness

src.eddie.geoserver.add_style(style_file: pathlib.Path, replace: bool = False) None

Create a GeoServer style in the default workspace for rasters using a SLD style definition file.

Parameters:
  • style_file (pathlib.Path) – The path to the style definition (SLD) file to upload.

  • replace (bool = False) – True if you want to replace the existing style, False to skip adding the style if one already exists.

src.eddie.geoserver.style_exists(style_name: str) bool

Check if a GeoServer style definition already exists for a given style_name. The style definition may be empty.

Parameters:

style_name (str) – The name of the style to check for

Returns:

True if the style exists, although it may be empty. False if it does not exist.

Return type:

bool

Raises:

HTTPError – If geoserver responds with anything but OK or NOT_FOUND, raises it as an exception since it is unexpected.

class src.eddie.geoserver.Workspaces

Bases: enum.StrEnum

Enum to label and access geoserver workspaces initialized within data_to_db.py.

STATIC_FILES_WORKSPACE

Workspace containing layers loaded from static files.

Type:

str

INPUT_LAYERS_WORKSPACE

Workspace containing layers loaded from external sources used as input for later modelling or visualisation.

Type:

str

STATIC_FILES_WORKSPACE = 'static_files'
INPUT_LAYERS_WORKSPACE = 'input_layers'
EXTRUDED_LAYERS_WORKSPACE = 'extruded_layers'
src.eddie.geoserver.get_terria_catalog() Catalog

Query geoserver for available layers from key workspaces, and return a terria catalog to serve the data.

Returns:

Represents the Terria JSON catalog items for each layer within the workspaces.

Return type:

Catalog

Raises:

HTTPError – If geoserver responds with anything but OK or NOT_FOUND, raises it as an exception since it is unexpected.