Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

35 - Don't create empty files if there are 0 features #39

Merged
merged 2 commits into from
Oct 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions open_buildings/download_buildings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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...")
Expand Down Expand Up @@ -216,6 +222,12 @@ 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 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
if not generate_sql:
print_timestamped_message(f"Writing to {dst}...")

Expand Down Expand Up @@ -251,12 +263,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)
Expand Down