opengeos / open-buildings

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

Install spatial extension if not installed #38

Closed darrenwiens closed 8 months ago

darrenwiens commented 8 months ago

Environment Information

Description

Just getting started with a fresh duckdb install, get_buildings fails because we try to load the spatial extension even if it has not been previously installed.

What I Did

pip install -e .
ob tools get_buildings 1.json my-buildings.geojson --country_iso RW

To Replicate

  1. Remove the spatial extension by removing the relevant files within ~/duckdb/extensions/...
  2. Try running get_buildings
darrenwiens commented 8 months ago

All of this is to say, if you want a proposed fix for it, I can make a quick PR. :smiley:

cholmes commented 8 months ago

So I think the easiest fix is probably just call 'install spatial' and 'load spatial' every time. Thanks for catching this, and makes sense that it wouldn't always be there.

I checked the extensions overview, and looks like you can use FROM duckdb_extensions(); to see the load status, but I've seen no downside to just calling 'install'.

Looking through the docs it does say 'If you are using the Python API client, you can install and load them with the install_extension(name: str) and load_extension(name: str) methods.' Maybe that's a slightly better way to do it? But if conn.execute("install spatial;load spatial;") (or break into two conn.executes) works then that's probably fine.

cholmes commented 8 months ago

Thanks for catching this, I assume it'll hit a number of people. Probably worth cutting a release when this gets in. If you can do a fix that'd be great, I gotta get to bed now.