0

I have a CSV file that I loaded into QGIS and I made points layers from X,Y columns that was in that CSV file.

Now, this file has a column that called "Value". This column is updated once a week and I want to update the values.

To do that I was saving the layer as a shapefile and I wanted to made a join from the new table and replace the values in that layer. The problem is that since I saved it as shapefile and I applied symbology on this layer, a column under the name "polygon name" just disappeared from the attribute table and I need the column.

Any ideas? By the way, if you know another way to update these values let me know.

2
  • 1
    Are you editing / modifying the csv or shapefile outside QGIS? For example using Excel?
    – BERA
    May 9 at 11:26
  • You can't properly edit CSV files in QGIS. If you need to add/change data inside QGIS as well as outside QGIS, using CSV is not a good idea. Better stick to a solution based on a server database like PostGIS.
    – Babel
    May 9 at 12:45

1 Answer 1

4

When you say the column has disappeared from the attribute table in the shapefile, I am going to assume you mean it's disappeared from the column drop-down list when you paste the symbology (presumably Categorised symbology) from the CSV to the shapefile.

And now the symbology isn't working properly any more because QGIS (and you) can't find the column that was used to categorise the symbology.


This can happen when your CSV column names are more than 10 characters long (including spaces etc), as shapefiles cannot support column names more than 10 characters long. So when converting CSV to shapefile, these column names get truncated by QGIS. For example, "Tree_health_2018" in your CSV gets truncated to "Tree_healt" in your shapeflie.

Furthermore, if you have many columns in your CSV that have the same first 10 letters, the truncation will replace the 10th letter with a number in QGIS. e.g. "Tree_health_2018", "Tree_health_2019" and "Tree_health_2020" in your CSV would get truncated to "Tree_healt", "Tree_heal1" and "Tree_heal2" respectively (or something similar).

This also applies when you are doing a join - let's say my shapefile has the above three columns, and now I want to join a column from the CSV called "Tree_health_2021". This will get truncated to "Tree_heal3" or similar.

See examples in Export shapefile with column name of csv file or change column names afterwards and When I join a table to a shapefile and then export it the titles of the columns are transformed to data1, data2


For your symbology to work properly when copied and pasted from one layer to another, it needs to have the same exact column names used to categorise or otherwise define the symbology (e.g. rule-based symbology, data-defined overrides for colour or size, etc.).


Some solutions for this specific problem:

Option 1

  • Change your symbology on the shapefile layer to use the truncated column name, instead of the original column name. If it is just a categorised symbology, you can use the column drop down box to find the right column. If it's a rule-based or otherwise complex symbology, you will need to find every reference to that column name and update accordingly.

Note: Once you have done this, you can save the symbology as a .qml file and/or save it as the default styling so it doesn't need to be re-created each time.

  • Make sure you do not have column names that have the same 10 first characters (especially when you apply the join from the CSV to the shapefile).

Option 2

  • Make sure your CSV only uses shapefile appropriate column names from the start (10 standard characters max including spaces).

Option 3

  • Don't use shapefile, use another spatial format such as geopackage that doesn't have this archaic 10-character limit.
0

Your Answer

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

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