1

I have a CSV file with following format :

UTC,Callsign,Position,Altitude
2021-05-11T11:44:38Z,FABCD,"28.084,7.452",500
...

So I can't import with personalized delimiters. I tried to use regular expression but doesn't find any documentation. What I need is to split the Position field into X and Y, so create an additional column and rename as X and Y. My field separator is , but my position in inside "". How can I write my regex to do this operation ?

2
  • Why don't you just remove the " " from the CSV file before importing in QGIS?
    – Cezar B
    Mar 11 at 12:02
  • Of course I can modify the CSV to create 2 new columns (what I do currently) but I'm curious how I could directly use regular expression, which is powerful enough (I think) to deal with this problem.
    – dmjf08
    Mar 11 at 12:12

2 Answers 2

1
  1. First import your data into QGIS.
  2. Open the processing tool : "Geometry by expression"
  3. Choose the point geometry
  4. Here the expression :
make_point(
    -- if the second number is longitude (~ X)
    regexp_substr("Position", '[0-9]*[.][0-9]*,([0-9]*[.][0-9]*)'),
    -- if the first number is latitude (~ Y)
    regexp_substr("Position", '([0-9]*[.][0-9]*),[0-9]*[.][0-9]*')
)

If the first number is latitude, so the point falls in Algeria.

If the first number is longitude, so invert the two expression lines and the point will fall in South Sudan.

0

In the Import Delimited Text dialog, choose the regular expression option and write:

,"|",|,

In Regex, the | acts as a boolean OR and will match the characters before or the characters after.

After this, you can choose which columns are latitude and longitude, but note that their names (the ones from the first row) will get shifted.

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.