1

In QGIS 3.34.15 I am trying to export a shapefile which is in LineString format to a CSV file, where I want the coordinates in XY format. Then I get this Error:

Creation of layer failed (OGR error: Geometry type Line String is not compatible with GEOMETRY=AS_XY.)

Can somebody please assist?

2 Answers 2

5

The error message is quite explicit: you cannot export a LineString geometry to CSV with the layer creation option GEOMETRY=AS_XY, since the "Geometry type Line String is not compatible with GEOMETRY=AS_XY".

If you want to export a text representation of the geometry, you need to set the GEOMETRY layer creation option to AS_WKT.

See https://gdal.org/en/stable/drivers/vector/csv.html#layer-creation-options.

2
  • Or simply use the presets. Commented Jul 7 at 8:04
  • @Erik, what do you mean exactly with "use the presets"? Commented Jul 7 at 8:17
4

A CSV file has a constant number of columns in each row, like a rectangular spreadsheet.

If you have LINESTRINGs, then each feature could have a different number of X-Y coordinate points making the line. How are you going to put them in a rectangular spreadsheet?

Yes, you could make the spreadsheet non-rectangular and pad each row with enough columns for the longest LINESTRING, but... ick.

The WKT format gets round this by storing the variable number of X-Y coordinates in a single text string.

Without knowing why you think you need LINESTRINGs as X-Y in a CSV, I'm not sure we can help more beyond "Can't be done".

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.