diff --git a/poly/example.ipynb b/poly/example.ipynb index 49d67ded..335a0661 100644 --- a/poly/example.ipynb +++ b/poly/example.ipynb @@ -8,13 +8,16 @@ "outputs": [], "source": [ "import h3\n", - "import util as u\n", "\n", - "def show_gj_str(gj_str):\n", + "def show_geo(geo):\n", + " \"\"\" Show something that implements __geo_interface__\n", + " \"\"\"\n", " import json\n", " from IPython.display import GeoJSON\n", + " # json.loads(gj_str)\n", + " geo = geo.__geo_interface__\n", " \n", - " return GeoJSON(json.loads(gj_str))" + " return GeoJSON(geo)" ] }, { @@ -37,7 +40,7 @@ "metadata": {}, "outputs": [], "source": [ - "mpoly = h3.cells_to_shape(cells)" + "mpoly = h3.cells_to_h3shape(cells)" ] }, { @@ -120,7 +123,7 @@ "metadata": {}, "outputs": [], "source": [ - "h3.shape_to_cells(mpoly, 9) == cells" + "h3.h3shape_to_cells(mpoly, 9) == cells" ] }, { @@ -132,7 +135,7 @@ }, "outputs": [], "source": [ - "str(h3.cells_to_shape([]))" + "str(h3.cells_to_h3shape([]))" ] }, { @@ -152,7 +155,7 @@ }, "outputs": [], "source": [ - "cells = h3.shape_to_cells(mpoly, 9)" + "cells = h3.h3shape_to_cells(mpoly, 9)" ] }, { @@ -164,63 +167,78 @@ }, "outputs": [], "source": [ - "mpoly[0].__geo_interface__" + "show_geo(mpoly)" + ] + }, + { + "cell_type": "markdown", + "id": "e38f73ae-d5e0-4b4b-8195-1098849e0059", + "metadata": {}, + "source": [ + "# example" ] }, { "cell_type": "code", "execution_count": null, - "id": "9002793c-263c-4898-a9b9-270a210789dd", + "id": "35d8f132-a3b2-4ead-8142-7c95343e8d40", "metadata": {}, "outputs": [], "source": [ - "gjs = u.cells_to_geojson(cells)" + "import geopandas as gpd\n", + "import shapely\n", + "import geodatasets" ] }, { "cell_type": "code", "execution_count": null, - "id": "b17fe7cb-f5d5-4225-9613-191e8b483abb", + "id": "07a20f53-0676-4820-b539-201b4575a722", "metadata": {}, "outputs": [], - "source": [] + "source": [ + "path_to_file = geodatasets.get_path('nybb')" + ] }, { "cell_type": "code", "execution_count": null, - "id": "absent-frontier", + "id": "0c0aa15b-8e67-4075-8675-dc6118a4fe1a", "metadata": {}, "outputs": [], "source": [ - "print(gjs[:100])" + "path_to_file" ] }, { "cell_type": "code", "execution_count": null, - "id": "meaningful-species", + "id": "5ef7ce20-68d1-473a-9838-94c38cb9f7d1", "metadata": {}, "outputs": [], "source": [ - "show_gj_str(gjs)" + "df = gpd.read_file(path_to_file).to_crs(epsg=4326)\n", + "df" ] }, { "cell_type": "code", "execution_count": null, - "id": "extreme-english", + "id": "fb280331-a13e-47ca-9808-1a11884c2bd1", "metadata": {}, "outputs": [], "source": [ - "set(u.geojson_to_cells(gjs,9)) == cells" + "gpd.__version__" ] }, { - "cell_type": "markdown", - "id": "e38f73ae-d5e0-4b4b-8195-1098849e0059", + "cell_type": "code", + "execution_count": null, + "id": "1fbfa7f2-e5b4-4b71-9684-ec3eacc4497f", "metadata": {}, + "outputs": [], "source": [ - "# example" + "gpd.datasets.get_path('nybb')" ] }, { @@ -253,6 +271,16 @@ "df" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "b5013bdb-e36c-4e5b-bf4b-613533a08d3f", + "metadata": {}, + "outputs": [], + "source": [ + "df.loc[0, \"geometry\"]" + ] + }, { "cell_type": "code", "execution_count": null, diff --git a/poly/maybe_docs.ipynb b/poly/maybe_docs.ipynb new file mode 100644 index 00000000..fcd1878e --- /dev/null +++ b/poly/maybe_docs.ipynb @@ -0,0 +1,152 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "f38834cc-0a97-4e61-bd96-86a995607f6f", + "metadata": {}, + "source": [ + "- i don't think we imported the stuff into the other interfaces!" + ] + }, + { + "cell_type": "markdown", + "id": "6d6cb01d-ab34-4657-9e69-c6f9749a309a", + "metadata": {}, + "source": [ + "Summary:\n", + "\n", + "```\n", + "geo <> shape <> cells\n", + "```\n", + "\n", + "Most users can use\n", + "\n", + "- `geo_to_cells`\n", + "- `cells_to_geo`\n", + "\n", + "\n", + "For an alternative interface, consider the classes\n", + "\n", + "- `H3Shape`\n", + "- `H3Poly`\n", + "- `H3MultiPoly`\n", + "\n", + "\n", + "We have a few functions for dealing with polygons in H3:\n", + "\n", + "- `h3shape_to_cells`\n", + "- `cells_to_h3shape`\n", + "\n", + "do i need:\n", + "\n", + "- `geo_to_h3shape`\n", + "- `h3shape_to_geo`\n", + "\n", + "Define `geo`:\n", + "\n", + "- anything that implements `__geo_interface__`\n", + "- a dictionary like `__geo_interface__`\n", + "- strings NO!" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5b1f822e-1cfd-46b8-b3ad-1cc5b477150d", + "metadata": {}, + "outputs": [], + "source": [ + "import h3" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "768bd740-f3fc-4157-a031-58e6d1fba9af", + "metadata": {}, + "outputs": [], + "source": [ + "h3.geo_to_cells?" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "32488485-5c18-41c7-9523-fa8b1169dd10", + "metadata": {}, + "outputs": [], + "source": [ + "h3.cells_to_geo?" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8809d6f3-7e63-4c8c-acf5-56cc5f475f3d", + "metadata": {}, + "outputs": [], + "source": [ + "h3.cells_to_h3shape?" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "55f04179-e3f8-4963-aa3f-fa948be9b5d8", + "metadata": {}, + "outputs": [], + "source": [ + "h3.h3shape_to_cells?" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d7907aca-9868-4d22-b58a-3245bd493538", + "metadata": {}, + "outputs": [], + "source": [ + "h3.geo_to_h3shape?" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6c128bbb-df95-44e5-b6ea-15f051fc2778", + "metadata": {}, + "outputs": [], + "source": [ + "h3.h3shape_to_geo?" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "bd16cc55-00ed-4ff3-bce5-3136003aaebe", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "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.11.1" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/requirements-dev.txt b/requirements-dev.txt index 85240b89..1eb851fd 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,3 +1,4 @@ jupyterlab jupyterlab-geojson geopandas +geodatasets diff --git a/src/h3/_h3shape.py b/src/h3/_h3shape.py index 78640e0f..4b58e4bc 100644 --- a/src/h3/_h3shape.py +++ b/src/h3/_h3shape.py @@ -5,7 +5,7 @@ class H3Shape(metaclass=ABCMeta): @property @abstractmethod def __geo_interface__(self): - pass + """ https://github.com/pytest-dev/pytest-cov/issues/428 """ class H3Poly(H3Shape):