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 sbtn_BrowseFile_Click(object sender, System.EventArgs e) { DF3DApplication app = DF3DApplication.Application; if (app == null || app.Current3DMapControl == null) { return; } System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog(); openFileDialog.Multiselect = false; openFileDialog.CheckFileExists = true; openFileDialog.Filter = "Shp File(*.shp)|*.shp"; openFileDialog.DefaultExt = ".shp"; if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string fileName = openFileDialog.FileName; IMultiPolygon multiPolygonFromFile = this.GetMultiPolygonFromFile(fileName); if (multiPolygonFromFile != null) { IGeometryFactory geometryFactory = new GeometryFactoryClass(); IGeometry geometry = multiPolygonFromFile.Clone2(gviVertexAttribute.gviVertexAttributeNone); ISurfaceSymbol surfaceSymbol = new SurfaceSymbolClass(); surfaceSymbol.Color = 1442840448u; surfaceSymbol.BoundarySymbol = new CurveSymbolClass { Color = 1442840448u }; this._renderGeo = app.Current3DMapControl.ObjectManager.CreateRenderMultiPolygon(geometry as IMultiPolygon, surfaceSymbol, app.Current3DMapControl.ProjectTree.RootID); int lastError = app.Current3DMapControl.GetLastError(); string str = string.Empty; if (lastError != 0) { //str = Logger.GetRenderCtrlError(lastError); } if (this._renderGeo == null) { XtraMessageBox.Show("多边形创建失败!" + str); } else { app.Current3DMapControl.HighlightHelper.VisibleMask = 1; app.Current3DMapControl.HighlightHelper.SetRegion(this._renderGeo.GetFdeGeometry()); app.Current3DMapControl.Camera.FlyToObject(this._renderGeo.Guid, gviActionCode.gviActionFlyTo); this.textEdit_FilePath.Text = fileName; System.Runtime.InteropServices.Marshal.ReleaseComObject(multiPolygonFromFile); } } } }
private List <IPoint> DisPerseLine(IPoint pStart, IPoint pEnd, double disperse) { if (pStart == null || pEnd == null) { return(null); } List <IPoint> result = new List <IPoint>(); IVector3 vector = new Vector3(); vector.Set(pStart.X, pStart.Y, pStart.Z); IVector3 vector2 = new Vector3(); vector2.Set(pEnd.X - pStart.X, pEnd.Y - pStart.Y, pEnd.Z - pStart.Z); double length = vector2.Length; int num = int.Parse(Math.Floor(length / disperse).ToString()); IGeometryFactory geoFact = new GeometryFactoryClass(); for (var i = 0; i <= num; i++) { var gvitechPoint = geoFact.CreatePoint(gviVertexAttribute.gviVertexAttributeZ); if (i == 0) { gvitechPoint.X = pStart.X; gvitechPoint.Y = pStart.Y; gvitechPoint.Z = pStart.Z; } else { if (i == num) { gvitechPoint.X = pEnd.X; gvitechPoint.Y = pEnd.Y; gvitechPoint.Z = pEnd.Z; } else { gvitechPoint.X = vector.X + vector2.X * i / num; gvitechPoint.Y = vector.Y + vector2.Y * i / num; gvitechPoint.Z = vector.Z + vector2.Z * i / num; } } result.Add(gvitechPoint); } return(result); }
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 ShowFlowDirect(IFeatureLayerPickResult pr) { if (pr == null) { return; } IRowBuffer row = null; IFdeCursor cursor = null; try { int fid = pr.FeatureId; DF3DFeatureClass dffc = DF3DFeatureClassManager.Instance.GetFeatureClassByID(pr.FeatureLayer.FeatureClassId.ToString()); if (dffc == null) { return; } IFeatureClass fc = dffc.GetFeatureClass(); FacilityClass fac = dffc.GetFacilityClass(); if (fc == null || fac == null || fac.Name != "PipeLine") { return; } DFDataConfig.Class.FieldInfo fi = fac.GetFieldInfoBySystemName("FlowDirect"); if (fi == null) { return; } IFieldInfoCollection fiCol = fc.GetFields(); int index = fiCol.IndexOf(fi.Name); if (index == -1) { return; } int indexShape = fiCol.IndexOf("Shape"); IQueryFilter filter = new QueryFilter(); filter.WhereClause = "oid=" + fid; cursor = fc.Search(filter, false); row = cursor.NextRow(); if (row == null) { return; } IPolyline line = null; if (indexShape != -1 && !row.IsNull(indexShape)) { object obj = row.GetValue(indexShape); if (obj != null && obj is IPolyline) { line = obj as IPolyline; } } string flowDirectValue = "0"; int type = 1;// 1表示具有流向字段;2表示从高到低 if (!row.IsNull(index)) { flowDirectValue = row.GetValue(index).ToString(); if (flowDirectValue != "0" && flowDirectValue != "1") { flowDirectValue = "0"; } type = 1; } else if (line != null) { if (line.StartPoint.Z > line.EndPoint.Z) { flowDirectValue = "0"; } else { flowDirectValue = "1"; } type = 2; } if (line == null) { return; } if (this._isAuth) { #region 流向渲染1 FacClassReg reg = FacilityInfoService.GetFacClassRegByFeatureClassID(fc.Guid.ToString()); if (reg == null) { return; } TopoClass tc = FacilityInfoService.GetTopoClassByFacClassCode(reg.FacClassCode); if (tc == null) { return; } FacStyleClass style = null; List <FacStyleClass> facilityStyles = FacilityInfoService.GetFacStyleByFacClassCode(reg.FacClassCode); if ((facilityStyles != null) && (facilityStyles.Count > 0)) { style = facilityStyles[0]; } PipeLineFac plfac = new PipeLineFac(reg, style, row, tc); IRenderModelPoint rmp = null; DrawGeometry.Ocx = DF3DApplication.Application.Current3DMapControl; plfac.ShowFlowDirection(int.Parse(flowDirectValue), out rmp); if (rmp != null) { this._listRender.Add(rmp.Guid); } #endregion } else { #region 流向渲染2 IEulerAngle angle = DF3DApplication.Application.Current3DMapControl.Camera.GetAimingAngles2(line.StartPoint, line.EndPoint); double dia = 0.0; string diaField = fac.GetFieldInfoNameBySystemName("Diameter"); int indexDia = fiCol.IndexOf(diaField); if (indexDia != -1 && !row.IsNull(indexDia)) { string diaStr = row.GetValue(indexDia).ToString(); int indexDia1 = diaStr.ToString().IndexOf('*'); if (indexDia1 != -1) { var dia1 = int.Parse(diaStr.ToString().Substring(0, indexDia1)); var dia2 = int.Parse(diaStr.ToString().Substring(indexDia1 + 1, diaStr.ToString().Length)); dia = ((dia1 > dia2) ? dia1 : dia2) * 0.001; } else { dia = int.Parse(diaStr) * 0.001; } } List <IPoint> points = new List <IPoint>(); if (flowDirectValue == "0") { for (int i = 0; i < line.PointCount; i++) { IPoint pt = line.GetPoint(i); pt.Z += dia / 2; points.Add(pt); } } else if (flowDirectValue == "1") { for (int i = line.PointCount - 1; i >= 0; i--) { IPoint pt = line.GetPoint(i); pt.Z += dia / 2; points.Add(pt); } } for (int i = 0; i < points.Count - 1; i++) { IPoint pt1 = points[i]; var pt2 = points[i + 1]; double delt = 0; double _rate, _distance; if (!(Math.Abs(dia) < 0.0000001)) { delt = 2.0 * dia; if (dia <= 0.5 && dia >= 0.3) { _rate = 7 * dia; _distance = 3 * dia / 0.4; } else if (dia < 0.3 && dia > 0.1) { _rate = 12 * dia; _distance = 6 * dia / 0.4; } else if (dia <= 0.1) { _rate = 22 * dia; _distance = 9 * dia / 0.4; } else { _rate = 3.5 * dia; _distance = 1.5 * dia / 0.4; } } else { _rate = 2.0; _distance = 3.0; //z = maxZ + 0.2; delt = 0.2; } List <IPoint> list = DisPerseLine(pt1, pt2, _distance); if (list.Count < 2) { return; } List <IPoint> list1 = new List <IPoint>(); IGeometryFactory geoFact = new GeometryFactoryClass(); for (int j = 0; j < list.Count - 1; j++) { IPoint p = geoFact.CreatePoint(gviVertexAttribute.gviVertexAttributeZ); p.X = (list[j].X + list[j + 1].X) / 2; p.Y = (list[j].Y + list[j + 1].Y) / 2; p.Z = (list[j].Z + list[j + 1].Z) / 2; list1.Add(p); } for (var m = 0; m < list1.Count; m++) { IPosition pos = new PositionClass(); pos.X = list1[m].X; pos.Y = list1[m].Y; pos.Altitude = list1[m].Z + delt; pos.AltitudeType = gviAltitudeType.gviAltitudeTerrainAbsolute; pos.Heading = angle.Heading; pos.Tilt = angle.Tilt; pos.Roll = angle.Roll; UInt32 color; if (type == 1) { color = 0xFFFFFF00; } else { color = 0xFF00FFFF; } ITerrainArrow rArrow = DF3DApplication.Application.Current3DMapControl.ObjectManager.CreateArrow(pos, 0.8 * _rate, 3, color, color, DF3DApplication.Application.Current3DMapControl.ProjectTree.RootID); this._listRender.Add(rArrow.Guid); } } #endregion } } catch (Exception ex) { } finally { if (cursor != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor); cursor = null; } if (row != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(row); row = null; } } }
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(); } } }