2

I need to extract attribute data from all features from a WMS source.

So far I've managed to get them "manually" specifying coordinates for each feature using Python and OWSlib like this:

from owslib.wms import WebMapService
wms = WebMapService(<WMS URL>)

fInfo = wms.getfeatureinfo(   
                     layers=['0'],
                     styles=['default'],
                     srs='EPSG:4326',    
                     bbox=(-68.68876,-23.09997,-67.82525,-21.12957), # manually set feature coordinates
                     size=(500,500),
                     format='image/jpeg',
                     query_layers=['0'],      
                     info_format='application/geojson',
                     xy=(250,250)
                     )
out = open(wms['0'].title.replace(" ", "_")+".json", "wb")
out.write(fInfo.read())
out.close()

So my problem is exactly that: I need to know beforehand where are all the features and specify a bounding box inside them.

Is there a way to list all features or objects from a WMS and download their metadata?

2
  • 2
    WMS is for maps and sends back rendered images which are just pixels. GetFeatureInfo sends a new request to the server and asks what features in the source data were used for rendering one certain pixel. If the same server happens to support also WFS you can use that for accessing the attributes.
    – user30184
    Apr 14, 2021 at 6:32
  • You could iterate over every pixel in an image to get all the attribute information.
    – nmtoken
    Jun 22, 2021 at 17:39

2 Answers 2

0

Is there a way to list all features or objects from a WMS and download their metadata?

Generally no, as generally a WMS GetMap response has no features just pixels ~ it returns an image (or video). The origin data may have features with attributes, but you can't through any WMS operation get a list of them.

Exceptionally you may find a WMS GetMap returns Vector Tiles, which give a generalised view of the underlying data, and those may return attribute data.

0

I agree with the other that claims that WMS isn't built for that, but sometimes it can be useful to do so anyway.

The level of success is probably determined by which WMS server it is, and if you can utilize vendor specific parameters for that server.

The principle would be to make one big request covering the entire expected extent and squeeze that into a really small map and "click" on a pixel. Ideally you would have the map only one ny one pixel large and "click" on that pixel. But in reality you may have to split it into several requests using a slightly larger tile size and "click" several pixels. It all depends on how the server will handle such an odd request, as the server would most likely render the map in memory with symbols and all and see which features produced a pixel in the map where "clicked". If you can utilize a vendor specific parameter, many servers have a parameter that can set a buffer size on the "clicked" pixel, so you can make the "click" cover several pixels at once. Geoserver has the buffer parameter for this.

Regardless of which WMS server it is, you must also set the feature_count parameter to the expected maximum features in one request. Be prepared that if this is a large number the server may not return all anyway, or deny the request, and then you are back to tiling your requests.

2
  • Have you got this to work on any service?
    – nmtoken
    Nov 23, 2022 at 13:43
  • I did something like this in a project a while ago on Geoserver. In that case I was interested in all features inside a given extent and not the ones outside. Making the map 1x1 pixel in that case returned too many false positives as neighboring features spilled into the "map". So I used a 25x25 pixels map and used the vendor specific radius parameter to cover the entire map. Using only the radius parameter on a normal sized map seemed to not work with Geoserver, probably because implementers did not expect anyone to need a 1000 pixels radius.
    – Stefan
    Nov 24, 2022 at 10:59

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.