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

Corrected format in getCoverage example

parent a33b5699
No related branches found
No related tags found
No related merge requests found
%% 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-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')
format=''
)
```
%% Output
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-3-c0e26f5657aa> in <module>()
4 bbox=bbox,
5 resx=250, resy=250,
----> 6 format=wcs.supportedFormats[0] # GeoTiff 16 bit integer
7 )
AttributeError: 'WebCoverageService_1_0_0' object has no attribute 'supportedFormats'
%% Cell type:markdown id: tags:
Now fetch the coverage for Senegal and save it to 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")
ph = 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
%matplotlib inline
plot.show(CEC, title='Mean pH between 0 and 5 cm deep in Senegal', cmap='gist_ncar')
plot.show(ph, title='Mean pH between 0 and 5 cm deep in Senegal', cmap='gist_ncar')
```
%% Cell type:code id: tags:
``` python
```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment