使用前事先准备好点的经纬度数据(数组lon,lat)以及数目(pointNum)。通过循环,把经纬度数据放进点集,随后导入ring类型中,最后放进polygon。
IPointCollection Points = new MultipointClass();
for (int k = 0; k < pointNum; k++)
{
IPoint p1 = new PointClass();
p1.X = lon[k];
p1.Y = lat[k];
Points.AddPoint(p1);
}
Ring ring = new RingClass();
for (int i2 = 0; i2 < pointNum; i2++)
{
ring.AddPoint(Points.Point[i2], Type.Missing, Type.Missing);
}
ring.AddPoint(Points.Point[0], Type.Missing, Type.Missing);//必须补充起点,作为终点
IGeometryCollection pointPolygon = new PolygonClass();
pointPolygon.AddGeometry(ring as IGeometry, Type.Missing, Type.Missing);
IPolygon polygonGeo = pointPolygon as IPolygon;
//把polygon添加进要素集
IFeature pFeature = pFeatureClass.CreateFeature();
pFeature.Shape = polygonGeo;
pFeature.Store();