1

Is there a way to clip WMS layers to our area of interest.

I have the following WMS layer that I want to clip for Polygon shown in Red.

enter image description here

I am getting the following error message if I try with SAGA Clip for Raster (and a similar message for GDAL).

enter image description here

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
ar-siddiqui
  • 1,738
  • 7
  • 30
  • 1
    You can do it by using the GDAL WMS driver https://gdal.org/drivers/raster/wms.html. – user30184 Dec 28 '19 at 08:33
  • Just make a GetMap request with the BBOX of interest. – nmtoken Dec 28 '19 at 13:33
  • For example like: https://www.mrlc.gov/geoserver/mrlc_display/NLCD_2016_Land_Cover_L48/ows?version=1.3.0&service=WMS&layers=NLCD_2016_Land_Cover_L48&styles&crs=epsg:2240&format=image/png&request=GetMap&width=500&height=500&BBOX=-247656.2,5428981.3,-240280.6,5434540.1& – nmtoken Dec 28 '19 at 14:01
  • @user30184 Can you please develop this answer a little more, I haven't work with WMS before and need further explanation. – ar-siddiqui Dec 28 '19 at 19:31
  • @nmtoken Can you please develop this answer a little more, I haven't work with WMS before and need further explanation. – ar-siddiqui Dec 28 '19 at 19:32
  • @nmtoken what is the purpose of Width and Height, I understand these are width and height in pixels but if I am downloading the data in geo tiff format it contains extent information. The NLCD Land Cover dataset is 30m resolution, so shouldn't it calculate pixels by itself? – ar-siddiqui Mar 09 '20 at 22:44
  • Width and height are required parameters of the WMS specification. A WMS is not generally regarded as download service, but rather a portrayal service. – nmtoken Mar 13 '20 at 10:58

2 Answers2

2

Is there a way to clip WMS layers to our area of interest

The quick answer here as alluded to in comments, is yes, because that's what a WMS does; it gives a representation of some data usually as an image according to a bounding box. So if you have a bounding box, you can make a request for your area of interest directly (in a browser). A WMS request to fetch an image would look like:

https://www.mrlc.gov/geoserver/mrlc_display/NLCD_2016_Land_Cover_L48/ows?version=1.3.0&service=WMS&layers=NLCD_2016_Land_Cover_L48&styles&crs=epsg:2240&format=image/png&request=GetMap&width=500&height=500&BBOX=-247656.2,5428981.3,-240280.6,5434540.1&

Which gives us:

GetMap example request as image

In QGIS you are doing requests like this every time you zoom and pan the map canvas, for your WMS layer.

If you want to export the WMS for the AOI then you can do so using the Processing Toolbox > Raster Tools > Convert Map to Raster

nmtoken
  • 13,355
  • 5
  • 38
  • 87
  • I understand what you are saying, but converting map to a raster wouldn't give me the best resolution output. Also, I am trying to do this inside a QGIS Graphic Model / Python Script. So Converting Map to Raster isnt an option for me. – ar-siddiqui Dec 30 '19 at 01:24
  • 1
    For ways of doing this with PyQGIS see: https://gis.stackexchange.com/questions/278812/saving-wms-layer-to-local-raster-in-pyqgis – nmtoken Dec 30 '19 at 15:48
0

This methodology has worked for me:

  1. Zoom to Area of Interest
  2. Open QGIS Network logger (>3.5 but <= 3.12) (you do NOT need this plugin if running QGIS 3.14 or higher! Networklogging is in QGIS itself since QGIS Pi / 3.14. Just press F12!)
  3. See what request URL that WMS is requesting - copy it.
  4. Run Download File Algorithm in QGIS, paste that URl
  5. It will download the tile as a raster file.
ar-siddiqui
  • 1,738
  • 7
  • 30