|
24 | 24 | "`OWSLib` enables you to connect to these services as \n", |
25 | 25 | "a client, mainly to fetch and query data from them. \n", |
26 | 26 | "Currently WMS, WFS, WCS, CSW, WPS, SOS, WMC and the more recent OGC APIs like \n", |
27 | | - "*OGC API - Features* (formerly called \"WFS version 3\") are supported.\n", |
| 27 | + "*OGC API - Features* are supported.\n", |
28 | 28 | "The list of supported services is growing. \n", |
29 | 29 | "\n", |
30 | 30 | "Documentation: https://owslib.readthedocs.io\n" |
|
150 | 150 | "# Get items (paged) in Lakes collection\n", |
151 | 151 | "lakes = oa_feat.collection('lakes')\n", |
152 | 152 | "lakes_query = oa_feat.collection_items('lakes')\n", |
153 | | - "lakes_query['features'][0]" |
| 153 | + "lakes_query['features'][0]\n", |
| 154 | + "\n", |
| 155 | + "# Plot first lake\n", |
| 156 | + "lake = lakes_query['features'][0]\n", |
| 157 | + "print(lake.get('properties').get('name'))\n", |
| 158 | + "from shapely.geometry import shape\n", |
| 159 | + "lakepolygon = shape(lake.get('geometry'))\n", |
| 160 | + "lakepolygon" |
154 | 161 | ] |
155 | 162 | }, |
156 | 163 | { |
|
258 | 265 | "cell_type": "markdown", |
259 | 266 | "metadata": {}, |
260 | 267 | "source": [ |
261 | | - "Download and save the data (image)" |
| 268 | + "Fetch and display the image via WMS" |
262 | 269 | ] |
263 | 270 | }, |
264 | 271 | { |
|
278 | 285 | " bbox=[1.0, 50.0, 10.0, 54.0],\n", |
279 | 286 | " format=\"image/png\")\n", |
280 | 287 | "\n", |
281 | | - "save_fp = 'test/10-wms.png'\n", |
282 | | - "with open(save_fp, 'wb') as out:\n", |
283 | | - "\tout.write(img.read())" |
284 | | - ] |
285 | | - }, |
286 | | - { |
287 | | - "cell_type": "markdown", |
288 | | - "metadata": {}, |
289 | | - "source": [ |
290 | | - "Display image in Notebook or view in browser via [this link](test/10-wms.png)." |
291 | | - ] |
292 | | - }, |
293 | | - { |
294 | | - "cell_type": "code", |
295 | | - "execution_count": null, |
296 | | - "metadata": { |
297 | | - "pycharm": { |
298 | | - "name": "#%%\n" |
299 | | - } |
300 | | - }, |
301 | | - "outputs": [], |
302 | | - "source": [ |
303 | | - "from IPython.display import Image\n", |
304 | | - "Image(filename=save_fp)" |
| 288 | + "from IPython.display import Image, display\n", |
| 289 | + "display(Image(data=img.read()))\n" |
305 | 290 | ] |
306 | 291 | }, |
307 | 292 | { |
|
500 | 485 | }, |
501 | 486 | "outputs": [], |
502 | 487 | "source": [ |
503 | | - "response = wfs.getfeature(typename='ms:cities', bbox=(15.7500260759, 42.65, 19.59976, 45.2337767604))" |
| 488 | + "response = wfs.getfeature(typename='ms:cities', bbox=(15.7500260759, 42.65, 19.59976, 45.2337767604))\n", |
| 489 | + "data = response.read()\n", |
| 490 | + "\n", |
| 491 | + "# Parse the GML response as Shapely geometries\n", |
| 492 | + "from io import BytesIO\n", |
| 493 | + "from geopandas import read_file\n", |
| 494 | + "gdf = read_file(BytesIO(data))\n", |
| 495 | + "\n", |
| 496 | + "# Combine the points in a MultiPoint\n", |
| 497 | + "from shapely import MultiPoint\n", |
| 498 | + "mpgeom = MultiPoint(list(gdf.geometry))\n", |
| 499 | + "\n", |
| 500 | + "# Plot the geometry\n", |
| 501 | + "mpgeom" |
504 | 502 | ] |
505 | 503 | }, |
506 | 504 | { |
|
888 | 886 | "tags": [] |
889 | 887 | }, |
890 | 888 | "source": [ |
891 | | - "Download data from selected layer and write to a file." |
| 889 | + "Download data from selected layer and plot." |
892 | 890 | ] |
893 | 891 | }, |
894 | 892 | { |
|
908 | 906 | "source": [ |
909 | 907 | "identifier = 'ge:boreholes_cores_rbins'\n", |
910 | 908 | "features = boreholes_wfs.getfeature([identifier])\n", |
| 909 | + "data = features.read()\n", |
| 910 | + "\n", |
| 911 | + "# Parse the GML response as Shapely geometries\n", |
| 912 | + "from io import BytesIO\n", |
| 913 | + "from geopandas import read_file\n", |
| 914 | + "gdf = read_file(BytesIO(data))\n", |
| 915 | + "\n", |
| 916 | + "# Combine the points in a MultiPoint\n", |
| 917 | + "from shapely import MultiPoint\n", |
| 918 | + "mpgeom = MultiPoint(list(gdf.geometry))\n", |
911 | 919 | "\n", |
912 | | - "with open('test/10-boreholes.gml', 'w', encoding='UTF-8') as out:\n", |
913 | | - " out.write(str(features.read(), 'UTF-8'))" |
| 920 | + "# Plot the geometry\n", |
| 921 | + "mpgeom" |
914 | 922 | ] |
915 | 923 | }, |
916 | 924 | { |
|
0 commit comments