子多边形增加方向,符合拓扑规则:
private void shp要素ToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
{
try
{
ILayer pLayer = m_mapControl.get_Layer(0);
IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer;
IFeature tmpFea = pFeatureLayer.FeatureClass.CreateFeature();
IPolygon pPolygon = new PolygonClass();
pPolygon = fun() as IPolygon;
IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer;
IFeature tmpFea = pFeatureLayer.FeatureClass.CreateFeature();
IPolygon pPolygon = new PolygonClass();
pPolygon = fun() as IPolygon;
//图形增加方向
ITopologicalOperator pTopo = pPolygon as ITopologicalOperator;
pTopo.Simplify();
if (pPolygon == null) return;
pTopo.Simplify();
if (pPolygon == null) return;
tmpFea.Shape = pPolygon;
tmpFea.Store();
}
catch (Exception err)
{
tmpFea.Store();
}
catch (Exception err)
{
}
}
IGeometry fun()
{
}
IGeometry fun()
{
//创建一个Ring对象
ISegmentCollection pSegCollection = new RingClass();
IPoint pt1 = new PointClass();
pt1.X = 0;
pt1.Y = 0;
pt1.X = 0;
pt1.Y = 0;
IPoint pt2 = new PointClass();
pt2.X = 1;
pt2.Y = 0;
IPoint pt3 = new PointClass();
pt3.X = 1;
pt3.Y = 1;
pt2.X = 1;
pt2.Y = 0;
IPoint pt3 = new PointClass();
pt3.X = 1;
pt3.Y = 1;
IPoint pt4 = new PointClass();
pt4.X = -2;
pt4.Y = -1;
IPoint pt5 = new PointClass();
pt5.X = 2;
pt5.Y = -1;
IPoint pt6 = new PointClass();
pt6.X = 2;
pt6.Y = 2;
object o = Type.Missing;
IPointCollection ptC1 = new RingClass() as IPointCollection;
ptC1.AddPoint(pt1,ref o ,ref o);
ptC1.AddPoint(pt2, ref o, ref o);
ptC1.AddPoint(pt3, ref o, ref o);
ptC1.AddPoint(pt1, ref o, ref o);
IPointCollection ptC2 = new RingClass() as IPointCollection;
ptC2.AddPoint(pt4, ref o, ref o);
ptC2.AddPoint(pt5, ref o, ref o);
ptC2.AddPoint(pt6, ref o, ref o);
ptC2.AddPoint(pt4, ref o, ref o);
ptC2.AddPoint(pt4, ref o, ref o);
ptC2.AddPoint(pt5, ref o, ref o);
ptC2.AddPoint(pt6, ref o, ref o);
ptC2.AddPoint(pt4, ref o, ref o);
(ptC1 as IRing).Close();
(ptC2 as IRing).Close();
(ptC2 as IRing).Close();
IGeometryCollection pGeometryColl = new PolygonClass();
pGeometryColl.AddGeometry(ptC1 as IRing, ref o, ref o);
pGeometryColl.AddGeometry(ptC1 as IRing, ref o, ref o);
pGeometryColl.AddGeometry(ptC2 as IRing, ref o, ref o);
return pGeometryColl as IGeometry;
}
}