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
No related branches found
No related tags found
No related merge requests found
File moved
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Obtaining a map segment from a WCS 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. 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: This time a connection is made to the service for soil pH:
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
from owslib.wcs import WebCoverageService from owslib.wcs import WebCoverageService
wcs = WebCoverageService('http://maps.isric.org/mapserv?map=/map/phh2o.map', version='1.0.0') wcs = WebCoverageService('http://maps.isric.org/mapserv?map=/map/phh2o.map', version='1.0.0')
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
A bounding box broadly matching Senegal: A bounding box broadly matching Senegal:
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
bbox = (-1784000, 1356000, -1140000, 1863000) bbox = (-1784000, 1356000, -1140000, 1863000)
``` ```
%% Cell type:markdown id: tags: %% 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: %% Cell type:code id: tags:
``` python ``` python
response = wcs.getCoverage( response = wcs.getCoverage(
identifier='phh2o_0-5cm_mean', identifier='phh2o_0-5cm_mean',
crs='urn:ogc:def:crs:EPSG::152160', crs='urn:ogc:def:crs:EPSG::152160',
bbox=bbox, bbox=bbox,
resx=250, resy=250, resx=250, resy=250,
format='GEOTIFF_16') format='GEOTIFF_16')
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Now fetch the coverage for Senegal and save it disk: Now fetch the coverage for Senegal and save it disk:
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
with open('./data/Senegal_pH_0-5_mean.tif', 'wb') as file: with open('./data/Senegal_pH_0-5_mean.tif', 'wb') as file:
file.write(response.read()) file.write(response.read())
``` ```
%% Cell type:markdown id: tags: %% 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: 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: %% Cell type:code id: tags:
``` python ``` python
import rasterio import rasterio
CEC = rasterio.open("./data/Senegal_pH_0-5_mean.tif", driver="GTiff") CEC = rasterio.open("./data/Senegal_pH_0-5_mean.tif", driver="GTiff")
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Finally, use the plot class to plot the map: Finally, use the plot class to plot the map:
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
from rasterio import plot from rasterio import plot
plot.show(CEC, title='Mean pH between 0 and 5 cm deep in Senegal', cmap='gist_ncar') 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