-
Notifications
You must be signed in to change notification settings - Fork 112
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
Add GeoPackage support #456
Conversation
@caspervdw could you try this version please? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! I'll now proceed with the testing
geoalchemy2/admin/dialects/sqlite.py
Outdated
if is_GeoPkg: | ||
if not dbapi_conn.execute("SELECT CheckGeoPackageMetaData();").fetchone()[0]: | ||
# This only works on the main database | ||
dbapi_conn.execute("SELECT gpkgCreateBaseTables();") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know it was already there: but the InitSpatialMetadata()
really takes a ridiculous amount of time. It can be mitigated by doing InitSpatialMetadata(1)
, and even more by calling "PRAGMA journal_mode = MEMORY"
before, but still, I think it is too heavy to do by default.
Maybe it is good to split it out in an "init_spatialite" and "init_geopackage"
function, for the user to call.
Next to that, as InitSpatialMetadata()
populates the srs table, I think it is good to try to populate the geopackage equivalent here as well. Not sure how though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree it's super long, that's why I use already initialized DBs in the tests.
Using InitSpatialMetadata(1)
could be interesting, though it would be a breaking change (or we could just let the use pass a parameter to load_spatialite
).
Anyway, I agree it should be consistent between SpatiaLite and gpkg, so I will see what's the best option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the end I added the possibility to pass an init_mode
to the function, so it is possible to initialize the table with no SRID and then add the relevant ones manually. Unfortunately, it is not possible to pass an argument to the sqlalchemy.event.listen
function, so if someone wants to use this argument he has to either create a new function that calls load_spatialite
with an hard-coded init_mode
or call load_spatialite
manually after the connection is created.
geoalchemy2/admin/dialects/sqlite.py
Outdated
VALUES ( | ||
'{}', | ||
'features', | ||
NULL, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- QGis and fiona require an identifier; as every table can only have 1 geometry column I suggest putting the table name over here.
- The desciption should be an empty string, not NULL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, let's make it compatible with QGIS, it makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made these changes and now it seems very close to a GeoPackage created by QGIS. Does it look good to you?
@adrien-berchet , I tested it and there seems to be a working geopackage generated. Some issues I could solve at my side One big suggestion is making this a different dialect; it seems logical looking at the code, and the "auto-discovery" gave some issues for me. For the rest it is looking good! |
Hi @caspervdw |
07b4ffc
to
945f2d6
Compare
@adrien-berchet I am 👍 on merging this. Two observations during testing: Alembic compatibility To make this work with alembic, you should register it as a dialect:
ogr-info complains If I run ogr-info on a gpkg generated using this PR I get:
Looking at the gpkg spec (section 1.1.1.1.3) there is indeed no mention of a VARCHAR. It should be These two are no blockers for us however, so, great work! |
In class GeoPackageImpl(SQLiteImpl):
"""Class to copy the Alembic implementation from SQLite to GeoPackage."""
__dialect__ = "geopackage" Isn't it enough? Did you import
I'm not able to reproduce this, do you know to which table and field this warning is related?
Great, thanks! |
@caspervdw I performed a few tests with Alembic and everything seems to work in my case so I don't know what's going on on your side. I still think it's because you did not import |
Sorry I indeed didn’t import the helpers. So that’s ok then! For ogr-info; I used the command line tool on Ubuntu 22.04. It is GDAL 3.4.1 . |
Ok, no problem :)
I'm still not able to reproduce this issue locally but there is only one place where I create |
Very sorry, I tried to reproduce, and it appeared I had a
That's all right, you can do it with a
|
Ahah ok, no problem.
Exactly. I improve the docs for this in #457 to be more complete. |
Solves #410
This PR adds support of GeoPackage using Spatialite.
Main things to check: