8

I've been looking for information on how to get layers names from certain WMS servers, but I didn't find any.

E.g. I have this server: http://sdi.geoportal.gov.pl/wms_prg/wmservice.aspx and I want to know what layers can I get from it. Is there any chance to know their names?

Thanks in advance!

2
  • How are you planning to access them? With ArcMap or any other program? Or do you need to create your own program?
    – kor_
    Commented Nov 12, 2012 at 11:10
  • Google Maps at my webpage and to take layers from WMS
    – GoMati
    Commented Nov 12, 2012 at 14:57

3 Answers 3

9

You should be able to use the GetCapabilities method of the WMS server to list all the data and operations available to you. Something like the following (though I've not got access to test what this returns) should hopefully be what you're looking for:

http://sdi.geoportal.gov.pl/wms_prg/wmservice.aspx?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetCapabilities

0
5

One could use OWSLib, an excellent OGC Web Services utility library in python.

Install with pip (or download sources from repository):

pip install OWSLib

Retrieve some info from the the WMS server:

>>> from owslib.wms import WebMapService
>>> wms = WebMapService("http://sdi.geoportal.gov.pl/wms_prg/wmservice.aspx")
>>> wms.identification.title
u'Us\u0142uga przegl\u0105dania (WMS) Pa\u0144stwowego Rejestru Granic dla obsza
ru Polski.'
>>> wms.identification.type
'OGC:WMS'
>>> wms.identification.version
'1.1.1'
>>> list(wms.contents)
['Nazwa_powiatu', 'Nazwa_gminy', 'Nazwa_wojewodztwa', 'Powiaty', 'Wojewodztwa',
'Gminy']

Consult the complete documentation for more.

1

Not really sure from your question how exaclty you wish to do this (or if you have a preference). However; to do this in a web app with javascript:

        var formatter = new OpenLayers.Format.WMSCapabilities();
        var endpoint = "path/to/wms/endpoint";
        var layers = [];

        // async call to geoserver (I'm using angular)
        $http.get(endpoint + 'request=GetCapabilities').

        success(function(data, status, headers, config) {

            // use the tool to parse the data
            var response = (formatter.read(data));

            // this object contains all the GetCapabilities data
            var capability = response.capability;

            // I want a list of names to use in my queries
            for(var i = 0; i < capability.layers.length; i ++){
                layers.push(capability.layers[i].name);
            }
        }).

        error(function(data, status, headers, config) {
            alert("terrible error logging..");
        });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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