void axRenderControl1_RcObjectEditFinish() { IMultiPolygon multiPolygon = currentRenderGeometry.GetFdeGeometry() as IMultiPolygon; if (multiPolygon == null) { multiPolygon = geoFactory.CreateGeometry(gviGeometryType.gviGeometryMultiPolygon, gviVertexAttribute.gviVertexAttributeZ) as IMultiPolygon; IPolygon polygon = currentRenderGeometry.GetFdeGeometry() as IPolygon; multiPolygon.AddPolygon(polygon); } this.axRenderControl1.Terrain.SetOceanRegion(multiPolygon); currentRenderGeometry.VisibleMask = gviViewportMask.gviViewNone; currentRenderGeometry.ViewingDistance = 10000; this.axRenderControl1.Camera.FlyToObject(currentRenderGeometry.Guid, gviActionCode.gviActionFollowAbove); this.axRenderControl1.InteractMode = gviInteractMode.gviInteractNormal; }
public static bool ConvertBuildingParam(IPolygon footprint, double startZ, double height, out IMultiPolygon segPolygon, out IPolyline route) { segPolygon = null; route = null; IPoint point = null; IPoint pointValue = null; IEnvelope envelope = null; IPolygon polygon = null; if (footprint == null) { return(false); } try { envelope = footprint.Envelope; segPolygon = DrawGeometry.geoFactory.CreateGeometry(gviGeometryType.gviGeometryMultiPolygon, gviVertexAttribute.gviVertexAttributeZ) as IMultiPolygon; route = DrawGeometry.geoFactory.CreateGeometry(gviGeometryType.gviGeometryPolyline, gviVertexAttribute.gviVertexAttributeZ) as IPolyline; point = DrawGeometry.geoFactory.CreatePoint(gviVertexAttribute.gviVertexAttributeZ); point.SetCoords(envelope.Center.X, envelope.Center.Y, 0.0, 0.0, 0); pointValue = point.Clone() as IPoint; pointValue.Z = startZ; route.AppendPoint(pointValue); pointValue = point.Clone() as IPoint; pointValue.Z = startZ + height; route.AppendPoint(pointValue); int pointCount = footprint.ExteriorRing.PointCount; polygon = DrawGeometry.geoFactory.CreateGeometry(gviGeometryType.gviGeometryPolygon, gviVertexAttribute.gviVertexAttributeZ) as IPolygon; for (int i = 0; i < pointCount; i++) { pointValue = footprint.ExteriorRing.GetPoint(i).Clone() as IPoint; pointValue.X -= point.X; pointValue.Y -= point.Y; polygon.ExteriorRing.AppendPoint(pointValue); } segPolygon.AddPolygon(polygon); return(true); } catch (Exception exception) { DrawGeometry.WriteLog(exception.StackTrace); return(false); } }
/// <summary> /// 挖洞 /// </summary> /// <param name="polygon"></param> /// <param name="deep"></param> public void DrawTerrainHole(IPolygon polygon, double deep) { if (polygon == null) { return; } IRing ring = polygon.ExteriorRing; if (!ring.IsClosed) { return; } IPoint point0 = ring.GetPoint(0); double lowestPoint = this.axRenderControl1.Terrain.GetElevation(point0.X, point0.Y, gviGetElevationType.gviGetElevationFromDatabase); IPolygon pBottom = geoFactory.CreateGeometry(gviGeometryType.gviGeometryPolygon, gviVertexAttribute.gviVertexAttributeZ) as IPolygon; pBottom.SpatialCRS = crs as ISpatialCRS; for (int i = 0; i < ring.PointCount; i++) { IPoint point = ring.GetPoint(i); point.Z = this.axRenderControl1.Terrain.GetElevation(point.X, point.Y, gviGetElevationType.gviGetElevationFromDatabase); if (point.Z < lowestPoint) { lowestPoint = point.Z; } ring.UpdatePoint(i, point); point = point.Clone2(gviVertexAttribute.gviVertexAttributeZ) as IPoint; pBottom.ExteriorRing.AppendPoint(point); } //b、计算底面 lowestPoint -= deep; for (int jj = 0; jj < pBottom.ExteriorRing.PointCount; jj++) { IPoint point1 = pBottom.ExteriorRing.GetPoint(jj); point1.Z = lowestPoint; pBottom.ExteriorRing.UpdatePoint(jj, point1); } ICurveSymbol cvSymbol = new CurveSymbol(); cvSymbol.Color = System.Drawing.Color.Yellow; ISurfaceSymbol sfside = new SurfaceSymbol(); sfside.BoundarySymbol = cvSymbol; sfside.Color = System.Drawing.Color.BurlyWood; ISurfaceSymbol sfbottom = new SurfaceSymbol(); sfbottom.BoundarySymbol = cvSymbol; sfbottom.Color = System.Drawing.Color.Green; rpolygon = this.axRenderControl1.ObjectManager.CreateRenderPolygon(pBottom, sfbottom, rootId); rpolygon.MaxVisibleDistance = 9999999; IMultiPolygon mpolygon = geoFactory.CreateGeometry(gviGeometryType.gviGeometryMultiPolygon, gviVertexAttribute.gviVertexAttributeZ) as IMultiPolygon; mpolygon.SpatialCRS = crs as ISpatialCRS; for (int i = 0; i < ring.PointCount - 1; i++) { IPolygon pSide = geoFactory.CreateGeometry(gviGeometryType.gviGeometryPolygon, gviVertexAttribute.gviVertexAttributeZ) as IPolygon; pSide.SpatialCRS = crs as ISpatialCRS; pSide.ExteriorRing.AppendPoint(polygon.ExteriorRing.GetPoint(i)); pSide.ExteriorRing.AppendPoint(pBottom.ExteriorRing.GetPoint(i)); pSide.ExteriorRing.AppendPoint(pBottom.ExteriorRing.GetPoint(i + 1)); pSide.ExteriorRing.AppendPoint(polygon.ExteriorRing.GetPoint(i + 1)); pSide.Close(); mpolygon.AddPolygon(pSide); //renderControl.ObjectManager.CreateRenderPolygon(pSide, sfside); } rmpolygon = this.axRenderControl1.ObjectManager.CreateRenderMultiPolygon(mpolygon, sfside, rootId); rmpolygon.MaxVisibleDistance = 99999999; hole = this.axRenderControl1.ObjectManager.CreateTerrainHole(polygon, rootId); currentRenderGeometry.VisibleMask = gviViewportMask.gviViewNone; }
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 btnConstructMultiPolygon_Click(object sender, EventArgs e) { if (gfactory == null) gfactory = new GeometryFactory(); multiPolygon = gfactory.CreateGeometry(gviGeometryType.gviGeometryMultiPolygon, gviVertexAttribute.gviVertexAttributeZ) as IMultiPolygon; if (multiPolygon == null) return; //添加第一个polygon IPolygon polygonFirst = gfactory.CreateGeometry(gviGeometryType.gviGeometryPolygon, gviVertexAttribute.gviVertexAttributeZ) as IPolygon; if (polygonFirst == null) return; /// 外环顺时针:1-4-3-2-1 /// 4-------3 /// | | /// | | /// 1-------2 IRing exteriorRing = polygonFirst.ExteriorRing; point = gfactory.CreatePoint(gviVertexAttribute.gviVertexAttributeZ); point.SetCoords(0, 0, 0, 0, 1); exteriorRing.AppendPoint(point); point.SetCoords(0, 200, 0, 0, 2); exteriorRing.AppendPoint(point); point.SetCoords(100, 200, 0, 0, 3); exteriorRing.AppendPoint(point); point.SetCoords(100, 0, 0, 0, 4); exteriorRing.AppendPoint(point); point.SetCoords(0, 0, 0, 0, 5); exteriorRing.AppendPoint(point); //闭合 /// 内环逆时针:1-2-3-4-1 /// 4-------3 /// | | /// | | /// 1-------2 IRing interiorRing = gfactory.CreateGeometry(gviGeometryType.gviGeometryRing, gviVertexAttribute.gviVertexAttributeZ) as IRing; point.SetCoords(25, 25, 0, 0, 1); interiorRing.AppendPoint(point); point.SetCoords(75, 25, 0, 0, 2); interiorRing.AppendPoint(point); point.SetCoords(75, 75, 0, 0, 3); interiorRing.AppendPoint(point); point.SetCoords(25, 75, 0, 0, 4); interiorRing.AppendPoint(point); point.SetCoords(25, 25, 0, 0, 5); interiorRing.AppendPoint(point); //闭合 polygonFirst.AddInteriorRing(interiorRing); //Clone一个新的内环 IRing pInteriorRingNew = interiorRing.Clone() as IRing; polygonFirst.AddInteriorRing(pInteriorRingNew); multiPolygon.AddPolygon(polygonFirst); //Clone一个新的polygon IPolygon pPolygonNew = polygonFirst.Clone() as IPolygon; multiPolygon.AddPolygon(pPolygonNew); MultiSurface geo = new MultiSurface(); // Geometry属性 geo.Dimension = multiPolygon.Dimension; if (multiPolygon.Envelope != null) { geo.MaxX = multiPolygon.Envelope.MaxX; geo.MaxY = multiPolygon.Envelope.MaxY; geo.MaxZ = multiPolygon.Envelope.MaxZ; geo.MinX = multiPolygon.Envelope.MinX; geo.MinY = multiPolygon.Envelope.MinY; geo.MinZ = multiPolygon.Envelope.MinZ; } geo.GeometryType = multiPolygon.GeometryType; geo.IsEmpty = multiPolygon.IsEmpty; geo.IsValid = multiPolygon.IsValid; geo.VertexAttribute = multiPolygon.VertexAttribute; geo.HasId = multiPolygon.HasId(); geo.HasM = multiPolygon.HasM(); geo.HasZ = multiPolygon.HasZ(); // GeometryCollection属性 geo.GeometryCount = multiPolygon.GeometryCount; geo.IsOverlap = multiPolygon.IsOverlap; // MultiSurface属性 geo.Area = multiPolygon.GetArea(); this.propertyGrid1.SelectedObject = geo; }
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(); } } }