gws.lib.mapserver.core

MapServer map wrapper.

Source code: gws.lib.mapserver.core

Module Contents

exception gws.lib.mapserver.core.Error

Bases: gws.Error

MapServer error.

class gws.lib.mapserver.core.Map(config: str = '')

Wrapper around a mapscript.mapObj.

MapServer errors are written to stderr.

mapObj: mapscript.mapObj

The wrapped MapServer map object.

add_layer(opts: gws.MapServerLayerOptions) → mapscript.layerObj

Add a layer to the map from layer options.

The layer is named _gws_<n> and switched on.

Parameters:

opts – Layer options. crs is required.

Returns:

The new MapServer layer object.

Raises:

Error – If the CRS is missing, the connection type is not supported, or MapServer cannot create the layer.

add_layer_from_config(config: str) → mapscript.layerObj

Add a layer to the map from a mapfile LAYER block.

Parameters:

config – Layer configuration in the mapfile syntax.

Returns:

The new MapServer layer object.

Raises:

Error – If MapServer cannot create the layer.

copy() → Map

Create a copy of the map.

Returns:

A new Map object with a clone of the MapServer map.

draw(bounds: gws.Bounds, size: gws.Size) → gws.Image

Render the map as a transparent PNG.

Parameters:
  • bounds – Extent and CRS to render.

  • size – Image size (width, height) in pixels.

Returns:

The rendered image.

Raises:

Error – If MapServer cannot render the map.

style_symbol(style: gws.StyleValues) → mapscript.styleObj

Create a MapServer marker style from style values.

The marker symbol is looked up by name in the symbol set of the map.

Parameters:

style – Style values with marker and optional marker_* values.

Returns:

A MapServer style object.

to_string() → str

Convert the map to a mapfile string.

Returns:

Mapfile content.

Raises:

Error – If MapServer cannot convert the map.

gws.lib.mapserver.core.new_map(config: str = '') → Map

Create a new map.

Parameters:

config – Mapfile content. If empty, an empty map is created.

Returns:

A Map object.

gws.lib.mapserver.core.version() → str

Return the MapServer version string.

Returns:

The version string, as returned by mapscript.msGetVersion.