我正在尝试创建一个 shapefile,但每次我都会遇到某种错误。我也尝试过使用 DotSpatial 和 NetTopologySuite 库,但它仍然无法正常工作。
我尝试使用 ShapefileDataWriter 但出现异常(System.ApplicationException:“必须先设置标题!”)我该如何解决?
using System;
using System.IO;
using NetTopologySuite.Features;
using NetTopologySuite.Geometries;
using NetTopologySuite.IO;
namespace SHP
{
class Program
{
static void Main(string[] args)
{
string filePath = Path.Combine(@"D:\SHP", "point_Created.shp");
var featureCollection = new FeatureCollection();
var geometryFactory = new GeometryFactory();
var header = new ShapefileHeader();
var point = geometryFactory.CreatePoint(new Coordinate(10, 20)); // x,y coordinates of the point
var attributes = new AttributesTable { { "Name", "My Point" } };
var feature = new Feature(point, attributes);
featureCollection.Add(feature);
var writer = new ShapefileDataWriter(filePath);
writer.Write(featureCollection); //System.ApplicationException:'Header must be set first!'
}
}
}