Skip to content

Commit

Permalink
update requirements, add blob download
Browse files Browse the repository at this point in the history
  • Loading branch information
jmargutt committed Feb 9, 2022
1 parent dbe3b12 commit 9b0a3a2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
6 changes: 3 additions & 3 deletions abd_model/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ numpy==1.19.1
osmium==3.0.1
Pillow==8.3.2
psycopg2-binary==2.8.5
rasterio==1.1.5
# rasterio==1.1.5
scikit-build==0.11.1
Shapely>=1.7.0
supermercado==0.1.1
toml==0.10.1
torch==1.6.0
torchvision==0.7.0
# torch==1.6.0
# torchvision==0.7.0
tqdm==4.48.2
webcolors==1.11.1
1 change: 1 addition & 0 deletions ada_tools/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# This file is autogenerated by pip-compile
azure-storage-blob==12.8.1
affine==2.3.0 # via ada_tools (setup.py), rasterio
attrs==19.3.0 # via ada_tools (setup.py), fiona, rasterio
beautifulsoup4==4.9.1 # via ada_tools (setup.py), bs4
Expand Down
19 changes: 16 additions & 3 deletions ada_tools/src/ada_tools/check_alternative_buildings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,18 @@
import pandas as pd
import os
from ada_tools.align_raster import align, translate
from azure.storage.blob import BlobServiceClient
from tqdm import tqdm
from shapely.geometry import Polygon


def download_blob(container, blobpath, filepath, secret):
blob_service_client = BlobServiceClient.from_connection_string(secret)
blob_client = blob_service_client.get_blob_client(container=container, blob=blobpath)
with open(filepath, "wb") as download_file:
download_file.write(blob_client.download_blob().readall())


def get_extent(raster: str) -> gpd.GeoDataFrame:
"""
get extent of raster, return it as geodataframe
Expand Down Expand Up @@ -43,24 +52,28 @@ def get_extent(raster: str) -> gpd.GeoDataFrame:


@click.command()
@click.option('--ext', default='extents.geojson', help='input buildings extents')
@click.option('--builds', default='input', help='input buildings directory')
@click.option('--container', help='blob storage container')
@click.option('--secret', help='blob storage secret')
@click.option('--raster', default='input', help='input raster')
@click.option('--refbuilds', default='buildings.geojson', help='input reference buildings')
@click.option('--dest', default='buildings.geojson', help='output')
def main(builds, raster, refbuilds, dest):
def main(ext, builds, container, secret, raster, refbuilds, dest):
"""
check if builds cover raster, if yes align with refbuilds and save as dest
"""
build_target = gpd.GeoDataFrame()
gdf_raster = get_extent(raster)
xmin, ymin, xmax, ymax = gdf_raster.total_bounds
gdf_builds_extents = gpd.read_file(os.path.join(builds, "extents.geojson"))
gdf_builds_extents = gpd.read_file(ext)
gdf_builds_extents = gdf_builds_extents.rename(columns={'file': 'alternative_buildings_file'})
res_intersection = gpd.overlay(gdf_raster, gdf_builds_extents, how='intersection')
if not res_intersection.empty:
for ix, row in res_intersection.iterrows():
build_file = row["alternative_buildings_file"]
gdf_build = gpd.read_file(os.path.join(builds, build_file))
download_blob(container, os.path.join(builds, build_file), build_file, secret)
gdf_build = gpd.read_file(build_file)
gdf_build_in_raster = gdf_build.cx[xmin:xmax, ymin:ymax]
if not gdf_build_in_raster.empty:
build_target = build_target.append(gdf_build_in_raster, ignore_index=True)
Expand Down

0 comments on commit 9b0a3a2

Please sign in to comment.