views:

694

answers:

1

Is there a way to convert a linear shape file 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.

+3  A: 

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.

Reed Copsey
Thanks for the swift response.I'm looking at http://gdal.org/ogr/ogr%5Fapitut.html first python example, which outputs from a SHP to CSV file.The example is done for a point layer, is there any significant difference to convert it for a line layer? What would be the format of the Node name? Will it be a number? Can I link it to another point layer that has all the node names in it?
dassouki
In a line, the features will be ogr.wkbLine instead of ogr.wkbPoint. You can return the name as a string using feature.GetFieldAsString(col). There is no way to handle "linking' directly in OGR, so you'd have to open the other data table and search it yourself, or copy the names across in GIS first.
Reed Copsey
That makes sense; well I’ll try it out and keep you updated on how I make out. I'm doing all this so i can do some network analysis on a line layer.
dassouki

related questions