How to create a transparent WMS overlay

I successfully overlaid the WMS layer on google maps v3, however, since the tile information is black on the transparent one, this is bad (for example, a satellite map), see some snippets, for example:

http://geoportal2.uhul.cz/wms_oprl/?SERVICE=WMS&REQUEST=GetMap&SERVICE=WMS&VERSION=1.1.1&LAYERS=HMLCR&FORMAT=image/png;%20mode=24bit&FGCOLOR = 0xFF0000&00668.600.675.675600.600.600.600.600.600.600.600.600.68.68. 660 .bg8 = 388 388 387 387 388 y8itgtg8bt = 561) 49.38237278700955 & WIDTH = 256 & HEIGHT = 256 & STYLES =

( This was a WMS link to get this snippet)

Question: how do I change the above WMS request to change the foreground color (currently black) to some custom color (e.g. red)? . In other words, how to style a layer? Perhaps the server can do this for this layer, as it is possible to do this through their web map application (which works only in IE), where you can choose a color. See this map image for example:

enter image description here

( The following link was used to extract the image - note that it contains the scale and logo, so this is not the correct tile.)

Unfortunately, this web application does not use WMS to get this stylized map, so I can’t just copy the style settings into the WMS request. I have to style using a WMS request (because this other request format is proprietary, retrieves the entire map not intended for tiles, and does not seem to support WGS coordinates) - will I do this?

I tried:

I’m lost, I would be grateful if you would point me in the right direction - or information, if it would even be resolved in WMS (for this layer).

“This is impossible” is also a useful answer for me!

Thanks in advance.

+4
source share
3 answers

At first glance, it seems that this is an implementation of Mapserver 5.x, and getCapabilities notes that UserDefinedSymbolization SupportSLD = "1" is activated at the map level, which means that all layers must inherit it.

Thus, theoretically, you should be able to supply SLDs either in the GET request or somewhere in the file, and specify the URL of your SLD in the GET request and be configured.

Writing an SLD will be annoying, but if you think that you have an SLD that should work, but doesn't insert it here.

+2
source

Use a wrapper script that reads an image from WMS and repaints it:

Wrapper

Here is an example written in PHP:

<?php $url = $_GET['url']; $im = imagecreatefrompng($url); if($im && imagefilter($im, IMG_FILTER_COLORIZE, 255, 0, 0, 0)){ // this line is only needed if original image has transparency (32bit/pixel) // and you want to preserve that transparency imagesavealpha($im, true); header('Content-type: image/png'); imagepng($im); }else{ echo 'Conversion failed.'; } imagedestroy($im); exit; ?> 

Then, instead of calling your WMS link, you call the packer and pass the WMS link as a parameter (recolor_png.php? Url = ...). The shell reads the original image and returns a new PNG with a colorized version. Remember that the link you pass as a parameter must be correctly encoded (all special characters are replaced with their hexadecimal notation% XX). In JavaScript, you can do this using the encodeURIComponent () method.

Here is a working example of using your link and the above shell on my server:

http://www.digilog.de/pub/stackoverflow/recolor_png2.php?url=http%3A%2F%2Fgeoportal2.uhul.cz%2Fwms_oprl%2F%3FSERVICE%3DWMS%26REQUEST%3DGetMap%26SERVICEVERS%3ERSMS 3D1.1.1% 26LAYERS% 3DHMLCR% 26FORMAT% 3Dimage% 2Fpng% 3B% 2520mode% 3D24bit% 26FGCOLOR% 3D0xFF0000% 26TRANSPARENT% 3DTRUE% 26SRS% 3DEPSG% 3A4326% 26BBOX% 3D16.58935546875342% 348493% 299.3493% 468 3,449.38,463,849,384,634,634,672,634,634,672,634,634,634,634,634,634. 38237278700955% 26WIDTH% 3D256% 26HEIGHT% 3D256% 26STYLES% 3D

This is the resulting image (translucent version):

recolor_png2.png
(source: digilog.de )

The same shell without translucent output (imagesavealpha removed from code):

http://www.digilog.de/pub/stackoverflow/recolor_png.php?url=http%3A%2F%2Fgeoportal2.uhul.cz%2Fwms_oprl%2F%3FSERVICE%3DWMS%26REQUEST%3DGetMap%26SERVICEVERS%3ERSMS 3D1.1.1% 26LAYERS% 3DHMLCR% 26FORMAT% 3Dimage% 2Fpng% 3B% 2520mode% 3D24bit% 26FGCOLOR% 3D0xFF0000% 26TRANSPARENT% 3DTRUE% 26SRS% 3DEPSG% 3A4326% 26BBOX% 3D16.58935546875342% 348493% 299.3493% 468 3,449.38,463,849,384,634,634,672,634,634,672,634,634,634,634,634,634. 38237278700955% 26WIDTH% 3D256% 26HEIGHT% 3D256% 26STYLES% 3D

And the resulting opaque image:

recolor_png.png
(source: digilog.de )

I will leave these wrappers online for a few days so you can check them out.

Caching

Since this conversion uses the processor heavily, it might be advisable to add some caching code to the shell:

  • create a hash code from the given URL, for example: $ hash = md5 ($ url)
  • check if image named $ hash.png exists in the storage subfolder
  • if so: read the image from the file and return it
  • otherwise: create an image, save it as $ hash.png in a subfolder and return it immediately

If you expect the contents of the WMS to change over time: also check the creation date of the cached images and delete them if they are too old (for example, a month or so). Thus, any changes to the WMS cards will be distributed to your system in a maximum of one month.

0
source

The WMS link already has some user options that allow you to do exactly what you ask. The link is as follows:

  http://geoportal2.uhul.cz/mapserv/php/mapserv3.php?project=oprl_2011&mode=map&mapsize=256%20256&layers=HMLCR%20&x=1322616184548&map_SMO_class_0_color=0%200%200&map_HMLCR_class_0_color=255%200%200&mapext=-679915.1258015268%20-1062651.2224427482%20-679660.3694656485%20-1062461.062442748 

If you check it, you will notice that between all parameters encoded by the URL, there is an interesting parameter: map_HMLCR_class_0_color

If you change its value to, say, green (whose RGB code is 0.255.0), the layers are displayed in green. Color is expressed as an RGB code. There is another parameter map_SMO_class_0_color , but I do not understand what this does. Perhaps it creates some function which is not displayed in this request?

Example for green:

  http://geoportal2.uhul.cz/mapserv/php/mapserv3.php?project=oprl_2011&mode=map&mapsize=256%20256&layers=HMLCR%20&x=1322616184548&map_SMO_class_0_color=0%20100%20200&map_HMLCR_class_0_color=0%20255%200&mapext=-679915.1258015268%20-1062651.2224427482%20-679660.3694656485%20-1062461.062442748 

which produces the following:

green styled request

Color representation with conggb in Mapserver

RGB triplet should be written as follows in the request:

 RGB 

(note that spaces are needed). Whose encoded UR1 representation:

 R%20G%20B 

since % 20 is how space is encoded in the urls.

-1
source

Source: https://habr.com/ru/post/1383785/


All Articles