2

The GDAL documentation describes how to convert a ShapeFile into CSV data. The layer create options (-lco parameter) allows to prepend the coordinates of Point features to the actual attributes values.

ogr2ogr -f CSV output.csv input.shp -lco GEOMETRY=AS_XY

Note that I omitted the Z-dimension for my example here.
For some reason this results in the following error message:

FAILED: Layer input already exists, and -append not specified.
        Consider using -append, or -overwrite.
ERROR 1: Terminating translation prematurely after failed
translation of layer input (use -skipfailures to skip errors)

I am using GDAL 1.10.0.

Questions:

  • How can I get this running?
  • Is there an option to omit the feature attributes: I only want to export the latitude and longitude values?
2

The "Layer input already exists" error is due to an existing file "output.csv", presumably from a previous attempt. This file needs to be deleted to make a new file (the -overwrite option sometimes works, but not always). From POSIX shells, use rm output.csv, or from a Windows shell, use del output.csv

To only show X,Y fields, provide an empty select field list to ogr2ogr by using: -select ""

  • 3
    There was no file named output.csv. The check seems to be buggy since the error did not disappear until I removed all .csv files in the folder. The -select option works. Thanks! – JJD Dec 7 '13 at 10:38
1

The error depicts that system don't have permissions to overwrite/append the output csv file because you have not mentioned it in your gdal ogr2ogr command.

Possible solution can be addition of these Params in your command

Ogr2ogr -f 'CSV' output.csv input.shp -lco GEOMETRY=AS_XY -append

I hope it will help.

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.