2

I'm working on a map layout engine using Python and ReportLab and have come across a problem and was wondering if anyone can give me some insight.

Scenario:

I'm trying to generate an image using OWSLib (see example code). The layer that I'm trying to render has an opacity of 40%. When I generate the image using the sample code the background is transparent but the features are not but if I generate the image using shp2img -m /www/cgi-bin/mapfiles/40e6b3a8.map -o test.png the features are 40% opaque. Any ideas how I can make this work using OWSLib or if I'm doing something wrong?

OWSLib example code

from owslib.wms import WebMapService
wms = WebMapService('http://localhost/cgi-bin/mapserv?MAP=/www/cgi-bin/mapfiles/40e6b3a8.map&', version='1.1.1')
img = wms.getmap(   layers=['vlyr_oqiJw4Ib4U'],
    srs='EPSG:26910',
    bbox=(685400,5616300,689500,5619500),
    size=(800, 600),
    format='image/png',
    transparent=True
)
print(img.geturl())
out = open('c:/temp/test2.png', 'wb')
out.write(img.read())
out.close()
1

Have you set the OPACITY for the layer in your MapServer map file?

This can also be altered by client applications through a URL setting a value from 0-100. In fact most parts of the map file can be modified.

If you add the following to your query string you should get a transparent image:

&map.layer[LAYERNAME]=OPACITY 80

Which when encoded looks like:

map.layer%5BLAYERNAME%5D%3DOPACITY%2080

I'm not sure how owslib handles additional custom parameters. Unfortunately you can't do something like the following due to the non-standard parameter name:

img = wms.getmap(   layers=['vlyr_oqiJw4Ib4U'],
    srs='EPSG:26910',
    bbox=(685400,5616300,689500,5619500),
    size=(800, 600),
    format='image/png',
    transparent=True,
    map.layer[vlyr_oqiJw4Ib4U]="OPACITY 80"
)

So you will have to add a custom function / event / override to add the OPACITY for a layer.

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.