Skip to content

Instantly share code, notes, and snippets.

@ajfriend
Created September 26, 2024 22:21
Show Gist options
  • Save ajfriend/dc33458c7cc0e0be88fbc8cee205ce6f to your computer and use it in GitHub Desktop.
Save ajfriend/dc33458c7cc0e0be88fbc8cee205ce6f to your computer and use it in GitHub Desktop.
Bug plotting logical regions of polygons
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "154c140d-b03a-4bea-a5bc-3429db1f54ac",
"metadata": {
"execution": {
"iopub.execute_input": "2024-09-26T22:15:43.015191Z",
"iopub.status.busy": "2024-09-26T22:15:43.013289Z",
"iopub.status.idle": "2024-09-26T22:15:43.047149Z",
"shell.execute_reply": "2024-09-26T22:15:43.046659Z",
"shell.execute_reply.started": "2024-09-26T22:15:43.015163Z"
}
},
"outputs": [],
"source": [
"import h3\n",
"\n",
"def logical_poly(cell, res):\n",
" \"\"\"\n",
" Return the polygon representing the geometric area covered\n",
" by the children of `cell` at resolution `res`.\n",
"\n",
" Expectation: A single polygon with one outer loop and no holes.\n",
" Currently: Getting multipolygons with holes (seems like a bug), or just errors for malformed polygons.\n",
" \"\"\"\n",
" kids = h3.cell_to_children(cell, res)\n",
" mpoly = h3.cells_to_h3shape(kids, tight=False)\n",
" return mpoly\n",
"\n",
"def do_res(res):\n",
" for p in h3.get_pentagons(0):\n",
" print(p, logical_poly(p, res))"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "14f6dd46-4cd3-4f8b-a289-7c5a10f4f550",
"metadata": {
"execution": {
"iopub.execute_input": "2024-09-26T22:15:43.048681Z",
"iopub.status.busy": "2024-09-26T22:15:43.048474Z",
"iopub.status.idle": "2024-09-26T22:15:43.053206Z",
"shell.execute_reply": "2024-09-26T22:15:43.052837Z",
"shell.execute_reply.started": "2024-09-26T22:15:43.048667Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"{'c': '4.0.0', 'python': '4.0.0b7'}"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"h3.versions()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "2deaf1e2-8531-452d-82e2-380e652d5698",
"metadata": {
"execution": {
"iopub.execute_input": "2024-09-26T22:15:43.054789Z",
"iopub.status.busy": "2024-09-26T22:15:43.054679Z",
"iopub.status.idle": "2024-09-26T22:15:43.057808Z",
"shell.execute_reply": "2024-09-26T22:15:43.057253Z",
"shell.execute_reply.started": "2024-09-26T22:15:43.054779Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"8009fffffffffff <LatLngMultiPoly: [5]>\n",
"801dfffffffffff <LatLngMultiPoly: [5]>\n",
"8031fffffffffff <LatLngMultiPoly: [5]>\n",
"804dfffffffffff <LatLngMultiPoly: [5]>\n",
"8063fffffffffff <LatLngMultiPoly: [5]>\n",
"8075fffffffffff <LatLngMultiPoly: [5]>\n",
"807ffffffffffff <LatLngMultiPoly: [5]>\n",
"8091fffffffffff <LatLngMultiPoly: [5]>\n",
"80a7fffffffffff <LatLngMultiPoly: [5]>\n",
"80c3fffffffffff <LatLngMultiPoly: [5]>\n",
"80d7fffffffffff <LatLngMultiPoly: [5]>\n",
"80ebfffffffffff <LatLngMultiPoly: [5]>\n"
]
}
],
"source": [
"do_res(0)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "8dd4e5d5-10b7-4c5b-8c01-8aeada0f21e9",
"metadata": {
"execution": {
"iopub.execute_input": "2024-09-26T22:15:43.058748Z",
"iopub.status.busy": "2024-09-26T22:15:43.058616Z",
"iopub.status.idle": "2024-09-26T22:15:43.062999Z",
"shell.execute_reply": "2024-09-26T22:15:43.062403Z",
"shell.execute_reply.started": "2024-09-26T22:15:43.058738Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"8009fffffffffff <LatLngMultiPoly: [10], [15/(10,)]>\n",
"801dfffffffffff <LatLngMultiPoly: [10], [15/(10,)]>\n",
"8031fffffffffff <LatLngMultiPoly: [20], [15]>\n",
"804dfffffffffff <LatLngMultiPoly: [10/(10,)], [15]>\n",
"8063fffffffffff <LatLngMultiPoly: [20], [15]>\n",
"8075fffffffffff <LatLngMultiPoly: [20], [15]>\n",
"807ffffffffffff <LatLngMultiPoly: [10/(10,)], [15]>\n",
"8091fffffffffff <LatLngMultiPoly: [20], [15]>\n",
"80a7fffffffffff <LatLngMultiPoly: [20], [15]>\n",
"80c3fffffffffff <LatLngMultiPoly: [20], [15]>\n",
"80d7fffffffffff <LatLngMultiPoly: [20], [15]>\n",
"80ebfffffffffff <LatLngMultiPoly: [20], [15]>\n"
]
}
],
"source": [
"do_res(1)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "74b5effb-c861-4c83-9d20-d4eb8c2d607f",
"metadata": {
"execution": {
"iopub.execute_input": "2024-09-26T22:15:43.063977Z",
"iopub.status.busy": "2024-09-26T22:15:43.063819Z",
"iopub.status.idle": "2024-09-26T22:15:43.153053Z",
"shell.execute_reply": "2024-09-26T22:15:43.152681Z",
"shell.execute_reply.started": "2024-09-26T22:15:43.063967Z"
}
},
"outputs": [
{
"ename": "ValueError",
"evalue": "Non-empty LatLngPoly loops need at least 3 points.",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[5], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mdo_res\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m2\u001b[39;49m\u001b[43m)\u001b[49m\n",
"Cell \u001b[0;32mIn[1], line 17\u001b[0m, in \u001b[0;36mdo_res\u001b[0;34m(res)\u001b[0m\n\u001b[1;32m 15\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mdo_res\u001b[39m(res):\n\u001b[1;32m 16\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m p \u001b[38;5;129;01min\u001b[39;00m h3\u001b[38;5;241m.\u001b[39mget_pentagons(\u001b[38;5;241m0\u001b[39m):\n\u001b[0;32m---> 17\u001b[0m \u001b[38;5;28mprint\u001b[39m(p, \u001b[43mlogical_poly\u001b[49m\u001b[43m(\u001b[49m\u001b[43mp\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mres\u001b[49m\u001b[43m)\u001b[49m)\n",
"Cell \u001b[0;32mIn[1], line 12\u001b[0m, in \u001b[0;36mlogical_poly\u001b[0;34m(cell, res)\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 5\u001b[0m \u001b[38;5;124;03mReturn the polygon representing the geometric area covered\u001b[39;00m\n\u001b[1;32m 6\u001b[0m \u001b[38;5;124;03mby the children of `cell` at resolution `res`.\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 9\u001b[0m \u001b[38;5;124;03mCurrently: Getting multipolygons with holes (seems like a bug), or just errors for malformed polygons.\u001b[39;00m\n\u001b[1;32m 10\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 11\u001b[0m kids \u001b[38;5;241m=\u001b[39m h3\u001b[38;5;241m.\u001b[39mcell_to_children(cell, res)\n\u001b[0;32m---> 12\u001b[0m mpoly \u001b[38;5;241m=\u001b[39m \u001b[43mh3\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcells_to_h3shape\u001b[49m\u001b[43m(\u001b[49m\u001b[43mkids\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtight\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m)\u001b[49m\n\u001b[1;32m 13\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m mpoly\n",
"File \u001b[0;32m~/work/2024-09-03_h3_compact_lookup/env/lib/python3.11/site-packages/h3/api/basic_str/__init__.py:477\u001b[0m, in \u001b[0;36mcells_to_h3shape\u001b[0;34m(cells, tight)\u001b[0m\n\u001b[1;32m 474\u001b[0m cells \u001b[38;5;241m=\u001b[39m _in_collection(cells)\n\u001b[1;32m 475\u001b[0m mpoly \u001b[38;5;241m=\u001b[39m _cy\u001b[38;5;241m.\u001b[39mcells_to_multi_polygon(cells)\n\u001b[0;32m--> 477\u001b[0m polys \u001b[38;5;241m=\u001b[39m \u001b[43m[\u001b[49m\u001b[43mLatLngPoly\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mpoly\u001b[49m\u001b[43m)\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mfor\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mpoly\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01min\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mmpoly\u001b[49m\u001b[43m]\u001b[49m\n\u001b[1;32m 478\u001b[0m out \u001b[38;5;241m=\u001b[39m LatLngMultiPoly(\u001b[38;5;241m*\u001b[39mpolys)\n\u001b[1;32m 480\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m tight \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(out) \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m1\u001b[39m:\n",
"File \u001b[0;32m~/work/2024-09-03_h3_compact_lookup/env/lib/python3.11/site-packages/h3/api/basic_str/__init__.py:477\u001b[0m, in \u001b[0;36m<listcomp>\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 474\u001b[0m cells \u001b[38;5;241m=\u001b[39m _in_collection(cells)\n\u001b[1;32m 475\u001b[0m mpoly \u001b[38;5;241m=\u001b[39m _cy\u001b[38;5;241m.\u001b[39mcells_to_multi_polygon(cells)\n\u001b[0;32m--> 477\u001b[0m polys \u001b[38;5;241m=\u001b[39m [\u001b[43mLatLngPoly\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mpoly\u001b[49m\u001b[43m)\u001b[49m \u001b[38;5;28;01mfor\u001b[39;00m poly \u001b[38;5;129;01min\u001b[39;00m mpoly]\n\u001b[1;32m 478\u001b[0m out \u001b[38;5;241m=\u001b[39m LatLngMultiPoly(\u001b[38;5;241m*\u001b[39mpolys)\n\u001b[1;32m 480\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m tight \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(out) \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m1\u001b[39m:\n",
"File \u001b[0;32m~/work/2024-09-03_h3_compact_lookup/env/lib/python3.11/site-packages/h3/_h3shape.py:58\u001b[0m, in \u001b[0;36mLatLngPoly.__init__\u001b[0;34m(self, outer, *holes)\u001b[0m\n\u001b[1;32m 56\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m loop \u001b[38;5;129;01min\u001b[39;00m loops:\n\u001b[1;32m 57\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(loop) \u001b[38;5;129;01min\u001b[39;00m (\u001b[38;5;241m1\u001b[39m, \u001b[38;5;241m2\u001b[39m):\n\u001b[0;32m---> 58\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mNon-empty LatLngPoly loops need at least 3 points.\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m 60\u001b[0m point_dimensions \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mset\u001b[39m(\u001b[38;5;28mmap\u001b[39m(\u001b[38;5;28mlen\u001b[39m, loop))\n\u001b[1;32m 61\u001b[0m \u001b[38;5;66;03m# empty set is possible for empty polygons, so we check if a subset\u001b[39;00m\n",
"\u001b[0;31mValueError\u001b[0m: Non-empty LatLngPoly loops need at least 3 points."
]
}
],
"source": [
"do_res(2)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "f3923c08-2cd2-4a63-9875-f6617ee21e4d",
"metadata": {
"execution": {
"iopub.execute_input": "2024-09-26T22:15:51.167258Z",
"iopub.status.busy": "2024-09-26T22:15:51.166777Z",
"iopub.status.idle": "2024-09-26T22:15:51.189009Z",
"shell.execute_reply": "2024-09-26T22:15:51.188245Z",
"shell.execute_reply.started": "2024-09-26T22:15:51.167226Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"8009fffffffffff <LatLngMultiPoly: [135/(4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4)], [20], [4], [4], [4], [4], [4], [4], [4], [4]>\n",
"801dfffffffffff <LatLngMultiPoly: [135/(4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4)], [4], [4], [20], [4], [4], [4], [4], [4], [4]>\n",
"8031fffffffffff <LatLngMultiPoly: [135/(4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4)], [4], [10/(10,)], [4], [4], [4], [4], [4], [4], [4]>\n",
"804dfffffffffff <LatLngMultiPoly: [135/(4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4)], [10/(10,)], [4], [4], [4], [4], [4], [4], [4], [4]>\n",
"8063fffffffffff <LatLngMultiPoly: [135/(4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4)], [20], [4], [4], [4], [4], [4], [4], [4], [4]>\n",
"8075fffffffffff <LatLngMultiPoly: [4], [135/(4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4)], [4], [20], [4], [4], [4], [4], [4], [4]>\n",
"807ffffffffffff <LatLngMultiPoly: [135/(4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4)], [4], [4], [20], [4], [4], [4], [4], [4], [4]>\n",
"8091fffffffffff <LatLngMultiPoly: [135/(4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4)], [4], [4], [4], [4], [20], [4], [4], [4], [4]>\n",
"80a7fffffffffff <LatLngMultiPoly: [135/(4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4)], [4], [20], [4], [4], [4], [4], [4], [4], [4]>\n",
"80c3fffffffffff <LatLngMultiPoly: [135/(4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4)], [20], [4], [4], [4], [4], [4], [4], [4], [4]>\n",
"80d7fffffffffff <LatLngMultiPoly: [20], [135/(4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4)], [4], [4], [4], [4], [4], [4], [4], [4]>\n",
"80ebfffffffffff <LatLngMultiPoly: [135/(4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4)], [20], [4], [4], [4], [4], [4], [4], [4], [4]>\n"
]
}
],
"source": [
"do_res(3)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "5f644551-0e0f-417e-b935-f4bbdd82f636",
"metadata": {
"execution": {
"iopub.execute_input": "2024-09-26T22:15:51.396568Z",
"iopub.status.busy": "2024-09-26T22:15:51.395939Z",
"iopub.status.idle": "2024-09-26T22:15:51.469049Z",
"shell.execute_reply": "2024-09-26T22:15:51.468779Z",
"shell.execute_reply.started": "2024-09-26T22:15:51.396530Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"8009fffffffffff <LatLngMultiPoly: [405]>\n",
"801dfffffffffff <LatLngMultiPoly: [405]>\n",
"8031fffffffffff <LatLngMultiPoly: [405]>\n",
"804dfffffffffff <LatLngMultiPoly: [405]>\n",
"8063fffffffffff <LatLngMultiPoly: [405]>\n",
"8075fffffffffff <LatLngMultiPoly: [405]>\n",
"807ffffffffffff <LatLngMultiPoly: [405]>\n",
"8091fffffffffff <LatLngMultiPoly: [405]>\n",
"80a7fffffffffff <LatLngMultiPoly: [405]>\n",
"80c3fffffffffff <LatLngMultiPoly: [405]>\n",
"80d7fffffffffff <LatLngMultiPoly: [405]>\n",
"80ebfffffffffff <LatLngMultiPoly: [405]>\n"
]
}
],
"source": [
"do_res(4)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "125061bc-ead8-4f43-93b0-44b8afa1b52a",
"metadata": {
"execution": {
"iopub.execute_input": "2024-09-26T22:15:51.660896Z",
"iopub.status.busy": "2024-09-26T22:15:51.660092Z",
"iopub.status.idle": "2024-09-26T22:15:52.028951Z",
"shell.execute_reply": "2024-09-26T22:15:52.028660Z",
"shell.execute_reply.started": "2024-09-26T22:15:51.660860Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"8009fffffffffff <LatLngMultiPoly: [1215/(4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4)], [20], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4]>\n",
"801dfffffffffff <LatLngMultiPoly: [1215/(4, 4, 4, 4, 4, 4, 4, 4, 10, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4)], [4], [4], [4], [4], [4], [4], [10], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4]>\n",
"8031fffffffffff <LatLngMultiPoly: [1215/(4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4)], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [20], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4]>\n",
"804dfffffffffff <LatLngMultiPoly: [4], [1215/(4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4)], [4], [4], [4], [4], [4], [20], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4]>\n",
"8063fffffffffff <LatLngMultiPoly: [1215/(4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4)], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [20], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4]>\n",
"8075fffffffffff <LatLngMultiPoly: [1215/(4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4)], [10/(10,)], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4]>\n",
"807ffffffffffff <LatLngMultiPoly: [1215/(4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4)], [20], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4]>\n",
"8091fffffffffff <LatLngMultiPoly: [1215/(4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4)], [20], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4]>\n",
"80a7fffffffffff <LatLngMultiPoly: [1215/(4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4)], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [10/(10,)], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4]>\n",
"80c3fffffffffff <LatLngMultiPoly: [1215/(4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4)], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [20], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4]>\n",
"80d7fffffffffff <LatLngMultiPoly: [1215/(4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4)], [4], [20], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4]>\n",
"80ebfffffffffff <LatLngMultiPoly: [1215/(4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4)], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [20], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4]>\n"
]
}
],
"source": [
"do_res(5)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "c2c3388a-460e-4e97-b7a8-13817b436003",
"metadata": {
"execution": {
"iopub.execute_input": "2024-09-26T22:15:52.029755Z",
"iopub.status.busy": "2024-09-26T22:15:52.029664Z",
"iopub.status.idle": "2024-09-26T22:15:53.622813Z",
"shell.execute_reply": "2024-09-26T22:15:53.622555Z",
"shell.execute_reply.started": "2024-09-26T22:15:52.029746Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"8009fffffffffff <LatLngMultiPoly: [3645]>\n",
"801dfffffffffff <LatLngMultiPoly: [3645]>\n",
"8031fffffffffff <LatLngMultiPoly: [3645]>\n",
"804dfffffffffff <LatLngMultiPoly: [3645]>\n",
"8063fffffffffff <LatLngMultiPoly: [3645]>\n",
"8075fffffffffff <LatLngMultiPoly: [3645]>\n",
"807ffffffffffff <LatLngMultiPoly: [3645]>\n",
"8091fffffffffff <LatLngMultiPoly: [3645]>\n",
"80a7fffffffffff <LatLngMultiPoly: [3645]>\n",
"80c3fffffffffff <LatLngMultiPoly: [3645]>\n",
"80d7fffffffffff <LatLngMultiPoly: [3645]>\n",
"80ebfffffffffff <LatLngMultiPoly: [3645]>\n"
]
}
],
"source": [
"do_res(6)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "f17cecd4-e667-4228-bcc7-243235d1a71a",
"metadata": {
"execution": {
"iopub.execute_input": "2024-09-26T22:15:53.623561Z",
"iopub.status.busy": "2024-09-26T22:15:53.623493Z",
"iopub.status.idle": "2024-09-26T22:15:55.444187Z",
"shell.execute_reply": "2024-09-26T22:15:55.443828Z",
"shell.execute_reply.started": "2024-09-26T22:15:53.623554Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"8009fffffffffff <LatLngMultiPoly: [10935], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4]>\n"
]
},
{
"ename": "ValueError",
"evalue": "Non-empty LatLngPoly loops need at least 3 points.",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[10], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mdo_res\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m7\u001b[39;49m\u001b[43m)\u001b[49m\n",
"Cell \u001b[0;32mIn[1], line 17\u001b[0m, in \u001b[0;36mdo_res\u001b[0;34m(res)\u001b[0m\n\u001b[1;32m 15\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mdo_res\u001b[39m(res):\n\u001b[1;32m 16\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m p \u001b[38;5;129;01min\u001b[39;00m h3\u001b[38;5;241m.\u001b[39mget_pentagons(\u001b[38;5;241m0\u001b[39m):\n\u001b[0;32m---> 17\u001b[0m \u001b[38;5;28mprint\u001b[39m(p, \u001b[43mlogical_poly\u001b[49m\u001b[43m(\u001b[49m\u001b[43mp\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mres\u001b[49m\u001b[43m)\u001b[49m)\n",
"Cell \u001b[0;32mIn[1], line 12\u001b[0m, in \u001b[0;36mlogical_poly\u001b[0;34m(cell, res)\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 5\u001b[0m \u001b[38;5;124;03mReturn the polygon representing the geometric area covered\u001b[39;00m\n\u001b[1;32m 6\u001b[0m \u001b[38;5;124;03mby the children of `cell` at resolution `res`.\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 9\u001b[0m \u001b[38;5;124;03mCurrently: Getting multipolygons with holes (seems like a bug), or just errors for malformed polygons.\u001b[39;00m\n\u001b[1;32m 10\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 11\u001b[0m kids \u001b[38;5;241m=\u001b[39m h3\u001b[38;5;241m.\u001b[39mcell_to_children(cell, res)\n\u001b[0;32m---> 12\u001b[0m mpoly \u001b[38;5;241m=\u001b[39m \u001b[43mh3\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcells_to_h3shape\u001b[49m\u001b[43m(\u001b[49m\u001b[43mkids\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtight\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m)\u001b[49m\n\u001b[1;32m 13\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m mpoly\n",
"File \u001b[0;32m~/work/2024-09-03_h3_compact_lookup/env/lib/python3.11/site-packages/h3/api/basic_str/__init__.py:477\u001b[0m, in \u001b[0;36mcells_to_h3shape\u001b[0;34m(cells, tight)\u001b[0m\n\u001b[1;32m 474\u001b[0m cells \u001b[38;5;241m=\u001b[39m _in_collection(cells)\n\u001b[1;32m 475\u001b[0m mpoly \u001b[38;5;241m=\u001b[39m _cy\u001b[38;5;241m.\u001b[39mcells_to_multi_polygon(cells)\n\u001b[0;32m--> 477\u001b[0m polys \u001b[38;5;241m=\u001b[39m \u001b[43m[\u001b[49m\u001b[43mLatLngPoly\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mpoly\u001b[49m\u001b[43m)\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mfor\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mpoly\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01min\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mmpoly\u001b[49m\u001b[43m]\u001b[49m\n\u001b[1;32m 478\u001b[0m out \u001b[38;5;241m=\u001b[39m LatLngMultiPoly(\u001b[38;5;241m*\u001b[39mpolys)\n\u001b[1;32m 480\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m tight \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(out) \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m1\u001b[39m:\n",
"File \u001b[0;32m~/work/2024-09-03_h3_compact_lookup/env/lib/python3.11/site-packages/h3/api/basic_str/__init__.py:477\u001b[0m, in \u001b[0;36m<listcomp>\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 474\u001b[0m cells \u001b[38;5;241m=\u001b[39m _in_collection(cells)\n\u001b[1;32m 475\u001b[0m mpoly \u001b[38;5;241m=\u001b[39m _cy\u001b[38;5;241m.\u001b[39mcells_to_multi_polygon(cells)\n\u001b[0;32m--> 477\u001b[0m polys \u001b[38;5;241m=\u001b[39m [\u001b[43mLatLngPoly\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mpoly\u001b[49m\u001b[43m)\u001b[49m \u001b[38;5;28;01mfor\u001b[39;00m poly \u001b[38;5;129;01min\u001b[39;00m mpoly]\n\u001b[1;32m 478\u001b[0m out \u001b[38;5;241m=\u001b[39m LatLngMultiPoly(\u001b[38;5;241m*\u001b[39mpolys)\n\u001b[1;32m 480\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m tight \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(out) \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m1\u001b[39m:\n",
"File \u001b[0;32m~/work/2024-09-03_h3_compact_lookup/env/lib/python3.11/site-packages/h3/_h3shape.py:58\u001b[0m, in \u001b[0;36mLatLngPoly.__init__\u001b[0;34m(self, outer, *holes)\u001b[0m\n\u001b[1;32m 56\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m loop \u001b[38;5;129;01min\u001b[39;00m loops:\n\u001b[1;32m 57\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(loop) \u001b[38;5;129;01min\u001b[39;00m (\u001b[38;5;241m1\u001b[39m, \u001b[38;5;241m2\u001b[39m):\n\u001b[0;32m---> 58\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mNon-empty LatLngPoly loops need at least 3 points.\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m 60\u001b[0m point_dimensions \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mset\u001b[39m(\u001b[38;5;28mmap\u001b[39m(\u001b[38;5;28mlen\u001b[39m, loop))\n\u001b[1;32m 61\u001b[0m \u001b[38;5;66;03m# empty set is possible for empty polygons, so we check if a subset\u001b[39;00m\n",
"\u001b[0;31mValueError\u001b[0m: Non-empty LatLngPoly loops need at least 3 points."
]
}
],
"source": [
"do_res(7)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "8cc7a233-9a2f-4b0b-b8c8-a8240f60b92c",
"metadata": {
"execution": {
"iopub.execute_input": "2024-09-26T22:16:02.414050Z",
"iopub.status.busy": "2024-09-26T22:16:02.413549Z",
"iopub.status.idle": "2024-09-26T22:17:18.825815Z",
"shell.execute_reply": "2024-09-26T22:17:18.825544Z",
"shell.execute_reply.started": "2024-09-26T22:16:02.414016Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"8009fffffffffff <LatLngMultiPoly: [32805]>\n",
"801dfffffffffff <LatLngMultiPoly: [32805]>\n",
"8031fffffffffff <LatLngMultiPoly: [32805]>\n",
"804dfffffffffff <LatLngMultiPoly: [32805]>\n",
"8063fffffffffff <LatLngMultiPoly: [32805]>\n",
"8075fffffffffff <LatLngMultiPoly: [32805]>\n",
"807ffffffffffff <LatLngMultiPoly: [32805]>\n",
"8091fffffffffff <LatLngMultiPoly: [32805]>\n",
"80a7fffffffffff <LatLngMultiPoly: [32805]>\n",
"80c3fffffffffff <LatLngMultiPoly: [32805]>\n",
"80d7fffffffffff <LatLngMultiPoly: [32805]>\n",
"80ebfffffffffff <LatLngMultiPoly: [32805]>\n"
]
}
],
"source": [
"do_res(8)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ab4a0073-6e90-4653-ab4c-da65bac06a1e",
"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.8"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment