koordinates / kart

Distributed version-control for geospatial and tabular data
https://kartproject.org
Other
515 stars 39 forks source link

Use push to bring repository updates to postgis (plugin kart QGIS) #982

Closed joaov03 closed 2 months ago

joaov03 commented 3 months ago

I'm trying to use the kart plugin performing actions together with postgis, that is, I want to import the data from the postgis database into my qgis repository and work on it. And then do the opposite, exporting to my postgis database.

I saw that there is a function called "push" in the kart plugin, when opening the window, it asks to enter a destination for this push, that is, the URL. According to the kart documentation, this URL is the bank's destination, having a pattern, being:

postgresql://[user[:password]@]host[:port]/dbname/dbschema

After having entered the URL and destination of my database, when proceeding, a pop-up appears showing an error like this: "git: 'remote-postgresql' is not a git command. See 'git --help'."

If anyone can help solve this problem and how to "push" the data from main directly to the postgis database, I would appreciate it.

olsen232 commented 3 months ago

Hi joaov03, A Kart repository is a lot like a git repository. It is stored on a file system (not a database) and it stores an entire history, made out of several commits. Kart repositories store the contents of your database in each commit, but they do so in a database agnostic way, so that they can be checked out into different working copies. Just like git - (if you are familiar with git) - it is this entire history, made out of commits and stored on a filesystem - that is pushed to a remote (another copy of the Kart repository). This history cannot be pushed to a database, and the pull and push commands are to control this functionality.

Ideally there would be a kart export command that works like kart import but in the opposite direction - taking the contents of the current commit and writing it to the destination of your choice. But, currently, there is not. Development of Kart is ongoing.

You can use kart create-workingcopy to get kart to write a snapshot of the current commit, in the database of your choice. Kart will also try to continue to manage that working copy however - it will track changes to that working copy, waiting to see if you want to commit those changes, and if you ask kart to check out a different branch it will update that working copy. This is ideal if you are using Kart to make and commit changes, but probably not what you want in this case.

I recommend you use kart create-workingcopy to get kart to create a working copy in your PG database, but don't ask it to overwrite any of the data that you have there, and don't use the tables in that working copy directly as part of your workflow. Instead, look through it and see which tables you want from it. Then, use PG commands to copy those tables to whereever you actually want them.

If you want kart to abandon or delete the working copy it creates, you can use kart create-workingcopy again to create a GPKG working copy in the kart folder. A Kart repository only ever has one working copy that it actively maintains - it will ask you what you want to do with the old one.

joaov03 commented 3 months ago

Okay, that's exactly what I wanted to know. You answered my question, thank you in advance for your attention.

hamishcampbell commented 2 months ago

Closing this with a note re future support: there is an experimental branch that provides from of this functionality: https://github.com/koordinates/kart/pull/944

From that branch you can export to a shapefile with

ogr2ogr -f SHP mydataset.shp /path/to/kart/repo mydataset