ส่งออกหรืออ่านคุณสมบัติ GIS, จุด, และรูปทรงเรขาคณิตจาก CSV ใน C#
Contents
[
Hide
]
ไลบรารี GIS C# Aspose.GIS ช่วยให้คุณอ่านคุณสมบัติจากไฟล์ค่าที่คั่นด้วยเครื่องหมายจุลภาค (CSV) ได้
การอ่านคุณสมบัติจากไฟล์ CSV
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-gis/Aspose.GIS-for-.NET | |
using (var layer = Drivers.Csv.OpenLayer(dataDir + "sample.csv")) | |
{ | |
// print attributes | |
foreach (var attribute in layer.Attributes) | |
{ | |
Console.Write($"'{attribute.Name}' "); | |
} | |
Console.WriteLine(); | |
// print records | |
foreach (var feature in layer) | |
{ | |
var dump = feature.GetValuesDump(); | |
foreach (var item in dump) | |
{ | |
Console.Write($"'{item}' "); | |
} | |
Console.WriteLine(); | |
} | |
} |
การอ่านจุดจากไฟล์ CSV
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-gis/Aspose.GIS-for-.NET | |
using (var layer = Drivers.Csv.OpenLayer(dataDir + "geometries.csv", | |
new CsvOptions() | |
{ | |
ColumnX = "x" , | |
ColumnY = "y", | |
ColumnZ = "z", | |
ColumnM = "m" | |
})) | |
{ | |
// print geometry in wkt format | |
foreach (var feature in layer) | |
{ | |
Console.Write($"'{feature.Geometry.AsText()}: "); | |
Console.WriteLine(); | |
} | |
} |
การอ่านรูปทรงเรขาคณิตโดยใช้คอลัมน์ WKT
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-gis/Aspose.GIS-for-.NET | |
using (var layer = Drivers.Csv.OpenLayer(dataDir + "geometries.csv", | |
new CsvOptions() | |
{ | |
ColumnWkt = "geom_data" | |
})) | |
{ | |
// print geometry in wkt format | |
foreach (var feature in layer) | |
{ | |
Console.Write($"'{feature.Geometry.AsText()}: "); | |
Console.WriteLine(); | |
} | |
} |
ส่งออกเป็นรูปแบบ CSV
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-gis/Aspose.GIS-for-.NET | |
// apply a custom delimiter and a column for geometry. | |
var options = new CsvOptions() | |
{ | |
ColumnWkt = "geom_data", | |
Delimiter = ';' | |
}; | |
// create a new CSV layer | |
using (var layer = Drivers.Csv.CreateLayer(dataDir + "csv_out.csv", options)) | |
{ | |
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) }); | |
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; | |
layer.Add(feature2); | |
} |