Skip to main content
Updated with a better tip.
Source Link
Simbamangu
  • 14.9k
  • 7
  • 60
  • 93

Not a neat solution, but try:

  1. Load the CSV file as a plain text table;
  2. Use regex to rewrite the linestrings;
  3. Save the CSV file again, then load it as a vector layer using the corrected geometry.

The function (field calculator) to find pairs of coordinates and swap them in the linestrings would be:

 regexp_replace( geometry, '(\\d+\\.\\d+) (\\d+\\.\\d+)', '\\2 \\1' )

You could use this to alter the geometry column in place ('update existing field'), or create a new field which you use when importing later.

In fact, you can find the CSV file in the QGIS browser and double-click to add it - it will load as a non-spatial table. Then use the field calculator to create a new text field wkt with the function above, then save your edits. If you double-click the file in the browser it will now load the new geometry from the wkt field.

Not a neat solution, but try:

  1. Load the CSV file as a plain text table;
  2. Use regex to rewrite the linestrings;
  3. Save the CSV file again, then load it as a vector layer using the corrected geometry.

The function (field calculator) to find pairs of coordinates and swap them in the linestrings would be:

 regexp_replace( geometry, '(\\d+\\.\\d+) (\\d+\\.\\d+)', '\\2 \\1' )

You could use this to alter the geometry column in place ('update existing field'), or create a new field which you use when importing later.

Not a neat solution, but try:

  1. Load the CSV file as a plain text table;
  2. Use regex to rewrite the linestrings;
  3. Save the CSV file again, then load it as a vector layer using the corrected geometry.

The function (field calculator) to find pairs of coordinates and swap them in the linestrings would be:

 regexp_replace( geometry, '(\\d+\\.\\d+) (\\d+\\.\\d+)', '\\2 \\1' )

You could use this to alter the geometry column in place ('update existing field'), or create a new field which you use when importing later.

In fact, you can find the CSV file in the QGIS browser and double-click to add it - it will load as a non-spatial table. Then use the field calculator to create a new text field wkt with the function above, then save your edits. If you double-click the file in the browser it will now load the new geometry from the wkt field.

Source Link
Simbamangu
  • 14.9k
  • 7
  • 60
  • 93

Not a neat solution, but try:

  1. Load the CSV file as a plain text table;
  2. Use regex to rewrite the linestrings;
  3. Save the CSV file again, then load it as a vector layer using the corrected geometry.

The function (field calculator) to find pairs of coordinates and swap them in the linestrings would be:

 regexp_replace( geometry, '(\\d+\\.\\d+) (\\d+\\.\\d+)', '\\2 \\1' )

You could use this to alter the geometry column in place ('update existing field'), or create a new field which you use when importing later.