{ "cells": [ { "cell_type": "markdown", "id": "6e263166-aad2-42eb-9a15-9ea1bcca5d8b", "metadata": {}, "source": [ "## Using shapefiles" ] }, { "cell_type": "raw", "id": "42cc4d64-7eba-40d0-ad71-423bb7b70793", "metadata": { "editable": true, "raw_mimetype": "text/restructuredtext", "slideshow": { "slide_type": "" }, "tags": [], "vscode": { "languageId": "raw" } }, "source": [ "The code below reads shapefile data as a :ref:`data-sources-file` source using :func:`from_source()`. Internally the data is represented as a geopandas dataframe. To make this example work geopandas **needs** to be installed." ] }, { "cell_type": "code", "execution_count": 1, "id": "4825665a-8fc1-4c24-b0fb-3c485bd462c5", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[33mWARNING: Error parsing requirements for nbsphinx: [Errno 2] No such file or directory: '/opt/homebrew/Caskroom/miniforge/base/envs/dev_ecc/lib/python3.10/site-packages/nbsphinx-0.9.3.dist-info/METADATA'\u001b[0m\u001b[33m\n", "\u001b[0m" ] } ], "source": [ "!pip install geopandas --quiet" ] }, { "cell_type": "code", "execution_count": 2, "id": "1ece2495-52e2-4678-8e9f-1a1d086a5975", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/8 [00:00ShapeFileReader(represented as a geopandas object):
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
BASWC4_IDIDNNAMECONTNNFISH_ACRESSOURCETHMNO_COUNTRIQ3CHECKEDLAEA_HALAEA_ACRESLAEA_PRMTRgeometry
0240811Indigirka2201100.002geoff2.dbf0None-10.000000e+000.00.0POLYGON ((139.68730 63.93320, 139.82028 64.030...
1343614Kolyma22014290.003geoff2.dbf0None-10.000000e+000.00.0POLYGON ((153.32126 70.87090, 153.33440 70.873...
243836Yenisey22036420.007final_draft22.db0International catchments-11.916399e+08473542164.810368035.7POLYGON ((84.03548 62.48704, 84.03149 62.49136...
3514878Tana0000.000final_draft22.db0International catchments-11.698563e+064197148.9750506.4POLYGON ((25.51510 68.64600, 25.40198 68.62086...
4610411Mackenzie55011530.006final_draft22.db0None50.000000e+000.00.0POLYGON ((-136.92070 68.20810, -136.88443 68.2...
...................................................
24925100Void0000.000None0International catchments57.292745e+0618020373.21867904.1POLYGON ((33.95228 -6.69550, 33.95243 -6.70446...
25027900Mangoky0000.000None0None54.310280e+0610650702.02127189.5POLYGON ((46.82328 -21.32725, 46.82447 -21.336...
25113916Lena22016430.009final_draft22.db0None-11.016640e+08251211777.313423660.9POLYGON ((102.72000 65.76000, 102.85008 65.906...
252103724Ob22024430.010final_draft22.db0International catchments-13.070918e+08758823924.113761196.3POLYGON ((84.03548 62.48704, 84.06540 62.45478...
25359214108Connecticut0000.000final_draft22.db0International catchments52.775322e+066857819.81427586.8POLYGON ((-71.16196 45.24421, -71.12241 45.182...
\n", "

254 rows × 16 columns

\n", "
" ], "text/plain": [ "ShapeFileReader(/var/folders/93/w0p869rx17q98wxk83gn9ys40000gn/T/earthkit-data-cgr/file-48ce4ac918e854d69bd7776b38e05c25eb66b4235111d1fa9cf48f78e4294d94.d/major_basins/Major_Basins_of_the_World.shp)" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ds" ] }, { "cell_type": "code", "execution_count": 5, "id": "e771de4b-ea35-48b6-8c50-445d3f65fd1f", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "BASWC4_ID 4\n", "ID 38\n", "N 36\n", "NAME Yenisey\n", "CONT 2\n", "NN 2036\n", "FISH_ 42\n", "ACRES 0.007\n", "SOURCETHM final_draft22.db\n", "NO_COUNTRI 0\n", "Q3 International catchments\n", "CHECKED -1\n", "LAEA_HA 191639888.63\n", "LAEA_ACRES 473542164.8\n", "LAEA_PRMTR 10368035.7\n", "geometry POLYGON ((84.03548431396484 62.48704147338867,...\n", "Name: 2, dtype: object" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ds[2]" ] }, { "cell_type": "code", "execution_count": 6, "id": "6e13cbe2-a2dc-4f5f-b4b2-871db1c24f6c", "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "" ], "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ds[2].geometry" ] }, { "cell_type": "raw", "id": "381dbf14-08ef-407a-a982-d00cef206615", "metadata": { "editable": true, "raw_mimetype": "text/restructuredtext", "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "We can access the data as a geopandas object by using :func:`to_geopandas`." ] }, { "cell_type": "code", "execution_count": 7, "id": "7b0c4e12-97b0-47a5-a709-2dd25fbf7a1b", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "outputs": [ { "data": { "text/plain": [ "geopandas.geodataframe.GeoDataFrame" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "gpd = ds.to_geopandas()\n", "type(gpd)" ] } ], "metadata": { "kernelspec": { "display_name": "dev_ecc", "language": "python", "name": "dev_ecc" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.13" } }, "nbformat": 4, "nbformat_minor": 5 }