diff --git a/02-WCS-getExtent.ipynb b/02-WCS-getExtent.ipynb index bcb4007d5cb301ddecf7c12e8bd9dad2ab666431..cfa727a8e6412e4512ed4ac7734dd624e37789ed 100644 --- a/02-WCS-getExtent.ipynb +++ b/02-WCS-getExtent.ipynb @@ -4,12 +4,17 @@ "cell_type": "markdown", "metadata": {}, "source": [ + "Obtaining a map segment from a WCS\n", + "====================\n", + "\n", + "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.\n", + "\n", "This time a connection is made to the service for soil pH:" ] }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -26,7 +31,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -37,26 +42,33 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Now fetch the coverage for Senegal:" + "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." ] }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ "response = wcs.getCoverage(\n", - " identifier='phh20_0-5cm_mean', \n", + " identifier='phh2o_0-5cm_mean', \n", " crs='urn:ogc:def:crs:EPSG::152160',\n", " bbox=bbox, \n", - " resx=1, resy=1, \n", - " format='GeoTIFF')" + " resx=250, resy=250, \n", + " format='GEOTIFF_16')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now fetch the coverage for Senegal and save it disk:" ] }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -68,55 +80,41 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "With the data on the client side some regular interaction can be started with a library like resterIO:" + "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", - "execution_count": 14, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "ename": "RasterioIOError", - "evalue": "'./data/Senegal_CEC0m.tif' not recognized as a supported file format.", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mCPLE_OpenFailedError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32mrasterio/_base.pyx\u001b[0m in \u001b[0;36mrasterio._base.DatasetBase.__init__\u001b[0;34m()\u001b[0m\n", - "\u001b[0;32mrasterio/_shim.pyx\u001b[0m in \u001b[0;36mrasterio._shim.open_dataset\u001b[0;34m()\u001b[0m\n", - "\u001b[0;32mrasterio/_err.pyx\u001b[0m in \u001b[0;36mrasterio._err.exc_wrap_pointer\u001b[0;34m()\u001b[0m\n", - "\u001b[0;31mCPLE_OpenFailedError\u001b[0m: './data/Senegal_CEC0m.tif' not recognized as a supported file format.", - "\nDuring handling of the above exception, another exception occurred:\n", - "\u001b[0;31mRasterioIOError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m<ipython-input-14-3c4dada614d1>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mrasterio\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mCEC\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mrasterio\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mopen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"./data/Senegal_CEC0m.tif\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdriver\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"GTiff\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 3\u001b[0m \u001b[0mshow\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mCEC\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtitle\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'Cation Exchange Capacity at 0 metres in Senegal'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcmap\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'gist_ncar'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/usr/lib/python3/dist-packages/rasterio/env.py\u001b[0m in \u001b[0;36mwrapper\u001b[0;34m(*args, **kwds)\u001b[0m\n\u001b[1;32m 428\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 429\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0menv_ctor\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msession\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0msession\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 430\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mf\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwds\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 431\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 432\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mwrapper\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/usr/lib/python3/dist-packages/rasterio/__init__.py\u001b[0m in \u001b[0;36mopen\u001b[0;34m(fp, mode, driver, width, height, count, crs, transform, dtype, nodata, sharing, **kwargs)\u001b[0m\n\u001b[1;32m 214\u001b[0m \u001b[0;31m# None.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 215\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mmode\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m'r'\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 216\u001b[0;31m \u001b[0ms\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mDatasetReader\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpath\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdriver\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mdriver\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msharing\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0msharing\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 217\u001b[0m \u001b[0;32melif\u001b[0m \u001b[0mmode\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m'r+'\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 218\u001b[0m \u001b[0ms\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mget_writer_for_path\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpath\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpath\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmode\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdriver\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mdriver\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msharing\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0msharing\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32mrasterio/_base.pyx\u001b[0m in \u001b[0;36mrasterio._base.DatasetBase.__init__\u001b[0;34m()\u001b[0m\n", - "\u001b[0;31mRasterioIOError\u001b[0m: './data/Senegal_CEC0m.tif' not recognized as a supported file format." - ] - } - ], + "outputs": [], "source": [ "import rasterio\n", - "CEC = rasterio.open(\"./data/Senegal_CEC0m.tif\", driver=\"GTiff\")\n", - "show(CEC, title='Cation Exchange Capacity at 0 metres in Senegal', cmap='gist_ncar')" + "CEC = rasterio.open(\"./data/Senegal_pH_0-5_mean.tif\", driver=\"GTiff\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Next steps:\n", - "https://publicwiki.deltares.nl/display/OET/WCS+primer\n", - "https://geoscripting-wur.github.io/PythonRaster/" + "Finally, use the plot class to plot the map:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from rasterio import plot\n", + "plot.show(CEC, title='Mean pH between 0 and 5 cm deep in Senegal', cmap='gist_ncar')" ] } ], "metadata": { "@webio": { - "lastCommId": "C7CD903630FF4971A278510DC0E27447", - "lastKernelId": "5e40268c-f755-4e83-aec6-935c11d843f6" + "lastCommId": "D3911297100443A589A0B69F3631EE47", + "lastKernelId": "75502dee-5a4b-4102-8195-4ec7f63b2135" }, "kernelspec": { "display_name": "Python 3",