Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Is there a way to choose the field delimiter when exporting to CSV with geometry as wkt in QGIS?

I have a shapefile with donut holes and I'd like to export it as a CSV. It's for a partner whose DB doesn't suppport spatial data.

I followed Greg Krakow's methodology to add a WKT field to my exported file (when exporting to csv, add GEOMETRY=AS_WKT in the "Layer" field, but the exported field delimiter is a comma: CSV with WKT field

The problem is that each coordinate pairs of my polygons (and I suspect it will be the same for lines) are separated by a comma too so I can't import the data back into QGIS

With point shapefile, it works like a charm.

Does anyone know if I can choose my field delimited when exporting to CSV? Choose a semicolon for instance?

I search on the web and QGIS' documentation, but didn't find anything.

THANKS!!

share|improve this question
2  
Have you checked the help page yet: gdal.org/ogr/drv_csv.html. It describes how to change the separator. –  underdark Dec 4 '12 at 16:43
    
I was looking for QGIS specifically... didn't think of looking for GDAL's help. Thanks!! –  fgcartographix Dec 4 '12 at 18:36
add comment

1 Answer 1

up vote 10 down vote accepted

I was able to export to CSV, using other than a comma, by separating the layer creation options in the Save As.. dialog with linebreaks.

Neither comma, nor space-separating them (even when they were in quotes) worked, but the linebreaks did the trick. To emphasize..

THIS APPROACH WORKED (linebreak-separated):

GEOMETRY=AS_WKT
SEPARATOR=SEMICOLON
LINEFORMAT=CRLF

But these approaches did NOT work...

(space-separated options):

GEOMETRY=AS_WKT SEPARATOR=SEMICOLON

(comma-separated options):

GEOMETRY=AS_WKT, SEPARATOR=SEMICOLON

(quoted, and either space or comma-separated LCOs):

"GEOMETRY=AS_WKT", "SEPARATOR=SEMICOLON"

As @underdark noted, there are some additional options discussed on the OGR CSV driver page you may want to be aware of. Specifically, the SEPARATOR parameter will accept either SEMICOLON or TAB in addition to COMMA. Also, you may want to experiment with the LINEFORMAT parameter, which supports either CRLF (dos/windows) or LF (unix).

A picture says a thousand words, so here's a screen grab. :)

enter image description here

share|improve this answer
    
Thanks! It's working. I don't know why though, but when I try to import my csv into QGIS, it says that it's not a valid layer and it can be added to the map...? I tried with a simple polygon (linestring and polygon) and it didn't work neither :( So I guess it's another question now... ;) –  fgcartographix Dec 4 '12 at 18:29
    
...interesting. I'm not sure how to explain that. I tried adding the one I created to the map and it worked. Then I tried adding a new one, as it created it (i.e. via the "Add saved file to map" option), and it also worked. What version of QGIS? 1.8? –  elrobis Dec 4 '12 at 18:57
    
1.8.0-Lisboa. It's working when I use the "Add saved file to map", not when I use the "Add delimited text layer" button. The semicolon delimiter is check as well as my field "WKT" selected for the geometry... It worked with a point layer earlier though... –  fgcartographix Dec 4 '12 at 19:10
1  
Ahh.. try going through the "Add Vector Layer.." button (like you would to add a shapefile), then browse into the folder with your .csv. At the bottom of the "Open OGR Supported Vector Layer" dialog, set "Files of type:" to Comma Separated Value [OGR]. Then your .csv should appear, and I bet it'll work. –  elrobis Dec 4 '12 at 19:15
    
You bet right! It worked with the "Add delimited text layer" after I opened my csv in Excel and resaved it too... Strange, but if it's working with the "Add Vector Layer" button, I'm ok with that. Strange behavior though... –  fgcartographix Dec 4 '12 at 19:22
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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