Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active November 10, 2021 13:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/afa4cdd274f018b334b9dcd202c7a578 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/afa4cdd274f018b334b9dcd202c7a578 to your computer and use it in GitHub Desktop.
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
layer.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
layer.Add(feature2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment