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

Add option to remove layer from repository #18

Closed
volaya opened this issue Oct 5, 2021 · 5 comments
Closed

Add option to remove layer from repository #18

volaya opened this issue Oct 5, 2021 · 5 comments

Comments

@volaya
Copy link
Contributor

volaya commented Oct 5, 2021

@hamishcampbell @rcoup Not sure how this is done in Kart, since I could not find a command for it.

Should the plugin just delete the table in the repo database and then commit?

@rcoup
Copy link
Member

rcoup commented Oct 5, 2021

I don't think that'll work. @olsen232 — is dropping the table in the working copy the right approach, or should we add a kart data rm <dataset> style command?

@volaya
Copy link
Contributor Author

volaya commented Oct 5, 2021

yes, i was just trying to figure out how to do it...but I guess that it's a much better solution to have a dedicated command

@olsen232
Copy link
Contributor

olsen232 commented Oct 6, 2021

You can delete a table in the working copy and then commit that. But I have nothing against a kart data rm command being implemented.

Background: There is an asymmetry here in kart at the moment - there is a dedicated command to to create a new dataset, kart import, but no dedicated command to delete a dataset. kart apply can create or delete datasets. And a dataset can be deleted manually by deleting it from the dataset and committing, but a dataset cannot be added in this way. These asymmetries are just for historical and pragmatic reasons - the proof-of-conecept of kart needed a way to get data into kart, but didn't need a way to delete it, and, kart needs to check for the possibility that working copy tables have been deleted and not crash, but it doesn't need to handle unexpected extra tables.

@volaya
Copy link
Contributor Author

volaya commented Oct 7, 2021

@olsen, @rcoup 232 Some comments about this, in case it can be useful for eventually adding that Kart command:

Apparently, you can delete a layer like that, and it works, but it can give problems later on.

I had a repo with two layers, removed one of them, and it was ok. But later I tried to reset the main branch to a few commits before (where it still had two layers), and got this error:

[12764] Failed to execute script kart_cli
Traceback (most recent call last):
File "lib\site-packages\sqlalchemy\engine\base.py", line 1707, in _execute_context
File "lib\site-packages\sqlalchemy\engine\default.py", line 716, in do_execute
pysqlite3.dbapi2.IntegrityError: UNIQUE constraint failed: gpkg_contents.table_name
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "kart_cli.py", line 4, in 
File "kart\cli.py", line 333, in entrypoint
File "lib\site-packages\click\core.py", line 829, in __call__
File "lib\site-packages\click\core.py", line 782, in main
File "kart\cli.py", line 157, in invoke
File "lib\site-packages\click\core.py", line 1259, in invoke
File "lib\site-packages\click\core.py", line 1066, in invoke
File "lib\site-packages\click\core.py", line 610, in invoke
File "lib\site-packages\click\decorators.py", line 21, in new_func
File "kart\checkout.py", line 360, in reset
File "kart\checkout.py", line 48, in reset_wc_if_needed
File "kart\working_copy\base.py", line 1140, in reset
File "kart\working_copy\base.py", line 849, in write_full
File "kart\working_copy\gpkg.py", line 249, in _write_meta
File "lib\site-packages\sqlalchemy\orm\session.py", line 1670, in execute
File "lib\site-packages\sqlalchemy\engine\base.py", line 1521, in _execute_20
File "lib\site-packages\sqlalchemy\sql\elements.py", line 314, in _execute_on_connection
File "lib\site-packages\sqlalchemy\engine\base.py", line 1400, in _execute_clauseelement
File "lib\site-packages\sqlalchemy\engine\base.py", line 1750, in _execute_context
File "lib\site-packages\sqlalchemy\engine\base.py", line 1931, in _handle_dbapi_exception
File "lib\site-packages\sqlalchemy\util\compat.py", line 211, in raise_
File "lib\site-packages\sqlalchemy\engine\base.py", line 1707, in _execute_context
File "lib\site-packages\sqlalchemy\engine\default.py", line 716, in do_execute
sqlalchemy.exc.IntegrityError: (pysqlite3.dbapi2.IntegrityError) UNIQUE constraint failed: gpkg_contents.table_name
[SQL: INSERT INTO gpkg_contents (table_name, data_type, identifier, description, srs_id) VALUES (?, ?, ?, ?, ?)]
[parameters: ('buildings', 'features', 'buildings: buildings', None, 2193)]
(Background on this error at: http://sqlalche.me/e/14/gkpj) 

Looks like, apart from deleting the layer table itself, other stuff has to be removed.

It works fine if, instead of just deleting the table with a DROP TABLE sentence you use gdal like this:

ds = gdal.OpenEx("path/to/repo/repo.gpkg", gdal.OF_UPDATE, allowed_drivers=['GPKG'])
for i in range(ds.GetLayerCount()):
    if ds.GetLayer(i).GetName() == layername:
        ds.DeleteLayer(i)

This will correctly clean the gpkg and update all tables.

I have added this to the plugin, but I would say it is safer to have the command in Kart, so users have an easy and safe way of removing a layer.

@rcoup
Copy link
Member

rcoup commented Oct 7, 2021

I have added this to the plugin, but I would say it is safer to have the command in Kart, so users have an easy and safe way of removing a layer.

Yeah, would prefer to wait until Kart has the functionality rather than adding at a QGIS plugin level. eg: the above won't clean up the gpkg_kart_track table.

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

No branches or pull requests

3 participants