opengeos / open-buildings

Tools for working with open building datasets
https://opengeos.github.io/open-buildings
Other
124 stars 17 forks source link

install spatial extension if not installed #41

Closed darrenwiens closed 11 months ago

darrenwiens commented 11 months ago

Resolves #38

In this PR, we attempt to load the spatial duckdb extension. If it fails to load because it has not been installed, install it, then load the extension.

felix-schott commented 11 months ago

A slightly more elegant solution would be this:

spatial_extension_query = conn.execute("SELECT * FROM duckdb_extensions() WHERE installed IS TRUE AND extension_name = 'spatial';").fetchone()
if spatial_extension_query is None:
    conn.execute("INSTALL spatial;")
conn.execute("LOAD spatial;")

I haven't checked but I imagine duckdb.duckdb.IOException can also indicate failure that isn't caused by the issue that we're facing here, so explicitly checking whether the extension is installed is better than try-except.

darrenwiens commented 11 months ago

@felix-schott Sure, that works for me. Thanks!