private void Calc(IPolygon polygon, double referenceHeight) { if (polygon == null) { return; } polygon.Close(); IGeometryFactory geoFact = new GeometryFactoryClass(); IMultiPolygon cutPolygon = geoFact.CreateGeometry(gviGeometryType.gviGeometryMultiPolygon, gviVertexAttribute.gviVertexAttributeZ) as IMultiPolygon; IMultiPolygon fillPolygon = geoFact.CreateGeometry(gviGeometryType.gviGeometryMultiPolygon, gviVertexAttribute.gviVertexAttributeZ) as IMultiPolygon; double cutVolumn = 0.0; double fillVolumn = 0.0; ITerrainAnalyse ta = new TerrainAnalyse(); ta.OnProcessing = _cb; ta.CalculateCutFill(polygon, 0.0, referenceHeight, ref cutPolygon, ref fillPolygon, ref cutVolumn, ref fillVolumn); //double surfaceArea = ta.GetSurfaceArea(polygon, 0.0); //string res = "挖 方 量:" + cutVolumn.ToString("0.000") + " 立方米\r\n填 方 量:" + fillVolumn.ToString("0.000") + " 立方米\r\n" + // "投影面积:" + polygon.Area().ToString("0.000") + " 平方米\r\n地表面积:" + surfaceArea.ToString("0.000") + " 平方米\r\n"; string res = "挖方量:" + cutVolumn.ToString("0.000") + " 立方米\r\n填方量:" + fillVolumn.ToString("0.000") + " 立方米"; if (_label != null) { _label.Text = res; } this.lcInfo.Text = res; if (cutPolygon != null) { SurfaceSymbol ss = new SurfaceSymbol(); ss.Color = 0xffc04000; _rCutPolygon = d3.ObjectManager.CreateRenderMultiPolygon(cutPolygon, ss, d3.ProjectTree.RootID); _rCutPolygon.HeightStyle = gviHeightStyle.gviHeightOnTerrain; if (this.ceCutRegion.Checked) { _rCutPolygon.VisibleMask = gviViewportMask.gviViewAllNormalView; } else { _rCutPolygon.VisibleMask = gviViewportMask.gviViewNone; } } if (fillPolygon != null) { SurfaceSymbol ss = new SurfaceSymbol(); ss.Color = 0xff0000c0; _rFillPolygon = d3.ObjectManager.CreateRenderMultiPolygon(fillPolygon, ss, d3.ProjectTree.RootID); _rFillPolygon.HeightStyle = gviHeightStyle.gviHeightOnTerrain; if (this.ceFillRegion.Checked) { _rFillPolygon.VisibleMask = gviViewportMask.gviViewAllNormalView; } else { _rFillPolygon.VisibleMask = gviViewportMask.gviViewNone; } } }
private void SetMakePolygonMode() { DF3DApplication app = DF3DApplication.Application; if (app == null || app.Current3DMapControl == null) { return; } this.textEdit_FilePath.Text = string.Empty; this.DeleteRenderGeo(ref this._renderGeo); app.Current3DMapControl.HighlightHelper.SetRegion(null); IGeometryFactory geometryFactory = new GeometryFactoryClass(); if (this.radioGroup1.SelectedIndex == 1) { base.WindowState = System.Windows.Forms.FormWindowState.Minimized; this.textEdit_FilePath.Enabled = false; this.sbtn_BrowseFile.Enabled = false; IPolygon polygon = geometryFactory.CreateGeometry(gviGeometryType.gviGeometryPolygon, gviVertexAttribute.gviVertexAttributeZ) as IPolygon; polygon.SpatialCRS = CommonUtils.Instance().GetCurrentFeatureDataset().SpatialReference; ISurfaceSymbol surfaceSymbol = new SurfaceSymbolClass(); surfaceSymbol.Color = 1442840448u; surfaceSymbol.BoundarySymbol = new CurveSymbolClass { Color = 1442840448u }; this._renderGeo = app.Current3DMapControl.ObjectManager.CreateRenderPolygon(polygon, surfaceSymbol, app.Current3DMapControl.ProjectTree.RootID); GeometryEdit.Instance().GeometryEditStart(this._renderGeo); } else { if (this.radioGroup1.SelectedIndex == 0) { this.textEdit_FilePath.Enabled = true; this.sbtn_BrowseFile.Enabled = true; } } }
private void CreateTerrainHole() { try { IGeometry geo = this._drawTool.GetGeo(); if (geo == null) { return; } IPolygon region = geo as IPolygon; region.Close(); IPolygon region2 = geo.Clone2(gviVertexAttribute.gviVertexAttributeNone) as IPolygon; double refheight = d3.Terrain.GetElevation(region2.Centroid.X, region2.Centroid.Y, gviGetElevationType.gviGetElevationFromMemory) - 30; ITerrainHole terrainHole = d3.ObjectManager.CreateTerrainHole(region, d3.ProjectTree.RootID); this._listRGuids.Add(terrainHole.Guid); IPolygon bottom = region.Clone() as IPolygon; for (int i = 0; i < bottom.ExteriorRing.PointCount; i++) { IPoint pointValue = bottom.ExteriorRing.GetPoint(i); pointValue.Z = refheight; bottom.ExteriorRing.UpdatePoint(i, pointValue); } ICurveSymbol cs = new CurveSymbol(); cs.Color = 0x00ffffff; ISurfaceSymbol bottomSS = new SurfaceSymbol(); bottomSS.ImageName = System.Windows.Forms.Application.StartupPath + "\\..\\Resource\\Images\\TerrainHole\\TextureBottom.jpg"; bottomSS.RepeatLengthU = 5; bottomSS.RepeatLengthV = 5; bottomSS.EnableLight = true; bottomSS.BoundarySymbol = cs; IRenderPolygon rBottom = d3.ObjectManager.CreateRenderPolygon(bottom, bottomSS, d3.ProjectTree.RootID); this._listRGuids.Add(rBottom.Guid); IGeometryFactory geoFact = new GeometryFactoryClass(); IMultiPolygon side = geoFact.CreateGeometry(gviGeometryType.gviGeometryMultiPolygon, gviVertexAttribute.gviVertexAttributeZ) as IMultiPolygon; for (int i = 0; i < region.ExteriorRing.PointCount - 1; i++) { IPolygon gon = geoFact.CreateGeometry(gviGeometryType.gviGeometryPolygon, gviVertexAttribute.gviVertexAttributeZ) as IPolygon; IPoint pt1 = region.ExteriorRing.GetPoint(i); IPoint pt1temp = pt1.Clone() as IPoint; if (pt1temp.Z < refheight) { pt1temp.Z = refheight; } IPoint pt2 = region.ExteriorRing.GetPoint(i + 1); IPoint pt2temp = pt2.Clone() as IPoint; if (pt2temp.Z < refheight) { pt2temp.Z = refheight; } IPoint pt3 = pt2.Clone() as IPoint; pt3.Z = refheight; IPoint pt4 = pt1.Clone() as IPoint; pt4.Z = refheight; gon.ExteriorRing.AppendPoint(pt1temp); gon.ExteriorRing.AppendPoint(pt2temp); gon.ExteriorRing.AppendPoint(pt3); gon.ExteriorRing.AppendPoint(pt4); gon.Close(); side.AddPolygon(gon); } ISurfaceSymbol sideSS = new SurfaceSymbol(); sideSS.ImageName = System.Windows.Forms.Application.StartupPath + "\\..\\Resource\\Images\\TerrainHole\\TextureSide.jpg"; sideSS.RepeatLengthU = 5; sideSS.RepeatLengthV = 5; sideSS.EnableLight = true; sideSS.BoundarySymbol = cs; IRenderMultiPolygon rSide = d3.ObjectManager.CreateRenderMultiPolygon(side, sideSS, d3.ProjectTree.RootID); this._listRGuids.Add(rSide.Guid); } catch (Exception ex) { } }
private void DrawBox() { try { IPolyline line = this._drawTool.GetGeo() as IPolyline; if (line == null || line.PointCount != 2) { return; } DF3DApplication app = DF3DApplication.Application; if (app == null || app.Current3DMapControl == null) { return; } if (this._renderBox != null) { app.Current3DMapControl.ObjectManager.DeleteObject(this._renderBox.Guid); this._renderBox = null; } if (this._renderPolygon != null) { app.Current3DMapControl.ObjectManager.DeleteObject(this._renderPolygon.Guid); this._renderPolygon = null; } double middleZ = (line.StartPoint.Z + line.EndPoint.Z) / 2; double minZ = middleZ + (double)this.seMinHeight.Value; double maxZ = middleZ + (double)this.seMaxHeight.Value; IPoint startPoint = line.StartPoint; IPoint endPoint = line.EndPoint; IEulerAngle ang = app.Current3DMapControl.Camera.GetAimingAngles2(startPoint, endPoint); IEulerAngle angcz = new EulerAngle(); angcz.Set(ang.Heading - 90, ang.Tilt, ang.Roll); IPoint pt1 = app.Current3DMapControl.Camera.GetAimingPoint2(startPoint, angcz, this.tbcClipDis.Value); IPoint pt2 = app.Current3DMapControl.Camera.GetAimingPoint2(endPoint, angcz, this.tbcClipDis.Value); ICRSFactory crsFact = new CRSFactory(); ISpatialCRS crs = crsFact.CreateFromWKT(app.Current3DMapControl.GetCurrentCrsWKT()) as ISpatialCRS; IGeometryFactory geoFact = new GeometryFactoryClass(); IPoint pointb1 = geoFact.CreatePoint(gviVertexAttribute.gviVertexAttributeZ); pointb1.SpatialCRS = crs; pointb1.SetCoords(startPoint.X, startPoint.Y, minZ, 0, 0); IPoint pointb2 = geoFact.CreatePoint(gviVertexAttribute.gviVertexAttributeZ); pointb2.SpatialCRS = crs; pointb2.SetCoords(endPoint.X, endPoint.Y, minZ, 0, 0); IPoint pointb3 = geoFact.CreatePoint(gviVertexAttribute.gviVertexAttributeZ); pointb3.SpatialCRS = crs; pointb3.SetCoords(pt2.X, pt2.Y, minZ, 0, 0); IPoint pointb4 = geoFact.CreatePoint(gviVertexAttribute.gviVertexAttributeZ); pointb1.SpatialCRS = crs; pointb4.SetCoords(pt1.X, pt1.Y, minZ, 0, 0); IPolygon polygonBottom = geoFact.CreateGeometry(gviGeometryType.gviGeometryPolygon, gviVertexAttribute.gviVertexAttributeZ) as IPolygon; polygonBottom.SpatialCRS = crs; polygonBottom.ExteriorRing.AppendPoint(pointb1); polygonBottom.ExteriorRing.AppendPoint(pointb2); polygonBottom.ExteriorRing.AppendPoint(pointb3); polygonBottom.ExteriorRing.AppendPoint(pointb4); IPoint pointt1 = geoFact.CreatePoint(gviVertexAttribute.gviVertexAttributeZ); pointt1.SpatialCRS = crs; pointt1.SetCoords(startPoint.X, startPoint.Y, maxZ, 0, 0); IPoint pointt2 = geoFact.CreatePoint(gviVertexAttribute.gviVertexAttributeZ); pointt2.SpatialCRS = crs; pointt2.SetCoords(endPoint.X, endPoint.Y, maxZ, 0, 0); IPoint pointt3 = geoFact.CreatePoint(gviVertexAttribute.gviVertexAttributeZ); pointt3.SpatialCRS = crs; pointt3.SetCoords(pt2.X, pt2.Y, maxZ, 0, 0); IPoint pointt4 = geoFact.CreatePoint(gviVertexAttribute.gviVertexAttributeZ); pointt4.SpatialCRS = crs; pointt4.SetCoords(pt1.X, pt1.Y, maxZ, 0, 0); IPolygon polygonTop = geoFact.CreateGeometry(gviGeometryType.gviGeometryPolygon, gviVertexAttribute.gviVertexAttributeZ) as IPolygon; polygonTop.SpatialCRS = crs; polygonTop.ExteriorRing.AppendPoint(pointt1); polygonTop.ExteriorRing.AppendPoint(pointt2); polygonTop.ExteriorRing.AppendPoint(pointt3); polygonTop.ExteriorRing.AppendPoint(pointt4); IPolygon polygon1 = geoFact.CreateGeometry(gviGeometryType.gviGeometryPolygon, gviVertexAttribute.gviVertexAttributeZ) as IPolygon; polygon1.SpatialCRS = crs; polygon1.ExteriorRing.AppendPoint(pointb1); polygon1.ExteriorRing.AppendPoint(pointb2); polygon1.ExteriorRing.AppendPoint(pointt2); polygon1.ExteriorRing.AppendPoint(pointt1); IPolygon polygon2 = geoFact.CreateGeometry(gviGeometryType.gviGeometryPolygon, gviVertexAttribute.gviVertexAttributeZ) as IPolygon; polygon2.SpatialCRS = crs; polygon2.ExteriorRing.AppendPoint(pointb1); polygon2.ExteriorRing.AppendPoint(pointb4); polygon2.ExteriorRing.AppendPoint(pointt4); polygon2.ExteriorRing.AppendPoint(pointt1); IPolygon polygon3 = geoFact.CreateGeometry(gviGeometryType.gviGeometryPolygon, gviVertexAttribute.gviVertexAttributeZ) as IPolygon; polygon3.SpatialCRS = crs; polygon3.ExteriorRing.AppendPoint(pointb2); polygon3.ExteriorRing.AppendPoint(pointb3); polygon3.ExteriorRing.AppendPoint(pointt3); polygon3.ExteriorRing.AppendPoint(pointt2); IPolygon polygon4 = geoFact.CreateGeometry(gviGeometryType.gviGeometryPolygon, gviVertexAttribute.gviVertexAttributeZ) as IPolygon; polygon4.SpatialCRS = crs; polygon4.ExteriorRing.AppendPoint(pointb3); polygon4.ExteriorRing.AppendPoint(pointb4); polygon4.ExteriorRing.AppendPoint(pointt4); polygon4.ExteriorRing.AppendPoint(pointt3); IMultiPolygon multiPolygon = geoFact.CreateGeometry(gviGeometryType.gviGeometryMultiPolygon, gviVertexAttribute.gviVertexAttributeZ) as IMultiPolygon; multiPolygon.SpatialCRS = crs; multiPolygon.AddPolygon(polygonBottom); multiPolygon.AddPolygon(polygonTop); //multiPolygon.AddPolygon(polygon1); multiPolygon.AddPolygon(polygon2); multiPolygon.AddPolygon(polygon3); multiPolygon.AddPolygon(polygon4); ISurfaceSymbol ss = new SurfaceSymbolClass(); ss.Color = 0x550000AA; ICurveSymbol cs = new CurveSymbolClass(); cs.Color = 0xff0000AA; ss.BoundarySymbol = cs; this._renderPolygon = app.Current3DMapControl.ObjectManager.CreateRenderPolygon(polygon1, ss, app.Current3DMapControl.ProjectTree.RootID); ISurfaceSymbol ss1 = new SurfaceSymbolClass(); ss1.Color = 0x88FFFFFF; ICurveSymbol cs1 = new CurveSymbolClass(); cs1.Color = 0xffffffff; ss1.BoundarySymbol = cs1; this._renderBox = app.Current3DMapControl.ObjectManager.CreateRenderMultiPolygon(multiPolygon, ss1, app.Current3DMapControl.ProjectTree.RootID); _env = null; _ang = null; _center = null; _env = new EnvelopeClass(); double xdis = Math.Sqrt((pointb1.X - pointb2.X) * (pointb1.X - pointb2.X) + (pointb1.Y - pointb2.Y) * (pointb1.Y - pointb2.Y)) / 2; double ydis = Math.Sqrt((pointb1.X - pointb4.X) * (pointb1.X - pointb4.X) + (pointb1.Y - pointb4.Y) * (pointb1.Y - pointb4.Y)) / 2; _env.MinZ = -ydis; _env.MaxZ = ydis; _env.MinX = -xdis; _env.MaxX = xdis; _env.MinY = -(maxZ - minZ) / 2.0; _env.MaxY = (maxZ - minZ) / 2.0; _center = geoFact.CreatePoint(gviVertexAttribute.gviVertexAttributeZ); _center.SpatialCRS = crs; _center.X = polygonBottom.Centroid.X; _center.Y = polygonBottom.Centroid.Y; _center.Z = polygon1.Centroid.Z; _ang = new EulerAngleClass(); _ang.Set(angcz.Heading, 0, 0); } catch (Exception ex) { } }
private void DrawControlRegion() { DF3DApplication app = DF3DApplication.Application; if (app == null || app.Current3DMapControl == null || !app.Current3DMapControl.Terrain.IsRegistered) { return; } if (this._renderBox != null) { app.Current3DMapControl.ObjectManager.DeleteObject(this._renderBox.Guid); this._renderBox = null; } IGeometry geo = this._drawTool.GetGeo(); if (geo == null || geo.GeometryType != gviGeometryType.gviGeometryPolygon) { return; } IPolygon polygon = geo as IPolygon; double terrainHeight = 0.0; if (app.Current3DMapControl.Terrain.IsRegistered) { terrainHeight = app.Current3DMapControl.Terrain.GetElevation(polygon.Centroid.X, polygon.Centroid.Y, gviGetElevationType.gviGetElevationFromDatabase); } double height = double.Parse(this.seLimitHeight.Value.ToString()) + terrainHeight; IGeometryFactory geoFact = new GeometryFactoryClass(); IMultiPolygon multiPolygon = geoFact.CreateGeometry(gviGeometryType.gviGeometryMultiPolygon, gviVertexAttribute.gviVertexAttributeZ) as IMultiPolygon; IPolygon polygonZ = geoFact.CreateGeometry(gviGeometryType.gviGeometryPolygon, gviVertexAttribute.gviVertexAttributeZ) as IPolygon; for (int i = 0; i < polygon.ExteriorRing.PointCount; i++) { IPoint ptTemp = geoFact.CreatePoint(gviVertexAttribute.gviVertexAttributeZ); IPoint pt1 = polygon.ExteriorRing.GetPoint(i); ptTemp.X = pt1.X; ptTemp.Y = pt1.Y; ptTemp.Z = height; polygonZ.ExteriorRing.AppendPoint(ptTemp); } multiPolygon.AddPolygon(polygonZ); for (int i = 0; i < polygon.ExteriorRing.PointCount - 1; i++) { IPoint pt0 = polygon.ExteriorRing.GetPoint(i); IPoint pt1 = polygon.ExteriorRing.GetPoint(i + 1); IPoint pt00 = polygonZ.ExteriorRing.GetPoint(i); IPoint pt11 = polygonZ.ExteriorRing.GetPoint(i + 1); IPolygon polygon1 = geoFact.CreateGeometry(gviGeometryType.gviGeometryPolygon, gviVertexAttribute.gviVertexAttributeZ) as IPolygon; polygon1.ExteriorRing.AppendPoint(pt0); polygon1.ExteriorRing.AppendPoint(pt1); polygon1.ExteriorRing.AppendPoint(pt11); polygon1.ExteriorRing.AppendPoint(pt00); multiPolygon.AddPolygon(polygon1); } IPoint ptL0 = polygon.ExteriorRing.GetPoint(0); IPoint ptL1 = polygon.ExteriorRing.GetPoint(polygon.ExteriorRing.PointCount - 1); IPoint ptL00 = polygonZ.ExteriorRing.GetPoint(0); IPoint ptL11 = polygonZ.ExteriorRing.GetPoint(polygon.ExteriorRing.PointCount - 1); IPolygon polygon2 = geoFact.CreateGeometry(gviGeometryType.gviGeometryPolygon, gviVertexAttribute.gviVertexAttributeZ) as IPolygon; polygon2.ExteriorRing.AppendPoint(ptL00); polygon2.ExteriorRing.AppendPoint(ptL11); polygon2.ExteriorRing.AppendPoint(ptL1); polygon2.ExteriorRing.AppendPoint(ptL0); multiPolygon.AddPolygon(polygon2); ISurfaceSymbol ss1 = new SurfaceSymbolClass(); ss1.Color = 0x88FFFFFF; ICurveSymbol cs1 = new CurveSymbolClass(); cs1.Color = 0xffffffff; ss1.BoundarySymbol = cs1; this._renderBox = app.Current3DMapControl.ObjectManager.CreateRenderMultiPolygon(multiPolygon, ss1, app.Current3DMapControl.ProjectTree.RootID); app.Current3DMapControl.HighlightHelper.Color = 0xAAFF0000; app.Current3DMapControl.HighlightHelper.SetRegion(geo); app.Current3DMapControl.HighlightHelper.MinZ = height; app.Current3DMapControl.HighlightHelper.VisibleMask = 15; }
private IMultiPolygon GetMultiPolygonFromFile(string sFilePath) { IDataSource dataSource = null; IFeatureDataSet featureDataSet = null; IFeatureClass featureClass = null; IFdeCursor fdeCursor = null; IMultiPolygon result; try { IConnectionInfo connectionInfo = new ConnectionInfoClass(); connectionInfo.ConnectionType = gviConnectionType.gviConnectionShapeFile; connectionInfo.Database = sFilePath; dataSource = ((IDataSourceFactory) new DataSourceFactoryClass()).OpenDataSource(connectionInfo); string[] featureDatasetNames = dataSource.GetFeatureDatasetNames(); if (featureDatasetNames != null && featureDatasetNames.Length > 0) { featureDataSet = dataSource.OpenFeatureDataset(featureDatasetNames[0]); string[] namesByType = featureDataSet.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable); if (namesByType != null && namesByType.Length > 0) { featureClass = featureDataSet.OpenFeatureClass(namesByType[0]); IFieldInfoCollection fields = featureClass.GetFields(); int num = -1; gviGeometryColumnType gviGeometryColumnType = gviGeometryColumnType.gviGeometryColumnUnknown; gviVertexAttribute vertexAttribute = gviVertexAttribute.gviVertexAttributeNone; for (int i = 0; i < fields.Count; i++) { IFieldInfo fieldInfo = fields.Get(i); if (fieldInfo.FieldType == gviFieldType.gviFieldGeometry && fieldInfo.GeometryDef != null) { num = i; gviGeometryColumnType = fieldInfo.GeometryDef.GeometryColumnType; vertexAttribute = fieldInfo.GeometryDef.VertexAttribute; break; } } if (num == -1 || gviGeometryColumnType != gviGeometryColumnType.gviGeometryColumnPolygon) { XtraMessageBox.Show("应选择面状矢量数据!"); result = null; } else { IGeometryFactory geometryFactory = new GeometryFactoryClass(); IMultiPolygon multiPolygon = geometryFactory.CreateGeometry(gviGeometryType.gviGeometryMultiPolygon, vertexAttribute) as IMultiPolygon; multiPolygon.SpatialCRS = featureDataSet.SpatialReference; fdeCursor = featureClass.Search(null, true); IRowBuffer rowBuffer; while ((rowBuffer = fdeCursor.NextRow()) != null) { object value = rowBuffer.GetValue(num); if (value != null && value is IGeometry) { IGeometry geometry = value as IGeometry; if (geometry.GeometryType == gviGeometryType.gviGeometryPolygon) { multiPolygon.AddPolygon(geometry as IPolygon); } else { if (geometry.GeometryType == gviGeometryType.gviGeometryMultiPolygon) { IMultiPolygon multiPolygon2 = geometry as IMultiPolygon; for (int j = 0; j < multiPolygon2.GeometryCount; j++) { IPolygon polygon = multiPolygon2.GetPolygon(j); if (polygon != null) { multiPolygon.AddPolygon(polygon); } } } } } } if (multiPolygon.GeometryCount < 1) { XtraMessageBox.Show("无可用范围数据!"); result = null; } else { result = multiPolygon; } } } else { XtraMessageBox.Show("打开shp文件失败!"); result = null; } } else { XtraMessageBox.Show("名称为空"); result = null; } } catch (System.Runtime.InteropServices.COMException ex) { XtraMessageBox.Show(ex.Message); result = null; } finally { if (dataSource != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(dataSource); dataSource = null; } if (featureDataSet != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(featureDataSet); featureDataSet = null; } if (featureClass != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(featureClass); featureClass = null; } if (fdeCursor != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(fdeCursor); fdeCursor = null; } } return(result); }
private void sbtn_Split_Click(object sender, System.EventArgs e) { DF3DApplication app = DF3DApplication.Application; if (app == null || app.Current3DMapControl == null) { return; } if (System.Windows.Forms.DialogResult.No != XtraMessageBox.Show("模型拆分不支持撤销操作,是否继续?", "询问", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Exclamation)) { IFeatureClass featureClass = null; IFdeCursor fdeCursor = null; app.Current3DMapControl.PauseRendering(false); WaitDialogForm waitDialogForm = null; try { int count = SelectCollection.Instance().GetCount(true); if (count <= 0) { XtraMessageBox.Show("未选中要拆分的模型!"); } else { if (this._renderGeo == null || this._renderGeo.GetFdeGeometry() == null) { XtraMessageBox.Show("请先绘制或选择拆分多边形!"); } else { IMultiPolygon multiPolygon = null; if (this.radioGroup1.SelectedIndex == 1) { IGeometryFactory geometryFactory = new GeometryFactoryClass(); multiPolygon = (geometryFactory.CreateGeometry(gviGeometryType.gviGeometryMultiPolygon, gviVertexAttribute.gviVertexAttributeZ) as IMultiPolygon); multiPolygon.AddPolygon(this._renderGeo.GetFdeGeometry() as IPolygon); } else { if (this.radioGroup1.SelectedIndex == 0) { multiPolygon = (this._renderGeo.GetFdeGeometry() as IMultiPolygon); } } if (multiPolygon == null) { XtraMessageBox.Show("获取裁剪多边形失败!"); } else { waitDialogForm = new WaitDialogForm(string.Empty, "正在拆分模型,请稍后..."); HashMap featureClassInfoMap = SelectCollection.Instance().FeatureClassInfoMap; System.Collections.Hashtable hashtable = new System.Collections.Hashtable(); foreach (DF3DFeatureClass featureClassInfo in featureClassInfoMap.Keys) { if (featureClassInfo.GetFeatureLayer().GeometryType == gviGeometryColumnType.gviGeometryColumnModelPoint) { System.Collections.Generic.List <int> list = new System.Collections.Generic.List <int>(); System.Collections.Generic.List <int> list2 = new System.Collections.Generic.List <int>(); IRowBufferCollection rowBufferCollection = new RowBufferCollectionClass(); IRowBufferCollection rowBufferCollection2 = new RowBufferCollectionClass(); ResultSetInfo resultSetInfo = featureClassInfoMap[featureClassInfo] as ResultSetInfo; DataTable resultSetTable = resultSetInfo.ResultSetTable; if (resultSetTable.Rows.Count >= 1) { featureClass = featureClassInfo.GetFeatureClass(); IResourceManager resourceManager = featureClass.FeatureDataSet as IResourceManager; string fidFieldName = featureClass.FidFieldName; int num = featureClass.GetFields().IndexOf(fidFieldName); foreach (DataRow dataRow in resultSetTable.Rows) { int num2 = int.Parse(dataRow[fidFieldName].ToString()); IRowBuffer row = featureClass.GetRow(num2); int position = row.FieldIndex(featureClassInfo.GetFeatureLayer().GeometryFieldName); IModelPoint modelPoint = row.GetValue(position) as IModelPoint; if (modelPoint != null) { Gvitech.CityMaker.Resource.IModel model = resourceManager.GetModel(modelPoint.ModelName); IGeometryConvertor geometryConvertor = new GeometryConvertorClass(); Gvitech.CityMaker.Resource.IModel model2 = null; Gvitech.CityMaker.Resource.IModel model3 = null; IModelPoint modelPoint2 = null; IModelPoint modelPoint3 = null; bool flag = geometryConvertor.SplitModelPointByPolygon2D(multiPolygon, model, modelPoint, out model2, out modelPoint2, out model3, out modelPoint3); if (flag && model2 != null && !model2.IsEmpty && modelPoint2 != null && model3 != null && !model3.IsEmpty && modelPoint3 != null) { System.Guid guid = System.Guid.NewGuid(); string text = guid.ToString(); resourceManager.AddModel(text, model2, null); resourceManager.RebuildSimplifiedModel(text); guid = System.Guid.NewGuid(); string text2 = guid.ToString(); resourceManager.AddModel(text2, model3, null); resourceManager.RebuildSimplifiedModel(text2); modelPoint3.ModelName = text2; row.SetValue(position, modelPoint3); rowBufferCollection.Add(row); list.Add(num2); modelPoint2.ModelName = text; IRowBuffer rowBuffer = row.Clone(false); rowBuffer.SetNull(num); rowBuffer.SetValue(position, modelPoint2); fdeCursor = featureClass.Insert(); fdeCursor.InsertRow(rowBuffer); int lastInsertId = fdeCursor.LastInsertId; rowBuffer.SetValue(num, lastInsertId); rowBufferCollection2.Add(rowBuffer); list2.Add(lastInsertId); System.Runtime.InteropServices.Marshal.ReleaseComObject(fdeCursor); fdeCursor = null; } } } featureClass.UpdateRows(rowBufferCollection, false); app.Current3DMapControl.FeatureManager.EditFeatures(featureClass, rowBufferCollection); app.Current3DMapControl.FeatureManager.CreateFeatures(featureClass, rowBufferCollection2); hashtable[featureClassInfo] = list2; //System.Runtime.InteropServices.Marshal.ReleaseComObject(featureClass); featureClass = null; System.Runtime.InteropServices.Marshal.ReleaseComObject(resourceManager); resourceManager = null; } } } SelectCollection.Instance().UpdateSelection(hashtable); base.Close(); base.DialogResult = System.Windows.Forms.DialogResult.OK; } } } } catch (System.Runtime.InteropServices.COMException ex) { XtraMessageBox.Show(ex.Message); } catch (System.UnauthorizedAccessException var_35_4EC) { XtraMessageBox.Show("拒绝访问"); } catch (System.Exception ex2) { XtraMessageBox.Show(ex2.Message); } finally { if (waitDialogForm != null) { waitDialogForm.Close(); } if (fdeCursor != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(fdeCursor); fdeCursor = null; } //if (featureClass != null && System.Runtime.InteropServices.Marshal.IsComObject(featureClass)) //{ // System.Runtime.InteropServices.Marshal.ReleaseComObject(featureClass); // featureClass = null; //} app.Current3DMapControl.ResumeRendering(); } } }