Created
March 12, 2019 06:04
-
-
Save Kirill888/4ce2f64413e660d1638afa23eede6eb0 to your computer and use it in GitHub Desktop.
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", | |
"metadata": {}, | |
"source": [ | |
"# Introduction\n", | |
"\n", | |
"GeoJSON extention provides a convenient way to display spatial data in a Jupyter notebook\n", | |
"\n", | |
"- https://github.com/jupyterlab/jupyter-renderers/tree/master/packages/geojson-extension\n", | |
"\n", | |
"`datacube.utils.geometry.GeoBox` is the main class used within datacube for describing footprints. By default it displays itself in textual form:" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"GeoBox(4000, 4000, Affine(25.0, 0.0, 1600000.0,\n", | |
" 0.0, -25.0, -3900000.0), EPSG:3577)" | |
] | |
}, | |
"execution_count": 1, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"from datacube.testutils.geom import AlbersGS\n", | |
"AlbersGS.tile_geobox((16, -40))" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"---------------------------------\n", | |
"We are going to monkey patch GeoBox class to use `GeoJSON` extention for display in the notebook, for that we define class method `_ipython_display_` that uses `GeoJSON` extension to render a map." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"from IPython.display import GeoJSON\n", | |
"from datacube.utils.geometry import GeoBox\n", | |
"GeoBox._ipython_display_ = lambda self: GeoJSON(self.geographic_extent.json)._ipython_display_()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"application/geo+json": { | |
"coordinates": [ | |
[ | |
[ | |
149.58260157828911, | |
-34.70891190784338 | |
], | |
[ | |
149.73417611149185, | |
-35.59955674769118 | |
], | |
[ | |
150.82704408569805, | |
-35.47120045856265 | |
], | |
[ | |
150.66638928114975, | |
-34.581923864170214 | |
], | |
[ | |
149.58260157828911, | |
-34.70891190784338 | |
] | |
] | |
], | |
"type": "Polygon" | |
}, | |
"text/plain": [ | |
"<IPython.display.GeoJSON object>" | |
] | |
}, | |
"metadata": { | |
"application/geo+json": { | |
"expanded": false, | |
"root": "root" | |
} | |
}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"AlbersGS.tile_geobox((16, -40))" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"------------------------------------\n", | |
"You can still view textual representation by adding extra `,` at the end of the line:" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"(GeoBox(4000, 4000, Affine(25.0, 0.0, 1600000.0,\n", | |
" 0.0, -25.0, -3900000.0), EPSG:3577),)" | |
] | |
}, | |
"execution_count": 4, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"AlbersGS.tile_geobox((16, -40))," | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"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.6.7" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks something like this: