/// <summary> /// 通过簇的点集计算簇的凸包 /// </summary> /// <returns></returns> public void CreateConvexHull(ISpatialReference spatialReference) { //少于3个点就不做 if (m_pointsList.Count < 3) { return; } IGeometryCollection geometryCollection = new MultipointClass(); for (int i = 0; i < m_pointsList.Count; i++) { geometryCollection.AddGeometry(m_pointsList[i] as IGeometry); } ITopologicalOperator pTopological = geometryCollection as ITopologicalOperator; IGeometry g = pTopological.ConvexHull(); if (g.GeometryType != esriGeometryType.esriGeometryPolygon) { return; } IPolygon convexHull = g as IPolygon; convexHull.SpatialReference = spatialReference; m_convexHull = convexHull; }
//根据创建的点要素做tin public void CreatTINs() { Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory"); IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType); Workspace = workspaceFactory.OpenFromFile(workspacepath, 0); IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)Workspace; //new tin 的范围 tin = new TinClass(); tin.Init(tinpath); IEnvelope EnvO = tin.Extent; IEnvelope Env = new EnvelopeClass(); Env.XMax = EnvO.XMax + 10; Env.YMax = EnvO.YMax + 10; Env.ZMax = EnvO.ZMax + 100; Env.XMin = EnvO.XMin + 10; Env.YMin = EnvO.YMin + 10; Env.ZMin = EnvO.ZMin + 100; // Instantiate a new empty TIN. ITinEdit[] TinEdit = new ITinEdit[SurfaceCount + 1]; object overwrite = true; for (int i = 0; i < SurfaceCount + 1; i++) { TinEdit[i] = new TinClass(); TinEdit[i].InitNew(Env); TinEdit[i].SaveAs(OutTinPath + "_" + i, ref overwrite); } IFeatureClass[] ISOpointFeatureClass = new IFeatureClass[SurfaceCount + 1]; for (int i = 0; i < SurfaceCount + 1; i++) { ISOpointFeatureClass[i] = featureWorkspace.OpenFeatureClass("Node_" + i); IGeometryCollection MultipointGeometryCollection = new MultipointClass(); MakeZAware(MultipointGeometryCollection as IGeometry); for (int p = 0; p < NodeCount - 4; p++) { IPoint onePoint = ISOpointFeatureClass[i].GetFeature(p + 1).Shape as IPoint; MakeZAware(onePoint); MultipointGeometryCollection.AddGeometry(onePoint); } (TinEdit[i] as ITinEdit2).SetToConstrainedDelaunay(); TinEdit[i].AddShapeZ(MultipointGeometryCollection as IGeometry, esriTinSurfaceType.esriTinMassPoint, 0, _missing); TinEdit[i].Save(); } }
/// <summary> /// 通过簇的点集计算簇的凸包 /// </summary> /// <returns></returns> public void CreateConvexHull(ISpatialReference spatialReference) { //少于3个点就不做 if (m_pointsList.Count < 3) return; IGeometryCollection geometryCollection = new MultipointClass(); for (int i = 0; i < m_pointsList.Count; i++) { geometryCollection.AddGeometry(m_pointsList[i] as IGeometry); } ITopologicalOperator pTopological = geometryCollection as ITopologicalOperator; IGeometry g = pTopological.ConvexHull(); if (g.GeometryType != esriGeometryType.esriGeometryPolygon) return; IPolygon convexHull = g as IPolygon; convexHull.SpatialReference = spatialReference; m_convexHull = convexHull; }
//添加实体对象 private void toolStripMenuItem1_Click(object sender, EventArgs e) { IGeometryCollection geometryCollection = new MultipointClass(); IMultipoint multipoint; object missing = Type.Missing; IPoint point; for (int i = 0; i < 10; i++) { point = new PointClass(); point.PutCoords(i * 2, i * 2); geometryCollection.AddGeometry(point as IGeometry, ref missing, ref missing); } multipoint = geometryCollection as IMultipoint; addFeature("multipoint", multipoint as IGeometry); this.axMapControl1.Extent = multipoint.Envelope; this.axMapControl1.Refresh(); }
//插入实体对象集 private void insertGeometriesCollectionToolStripMenuItem_Click(object sender, EventArgs e) { IGeometryCollection geometryCollection1 = new MultipointClass(); IGeometryCollection geometryCollection2 = new MultipointClass(); IGeometryCollection geometryCollection3 = new MultipointClass(); IGeometryCollection geometryCollection4 = new MultipointClass(); IMultipoint multipoint; object missing = Type.Missing; IPoint point; //创建3个实体对象集 for (int i = 0; i < 10; i++) { point = new PointClass(); point.PutCoords(i * 2, i); geometryCollection1.AddGeometry(point as IGeometry, ref missing, ref missing); } for (int i = 0; i < 10; i++) { point = new PointClass(); point.PutCoords(i, i); geometryCollection2.AddGeometry(point as IGeometry, ref missing, ref missing); } for (int i = 0; i < 10; i++) { point = new PointClass(); point.PutCoords(i, i * 2); geometryCollection3.AddGeometry(point as IGeometry, ref missing, ref missing); } geometryCollection1.InsertGeometryCollection(1, geometryCollection2); geometryCollection1.InsertGeometryCollection(1, geometryCollection3); multipoint = geometryCollection1 as IMultipoint; addFeature("multipoint", multipoint as IGeometry); this.axMapControl1.Extent = multipoint.Envelope; this.axMapControl1.Refresh(); }