Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add download buildings example #11

Merged
merged 2 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 141 additions & 0 deletions docs/examples/download_buildings.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# %pip install open-buildings"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Iimport libraries"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import leafmap.foliumap as leafmap\n",
"import geopandas as gpd"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Read the tile geojson."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"url = 'https://sites.research.google/open-buildings/tiles.geojson'\n",
"gdf = gpd.read_file(url)\n",
"gdf.sort_values(by='size_mb', ascending=True, inplace=True)\n",
"gdf.head()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(f\"Number of tiles: {len(gdf)}\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"m = leafmap.Map()\n",
"m.add_gdf(gdf, layer_name=\"Open Buildings\")\n",
"m"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Get the tile URLs."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"urls = gdf['tile_url'].tolist()\n",
"urls[:5]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Specify the output directory."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"out_dir = os.path.expanduser('~/Downloads/')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Download all the tiles might take a while. Let's download only the first 10 tiles. "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"leafmap.download_files(urls[:10], out_dir=out_dir)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "geo",
"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.10.9"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
4 changes: 2 additions & 2 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ plugins:
- mkdocs-jupyter:
include_source: True
ignore_h1_titles: True
execute: True
execute: true
allow_errors: false
ignore: ["conf.py"]
execute_ignore: ["*ignore.ipynb"]
Expand Down Expand Up @@ -80,7 +80,7 @@ nav:
- Changelog: changelog.md
- Report Issues: https://github.com/cholmes/open-buildings/issues
- Examples:
- examples/intro.ipynb
- examples/download_buildings.ipynb
- API Reference:
- open_buildings module: open_buildings.md
- common module: common.md
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ pandas
geopandas
shapely
openlocationcode
tabulate
tabulate
leafmap
1 change: 1 addition & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ coverage
Sphinx
twine
Click
codespell