面文件都有几何类型. arcengine在绘图时,不规则的多边形的几何类型是esriGeometryPolygon,矩形的几何类型是esriGeometryEnvelope,圆的几何类型是esriGeometryPolygon. 在将IGeometry转为IFeatureClass的过程中,矩形的会报错,所以想到将矩形转面.
IGeometry geometry;//绘制好的矩形
IEnvelope envelope = geometry as IEnvelope;
IPoint pt = new PointClass();
IPointCollection ptc = new PolygonClass();
object _missing = Type.Missing;
pt.PutCoords(envelope.XMin,envelope.YMin);
ptc.AddPoint(pt, ref _missing, ref _missing);
pt.PutCoords(envelope.XMin,envelope.YMax);
ptc.AddPoint(pt, ref _missing, ref _missing);
pt.PutCoords(envelope.XMax,envelope.YMax);
ptc.AddPoint(pt, ref _missing, ref _missing);
pt.PutCoords(envelope.XMax,envelope.YMin);
ptc.AddPoint(pt, ref _missing, ref _missing);
IPolygon polygon = new PolygonClass();
polygon = ptc as IPolygon;
geometry = polygon as IGeometry;
参考: