[GIS] Converting line shapefile into CSV with nodes and links

convertcsvogrshapefile

Is there a way to convert a linear shapefile into a CSV file of the following format:

Node_1 Node_2 attribute_1 …. attribute_x
1 2 "hello" …. 567845.334

I have looked at GDAL/OGR2OGR and PostGIS and I don't think either converts the data to the format I want.

I don't mind writing a script to do it, if I'm guided in the right direction.

Best Answer

The utility programs included in OGR (OGR2OGR) will not do this directly, but it will be very easy to use OGR to accomplish this.

You would need to write a script/program in any of the languages supported by OGR. You could just have it open the shapefile, read each feature, and write out the points + data in a CSV format.

The sample C++ code on the Wiki actually shows nearly every OGR API call required for this.