From 10a26ed3b6521615cfe1037541c394632c37f2a8 Mon Sep 17 00:00:00 2001 From: Darren Wiens Date: Tue, 10 Oct 2023 16:38:37 -0700 Subject: [PATCH 1/2] do not create 0 feature files --- open_buildings/download_buildings.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/open_buildings/download_buildings.py b/open_buildings/download_buildings.py index 6489787..28d98f9 100644 --- a/open_buildings/download_buildings.py +++ b/open_buildings/download_buildings.py @@ -137,6 +137,12 @@ def print_timestamped_message(message): current_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") click.echo(f"[{current_time}] {message}") + def print_elapsed_time(start_time): + end_time = time.time() + + elapsed_time = end_time - start_time + print_timestamped_message(f"Operation took {elapsed_time:.2f} seconds.") + start_time = time.time() if verbose: print_timestamped_message("Reading GeoJSON input...") @@ -216,6 +222,10 @@ def print_timestamped_message(message): count = conn.execute("SELECT COUNT(*) FROM buildings;").fetchone()[0] print_timestamped_message(f"Downloaded {count} features into DuckDB.") + if count == 0: + if verbose: + print_elapsed_time(start_time) + return if not generate_sql: print_timestamped_message(f"Writing to {dst}...") @@ -251,12 +261,9 @@ def print_timestamped_message(message): 'flatgeobuf': 'FlatGeobuf' } conn.execute(f"COPY buildings TO '{dst}' WITH (FORMAT GDAL, DRIVER '{gdal_format[format]}');") - end_time = time.time() - + if verbose: - elapsed_time = end_time - start_time - print_timestamped_message(f"Operation took {elapsed_time:.2f} seconds.") - + print_elapsed_time(start_time) # Registering the commands with the main group cli.add_command(quadkey) From 9f48c998a4e7d3d5c09acecc0895facd3a2ab7bc Mon Sep 17 00:00:00 2001 From: Chris Holmes Date: Tue, 10 Oct 2023 21:56:46 -0700 Subject: [PATCH 2/2] Update download_buildings.py --- open_buildings/download_buildings.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/open_buildings/download_buildings.py b/open_buildings/download_buildings.py index 28d98f9..c32ca79 100644 --- a/open_buildings/download_buildings.py +++ b/open_buildings/download_buildings.py @@ -223,6 +223,8 @@ def print_elapsed_time(start_time): print_timestamped_message(f"Downloaded {count} features into DuckDB.") if count == 0: + if country_iso is not None: + print_timestamped_message(f"If you are sure that your GeoJSON should have buildings then check to be sure that {country_iso} is the right code.") if verbose: print_elapsed_time(start_time) return