Example #1
0
        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)
            {
            }
        }
Example #2
0
        private void MainForm_Load(object sender, System.EventArgs e)
        {
            // 初始化RenderControl控件
            IPropertySet ps = new PropertySet();

            ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL);
            this.axRenderControl1.Initialize(true, ps);
            this.axRenderControl1.Camera.FlyTime = 1;

            ICRSFactory crsfac = new CRSFactory();

            _currentCRS = (crsfac.CreateFromWKT(this.axRenderControl1.GetCurrentCrsWKT())) as ISpatialCRS;

            rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID;

            // 设置天空盒

            if (System.IO.Directory.Exists(strMediaPath))
            {
                string  tmpSkyboxPath = strMediaPath + @"\skybox";
                ISkyBox skybox        = this.axRenderControl1.ObjectManager.GetSkyBox(0);
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg");
            }
            else
            {
                MessageBox.Show("请不要随意更改SDK目录名");
                return;
            }

            this.axRenderControl1.Camera.FlyTime = 0;

            // 加载瓦片图层
            string       tilelayerString = (strMediaPath + @"\sdk.tdb");
            I3DTileLayer layer           = this.axRenderControl1.ObjectManager.Create3DTileLayer(tilelayerString, "", rootId);

            this.axRenderControl1.Camera.FlyToObject(layer.Guid, gviActionCode.gviActionFlyTo);
            // 添加节点到界面控件上
            myListNode item = new myListNode("tilelayer", TreeNodeType.NT_TiltedLAYER, layer);

            item.Checked = true;
            listView1.Items.Add(item);

            #region 加载FDB
            try
            {
                IConnectionInfo ci = new ConnectionInfo();
                ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x;
                string tmpFDBPath = (strMediaPath + @"\SDKDEMO.FDB");
                ci.Database = tmpFDBPath;
                IDataSourceFactory dsFactory = new DataSourceFactory();
                IDataSource        ds        = dsFactory.OpenDataSource(ci);
                string[]           setnames  = (string[])ds.GetFeatureDatasetNames();
                if (setnames.Length == 0)
                {
                    return;
                }
                IFeatureDataSet dataset = ds.OpenFeatureDataset(setnames[0]);
                _datasetCRS = dataset.SpatialReference;

                //遍历FeatureClass
                string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable);
                if (fcnames.Length == 0)
                {
                    return;
                }
                fcMap    = new Hashtable(fcnames.Length);
                fcuidMap = new Hashtable(fcnames.Length);
                foreach (string name in fcnames)
                {
                    IFeatureClass fc = dataset.OpenFeatureClass(name);
                    // 找到空间列字段
                    List <string>        geoNames   = new List <string>();
                    IFieldInfoCollection fieldinfos = fc.GetFields();
                    for (int i = 0; i < fieldinfos.Count; i++)
                    {
                        IFieldInfo fieldinfo = fieldinfos.Get(i);
                        if (null == fieldinfo)
                        {
                            continue;
                        }
                        IGeometryDef geometryDef = fieldinfo.GeometryDef;
                        if (null == geometryDef)
                        {
                            continue;
                        }
                        if (geometryDef.GeometryColumnType == gviGeometryColumnType.gviGeometryColumnPolygon)
                        {
                            geoNames.Add(fieldinfo.Name);
                        }
                    }
                    fcMap.Add(fc, geoNames);
                    fcuidMap.Add(fc.Guid, fc);
                }
            }
            catch (COMException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
                return;
            }
            #endregion

            //CreateFeautureLayer for 矢量贴地
            foreach (IFeatureClass fc in fcMap.Keys)
            {
                List <string> geoNames = (List <string>)fcMap[fc];
                if (geoNames.Count == 0)
                {
                    continue;
                }

                #region 定义几何物体渲染风格
                ICurveSymbol cs = new CurveSymbol();
                cs.Color = System.Drawing.Color.Empty;  //防止贴瓦片时出现绿色竖边
                IValueMapGeometryRender geoRender = new ValueMapGeometryRender();
                {
                    IRangeRenderRule rangeRule = new RangeRenderRule();
                    rangeRule.LookUpField = "oid";
                    rangeRule.MaxValue    = 1100;
                    rangeRule.MinValue    = 1000;
                    rangeRule.IncludeMin  = false;

                    ISurfaceSymbol geoSymbol = new SurfaceSymbol();
                    geoSymbol.Color          = System.Drawing.Color.Yellow;
                    geoSymbol.BoundarySymbol = cs;

                    IGeometryRenderScheme grs = new GeometryRenderScheme();
                    grs.AddRule(rangeRule);
                    grs.Symbol = geoSymbol;
                    geoRender.AddScheme(grs);
                }
                {
                    IRangeRenderRule rangeRule = new RangeRenderRule();
                    rangeRule.LookUpField = "oid";
                    rangeRule.MaxValue    = 1200;
                    rangeRule.MinValue    = 1100;
                    rangeRule.IncludeMin  = false;

                    ISurfaceSymbol geoSymbol = new SurfaceSymbol();
                    geoSymbol.Color          = System.Drawing.Color.Blue;
                    geoSymbol.BoundarySymbol = cs;

                    IGeometryRenderScheme grs = new GeometryRenderScheme();
                    grs.AddRule(rangeRule);
                    grs.Symbol = geoSymbol;
                    geoRender.AddScheme(grs);
                }
                {
                    IRangeRenderRule rangeRule = new RangeRenderRule();
                    rangeRule.LookUpField = "oid";
                    rangeRule.MaxValue    = 1300;
                    rangeRule.MinValue    = 1200;
                    rangeRule.IncludeMin  = false;

                    ISurfaceSymbol geoSymbol = new SurfaceSymbol();
                    geoSymbol.Color          = System.Drawing.Color.Green;
                    geoSymbol.BoundarySymbol = cs;

                    IGeometryRenderScheme grs = new GeometryRenderScheme();
                    grs.AddRule(rangeRule);
                    grs.Symbol = geoSymbol;
                    geoRender.AddScheme(grs);
                }
                {
                    IRangeRenderRule rangeRule = new RangeRenderRule();
                    rangeRule.LookUpField = "oid";
                    rangeRule.MaxValue    = 1400;
                    rangeRule.MinValue    = 1300;
                    rangeRule.IncludeMin  = false;

                    ISurfaceSymbol geoSymbol = new SurfaceSymbol();
                    geoSymbol.Color          = System.Drawing.Color.Goldenrod;
                    geoSymbol.BoundarySymbol = cs;

                    IGeometryRenderScheme grs = new GeometryRenderScheme();
                    grs.AddRule(rangeRule);
                    grs.Symbol = geoSymbol;
                    geoRender.AddScheme(grs);
                }
                {
                    ISurfaceSymbol geoSymbol = new SurfaceSymbol();
                    geoSymbol.Color          = System.Drawing.Color.Fuchsia;
                    geoSymbol.BoundarySymbol = cs;

                    IGeometryRenderScheme geoSchemeOther = new GeometryRenderScheme();
                    geoSchemeOther.Symbol = geoSymbol;
                    geoRender.AddScheme(geoSchemeOther);
                }
                #endregion
                geoRender.HeightStyle = gviHeightStyle.gviHeightOnEverything;

                IFeatureLayer fcLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer(fc, geoNames[0], null, geoRender, rootId);
                if (fcLayer != null)
                {
                    fcLayer.VisibleMask = gviViewportMask.gviViewNone;

                    // 添加节点到界面控件上
                    myListNode item2 = new myListNode(fc.Name + "_" + geoNames[0], TreeNodeType.NT_FeatureLayer, fcLayer);
                    item.Checked = false;
                    listView1.Items.Add(item2);
                }
                else
                {
                    MessageBox.Show("Create FeatureLayer Failed! " + this.axRenderControl1.GetLastError().ToString());
                }
            }

            // 注册事件
            this.axRenderControl1.RcMouseClickSelect += new Gvitech.CityMaker.Controls._IRenderControlEvents_RcMouseClickSelectEventHandler(axRenderControl1_RcMouseClickSelect);


            //设置highlight可用
            this.axRenderControl1.HighlightHelper.VisibleMask = 1;



            {
                this.helpProvider1.SetShowHelp(this.axRenderControl1, true);
                this.helpProvider1.SetHelpString(this.axRenderControl1, "");
                this.helpProvider1.HelpNamespace = "TileHole.html";
            }
        }