Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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.

Scenerio:

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? Thank you for any help.

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()
share|improve this question

1 Answer 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.

share|improve this answer
    
Thanks I'll give it a try. –  gridcell Dec 2 '11 at 15:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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