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

Geopackage support #55

Merged
merged 50 commits into from
Feb 29, 2024
Merged

Geopackage support #55

merged 50 commits into from
Feb 29, 2024

Conversation

margrietpalm
Copy link
Contributor

@margrietpalm margrietpalm commented Feb 8, 2024

Support geopackage sqlite dialect:

  • Support reading geopackage files (.gpkg) files, note that per specification geopackes are required to have this extension
  • Add functionality to convert spatialite to geopackage: schema.upgrade(convert_to_geopackage=True)
  • Run all tests using the latest schema with geopackage instead of spatialiate

Note that the default settings is schema.upgrade(convert_to_geopackage=False). Hence without any changes to threedi-api the geopackage will not be used.

Note2 geopackage conversion requires ogr2ogr >= 3.4, which is part of gdal-bin. If ogr2ogr is not properly installed or a too old version is present, the conversion is not done and a warning is raised.

Local tests can be done by installing threedi-schema==0.219.2.dev1

margrietpalm and others added 28 commits February 2, 2024 07:48
* Apply pre-conversion modifications to temporary database
* Add docstring
@margrietpalm margrietpalm force-pushed the margriet_45_geopackage branch from 15a5144 to 21b0e85 Compare February 12, 2024 13:27
@margrietpalm
Copy link
Contributor Author

Tests falen voor oude python en ubuntu

  • Falende tests:
    • Ubuntu 20.04:
    • sqlite 3.31.1 2020-01-27 19:55:54 3bfa9cc97da10598521b342961df8f5f68c7388fa117345eeb516eaa837balt1
    • GDAL 3.0.4, released 2020/01/28
    • python 3.8 of 3.9
    • sqlalchemy==1.4.44 alembic==1.8.* geoalchemy2==0.14.0
  • Werkende tests:
    • Ubuntu 22.04
    • sqlite 3.37.2 2022-01-06 13:25:41 872ba256cbf61d9290b571c0e6d82a20c224ca3ad82971edc46b29818d5dalt1
    • GDAL 3.4.1, released 2021/12/27
    • Python
      • 3.10 + sqlalchemy==1.4.44 alembic==1.8.* geoalchemy2==0.14.0
      • 3.11 + sqlalchemy==2.0.24 alembic==1.13.1 geoalchemy2==0.14.3
      • 3.12 + sqlalchemy==2.0.* alembic==1.13.* geoalchemy2==0.14.*

Gerelateerde problemen (allemaal qgis):

@margrietpalm margrietpalm force-pushed the margriet_45_geopackage branch from 21bf28c to fb892f0 Compare February 26, 2024 10:50
Copy link
Contributor

@jpprins1 jpprins1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall: looks very good!

I've added some comments with some (minor) things to address/look at.

.github/workflows/test.yml Outdated Show resolved Hide resolved
threedi_schema/application/schema.py Show resolved Hide resolved
threedi_schema/application/schema.py Outdated Show resolved Hide resolved
threedi_schema/application/schema.py Outdated Show resolved Hide resolved
class ThreediDatabase:
def __init__(self, path, echo=False):
self.path = path
self._path = path
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self._path = path
self.path = path if isinstance(path, Path) else Path(path)

Is shorter and allows to drop the path property and @path.setter property

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks the current working of _path and path. I introduced the setter to control the type of ThreediDatabase.path because it is set from multiple libraries, sometimes with a Path and sometimes with a string. With this implementation self._path is always a string and self.path will return a path; and setting ThreediDatabase.path will ensure that both self._path and self.path are set properly.

It would be nicer to just have self.path and make is a Path (and add type hints). However, that also involves threedi-api; and I feel that this PR is complex enough as it is.

Note that self._path is now also cast to a string in the constructor 9fd2fe6.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I saw in the test that a Path instance was passed as parameter to ThreediDatabase(xxxx) # constructor
My suggestion also works if a string is passed. It's just converted into a Path.

The only thing that is not backwards-compatible is:

  1. db = ThreediDatabase("/tmp/blaat.gpkg") and directly getting db.path as a string. (note: same new behaviour as your property introduced)
  2. db = ThreediDatabase("/tmp/no_really_the.gpkg") ; db.path = "/tmp/the_real.gpkg". This is going to crash, but can be fixed by "path = self.path if isinstance(self.path, Path) else Path(self.path)" in the get_engine method.

Maybe 2 is actually the better solution. Convert it there to a Path instance if it not already the case:

path = self.path if isinstance(self.path, Path) else Path(self.path)

The property, setter and self._path can all be dropped and self.path stays exactly the same as what the user has put into the class constructor. And changing it after initialisation also works.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modified in d5f8545. Note that using a Path in get_engine is necessary to handle the in-memory sqlite. This is because str(Path("")) and str("") don't match, but Path("") and Path(str("")) do.

threedi_schema/application/threedi_database.py Outdated Show resolved Hide resolved
threedi_schema/tests/test_gpkg.py Show resolved Hide resolved
Copy link
Contributor

@jpprins1 jpprins1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@margrietpalm margrietpalm merged commit f661627 into master Feb 29, 2024
6 checks passed
@margrietpalm margrietpalm deleted the margriet_45_geopackage branch February 29, 2024 10:06
@margrietpalm margrietpalm restored the margriet_45_geopackage branch March 12, 2024 09:25
@daanvaningen daanvaningen deleted the margriet_45_geopackage branch March 12, 2024 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants