-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from wri/feature/overture_building
Feature/overture building
- Loading branch information
Showing
6 changed files
with
223 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -163,3 +163,6 @@ cython_debug/ | |
/keys | ||
keys/ | ||
wri-gee-358d958ce7c6.json | ||
|
||
# data | ||
/data |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import geopandas as gpd | ||
import subprocess | ||
from io import StringIO | ||
|
||
from .layer import Layer | ||
|
||
|
||
class OvertureBuildings(Layer): | ||
def __init__(self, **kwargs): | ||
super().__init__(**kwargs) | ||
|
||
def get_data(self, bbox): | ||
bbox_str = ','.join(map(str, bbox)) | ||
|
||
command = [ | ||
"overturemaps", "download", | ||
"--bbox="+bbox_str, | ||
"-f", "geojson", | ||
"--type=building" | ||
] | ||
|
||
result = subprocess.run(command, capture_output=True, text=True) | ||
|
||
if result.returncode == 0: | ||
geojson_data = result.stdout | ||
overture_buildings = gpd.read_file(StringIO(geojson_data)) | ||
else: | ||
print("Error occurred:", result.stderr) | ||
|
||
return overture_buildings |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,3 +25,4 @@ dependencies: | |
- pip: | ||
- cartoframes==1.2.5 | ||
- git+https://github.com/isciences/exactextract | ||
- overturemaps==0.6.0 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Setup" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import os\n", | ||
"import geopandas as gpd" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# # update the wd path to be able to laod the module\n", | ||
"os.chdir('../..')\n", | ||
"os.getcwd()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Get Area of Interest" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# load boundary from s3\n", | ||
"boundary_path = 'https://cities-indicators.s3.eu-west-3.amazonaws.com/data/boundaries/boundary-BRA-Salvador-ADM4union.geojson'\n", | ||
"city_gdf = gpd.read_file(boundary_path, driver='GeoJSON')\n", | ||
"city_gdf.head()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Get area in sqare km\n", | ||
"city_gdf.to_crs(epsg=3857).area / 10**6" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Get Layer" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from city_metrix.layers import OvertureBuildings" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"overture_buildings = OvertureBuildings().get_data(city_gdf.total_bounds)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Save to file" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 30, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/html": [ | ||
"\n", | ||
" <style>\n", | ||
" .geemap-dark {\n", | ||
" --jp-widgets-color: white;\n", | ||
" --jp-widgets-label-color: white;\n", | ||
" --jp-ui-font-color1: white;\n", | ||
" --jp-layout-color2: #454545;\n", | ||
" background-color: #383838;\n", | ||
" }\n", | ||
"\n", | ||
" .geemap-dark .jupyter-button {\n", | ||
" --jp-layout-color3: #383838;\n", | ||
" }\n", | ||
"\n", | ||
" .geemap-colab {\n", | ||
" background-color: var(--colab-primary-surface-color, white);\n", | ||
" }\n", | ||
"\n", | ||
" .geemap-colab .jupyter-button {\n", | ||
" --jp-layout-color3: var(--colab-primary-surface-color, white);\n", | ||
" }\n", | ||
" </style>\n", | ||
" " | ||
], | ||
"text/plain": [ | ||
"<IPython.core.display.HTML object>" | ||
] | ||
}, | ||
"metadata": {}, | ||
"output_type": "display_data" | ||
} | ||
], | ||
"source": [ | ||
"# Create a data folder if it does not exist\n", | ||
"if not os.path.exists('data'):\n", | ||
" os.makedirs('data')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Save the overture_buildings to a geoparquet file\n", | ||
"# This is much quicker and creates a significantly smaller file compared to geojson\n", | ||
"overture_buildings.to_parquet('data/overture_buildings.geoparquet')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Save the overture_buildings to a geojson file\n", | ||
"overture_buildings.to_file('data/overture_buildings.geojson', driver='GeoJSON')" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "cities-cif", | ||
"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.12" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
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