4

I'm trying to create a Web Map Context(WMC) file using OWSLib. WMC is supported, but there are no examples on any official pages: OWSLib 0.14.0 documentation, PyPI~ OWSLib 0.14.0, GitHib OWSLib examples.

I have a client showing some WMS map layers:

Map we want to encapsulate as WMC

There are six layers, from four different Web Map Services (WMS)

The WMS GetMap request for the base layer is:

http://ogc2.bgs.ac.uk/geoserver/OneG/wms?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&BBOX=-3475652.856302516069,-3703399.183262269478,5088484.602957472205,3983478.759379811119&SRS=EPSG:3413&WIDTH=986&HEIGHT=886&LAYERS=ARCTIC_NASA_BLUEMARBLE&STYLES=&FORMAT=image/jpeg&FORMAT_OPTIONS=dpi:96&

One of the other layers (submarine volcanoes) is:

http://emodnet-geology.eu/cgi-bin/BGS_ISPRA_EMODNET_Geology/ows?language=eng&&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&BBOX=5669.550000000000182,-3703399.183262269478,5088484.602957472205,3144980&SRS=EPSG:3413&WIDTH=586&HEIGHT=789&LAYERS=World_EMODnet_EN_250k_Submarine_Volcanoes_points&STYLES=&FORMAT=image/png&MAP_RESOLUTION=96&TRANSPARENT=TRUE&

etc.

The context I am trying to create should look something like:

<?xml version="1.0" encoding="UTF-8"?>
<ViewContext version="1.1.0" id="some_unique_id1"
    xsi:schemaLocation="http://www.opengis.net/context http://schemas.opengis.net/context/1.1.0/context.xsd"
    xmlns="http://www.opengis.net/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink">
    <General>
        <Window width="1205" height="735"/>
        <BoundingBox SRS="EPSG:3413" minx="-3571059.167819473" miny="-4645193.605181879" maxx="4940480.654283983" maxy="546492.5103750005"/>
        <Title>Cool maps</Title>
        <Abstract>A web map context showing some services that have NSIDC support</Abstract>
    </General>
    <LayerList>
        <!-- The specification says: 'The Layers are presented in a bottom to top approach.' -->
        <Layer queryable="1" hidden="0">
            <Server service="OGC:WMS" version="1.1.1" title="BGS_NASA_EN_BLUE_MARBLE">
                <OnlineResource xlink:type="simple" xlink:href="http://ogc2.bgs.ac.uk/geoserver/OneG/ows?"/>
            </Server>
            <Name>ARCTIC_NASA_BLUEMARBLE</Name>
            <Title>ARCTIC_NASA_BLUEMARBLE</Title>
            <Abstract>Blue Marble image (90 to 30 degrees North) for use as Arctic backdrop for the OneGeology portal. This backdrop is intended to be displayed in EPSG:3413 projection.</Abstract>
            <SRS>EPSG:3413</SRS>
            <FormatList>
                <Format>image/png</Format>
                <Format>image/geotiff</Format>
                <Format current="1">image/jpeg</Format>
                <Format>image/png; mode=8bit</Format>
            </FormatList>
            <StyleList>
                <Style current="1">
                    <Name/>
                    <Title>Default</Title>
                </Style>
            </StyleList>
        </Layer>
        <Layer />
        <Layer />
        <Layer />
        <Layer />
        <Layer />
    </LayerList>
</ViewContext>

wmc.py tells us that...

class MapContext: """ Map Context abstraction It uses a Map representation as input and export it as as map context

But I'm not sure what a Map representation is in this context.

I tried:

import owslib.wmc as wmc
context_for_basemap_map2 = wmc.mapToWebMapContext("http://ogc2.bgs.ac.uk/geoserver/OneG/wms?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&BBOX=-3475652.856302516069,-3703399.183262269478,5088484.602957472205,3983478.759379811119&SRS=EPSG:3413&WIDTH=986&HEIGHT=886&LAYERS=ARCTIC_NASA_BLUEMARBLE&STYLES=&FORMAT=image/jpeg&FORMAT_OPTIONS=dpi:96&ID=some_unique_id1&")

But I get error:

C:\Python36\python.exe E:/.../wmc-test.py
Traceback (most recent call last):
File "E:/.../wmc-test.py", line 65, in <module>
context_for_basemap_map2 = wmc.mapToWebMapContext("http://ogc2.bgs.ac.uk/geoserver/OneG/wms?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&BBOX=-3475652.856302516069,-3703399.183262269478,5088484.602957472205,3983478.759379811119&SRS=EPSG:3413&WIDTH=986&HEIGHT=886&LAYERS=ARCTIC_NASA_BLUEMARBLE&STYLES=&FORMAT=image/jpeg&FORMAT_OPTIONS=dpi:96&ID=some_unique_id1&")
File "C:\Python36\lib\site-packages\owslib\wmc.py", line 209, in mapToWebMapContext
return MapContext(map)()
File "C:\Python36\lib\site-packages\owslib\wmc.py", line 141, in __call__
wmc_doc_tree = self._getRootElement()
File "C:\Python36\lib\site-packages\owslib\wmc.py", line 47, in _getRootElement
'id' : self._map.id,
AttributeError: 'str' object has no attribute 'id'

I tried:

import owslib.wms as wms
import owslib.wmc as wmc
w = wms.WebMapService("http://ogc2.bgs.ac.uk/geoserver/OneG/ows?", version='1.1.1')
img = w.getmap(layers=["ARCTIC_NASA_BLUEMARBLE"], srs='EPSG:3413', bbox=(-3475652, -3703399, 5088484, 3983478), size=(986, 886), format='image/jpeg', transparent=False, method="Get", exceptions="application/vnd.ogc.se_xml", format_options="dpi:96", queryable="0", id="some_unique_id1")
context_for_basemap_map = wmc.mapToWebMapContext(img)

But I get error:

C:\Python36\python.exe E:/.../wmc-test.py
Traceback (most recent call last):
File "E:/.../wmc-test.py", line 49, in <module>
context_for_basemap_map = wmc.mapToWebMapContext(img)
File "C:\Python36\lib\site-packages\owslib\wmc.py", line 209, in mapToWebMapContext
return MapContext(map)()
File "C:\Python36\lib\site-packages\owslib\wmc.py", line 141, in __call__
wmc_doc_tree = self._getRootElement()
File "C:\Python36\lib\site-packages\owslib\wmc.py", line 47, in _getRootElement
'id' : self._map.id,
AttributeError: 'ResponseWrapper' object has no attribute 'id'

How do I create the context?

1

It would appear OWSlib has no internal error handling, which makes it very hard to debug. No tests for wmc.py either, which is a drag. From what I can see, you've tried handing off mapToWebMapContext() a URL string and a raster image, when it is in fact expecting a map object.

Unfortunately, I don't know what a Map Representation is either, and apparently you'll need to ask the mailing list if you want to know.

Looking at the source code for wmc.py, the object you pass to MapContext needs to have the following attributes or methods:

  • .size
  • .srs.split()
  • .visible_layers
  • .bounds
  • .url
  • .format
  • .layertitles

Looking at the codebase, layertitles and visible_layers don't show up anywhere else than in wmc.py.

So as of writing, it would appear as though OWSlib cannot be used for WMCs. One better would be for you to rewrite it and submit a PR.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.