|
6 | 6 | import pandas as pd |
7 | 7 | import os |
8 | 8 | from ada_tools.align_raster import align, translate |
| 9 | +from azure.storage.blob import BlobServiceClient |
9 | 10 | from tqdm import tqdm |
10 | 11 | from shapely.geometry import Polygon |
11 | 12 |
|
| 13 | + |
| 14 | +def download_blob(container, blobpath, filepath, secret): |
| 15 | + blob_service_client = BlobServiceClient.from_connection_string(secret) |
| 16 | + blob_client = blob_service_client.get_blob_client(container=container, blob=blobpath) |
| 17 | + with open(filepath, "wb") as download_file: |
| 18 | + download_file.write(blob_client.download_blob().readall()) |
| 19 | + |
| 20 | + |
12 | 21 | def get_extent(raster: str) -> gpd.GeoDataFrame: |
13 | 22 | """ |
14 | 23 | get extent of raster, return it as geodataframe |
@@ -43,24 +52,28 @@ def get_extent(raster: str) -> gpd.GeoDataFrame: |
43 | 52 |
|
44 | 53 |
|
45 | 54 | @click.command() |
| 55 | +@click.option('--ext', default='extents.geojson', help='input buildings extents') |
46 | 56 | @click.option('--builds', default='input', help='input buildings directory') |
| 57 | +@click.option('--container', help='blob storage container') |
| 58 | +@click.option('--secret', help='blob storage secret') |
47 | 59 | @click.option('--raster', default='input', help='input raster') |
48 | 60 | @click.option('--refbuilds', default='buildings.geojson', help='input reference buildings') |
49 | 61 | @click.option('--dest', default='buildings.geojson', help='output') |
50 | | -def main(builds, raster, refbuilds, dest): |
| 62 | +def main(ext, builds, container, secret, raster, refbuilds, dest): |
51 | 63 | """ |
52 | 64 | check if builds cover raster, if yes align with refbuilds and save as dest |
53 | 65 | """ |
54 | 66 | build_target = gpd.GeoDataFrame() |
55 | 67 | gdf_raster = get_extent(raster) |
56 | 68 | xmin, ymin, xmax, ymax = gdf_raster.total_bounds |
57 | | - gdf_builds_extents = gpd.read_file(os.path.join(builds, "extents.geojson")) |
| 69 | + gdf_builds_extents = gpd.read_file(ext) |
58 | 70 | gdf_builds_extents = gdf_builds_extents.rename(columns={'file': 'alternative_buildings_file'}) |
59 | 71 | res_intersection = gpd.overlay(gdf_raster, gdf_builds_extents, how='intersection') |
60 | 72 | if not res_intersection.empty: |
61 | 73 | for ix, row in res_intersection.iterrows(): |
62 | 74 | build_file = row["alternative_buildings_file"] |
63 | | - gdf_build = gpd.read_file(os.path.join(builds, build_file)) |
| 75 | + download_blob(container, os.path.join(builds, build_file), build_file, secret) |
| 76 | + gdf_build = gpd.read_file(build_file) |
64 | 77 | gdf_build_in_raster = gdf_build.cx[xmin:xmax, ymin:ymax] |
65 | 78 | if not gdf_build_in_raster.empty: |
66 | 79 | build_target = build_target.append(gdf_build_in_raster, ignore_index=True) |
|
0 commit comments