Last active
March 24, 2023 01:03
-
-
Save akhenakh/3cce87fe139096259e348ad3a4b9d9f2 to your computer and use it in GitHub Desktop.
Go Jupyter kernel demonstrate how to use h3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"id": "c1a44309-44e0-4492-9c90-f899b1d1bd39", | |
"metadata": {}, | |
"source": [ | |
"## Jupyter Notebook with Go, h3 & SVG display of GeoJSON\n", | |
"\n", | |
"Install a Go kernel: https://github.com/janpfeifer/gonb\n", | |
"\n", | |
"### Note For Mac\n", | |
"\n", | |
"After running `gonb --install` you need to move it to the proper directoy\n", | |
"\n", | |
"```sh\n", | |
"mv /Users/${USER}/.local/share/jupyter/kernels/gonb /Users/${USER}/Library/Jupyter/kernels/\n", | |
"```" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 31, | |
"id": "a9e71674-2fc0-4feb-ad7f-21631af35c17", | |
"metadata": { | |
"tags": [] | |
}, | |
"outputs": [], | |
"source": [ | |
"import \"fmt\"" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 32, | |
"id": "d3b6f840-4fd9-478b-a7b6-a13a45dfbad7", | |
"metadata": { | |
"tags": [] | |
}, | |
"outputs": [], | |
"source": [ | |
"import \"github.com/uber/h3-go/v4\"" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 33, | |
"id": "d1466d78-21ca-4423-a0a6-2731c7fef9f3", | |
"metadata": { | |
"tags": [] | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"8928308280fffff" | |
] | |
} | |
], | |
"source": [ | |
"%%\n", | |
"ll := h3.NewLatLng(37.775938728915946, -122.41795063018799)\n", | |
"resolution := 9 \n", | |
"cell := h3.LatLngToCell(ll, resolution)\n", | |
"fmt.Printf(\"%s\", cell)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 34, | |
"id": "161a684f-1dc7-450f-94d8-fee606ae3b84", | |
"metadata": { | |
"tags": [] | |
}, | |
"outputs": [], | |
"source": [ | |
"import svg \"github.com/whosonfirst/go-geojson-svg\"" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 35, | |
"id": "2cee3ada-5a5f-4f58-98e9-62da1baacfba", | |
"metadata": { | |
"tags": [] | |
}, | |
"outputs": [], | |
"source": [ | |
"import \"github.com/janpfeifer/gonb/gonbui\"" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 36, | |
"id": "195ca2b6-c876-48e2-8a7a-1f12f2623fbc", | |
"metadata": { | |
"tags": [] | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div><svg width=\"400.000000\" height=\"400.000000\"><path d=\"M0.000000 271.651090,372.585670 0.000000,122.118380 400.000000,0.000000 271.651090 Z\"/></svg></div>" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"%%\n", | |
"s := svg.New()\n", | |
"if err := s.AddGeometry(`{\"type\": \"Polygon\", \"coordinates\": [[[10.4,20.5], [40.3,42.3], [20.2, 10.2], [10.4,20.5]]]}`); err != nil {\n", | |
" log.Fatalf(\"unexpected error %v\", err)\n", | |
"}\n", | |
"gonbui.DisplaySVG(s.Draw(400, 400))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "63d623ac-7aa5-443c-a1d1-d7e80e2cac8d", | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Go (gonb)", | |
"language": "go", | |
"name": "gonb" | |
}, | |
"language_info": { | |
"codemirror_mode": "", | |
"file_extension": ".go", | |
"mimetype": "", | |
"name": "go", | |
"nbconvert_exporter": "", | |
"pygments_lexer": "", | |
"version": "go1.20.2" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment