Skip to content

Commit

Permalink
Added download buildings example
Browse files Browse the repository at this point in the history
Add download buildings example
  • Loading branch information
giswqs authored Jul 26, 2023
2 parents ae857e7 + 7e5f5dd commit 01391a4
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 3 deletions.
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

0 comments on commit 01391a4

Please sign in to comment.