From dc0774360d2666bcff5b97ee81e3d8c89ba40b98 Mon Sep 17 00:00:00 2001 From: mtravis Date: Mon, 16 Oct 2023 14:10:22 +0100 Subject: [PATCH] added geocoding function --- open_buildings/download_buildings.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/open_buildings/download_buildings.py b/open_buildings/download_buildings.py index 610161d..997c980 100644 --- a/open_buildings/download_buildings.py +++ b/open_buildings/download_buildings.py @@ -1,7 +1,7 @@ import json import click from math import tan, cos, log, pi -from shapely.geometry import shape +from shapely.geometry import shape, box from typing import Dict, Any, Union import mercantile import duckdb @@ -15,6 +15,7 @@ import subprocess from shapely import wkb import shutil +import osmnx from open_buildings.settings import Source, Format, settings @@ -43,6 +44,11 @@ def geojson_to_wkt(data: dict) -> str: geometry = shape(data['geometry']) return geometry.wkt +def geocode_to_wkt(data: str): + location = ox.geocode_to_gdf(data) + wkt = box(*location.total_bounds) + return wkt + def quadkey_to_geojson(quadkey: str) -> dict: # Convert the quadkey to tile coordinates tile = mercantile.quadkey_to_tile(quadkey)