Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Export Features to a CSV File using C#
var options = new CsvOptions()
ColumnWkt = "geom_data",
Delimiter = ';'
// Create a new CSV layer
using (var layer = Drivers.Csv.CreateLayer(dataDir + "csv_out.csv", options))
// Add attributes
layer.Attributes.Add(new FeatureAttribute("string_data", AttributeDataType.String));
layer.Attributes.Add(new FeatureAttribute("int_data", AttributeDataType.Integer));
layer.Attributes.Add(new FeatureAttribute("bool_data", AttributeDataType.Boolean));
layer.Attributes.Add(new FeatureAttribute("float_data", AttributeDataType.Double));
Feature feature = layer.ConstructFeature();
feature.SetValue("string_data", "string value");
feature.SetValue("int_data", 10);
feature.SetValue("bool_data", true);
feature.SetValue("float_data", 3.14);
feature.Geometry = new LineString(new[] { new Point(0, 0), new Point(1, 1) });
// Add Feature
Feature feature2 = layer.ConstructFeature();
feature2.SetValue("string_data", "string value2");
feature2.SetValue("int_data", 100);
feature2.SetValue("bool_data", false);
feature2.SetValue("float_data", 3.1415);
feature2.Geometry = Geometry.Null;
// Add feature
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment