Skip to content
Snippets Groups Projects
Commit 1e528d1e authored by Luís de Sousa's avatar Luís de Sousa
Browse files

Corrected file name for basics section

parent c0e4a319
Branches
No related tags found
No related merge requests found
File moved
%% Cell type:markdown id: tags:
Obtaining a map segment from a WCS
====================
Obtaining a map segment is another operation greatly simplified by the [OWSLib](https://geopython.github.io/OWSLib/) package. This case is conducted from a pre-established bounding box.
This time a connection is made to the service for soil pH:
%% Cell type:code id: tags:
``` python
from owslib.wcs import WebCoverageService
wcs = WebCoverageService('http://maps.isric.org/mapserv?map=/map/phh2o.map', version='1.0.0')
```
%% Cell type:markdown id: tags:
A bounding box broadly matching Senegal:
%% Cell type:code id: tags:
``` python
bbox = (-1784000, 1356000, -1140000, 1863000)
```
%% Cell type:markdown id: tags:
The `getCoverage` method can now be used to fetch the map segment within the bounding box. Note the other parameters, [Section 1](01-WCS-basic.ipynb) showed how to obtain them.
The `getCoverage` method can now be used to fetch the map segment within the bounding box. Note the other parameters, [Section 1](01-WCS-basics.ipynb) showed how to obtain them.
%% Cell type:code id: tags:
``` python
response = wcs.getCoverage(
identifier='phh2o_0-5cm_mean',
crs='urn:ogc:def:crs:EPSG::152160',
bbox=bbox,
resx=250, resy=250,
format='GEOTIFF_16')
```
%% Cell type:markdown id: tags:
Now fetch the coverage for Senegal and save it disk:
%% Cell type:code id: tags:
``` python
with open('./data/Senegal_pH_0-5_mean.tif', 'wb') as file:
file.write(response.read())
```
%% Cell type:markdown id: tags:
With the data on the client side some regular interaction can be started with a library like [rasterIO](https://rasterio.readthedocs.io/). First open the file from disk:
%% Cell type:code id: tags:
``` python
import rasterio
CEC = rasterio.open("./data/Senegal_pH_0-5_mean.tif", driver="GTiff")
```
%% Cell type:markdown id: tags:
Finally, use the plot class to plot the map:
%% Cell type:code id: tags:
``` python
from rasterio import plot
plot.show(CEC, title='Mean pH between 0 and 5 cm deep in Senegal', cmap='gist_ncar')
```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment