In QGIS, I have a WMS layer. I am saving it to my hard drive by right click > "Save As…". Just like in HDunn's answer here. This is about my understanding of the topic, already this code is strange and not really understandable for me.
However, "Save As…" is resampling the original data by averageing it, which is not OK for me since the original raster is a categorical one. I do not know the resolution of the original WMS file (it is not included in it's description).
How could I save it with either the original resolution (and CRS) and/or with other resampling method than averaging? Natural Neighbour would be fair enough although Most Frequent Value would be most accurate. Is that possible without Python? I also understand of R, if that helps.
Best Answer
For a reference of the GeoServer WMS services:
https://docs.geoserver.org/stable/en/user/services/wms/reference.html
Get server capabilities:
The server returns an XML file, open it with a web browser.
Assuming you want to download layer 4, these are the parts that interest you:
There you can find the available image formats, the reference systems and the regions (expressed in those reference systems), which you can request.
Assuming you want to obtain a TIFF file in EPSG:4326 system, of the region between latitudes 20.3 and 20.4 degrees, and longitudes between 48.0 and 48.1 degrees, with a resolution of 0.0001 degree (a grid of 1000 rows and 1000 columns).
The region is small enough to be able to download quickly and the resolution is good enough, probably the maximum that the server can provide (observe the pixels in QGIS, in the WMS layer, and its size in WGS84 coordinates).
Then, when looking at wider regions, keep in mind that you should not exceed the limits set by the server, or return an error.
The GetMap way
You can request that map through a web browser, typing the URL of the GetMap query:
The server will return a TIFF file with the requested map, but without referencing.
When you add it as a raster layer to QGIS, it will ask you to specify the reference system and project the image onto the canvas.
The result is that QGIS will place the image in latitude 0 and longitude 0, and the image will measure 1000 degrees wide by 1000 degrees long.
You must georeference it.
The GRASS GIS way
Assuming you already have your Location and Mapset determined to work on EPSG:4326, the first step is to establish the region:
I'm going to copy the commands already formed, but if you run just
g.region
a GUI is open that can help you in the process of setting the parameters.You can verify that the region was created and loaded as the default region with the command
g.region -p
.Then, download the image from the server:
GRASS GIS will connect to the server, download the map and load it to the canvas.
It is a good idea to check the information on the map:
According to the documentation of g.out.gdal, the data type for the output of raster values between 0 and 65535 can be UInt16, therefore the output command can be:
And that's it, when you load the image as a raster layer in QGIS, you will not notice any difference with the WMS layer.
I recommend that you do not intend to download very large regions with this resolution. Note that the WMS layer requests different resolutions depending on the zoom level, and when the zoom level is high the regions are small.