3

In QGIS I can import data tables (CSV in particular) which have no inherent geometry (and no lat/lon columns) into QGIS. There doesn't seem to be any obvious way to manipulate that data (edit/save).

(Obviously this data has a reference column which links to data which does have geometry).

It's documented that (at QGIS 2.6) it's not possible to edit/save CSV files:

I am aware that I could edit data in another application, repeatedly returning to this, saving as CSV and importing into QGIS, but this seems very clumsy and inefficient. I'd like to remain within QGIS.

I'm guessing that there are many workarounds for this which are simple for those experienced with using databases, but on other GIS software it's a trivial task to work with a geometry-free table.

How do I set-up a spatialite database for this purpose?

3 Answers 3

2

I have by chance this morning discovered a secondary answer to this question which I've not seen mentioned anywhere, and which seems worth a full description.

The CSV file is loaded into QGIS in the normal way (using the button for doing this). Then this can be saved as (right click the layer entry and 'Save as...') an ESRI Shapefile. This produces a couple of files (interestingly none of them actually ending in .shp

If you open the file with the ending .dbf (using the button for loading a vector layer) this can be used in the way I envisaged. Editing/saving works as you'd expect. All the expected joins or relationships work well.

A second way to achieve the same thing is to use the ogr2ogr tool to convert from a csv file to a "ESRI Shapefile". This seems to produce only one file - with the ending .dbf

These seem to be almost identical processes. I did get one minor difference in behaviour when looking at the automatically produced data form arising from a relationship....

Specifically, I have a SHP file with objects, and CSV entries with a linking reference in one field. I set up a relationship in project properties. This is a one-to-many relationship (many entries in the CSV may match one object in the SHP). In the QGIS form which appears using the identify tool things work as expected when using the first of my methods. When using the ogr2ogr produced file instead there seem to be missing titles in the left column of the subform (i.e. identifying related entries from the CSV).

I'm anticipating that this process may lead to be having a file which others can edit - the .dbf file can certainly be edited in LibreOffice scalc (although if I don't delete and re-establish the relationship QGIS crashes).

2
  • Just a minor note to add that I can't make this solution work easily with MS Office software. I fail to get the dbf into Access and Excel won't save to a dbf. Commented Sep 10, 2015 at 11:19
  • Interestingly, I have discovered that, in QGIS version 3.12, exporting an imported csv file to ...csv (without necessarily changing anything) and leaving the Add saved file to map option checked, the newly added identical layer's attribute table then appears as editable (i.e. the Edit button can be clicked). Commented Nov 14, 2021 at 21:11
1

Use the QGIS plugin QSpatiaLite controlling your Spatialite db, for storing CSV files. With this plugin you can create a new database, upload, query and edit data.

5
  • Thanks Jakob. I'd need a lot more detail to properly understand this. Is the CSV loaded into the Spatialite database? Is it created in the database? How is this done? Does this handle export back to the original CSV? Like I say, in other applications this is a very very easy process, so I'm looking for an answer which is appropriate for a fairly new user of QGIS, not someone already competent with Spatialite (someone like me, but also I think very many other users). Thanks. Commented Feb 11, 2015 at 12:24
  • Take a look at the plugin. In QSpatialLite you have buttons for importing and exporting CSV. The original CSV file is not connected to the db.
    – Jakob
    Commented Feb 11, 2015 at 12:29
  • Also take a look at you other question: gis.stackexchange.com/questions/133919/…
    – Jakob
    Commented Feb 11, 2015 at 12:31
  • Thanks Jakob. Your answer on the other question looks clear and very helpful. If after investigating further I understand this properly I'll return myself to this question and I'll answer it separately - obviously the questions are linked, but this one applies to many more situations (and QGIS users) than the other one and I think deserves its own answer. Commented Feb 11, 2015 at 13:01
  • I have made this work through trial and error. I agree that it is a way to achieve what I asked. For the moment I'm not going to mark the question as answered as I'm hoping for an answer which helps me and others navigate the process of working with a Spatialite database for the first time (given that on other software this is a trivial task). Trial and error has involved things like 1) having to create a CSV file to load into Spatialite purely to define the table columns, 2) pretending I was creating a data with a geometry even though I didn't need this, 3) negotiating error messages. Commented Feb 11, 2015 at 18:44
0

There is a plugin which allows this to be done, turn on experimental plugins. Why can't I edit attribute table imported through 'text as layer'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.