I have CSV file with have ID which is repeating, something like:

ID     other values..
1       njhb
1       njhb
2       njhb
2       njhb
1       njhb

Anyway, I have in shapefile that ID which is not repeating:

ID2      geoemetry
1          g1
2          g2


I want to merge that values, something like Descartes multiplication, so the output will be:

ID     other values..     ID2    geometry
1       njhb                1      g1
1       njhb                1      g1
2       njhb                2      g2
2       njhb                2      g2
1       njhb                1      g1

Join function in QGIS don't merge it, just take first corresponding value from each and join and rest ignores.

  • 1
    You need to go the otherway around. Choose your CSV as master and add the shapefile as joined layer. Since you have the geometry stored in a column this should be no problem. – MrXsquared Dec 3 '18 at 17:35
  • I don't have it, that was only for example. I thing I am gonna use postgis. But I would like to know how to do it in QGIS – user123480 Dec 3 '18 at 17:40

Its a bit tricky to do but you get your result.

First select your CSV and create a join to your shapefile. You will get all results but without geometry.

To fix that you can now create a new virtual field in your CSV. Open your attribute table and start the field calculator. Choose text, unlimited length (text), as field name choose wkt_geom ideally and enter the following code:


point2 is my shapefile layer; replace it with the name of your shapefile layer.

id is the matching field in my shapefile layer; replace it with your ID in your shapefile layer.

attribute($currentfeature,'id') is the matching field in my CSV layer; replace it with yours.

enter image description here

After you've done this, save your CSV as a new CSV. (I'm not aware of a method to change geometry source of a already added CSV file; please correct me if there is one)

Now you can import your new CSV with geometry. Do whatever you want with it, e.g. save it as shapefile or something else.

| improve this answer | |
  • It is changed, I've lost some lines. :O – user123480 Dec 3 '18 at 20:10
  • Is it possible to use increase precision, so I wouldn't lost those lines? – user123480 Dec 3 '18 at 20:14
  • what lines did you loose? You will keep ALL data in your original CSV and just add the matching data and geometry of your shapefile. Check if all id's can be matched. Also check for field types of your matching-fields. – MrXsquared Dec 3 '18 at 20:17
  • I checked, I have exact number of rows in csv file, probably don't every line have a pair in csv file. I lost about 10 lines. I can't control new shp file manually because i have 57k features. :D Is it posible just to select manually those 10 missing lines and add to a new shapefile? – user123480 Dec 3 '18 at 20:20
  • Btw instead of that, everything is same. Geometry wasn't lost. :) – user123480 Dec 3 '18 at 20:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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