Dotspatial 创建面状图层

时间:2021-09-10 16:51:25

using DotSpatial.Controls;
using DotSpatial.Data;
using DotSpatial.Data.Forms;
using DotSpatial.Plugins.Measure;
using DotSpatial.Symbology;
using DotSpatial.Topology;
using DotSpatial.Topology.Algorithm;
using Point = DotSpatial.Topology.Point;
using PointShape = DotSpatial.Symbology.PointShape;

Shapefile s = new Shapefile();

//面状要素
FeatureSet fs = new FeatureSet(FeatureType.Polygon);

//增加字段
fs.DataTable.Columns.Add(new DataColumn("ID", typeof (int)));
fs.DataTable.Columns.Add(new DataColumn("Text", typeof (string)));

//坐标列表
List<Coordinate> vertices = new List<Coordinate>();
vertices.Add(new Coordinate(0, 0));
vertices.Add(new Coordinate(0, 100));
vertices.Add(new Coordinate(100, 100));
vertices.Add(new Coordinate(100, 0));

//创建多边形要素

Polygon geom = new Polygon(vertices);
IFeature feature = fs.AddFeature(geom);
feature.DataRow.BeginEdit();
feature.DataRow["ID"] = 1;
feature.DataRow["Text"] = "Hello world";
feature.DataRow.EndEdit();

//存储
fs.SaveAs("d:\\test.shp", true);