Wednesday 1 July 2015

export - Creating CSV with geometry as WKT in QGIS (with choosing field delimiter)


Is there a way to choose the field delimiter when exporting a 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 support 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's documentation but didn't find anything.



Answer



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


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...