gws.gis.ms

MapServer support.

This module dynamically creates and renders MapServer maps.

To render a map, create a map object with new_map, add layers to it using add_ methods and invoke draw.

Reference: MapServer documentation (https://mapserver.org/documentation.html)

Example usage:

import gws.gis.ms as ms

# create a new map
map = ms.new_map()

# add a raster layer from an image file
map.add_layer(
    ms.LayerOptions(
        type=ms.LayerType.raster,
        path='/path/to/image.tif',
    )
)

# add a layer using a configuration string
map.add_layer_from_config('''
    LAYER
        TYPE LINE
        STATUS ON
        FEATURE
            POINTS
                751539 6669003
                751539 6672326
                755559 6672326
            END
        END
        CLASS
            STYLE
                COLOR 0 255 0
                WIDTH 5
            END
        END
    END
''')

# draw the map into an Image object
img = map.draw(
    bounds=gws.Bounds(
        extent=[738040, 6653804, 765743, 6683686],
        crs=gws.lib.crs.WEBMERCATOR,
    ),
    size=(800, 600),
)

# save the image to a file
img.to_path('/path/to/output.png')

Source code: gws.gis.ms

Submodules

Package Contents

exception gws.gis.ms.Error

Bases: gws.Error

Generic GWS error.

class gws.gis.ms.LayerOptions(*args, **kwargs)

Bases: gws.Data

Options for a mapserver layer.

connectionString: str

Connection string for the data source.

connectionType: str

Type of connection (e.g., ‘postgres’).

crs: gws.Crs

Layer CRS.

dataString: str

Layer DATA option.

path: str

Path to the image file.

processing: list[str]

Processing options for the layer.

sldName: str

Name of an SLD NamedLayer to apply.

sldPath: str

Path to SLD file for styling the layer.

style: gws.StyleValues

Style for the layer.

tileIndex: str

Path to the tile index SHP file

transparentColor: str

Color to treat as transparent in the layer (OFFSITE).

type: LayerType

Layer type.

class gws.gis.ms.LayerType(*args, **kwds)

Bases: gws.Enum

MapServer layer type.

line = 'line'
point = 'point'
polygon = 'polygon'
raster = 'raster'
class gws.gis.ms.Map(config: str = '')

MapServer map object wrapper.

mapObj: mapscript.mapObj
add_layer(opts: LayerOptions) mapscript.layerObj

Adds a layer to the map.

add_layer_from_config(config: str) mapscript.layerObj

Adds a layer to the map using a configuration string.

copy() Map

Creates a copy of the current map object.

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

Renders the map within the given bounds and size.

Parameters:
  • bounds – The spatial extent to render.

  • size – The output image size.

Returns:

The rendered map image.

style_symbol(style: gws.StyleValues) mapscript.styleObj
to_string() str

Converts the map object to a configuration string.

gws.gis.ms.new_map(config: str = '') Map

Creates a new Map instance from a Mapfile string.

gws.gis.ms.version() str

Returns the MapServer version string.