:tocdepth: 3 :py:mod:`gws.gis.ms` ==================== .. py:module:: gws.gis.ms .. autoapi-nested-parse:: 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:** :source:`gws.gis.ms` Submodules ---------- .. toctree:: :titlesonly: :maxdepth: 1 util/index.rst Package Contents ---------------- .. py:exception:: Error Bases: :py:obj:`gws.Error` Generic GWS error. .. py:class:: LayerOptions(*args, **kwargs) Bases: :py:obj:`gws.Data` Options for a mapserver layer. .. py:attribute:: connectionString :type: str Connection string for the data source. .. py:attribute:: connectionType :type: str Type of connection (e.g., 'postgres'). .. py:attribute:: crs :type: gws.Crs Layer CRS. .. py:attribute:: dataString :type: str Layer DATA option. .. py:attribute:: path :type: str Path to the image file. .. py:attribute:: processing :type: list[str] Processing options for the layer. .. py:attribute:: sldName :type: str Name of an SLD NamedLayer to apply. .. py:attribute:: sldPath :type: str Path to SLD file for styling the layer. .. py:attribute:: style :type: gws.StyleValues Style for the layer. .. py:attribute:: tileIndex :type: str Path to the tile index SHP file .. py:attribute:: transparentColor :type: str Color to treat as transparent in the layer (OFFSITE). .. py:attribute:: type :type: LayerType Layer type. .. py:class:: LayerType(*args, **kwds) Bases: :py:obj:`gws.Enum` MapServer layer type. .. py:attribute:: line :value: 'line' .. py:attribute:: point :value: 'point' .. py:attribute:: polygon :value: 'polygon' .. py:attribute:: raster :value: 'raster' .. py:class:: Map(config: str = '') MapServer map object wrapper. .. py:attribute:: mapObj :type: mapscript.mapObj .. py:method:: add_layer(opts: LayerOptions) -> mapscript.layerObj Adds a layer to the map. .. py:method:: add_layer_from_config(config: str) -> mapscript.layerObj Adds a layer to the map using a configuration string. .. py:method:: copy() -> Map Creates a copy of the current map object. .. py:method:: draw(bounds: gws.Bounds, size: gws.Size) -> gws.Image Renders the map within the given bounds and size. :param bounds: The spatial extent to render. :param size: The output image size. :returns: The rendered map image. .. py:method:: style_symbol(style: gws.StyleValues) -> mapscript.styleObj .. py:method:: to_string() -> str Converts the map object to a configuration string. .. py:function:: new_map(config: str = '') -> Map Creates a new Map instance from a Mapfile string. .. py:function:: version() -> str Returns the MapServer version string.