private void CreateFeautureLayer() { bool hasfly = false; foreach (FeatureClass fc in _featureClassMapping.Keys) { List <string> geoNames = _featureClassMapping[fc]; foreach (string geoName in geoNames) { if (!geoName.Equals("Geometry")) { continue; } IFeatureLayer featureLayer = _axRenderControl.ObjectManager.CreateFeatureLayer(fc, geoName, null, null); featureLayer.MaxVisibleDistance = 500000000; _featureLayerMaps.Add(new FeatureLayerMap(featureLayer, fc)); if (!hasfly) { IFieldInfoCollection fieldinfos = fc.GetFields(); IFieldInfo fieldinfo = fieldinfos.Get(fieldinfos.IndexOf(geoName)); IGeometryDef geometryDef = fieldinfo.GeometryDef; IEnvelope env = geometryDef.Envelope; if (env == null || (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 && env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0)) { continue; } //var angle = SetAngle(0, -20, 0); //SetCameraLookAt(env.Center, 1000, angle); } hasfly = true; } } }
private void SetDomainTree() { if (comboBoxDomains.SelectedIndex < 0 || fieldNamesHasDomain.Count == 0) { return; } string fieldName = fieldNamesHasDomain[comboBoxDomains.SelectedIndex]; int index = fieldinfos.IndexOf(fieldName); IFieldInfo field = fieldinfos.Get(index); IDomain domainSelect = field.Domain; if (domainSelect == null) { return; } nodekeyMap.Clear(); this.treeViewDomain.Nodes.Clear(); if (domainSelect.DomainType == gviDomainType.gviDomainCodedValue) { ICodedValueDomain codedomain = domainSelect as ICodedValueDomain; int nCodes = codedomain.CodeCount; for (int c = 0; c < nCodes; c++) { string codename = codedomain.GetCodeName(c); object codevalue = codedomain.GetCodeValue(c); this.treeViewDomain.Nodes.Add(codevalue.ToString(), codename, 2, 2); nodekeyMap.Add(codename, c); TreeNode pNode = this.treeViewDomain.Nodes.Find(codevalue.ToString(), true)[0]; pNode.Checked = true; } //其它值 { this.treeViewDomain.Nodes.Add("other", "other", 2, 2); nodekeyMap.Add("other", nCodes); TreeNode pNode = this.treeViewDomain.Nodes.Find("other", true)[0]; pNode.Checked = true; } } else { IRangeDomain rangedomain = domainSelect as IRangeDomain; object minValue = rangedomain.MinValue; object maxValue = rangedomain.MaxValue; } }
private void CreateFeautureLayer() { bool hasfly = false; foreach (FeatureClass fc in fcMap.Keys) { List <string> geoNames = (List <string>)fcMap[fc]; foreach (string geoName in geoNames) { if (!geoName.Equals("Geometry")) { continue; } IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer( fc, geoName, null, null); if (!hasfly) { IFieldInfoCollection fieldinfos = fc.GetFields(); IFieldInfo fieldinfo = fieldinfos.Get(fieldinfos.IndexOf(geoName)); IGeometryDef geometryDef = fieldinfo.GeometryDef; env = geometryDef.Envelope; if (env == null || (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 && env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0)) { continue; } EulerAngle angle = new EulerAngle(); angle.Set(0, -20, 0); if (geoFactory == null) { geoFactory = new GeometryFactory(); } IPoint pos = geoFactory.CreatePoint(i3dVertexAttribute.i3dVertexAttributeZ); pos.SpatialCRS = datasetCRS; pos.Position = env.Center; this.axRenderControl1.Camera.LookAt2(pos, 1000, angle); } hasfly = true; } } }
public bool CompareFeatureClass(IFieldInfoCollection fields1, IFieldInfoCollection fields2) { if (fields1.Count != fields2.Count) { return(false); } for (int i = 0; i < fields1.Count; i++) { IFieldInfo fieldInfo = fields1.Get(i); int num = fields2.IndexOf(fieldInfo.Name); if (num == -1) { return(false); } if (!fieldInfo.Equal(fields2.Get(num))) { return(false); } } return(true); }
private void menuLoadData_Click(object sender, EventArgs e) { if (layers.Count > 0) { MessageBox.Show("数据已加载"); return; } // CreateFeautureLayer bool hasfly = false; foreach (IFeatureClass fc in fcMap.Keys) { List <string> geoNames = (List <string>)fcMap[fc]; foreach (string geoName in geoNames) { IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer( fc, geoName, null, null, rootId); layers.Add(featureLayer); if (!hasfly) { IFieldInfoCollection fieldinfos = fc.GetFields(); IFieldInfo fieldinfo = fieldinfos.Get(fieldinfos.IndexOf(geoName)); IGeometryDef geometryDef = fieldinfo.GeometryDef; IEnvelope env = geometryDef.Envelope; if (env == null || (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 && env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0)) { continue; } IEulerAngle angle = new EulerAngle(); angle.Set(0, -20, 0); this.axRenderControl1.Camera.LookAt(env.Center, 1000, angle); } hasfly = true; } } }
private void MainForm_Load(object sender, System.EventArgs e) { // 初始化RenderControl控件 IPropertySet ps = new PropertySet(); ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL); this.axRenderControl1.Initialize(true, ps); 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; } // 加载FDB try { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\empty.FDB"); ci.Database = tmpFDBPath; IDataSourceFactory dsFactory = new DataSourceFactory(); IDataSource ds = dsFactory.OpenDataSource(ci); TreeNode sourceNode = new TreeNode(ci.Database); this.treeViewCatalogTree.Nodes.Add(sourceNode); // 获取第1个dataset string[] setnames = (string[])ds.GetFeatureDatasetNames(); if (setnames.Length == 0) { return; } dataset = ds.OpenFeatureDataset(setnames[0]); TreeNode setNode = new TreeNode(setnames[0]); sourceNode.Nodes.Add(setNode); // 获取第1个featureclass string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable); if (fcnames.Length == 0) { return; } fc = dataset.OpenFeatureClass(fcnames[0]); TreeNode fcNode = new TreeNode(fcnames[0]); setNode.Nodes.Add(fcNode); // 找到空间列字段 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; } geoNames.Add(fieldinfo.Name); } } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); return; } // CreateFeautureLayer layerList = new List <IFeatureLayer>(); foreach (string geoName in geoNames) { //****特别注意**** ISimpleGeometryRender geoRender = new SimpleGeometryRender(); geoRender.RenderGroupField = "Groupid"; //**************** IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer( fc, geoName, null, geoRender, rootId); layerList.Add(featureLayer); // 设置featureLayer可见 SetGroupVisiable(dataset, featureLayer); IFieldInfoCollection fieldinfos = fc.GetFields(); IFieldInfo fieldinfo = fieldinfos.Get(fieldinfos.IndexOf(geoName)); IGeometryDef geometryDef = fieldinfo.GeometryDef; IEnvelope env = geometryDef.Envelope; if (env == null || (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 && env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0)) { continue; } IEulerAngle angle = new EulerAngle(); angle.Set(0, -20, 0); this.axRenderControl1.Camera.LookAt(env.Center, 1000, angle); } this.treeViewCatalogTree.ExpandAll(); // 加载FeatureDataSet对应的LogicGroupTree到界面控件 nodekeyMap = new Hashtable(); byte[] bb = GetLogicTreeContent(dataset); if (bb != null) { string strContent = System.Text.Encoding.UTF8.GetString(bb).Trim(); ShowCurDataSet(strContent); } // 删除回收站及其子节点 foreach (TreeNode node in this.treeViewLogicTree.Nodes[0].Nodes) { if (node.Text.Equals("回收站")) { this.treeViewLogicTree.Nodes.Remove(node); } } { this.helpProvider1.SetShowHelp(this.axRenderControl1, true); this.helpProvider1.SetHelpString(this.axRenderControl1, ""); this.helpProvider1.HelpNamespace = "ImportModel.html"; } CommonEntity.RenderEntity = this.axRenderControl1; CommonEntity.FormEntity = this; }
private void CmdEditFacilityStyle_FacStyleClassChangedEvent(DF3DPipeCreateTool.Class.FacStyleClass style) { try { this.beforeRowBufferMap.Clear(); if (style == null) { return; } DF3DFeatureClass dffc = CommonUtils.Instance().CurEditLayer; if (dffc == null) { return; } IFeatureClass fc = dffc.GetFeatureClass(); if (fc == null) { return; } FacClassReg reg = FacilityInfoService.GetFacClassRegByFeatureClassID(fc.GuidString); if (reg == null) { return; } TopoClass tc = FacilityInfoService.GetTopoClassByFacClassCode(reg.FacClassCode); if (tc == null) { return; } FacilityClass facc = reg.FacilityType; if (facc == null) { return; } IResourceManager manager = fc.FeatureDataSet as IResourceManager; if (manager == null) { return; } IFieldInfoCollection fields = fc.GetFields(); //int indexGroupid = -1; //int indexClassify = -1; //SubClass sc = null; //MajorClass mc = LogicDataStructureManage3D.Instance.GetMajorClassByDFFeatureClassID(fc.GuidString); //if (mc != null) //{ // indexClassify = fields.IndexOf(mc.ClassifyField); // indexGroupid = fields.IndexOf("GroupId"); //} int index = fields.IndexOf("StyleId"); if (index == -1) { return; } int mnindex = fields.IndexOf("ModelName"); int mpindex = fields.IndexOf("Geometry"); if (mpindex == -1) { return; } HashMap hm = SelectCollection.Instance().GetSelectGeometrys(); if (hm != null && hm.Count == 1) { IRowBufferCollection res = new RowBufferCollection(); IRowBufferCollection rowBufferCollection = hm[dffc] as IRowBufferCollection; if (rowBufferCollection != null) { for (int i = 0; i < rowBufferCollection.Count; i++) { IRowBuffer rowBuffer = rowBufferCollection.Get(i); Fac fac = null; IModelPoint mp = null; IModel finemodel = null; IModel simplemodel = null; string name = ""; switch (facc.Name) { case "PipeNode": fac = new PipeNodeFac(reg, style, rowBuffer, tc); break; case "PipeLine": fac = new PipeLineFac(reg, style, rowBuffer, tc, false, false); break; case "PipeBuild": case "PipeBuild1": fac = new PipeBuildFac(reg, style, rowBuffer); break; } if (UCAuto3DCreate.RebuildModel(fac, style, out mp, out finemodel, out simplemodel, out name)) { if (finemodel == null || mp == null) { continue; } mp.ModelEnvelope = finemodel.Envelope; rowBuffer.SetValue(mpindex, mp); rowBuffer.SetValue(index, style.ObjectId); //if (mc != null) //{ // if (indexClassify != -1 && indexGroupid != -1) // { // } //} bool bRes = false; if (!string.IsNullOrEmpty(mp.ModelName)) { if (!manager.ModelExist(mp.ModelName)) { if (manager.AddModel(mp.ModelName, finemodel, simplemodel)) { bRes = true; } } else { if (manager.UpdateModel(mp.ModelName, finemodel) && manager.UpdateSimplifiedModel(mp.ModelName, simplemodel)) { bRes = true; } } } if (bRes) { res.Add(rowBuffer); } } } } beforeRowBufferMap[dffc] = res; //SelectCollection.Instance().Clear(); UpdateDatabase(); DF3DApplication app = DF3DApplication.Application; if (app == null || app.Current3DMapControl == null) { return; } app.Current3DMapControl.FeatureManager.RefreshFeatureClass(fc); } } catch (Exception ex) { } }
public FeatureClassIndexDlg(IFeatureClass pFc) { InitializeComponent(); featureCls = pFc; fcFields = pFc.GetFields(); featureCls.LockType = gviLockType.gviLockExclusiveSchema; List <string> geoFields = new List <string>(); for (int l = 0; l < fcFields.Count; l++) { IFieldInfo myField = fcFields.Get(l); if (myField != null && myField.FieldType == gviFieldType.gviFieldGeometry) { geoFields.Add(myField.Name); } } //读取FC的索引信息 //属性索引 IDbIndexInfoCollection DbIndexInfos = featureCls.GetDbIndexInfos(); if (DbIndexInfos != null) { for (int k = 0; k < DbIndexInfos.Count; k++) { IDbIndexInfo DbIndex = DbIndexInfos.Get(k); if (DbIndex.FieldCount == 1) { string getName = DbIndex.GetFieldName(0); int ind = fcFields.IndexOf(getName); if (ind >= 0) { IFieldInfo unVaildField = fcFields.Get(ind); if (unVaildField.FieldType == gviFieldType.gviFieldFID || unVaildField.FieldType == gviFieldType.gviFieldGeometry || unVaildField.FieldType == gviFieldType.gviFieldBlob) { continue; } } else { continue; } } AttrIndexList.Add(DbIndex.Name); this.lb_AttrIndex.Items.Add(new myAttrIndex(DbIndex, false)); } } //空间索引 IIndexInfoCollection GridIndexInfos = featureCls.GetSpatialIndexInfos(); if (GridIndexInfos != null) { GridIndexHash = new Hashtable(GridIndexInfos.Count); for (int k = 0; k < GridIndexInfos.Count; k++) { IGridIndexInfo GridIndex = GridIndexInfos.Get(k) as IGridIndexInfo; if (GridIndex != null) { GridIndexHash.Add(GridIndex.GeoColumnName, GridIndex); CheckIndexEdit GridIndexItem = new CheckIndexEdit(GridIndex.GeoColumnName); GridIndexItem.ExistIndex = new IndexAboutGeometry(GridIndex.L1, GridIndex.L2, GridIndex.L3, true); GridIndexItem.NewIndex = new IndexAboutGeometry(GridIndex.L1, GridIndex.L2, GridIndex.L3, true); this.lb_SpatialIndexGeo.Items.Add(GridIndexItem); } } foreach (string sGeoColumn in geoFields) { if (GridIndexHash.ContainsKey(sGeoColumn)) { continue; } CheckIndexEdit GridIndexItem = new CheckIndexEdit(sGeoColumn); GridIndexItem.ExistIndex = null; GridIndexItem.NewIndex = new IndexAboutGeometry(0, 0, 0, false); this.lb_SpatialIndexGeo.Items.Add(GridIndexItem); } } //渲染索引 IIndexInfoCollection RenderIndexInfos = featureCls.GetRenderIndexInfos(); if (RenderIndexInfos != null) { RenderIndexHash = new Hashtable(RenderIndexInfos.Count); for (int k = 0; k < RenderIndexInfos.Count; k++) { IRenderIndexInfo RenderIndex = RenderIndexInfos.Get(k) as IRenderIndexInfo; if (RenderIndex != null) { RenderIndexHash.Add(RenderIndex.GeoColumnName, RenderIndex); CheckIndexEdit RenderIndexItem = new CheckIndexEdit(RenderIndex.GeoColumnName); RenderIndexItem.ExistIndex = new IndexAboutGeometry(RenderIndex.L1, 0, 0, true); RenderIndexItem.NewIndex = new IndexAboutGeometry(RenderIndex.L1, 0, 0, true); this.lb_RenderIndexGeo.Items.Add(RenderIndexItem); } } foreach (string sGeoColumn in geoFields) { if (RenderIndexHash.ContainsKey(sGeoColumn)) { continue; } CheckIndexEdit RenderIndexItem = new CheckIndexEdit(sGeoColumn); RenderIndexItem.ExistIndex = null; RenderIndexItem.NewIndex = new IndexAboutGeometry(0, 0, 0, false); this.lb_RenderIndexGeo.Items.Add(RenderIndexItem); } //填充渲染索引的ListBoxControl控件,一个是lbc_FieldsAvailable,另一个是lbc_FieldsSelected for (int k = 0; k < fcFields.Count; k++) { IFieldInfo fcField = fcFields.Get(k); if (fcField.FieldType == gviFieldType.gviFieldFID || fcField.FieldType == gviFieldType.gviFieldGeometry || fcField.FieldType == gviFieldType.gviFieldBlob) { continue; } if (fcField.RegisteredRenderIndex) { this.lb_RenderField.Items.Add(new myFieldInfo(fcField)); RegRenderIndexFields.Add(fcField.Name); RegRenderIndexHash.Add(fcField.Name, fcField); } else { this.lb_RenderAllField.Items.Add(new myFieldInfo(fcField)); } } } }
public override void Run(object sender, EventArgs e) { try { app = DF3DApplication.Application; if (app == null || app.Current3DMapControl == null) { return; } this._geoFact = new GeometryFactory(); Map3DCommandManager.Push(this); DF3DFeatureClass dffc = CommonUtils.Instance().CurEditLayer; if (dffc != null) { this._facType = dffc.GetFacilityClassName(); _strGeometryFieldName = ""; if (this._facType == "PipeLine" || this._facType == "PipeNode" || this._facType == "PipeBuild" || this._facType == "PipeBuild1") { _strGeometryFieldName = "Shape"; } else { IFeatureLayer fl = dffc.GetFeatureLayer(); if (fl != null) { _strGeometryFieldName = fl.GeometryFieldName; } } if (!string.IsNullOrEmpty(_strGeometryFieldName)) { IFeatureClass fc = dffc.GetFeatureClass(); if (fc != null) { IFieldInfoCollection fiCol = fc.GetFields(); int index = fiCol.IndexOf(_strGeometryFieldName); if (index != -1) { IFieldInfo fi = fiCol.Get(index); if (fi.GeometryDef != null) { this._geoType = fi.GeometryDef.GeometryColumnType; } } } switch (this._geoType) { case gviGeometryColumnType.gviGeometryColumnModelPoint: //添加方式:1、鼠标添加;2、文件添加 FrmInsertModel dlg = new FrmInsertModel(); if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string filePath = dlg.FilePath; string ext = Path.GetExtension(filePath); if (File.Exists(filePath)) { int insertType = dlg.InsertType; if (insertType == 0 && ext.ToLower() == ".osg") { this._drawTool = DrawToolService.Instance.CreateDrawTool(DrawType._3DModel); if (this._drawTool != null) { (this._drawTool as Draw3DModel).Set3DModelFilePath(filePath); this._drawTool.OnStartDraw += new OnStartDraw(this.OnStartDraw); this._drawTool.OnFinishedDraw += new OnFinishedDraw(this.OnFinishedDraw); this._drawTool.Start(); } } else if (insertType == 1 && ext.ToLower() == ".xml") { } } } break; case gviGeometryColumnType.gviGeometryColumnPoint: if (this._facType == "PipeNode") { // 添加附属设施或者管点 } else { // 添加点 this._drawTool = DrawToolService.Instance.CreateDrawTool(DrawType.Point); if (this._drawTool != null) { this._drawTool.OnStartDraw += new OnStartDraw(this.OnStartDraw); this._drawTool.OnFinishedDraw += new OnFinishedDraw(this.OnFinishedDraw); this._drawTool.Start(); } } break; case gviGeometryColumnType.gviGeometryColumnPolyline: if (this._facType == "PipeLine" || this._facType == "PipeBuild" || this._facType == "PipeBuild1") { // 选择管线或辅助样式 } else { // 添加线 this._drawTool = DrawToolService.Instance.CreateDrawTool(DrawType.Polyline); if (this._drawTool != null) { this._drawTool.OnStartDraw += new OnStartDraw(this.OnStartDraw); this._drawTool.OnFinishedDraw += new OnFinishedDraw(this.OnFinishedDraw); this._drawTool.Start(); } } break; case gviGeometryColumnType.gviGeometryColumnPolygon: if (this._facType == "PipeBuild" || this._facType == "PipeBuild1") { // 选择管线辅助样式 } else { // 添加面 this._drawTool = DrawToolService.Instance.CreateDrawTool(DrawType.Polygon); if (this._drawTool != null) { this._drawTool.OnStartDraw += new OnStartDraw(this.OnStartDraw); this._drawTool.OnFinishedDraw += new OnFinishedDraw(this.OnFinishedDraw); this._drawTool.Start(); } } break; default: return; } } } } catch (Exception ex) { } finally { } }
private void MainForm_Load(object sender, System.EventArgs e) { // 初始化RenderControl控件 IPropertySet ps = new PropertySet(); ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL); this.axRenderControl1.Initialize(true, ps); 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; } // 加载FDB场景 try { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\REVIT-ALL2013.FDB"); ci.Database = tmpFDBPath; IDataSourceFactory dsFactory = new DataSourceFactory(); IDataSource ds = dsFactory.OpenDataSource(ci); string[] setnames = (string[])ds.GetFeatureDatasetNames(); if (setnames.Length == 0) { return; } dataset = ds.OpenFeatureDataset(setnames[0]); string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable); if (fcnames.Length == 0) { return; } fcMap = 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; } geoNames.Add(fieldinfo.Name); } fcMap.Add(fc, geoNames); } } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); return; } // CreateFeautureLayer bool hasfly = false; foreach (IFeatureClass fc in fcMap.Keys) { List <string> geoNames = (List <string>)fcMap[fc]; foreach (string geoName in geoNames) { if (!geoName.Equals("Geometry")) { continue; } this.axRenderControl1.ObjectManager.CreateFeatureLayer(fc, geoName, null, null, rootId); if (!hasfly) { IFieldInfoCollection fieldinfos = fc.GetFields(); IFieldInfo fieldinfo = fieldinfos.Get(fieldinfos.IndexOf(geoName)); IGeometryDef geometryDef = fieldinfo.GeometryDef; IEnvelope env = geometryDef.Envelope; if (env == null || (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 && env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0)) { continue; } angle.Set(0, -20, 0); point = new GeometryFactory().CreatePoint(gviVertexAttribute.gviVertexAttributeZ); point.SpatialCRS = fc.FeatureDataSet.SpatialReference; point.SetCoords(env.Center.X, env.Center.Y, env.Center.Z, 0, 0); this.axRenderControl1.Camera.LookAt2(point, 100, angle); } hasfly = true; } } { this.helpProvider1.SetShowHelp(this.axRenderControl1, true); this.helpProvider1.SetHelpString(this.axRenderControl1, ""); this.helpProvider1.HelpNamespace = "Revit.html"; } }
/// <summary> /// 打开FDB数据 /// </summary> /// <param name="filePath"></param> /// <returns></returns> List <IFeatureLayer> openFDB(string filePath) { Hashtable featuerClassList = new Hashtable(); #region 提取数据 //连接器 IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x;//FDB //ci.ConnectionType = gviConnectionType.gviConnectionSQLite3;//SDB ci.Password = null; ci.Database = filePath; //通过连接器打开数据源 IDataSourceFactory dsFac = new DataSourceFactory(); IDataSource ds = dsFac.OpenDataSource(ci); //查找数据源中所有的数据集 string[] featureDataSetNames = ds.GetFeatureDatasetNames(); if (featureDataSetNames.Length == 0) { Console.WriteLine("打开失败!"); return(null); } //获取数据集,一般只有一个,多个时要遍历 IFeatureDataSet dataset = ds.OpenFeatureDataset(featureDataSetNames[0]); //查找数据集中的所有要素类 string[] featureClassNames = dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable); if (featureClassNames.Length == 0) { Console.WriteLine("没有找到要素类!"); return(null); } for (int fci = 0; fci < featureClassNames.Length; fci++) { IFeatureClass fc = dataset.OpenFeatureClass(featureClassNames[fci]); //创建一个容器,放fc的几何属性名称 List <string> geoNames = new List <string>(); //查找要素类中所有属性 IFieldInfoCollection fieldInfos = fc.GetFields(); for (int fieldi = 0; fieldi < fieldInfos.Count; fieldi++) { IFieldInfo fieldinfo = fieldInfos.Get(fieldi); if (fieldinfo == null || fieldinfo.GeometryDef == null) { continue; } geoNames.Add(fieldinfo.Name); } featuerClassList[fc] = geoNames; } #endregion List <IFeatureLayer> fls = new List <IFeatureLayer>(); #region 塞入三维对象 bool hasfly = false; foreach (IFeatureClass fc in featuerClassList.Keys) { List <string> geoNames = (List <string>)featuerClassList[fc]; foreach (string geoName in geoNames) { if (geoName.Equals("Geometry")) { IFeatureLayer fl = axRenderControl.ObjectManager.CreateFeatureLayer(fc, geoName, null, null, Guid.Empty); if (fl != null) { fls.Add(fl); } } //jump once! if (!hasfly) { IFieldInfoCollection fieldInfos = fc.GetFields(); IFieldInfo fieldinfo = fieldInfos.Get(fieldInfos.IndexOf(geoName)); IGeometryDef gd = fieldinfo.GeometryDef; IEnvelope enve = gd.Envelope; if (enve != null) { axRenderControl.Camera.LookAtEnvelope(enve); hasfly = true; } } } } #endregion return(fls); }
private void AddRecord() { try { this.beforeRowBufferMap.Clear(); SelectCollection.Instance().Clear(); DF3DFeatureClass featureClassInfo = CommonUtils.Instance().CurEditLayer; if (featureClassInfo == null) { return; } IFeatureClass fc = featureClassInfo.GetFeatureClass(); if (fc == null) { return; } IFeatureLayer fl = featureClassInfo.GetFeatureLayer(); if (fl == null) { return; } IFieldInfoCollection fields = fc.GetFields(); int indexGeo = fields.IndexOf(fl.GeometryFieldName); if (indexGeo == -1) { return; } IFieldInfo fiGeo = fields.Get(indexGeo); if (fiGeo == null || fiGeo.GeometryDef == null) { return; } IGeometry geo = this._drawTool.GetGeo(); if (geo.GeometryType != gviGeometryType.gviGeometryPolygon) { return; } IPolygon polygon = geo as IPolygon; IPolygon geoOut = this._geoFact.CreateGeometry(gviGeometryType.gviGeometryPolygon, fiGeo.GeometryDef.VertexAttribute) as IPolygon; for (int i = 0; i < polygon.ExteriorRing.PointCount; i++) { IPoint ptGet = polygon.ExteriorRing.GetPoint(i); IPoint pttemp = ptGet.Clone2(fiGeo.GeometryDef.VertexAttribute) as IPoint; if (fiGeo.GeometryDef.HasZ) { pttemp.SetCoords(ptGet.X, ptGet.Y, ptGet.Z, 0, 0); } else { pttemp.SetCoords(ptGet.X, ptGet.Y, 0, 0, 0); } geoOut.ExteriorRing.AppendPoint(pttemp); } IRowBufferCollection rowCol = new RowBufferCollection(); IRowBufferFactory fac = new RowBufferFactory(); IRowBuffer row = fac.CreateRowBuffer(fields); row.SetValue(indexGeo, geoOut); foreach (DataRow dr in this._dt.Rows) { IFieldInfo fi = dr["F"] as IFieldInfo; if (fi == null) { continue; } string fn = fi.Name; int index = fields.IndexOf(fn); if (index != -1) { if (dr["FV"] == null) { row.SetNull(index); } else { string strobj = dr["FV"].ToString(); bool bRes = false; switch (fi.FieldType) { case gviFieldType.gviFieldBlob: case gviFieldType.gviFieldGeometry: case gviFieldType.gviFieldUnknown: break; case gviFieldType.gviFieldFloat: float f; bRes = float.TryParse(strobj, out f); if (bRes) { row.SetValue(index, f); } else { row.SetNull(index); } break; case gviFieldType.gviFieldDouble: double d; bRes = double.TryParse(strobj, out d); if (bRes) { row.SetValue(index, d); } else { row.SetNull(index); } break; case gviFieldType.gviFieldFID: case gviFieldType.gviFieldUUID: case gviFieldType.gviFieldInt16: Int16 i16; bRes = Int16.TryParse(strobj, out i16); if (bRes) { row.SetValue(index, i16); } else { row.SetNull(index); } break; case gviFieldType.gviFieldInt32: Int32 i32; bRes = Int32.TryParse(strobj, out i32); if (bRes) { row.SetValue(index, i32); } else { row.SetNull(index); } break; case gviFieldType.gviFieldInt64: Int64 i64; bRes = Int64.TryParse(strobj, out i64); if (bRes) { row.SetValue(index, i64); } else { row.SetNull(index); } break;; case gviFieldType.gviFieldString: row.SetValue(index, strobj); break; case gviFieldType.gviFieldDate: DateTime dt; bRes = DateTime.TryParse(strobj, out dt); if (bRes) { row.SetValue(index, dt); } else { row.SetNull(index); } break; default: break; } } } } rowCol.Add(row); beforeRowBufferMap[featureClassInfo] = rowCol; UpdateDatabase(); } catch (Exception ex) { } }
public static void AddAndVisualizeBaseData(IConnectionInfo ci, string geoColumnName, TreeList parentTree, bool bNeedFly = false, bool bTempData = true) { try { if (ci == null || parentTree == null) { return; } if (bTempData) { WaitForm.Start("正在加载三维数据,请稍后...", "提示"); } DF3DApplication app = DF3DApplication.Application; if (app == null || app.Current3DMapControl == null) { return; } AxRenderControl d3 = app.Current3DMapControl; IDataSourceFactory dsFactory = new DataSourceFactory(); if (!dsFactory.HasDataSource(ci)) { return; } IDataSource ds = dsFactory.OpenDataSource(ci); if (ds == null) { return; } //TreeNodeDatabase tnDatabase = new TreeNodeDatabase() //{ // Name = ci.ConnectionType == gviConnectionType.gviConnectionFireBird2x ? System.IO.Path.GetFileNameWithoutExtension(ci.Database) : ci.Database, // CustomValue = ds, // Temp = bTempData //}; //tnDatabase.OwnNode = parentTree.AppendNode(new object[] { tnDatabase.Name }, (TreeListNode)null); //tnDatabase.Visible = true; string[] setnames = (string[])ds.GetFeatureDatasetNames(); if (setnames.Length == 0) { return; } for (int j = 0; j < setnames.Length; j++) { IFeatureDataSet dataset = ds.OpenFeatureDataset(setnames[j]); string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable); if (fcnames.Length == 0) { continue; } TreeNodeDataset tnDataset = new TreeNodeDataset() { Name = dataset.Alias, CustomValue = dataset, Temp = bTempData }; tnDataset.OwnNode = parentTree.AppendNode(new object[] { tnDataset.Name }, (TreeListNode)null); //tnDatabase.Add(tnDataset); foreach (string name in fcnames) { IFeatureClass fc = dataset.OpenFeatureClass(name); if (fc == null) { continue; } TreeNodeFeatureClass tnFeatureClass = new TreeNodeFeatureClass(fc.GuidString) { Name = fc.AliasName, CustomValue = fc, Temp = bTempData }; tnDataset.Add(tnFeatureClass); IFieldInfoCollection fieldinfos = fc.GetFields(); if (fieldinfos == null) { continue; } int index = fieldinfos.IndexOf(geoColumnName); if (index == -1) { } else { IFieldInfo fieldinfo = fieldinfos.Get(index); if (null == fieldinfo) { continue; } IGeometryDef geometryDef = fieldinfo.GeometryDef; IFeatureLayer fl = null; if (null != geometryDef) { fl = d3.ObjectManager.CreateFeatureLayer(fc, fieldinfo.Name, null, null, d3.ProjectTree.RootID); tnFeatureClass.SetVisualFeatureLayer(fl); switch (geometryDef.GeometryColumnType) { case gviGeometryColumnType.gviGeometryColumnModelPoint: tnFeatureClass.Visible = true; tnFeatureClass.ImageIndex = 3; break; case gviGeometryColumnType.gviGeometryColumnPOI: case gviGeometryColumnType.gviGeometryColumnPoint: tnFeatureClass.Visible = false; tnFeatureClass.ImageIndex = 4; break; case gviGeometryColumnType.gviGeometryColumnPolyline: tnFeatureClass.Visible = false; tnFeatureClass.ImageIndex = 5; break; case gviGeometryColumnType.gviGeometryColumnPolygon: tnFeatureClass.Visible = false; tnFeatureClass.ImageIndex = 6; break; } } // 加入管理类 if (!bTempData && fl != null) { DF3DFeatureClass dfFC = new DF3DFeatureClass(fc); dfFC.SetFeatureLayer(fl); dfFC.SetTreeLayer(tnFeatureClass); Render3D.Instance.SetRender(tnFeatureClass, dfFC); DF3DFeatureClassManager.Instance.Add(dfFC); } if (fl != null && bNeedFly) { IEulerAngle angle = new EulerAngle(); angle.Set(0, -20, 0); d3.Camera.SetCamera(fl.Envelope.Center, angle, gviSetCameraFlags.gviSetCameraNoFlags); bNeedFly = false; } } } tnDataset.CollapseAll(); } //tnDatabase.CollapseAll(); //ds.Close(); } catch (Exception ex) { XtraMessageBox.Show("加载三维数据失败,请检查数据是否被占用或链接是否有错误。", "提示"); LoggingService.Error("加载三维数据失败:" + ex.Message); } finally { if (bTempData) { WaitForm.Stop(); } } }
public static void VisualizePipeData(Dictionary <string, IFeatureClass> fcs, Dictionary <string, string> relation, string geoColumnName, IGroupLayer groupLayer, Dictionary <string, string> pipeCatelog, Dictionary <string, string> childPipeCatelog, Dictionary <string, IRowBuffer> infos, bool bNeedFly = false, bool bTempData = true) { try { foreach (KeyValuePair <string, string> kv in childPipeCatelog) { string code = kv.Key.ToString(); string pcode = kv.Value.ToString(); if (!relation.ContainsKey(code) && pcode != "-1") { Dictionary <string, string> cchildPipeCatelog = FindChildRelationByPCode(code, pipeCatelog); if (cchildPipeCatelog == null || cchildPipeCatelog.Count == 0) { continue; } IRowBuffer row = infos[code]; string name = row.GetValue(row.FieldIndex("Name")).ToString(); Group g = new Group() { Name = name, CustomValue = row, Temp = bTempData }; g.Visible = true; groupLayer.Add(g); VisualizePipeData(fcs, relation, geoColumnName, g, pipeCatelog, cchildPipeCatelog, infos, bNeedFly, bTempData); } else if (relation.ContainsKey(code) && fcs.ContainsKey(relation[code])) { DF3DApplication app = DF3DApplication.Application; if (app == null || app.Current3DMapControl == null) { return; } AxRenderControl d3 = app.Current3DMapControl; IRowBuffer row = infos[code]; string name = row.GetValue(row.FieldIndex("Name")).ToString(); IFeatureClass fc = fcs[relation[code]]; TreeNodeFeatureClass tnFeatureClass = new TreeNodeFeatureClass() { Name = name, CustomValue = fc, //Tag = row, Temp = bTempData }; groupLayer.Add(tnFeatureClass); IFieldInfoCollection fieldinfos = fc.GetFields(); if (fieldinfos == null) { continue; } int index = fieldinfos.IndexOf(geoColumnName); if (index == -1) { } else { IFieldInfo fieldinfo = fieldinfos.Get(index); if (null == fieldinfo) { continue; } IGeometryDef geometryDef = fieldinfo.GeometryDef; IFeatureLayer fl = null; if (null != geometryDef) { fl = d3.ObjectManager.CreateFeatureLayer(fc, fieldinfo.Name, null, null, d3.ProjectTree.RootID); tnFeatureClass.SetVisualFeatureLayer(fl); tnFeatureClass.Visible = true; switch (geometryDef.GeometryColumnType) { case gviGeometryColumnType.gviGeometryColumnModelPoint: tnFeatureClass.ImageIndex = 3; break; case gviGeometryColumnType.gviGeometryColumnPOI: case gviGeometryColumnType.gviGeometryColumnPoint: tnFeatureClass.ImageIndex = 4; break; case gviGeometryColumnType.gviGeometryColumnPolyline: tnFeatureClass.ImageIndex = 5; break; case gviGeometryColumnType.gviGeometryColumnPolygon: tnFeatureClass.ImageIndex = 6; break; } } if (fl != null && !bTempData) { DF3DFeatureClass dfFC = new DF3DFeatureClass(fcs[relation[code]]); if (dfFC == null) { continue; } DF3DFeatureClassManager.Instance.Add(dfFC); } if (fl != null && bNeedFly) { IEulerAngle angle = new EulerAngle(); angle.Set(0, -20, 0); d3.Camera.SetCamera(fl.Envelope.Center, angle, gviSetCameraFlags.gviSetCameraNoFlags); bNeedFly = false; } } } } } catch (Exception ex) { } }
private void AddRecord() { try { this.beforeRowBufferMap.Clear(); SelectCollection.Instance().Clear(); if (reg == null || tc == null) { return; } FacStyleClass style = this.cmbStyle.EditValue as FacStyleClass; if (style == null) { return; } SubClass sc = this.cmbClassify.EditValue as SubClass; DF3DFeatureClass featureClassInfo = CommonUtils.Instance().CurEditLayer; if (featureClassInfo == null) { return; } IFeatureClass fc = featureClassInfo.GetFeatureClass(); if (fc == null) { return; } IResourceManager manager = fc.FeatureDataSet as IResourceManager; if (manager == null) { return; } IFeatureLayer fl = featureClassInfo.GetFeatureLayer(); if (fl == null) { return; } IFieldInfoCollection fields = fc.GetFields(); int indexOid = fields.IndexOf(fc.FidFieldName); if (indexOid == -1) { return; } int mpindex = fields.IndexOf(fl.GeometryFieldName); if (mpindex == -1) { return; } int indexShape = fields.IndexOf("Shape"); if (indexShape == -1) { return; } int indexFootPrint = fields.IndexOf("FootPrint"); if (indexFootPrint == -1) { return; } int indexStyleId = fields.IndexOf("StyleId"); if (indexStyleId == -1) { return; } int indexFacilityId = fields.IndexOf("FacilityId"); if (indexFacilityId == -1) { return; } IFieldInfo fiShape = fields.Get(indexShape); if (fiShape == null || fiShape.GeometryDef == null) { return; } IGeometry geo = this._drawTool.GetGeo(); if (geo.GeometryType != gviGeometryType.gviGeometryPoint) { return; } IPoint pt = geo as IPoint; IPoint geoOut = pt.Clone2(fiShape.GeometryDef.VertexAttribute) as IPoint; if (fiShape.GeometryDef.HasZ) { geoOut.SetCoords(pt.X, pt.Y, pt.Z, 0, 0); } else { geoOut.SetCoords(pt.X, pt.Y, 0, 0, 0); } IQueryFilter filter = new QueryFilter(); filter.WhereClause = "1=1"; filter.ResultBeginIndex = 0; filter.ResultLimit = 1; filter.PostfixClause = "ORDER BY " + fc.FidFieldName + " desc"; IFdeCursor cursor = null; cursor = fc.Search(filter, false); IRowBuffer rowtemp = cursor.NextRow(); int oid = 0; if (rowtemp != null) { oid = int.Parse(rowtemp.GetValue(indexOid).ToString()); } if (cursor != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor); cursor = null; } IRowBufferFactory fac = new RowBufferFactory(); IRowBuffer row = fac.CreateRowBuffer(fields); row.SetValue(indexOid, oid + 1); row.SetValue(indexShape, geoOut); row.SetValue(indexFootPrint, geoOut.Clone2(gviVertexAttribute.gviVertexAttributeNone)); row.SetValue(indexStyleId, style.ObjectId); row.SetValue(indexFacilityId, BitConverter.ToString(ObjectIdGenerator.Generate()).Replace("-", string.Empty).ToLowerInvariant()); if (sc != null) { int indexClassify = fields.IndexOf(this._classifyName); int indexGroupId = fields.IndexOf("GroupId"); if (indexClassify != -1 && indexGroupId != -1) { row.SetValue(indexClassify, sc.Name); row.SetValue(indexGroupId, sc.GroupId); } } foreach (DataRow dr in this._dt.Rows) { IFieldInfo fi = dr["F"] as IFieldInfo; if (fi == null) { continue; } string fn = fi.Name; int index = fields.IndexOf(fn); if (index != -1) { if (dr["FV"] == null) { row.SetNull(index); } else { string strobj = dr["FV"].ToString(); bool bRes = false; switch (fi.FieldType) { case gviFieldType.gviFieldBlob: case gviFieldType.gviFieldGeometry: case gviFieldType.gviFieldUnknown: break; case gviFieldType.gviFieldFloat: float f; bRes = float.TryParse(strobj, out f); if (bRes) { row.SetValue(index, f); } else { row.SetNull(index); } break; case gviFieldType.gviFieldDouble: double d; bRes = double.TryParse(strobj, out d); if (bRes) { row.SetValue(index, d); } else { row.SetNull(index); } break; case gviFieldType.gviFieldFID: case gviFieldType.gviFieldUUID: case gviFieldType.gviFieldInt16: Int16 i16; bRes = Int16.TryParse(strobj, out i16); if (bRes) { row.SetValue(index, i16); } else { row.SetNull(index); } break; case gviFieldType.gviFieldInt32: Int32 i32; bRes = Int32.TryParse(strobj, out i32); if (bRes) { row.SetValue(index, i32); } else { row.SetNull(index); } break; case gviFieldType.gviFieldInt64: Int64 i64; bRes = Int64.TryParse(strobj, out i64); if (bRes) { row.SetValue(index, i64); } else { row.SetNull(index); } break;; case gviFieldType.gviFieldString: row.SetValue(index, strobj); break; case gviFieldType.gviFieldDate: DateTime dt; bRes = DateTime.TryParse(strobj, out dt); if (bRes) { row.SetValue(index, dt); } else { row.SetNull(index); } break; default: break; } } } } Fac plf = new PipeNodeFac(reg, style, row, tc); IModelPoint mp = null; IModel finemodel = null; IModel simplemodel = null; string name = ""; if (UCAuto3DCreate.RebuildModel(plf, style, out mp, out finemodel, out simplemodel, out name)) { if (finemodel == null || mp == null) { return; } mp.ModelEnvelope = finemodel.Envelope; row.SetValue(mpindex, mp); //if (mc != null) //{ // if (indexClassify != -1 && indexGroupid != -1) // { // } //} bool bRes = false; if (!string.IsNullOrEmpty(mp.ModelName)) { if (!manager.ModelExist(mp.ModelName)) { if (manager.AddModel(mp.ModelName, finemodel, simplemodel)) { bRes = true; } } else { if (manager.UpdateModel(mp.ModelName, finemodel) && manager.UpdateSimplifiedModel(mp.ModelName, simplemodel)) { bRes = true; } } } if (!bRes) { return; } IRowBufferCollection rowCol = new RowBufferCollection(); rowCol.Add(row); beforeRowBufferMap[featureClassInfo] = rowCol; UpdateDatabase(); app.Current3DMapControl.FeatureManager.RefreshFeatureClass(fc); } } catch (Exception ex) { } }
public void Init() { try { this._ds = DF3DPipeCreateApp.App.PipeLib; if (this._ds == null) { this.Enabled = false; return; } this.treeList1.ClearNodes(); if (!this._init3DControl) { this._init3DControl = Init3DControl(); } if (!this._init3DControl) { this.Enabled = false; return; } if (this._init3DControl) { foreach (Guid guid in allFLGuid) { this.AxRenderControl3D.ObjectManager.DeleteObject(guid); } this.allFLGuid.Clear(); foreach (Guid guid in allTLGuid) { this.AxRenderControl3D.ObjectManager.DeleteObject(guid); } this.allTLGuid.Clear(); this._dictFeatureClass.Clear(); WaitForm.Start("正在加载数据...", "请稍后"); bool bHaveFly = false; Guid gd = Guid.NewGuid(); string[] fdsNames = this._ds.GetFeatureDatasetNames(); if (fdsNames == null) { return; } foreach (string fdsName in fdsNames) { IFeatureDataSet fds = this._ds.OpenFeatureDataset(fdsName); if (fds == null) { continue; } TreeListNode fdsNode = this.treeList1.AppendNode(new object[] { fds.Name, fds }, null); fdsNode.StateImageIndex = 0; string[] fcNames = fds.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable); if (fcNames == null) { continue; } foreach (string fcName in fcNames) { IFeatureClass fc = fds.OpenFeatureClass(fcName); if (fc == null) { continue; } this._dictFeatureClass[fc.Guid] = fc; string name = string.IsNullOrEmpty(fc.AliasName) ? fc.Name : fc.AliasName; TreeListNode fcNode = this.treeList1.AppendNode(new object[] { name, fc }, fdsNode); fcNode.StateImageIndex = 1; IFieldInfoCollection fiCol = fc.GetFields(); int indexGeo = fiCol.IndexOf("Geometry"); if (indexGeo != -1) { IFieldInfo fi = fiCol.Get(indexGeo); if (fi.GeometryDef != null) { IFeatureLayer fl = this.AxRenderControl3D.ObjectManager.CreateFeatureLayer(fc, fi.Name, null, null, this.AxRenderControl3D.ProjectTree.RootID); if (fl == null) { continue; } fl.MaxVisibleDistance = 100000; TreeListNode flNode = this.treeList1.AppendNode(new object[] { fi.Name, fl }, fcNode); flNode.StateImageIndex = 2; if (fi.GeometryDef.GeometryColumnType == gviGeometryColumnType.gviGeometryColumnModelPoint) { fl.VisibleMask = gviViewportMask.gviViewAllNormalView; fl.ForceCullMode = true; fl.CullMode = Gvitech.CityMaker.Resource.gviCullFaceMode.gviCullNone; flNode.Checked = true; } else { fl.VisibleMask = gviViewportMask.gviViewNone; flNode.Checked = false; } bHaveFly = true; gd = fl.Guid; this.allFLGuid.Add(fl.Guid); } } int indexShp = fiCol.IndexOf("Shape"); if (indexShp != -1) { IFieldInfo fi = fiCol.Get(indexShp); if (fi.GeometryDef != null) { IFeatureLayer fl = this.AxRenderControl3D.ObjectManager.CreateFeatureLayer(fc, fi.Name, null, null, this.AxRenderControl3D.ProjectTree.RootID); if (fl == null) { continue; } fl.MaxVisibleDistance = 100000; TreeListNode flNode = this.treeList1.AppendNode(new object[] { fi.Name, fl }, fcNode); flNode.StateImageIndex = 2; if (fi.GeometryDef.GeometryColumnType == gviGeometryColumnType.gviGeometryColumnModelPoint) { fl.VisibleMask = gviViewportMask.gviViewAllNormalView; flNode.Checked = true; } else { fl.VisibleMask = gviViewportMask.gviViewNone; flNode.Checked = false; } bHaveFly = true; gd = fl.Guid; this.allFLGuid.Add(fl.Guid); } } int indexFoot = fiCol.IndexOf("FootPrint"); if (indexFoot != -1) { IFieldInfo fi = fiCol.Get(indexFoot); if (fi.GeometryDef != null) { IFeatureLayer fl = this.AxRenderControl3D.ObjectManager.CreateFeatureLayer(fc, fi.Name, null, null, this.AxRenderControl3D.ProjectTree.RootID); fl.MaxVisibleDistance = 100000; if (fl == null) { continue; } TreeListNode flNode = this.treeList1.AppendNode(new object[] { fi.Name, fl }, fcNode); flNode.StateImageIndex = 2; if (fi.GeometryDef.GeometryColumnType == gviGeometryColumnType.gviGeometryColumnModelPoint) { fl.VisibleMask = gviViewportMask.gviViewAllNormalView; flNode.Checked = true; } else { fl.VisibleMask = gviViewportMask.gviViewNone; flNode.Checked = false; } bHaveFly = true; gd = fl.Guid; this.allFLGuid.Add(fl.Guid); } } } } this.treeList1.ExpandAll(); if (bHaveFly) { this.AxRenderControl3D.Camera.FlyToObject(gd, gviActionCode.gviActionFlyTo); } } } catch (Exception ex) { } finally { WaitForm.Stop(); } }
public MainForm() { InitializeComponent(); // 初始化RenderControl控件 IPropertySet ps = new PropertySet(); ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL); this.axRenderControl1.Initialize(true, ps); this.axRenderControl1.Camera.FlyTime = 1; 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; } // 加载FDB场景 try { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\BIMTIME.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]); string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable); if (fcnames.Length == 0) { return; } fcMap = 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; } geoNames.Add(fieldinfo.Name); } fcMap.Add(fc, geoNames); bool bHasTemp = fc.HasTemporal(); if (bHasTemp) { ITemporalManager tm = fc.TemporalManager; if (tm != null) { try { DateTime[] times = tm.GetKeyDatetimes(); for (int i = 0; i < times.Length; i++) { if (keyDatetimesList.Contains(times[i])) { continue; } keyDatetimesList.Add(times[i]); } } catch (COMException) { } } } } } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); return; } // 设置时间轴 keyDatetimesList.Sort(); if (keyDatetimesList.Count > 3) { TimeSpan tsmin = keyDatetimesList[0] - dayLongLongAgo; this.trackBarTime.Minimum = tsmin.Days - 1; this.trackBarTimeCompare.Minimum = tsmin.Days - 1; TimeSpan tsmax = keyDatetimesList[keyDatetimesList.Count - 2] - dayLongLongAgo; this.trackBarTime.Maximum = tsmax.Days + 1; this.trackBarTimeCompare.Maximum = tsmax.Days + 1; } // CreateFeautureLayer bool hasfly = false; foreach (IFeatureClass fc in fcMap.Keys) { List <string> geoNames = (List <string>)fcMap[fc]; foreach (string geoName in geoNames) { IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer( fc, geoName, null, null, rootId); if (featureLayer == null) { continue; } #region 设置时态 featureLayer.EnableTemporal = true; layerList.Add(featureLayer); //设置curLayer的时刻 this.trackBarTime.Value = this.trackBarTime.Minimum; DateTime d = dayLongLongAgo.AddDays((double)this.trackBarTime.Value); this.labelTime.Text = d.ToString(); featureLayer.Time = d; #endregion #region 比较规则 pset.SetProperty("提前", "$(starttime)"); featureLayer.CompareRenderRuleVariants = pset; IValueMapGeometryRender render = new ValueMapGeometryRender(); { IGeometryRenderScheme scheme = new GeometryRenderScheme(); IComparedRenderRule rule = new ComparedRenderRule(); rule.LookUpField = "实际开始时间"; rule.CompareVariant = "提前"; rule.CompareOperator = gviCompareType.gviCompareLess; scheme.AddRule(rule); IModelPointSymbol symbol = new ModelPointSymbol(); symbol.EnableColor = true; symbol.Color = System.Drawing.Color.Green; scheme.Symbol = symbol; render.AddScheme(scheme); } { IGeometryRenderScheme scheme = new GeometryRenderScheme(); IComparedRenderRule rule = new ComparedRenderRule(); rule.LookUpField = "实际开始时间"; rule.CompareVariant = "提前"; rule.CompareOperator = gviCompareType.gviCompareGreaterOrEqual; scheme.AddRule(rule); IModelPointSymbol symbol = new ModelPointSymbol(); symbol.EnableColor = false; scheme.Symbol = symbol; render.AddScheme(scheme); } featureLayer.SetGeometryRender(render); #endregion if (!hasfly) { IFieldInfoCollection fieldinfos = fc.GetFields(); IFieldInfo fieldinfo = fieldinfos.Get(fieldinfos.IndexOf(geoName)); IGeometryDef geometryDef = fieldinfo.GeometryDef; IEnvelope env = geometryDef.Envelope; if (env == null || (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 && env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0)) { continue; } angle.Set(0, -52, 0); position.Set(-13.44, -88.77, 59.28); this.axRenderControl1.Camera.LookAt(position, 100, angle); hasfly = true; } } } { this.helpProvider1.SetShowHelp(this.axRenderControl1, true); this.helpProvider1.SetHelpString(this.axRenderControl1, ""); this.helpProvider1.HelpNamespace = "FiveDShow.html"; } }
private void MainForm_Load(object sender, System.EventArgs e) { // 初始化RenderControl控件 IPropertySet ps = new PropertySet(); ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL); ps.SetProperty("QuadBufferStereo", true); //设置四缓冲立体启用 this.axRenderControl1.Initialize(true, ps); this.axRenderControl1.Camera.FlyTime = 1; 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; } #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]); string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable); if (fcnames.Length == 0) { return; } fcMap = 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; } geoNames.Add(fieldinfo.Name); } fcMap.Add(fc, geoNames); } } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); return; } // CreateFeautureLayer bool hasfly = false; foreach (IFeatureClass fc in fcMap.Keys) { List <string> geoNames = (List <string>)fcMap[fc]; foreach (string geoName in geoNames) { if (!geoName.Equals("Geometry")) { continue; } IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer( fc, geoName, null, null, rootId); if (!hasfly) { IFieldInfoCollection fieldinfos = fc.GetFields(); IFieldInfo fieldinfo = fieldinfos.Get(fieldinfos.IndexOf(geoName)); IGeometryDef geometryDef = fieldinfo.GeometryDef; IEnvelope env = geometryDef.Envelope; if (env == null || (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 && env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0)) { continue; } IEulerAngle angle = new EulerAngle(); angle.Set(0, -20, 0); this.axRenderControl1.Camera.LookAt(env.Center, 1000, angle); } hasfly = true; } } #endregion // 下拉框控件默认选中第一项 this.toolStripComboBoxViewportMode.SelectedIndex = 0; this.txtEyeSeparation.Text = this.axRenderControl1.GetRenderParam(gviRenderControlParameters.gviRenderParamStereoEyeSeparation).ToString(); this.txtFusionDistance.Text = this.axRenderControl1.GetRenderParam(gviRenderControlParameters.gviRenderParamStereoFusionDistance).ToString(); this.txtScreenDistance.Text = this.axRenderControl1.GetRenderParam(gviRenderControlParameters.gviRenderParamStereoScreenDistance).ToString(); this.txtFusionDistance.TextChanged += new System.EventHandler(this.txtFusionDistance_TextChanged); this.txtEyeSeparation.TextChanged += new System.EventHandler(this.txtEyeSeparation_TextChanged); this.txtScreenDistance.TextChanged += new System.EventHandler(this.txtScreenDistance_TextChanged); { this.helpProvider1.SetShowHelp(this.axRenderControl1, true); this.helpProvider1.SetHelpString(this.axRenderControl1, ""); this.helpProvider1.HelpNamespace = "StereoDisplay.html"; } }
private void LoadProperty() { try { DF3DFeatureClass featureClassInfo = CommonUtils.Instance().CurEditLayer; if (featureClassInfo == null) { return; } IFeatureClass fc = featureClassInfo.GetFeatureClass(); if (fc == null) { return; } IFieldInfoCollection fiCol = fc.GetFields(); if (fiCol == null) { return; } FacilityClass fac = featureClassInfo.GetFacilityClass(); if (fac == null) { for (int i = 0; i < fiCol.Count; i++) { IFieldInfo fi = fiCol.Get(i); if (fi.Name == fc.FidFieldName) { continue; } switch (fi.FieldType) { case gviFieldType.gviFieldBlob: case gviFieldType.gviFieldGeometry: case gviFieldType.gviFieldUnknown: continue; //case gviFieldType.gviFieldFloat: //case gviFieldType.gviFieldDouble: // break; //case gviFieldType.gviFieldFID: //case gviFieldType.gviFieldUUID: //case gviFieldType.gviFieldInt16: //case gviFieldType.gviFieldInt32: //case gviFieldType.gviFieldInt64: // break; //case gviFieldType.gviFieldString: // break; //case gviFieldType.gviFieldDate: default: DataRow dr = this._dt.NewRow(); dr["FN"] = string.IsNullOrEmpty(fi.Alias) ? fi.Name : fi.Alias; dr["FV"] = null; dr["F"] = fi; this._dt.Rows.Add(dr); break; } } } else { List <DFDataConfig.Class.FieldInfo> list = fac.FieldInfoCollection; if (list != null) { foreach (DFDataConfig.Class.FieldInfo fi1 in list) { if (!fi1.CanQuery) { continue; } int index = fiCol.IndexOf(fi1.Name); if (index == -1) { continue; } IFieldInfo fi = fiCol.Get(index); if (fi == null) { continue; } switch (fi.FieldType) { case gviFieldType.gviFieldBlob: case gviFieldType.gviFieldGeometry: case gviFieldType.gviFieldUnknown: continue; //case gviFieldType.gviFieldFloat: //case gviFieldType.gviFieldDouble: // break; //case gviFieldType.gviFieldFID: //case gviFieldType.gviFieldUUID: //case gviFieldType.gviFieldInt16: //case gviFieldType.gviFieldInt32: //case gviFieldType.gviFieldInt64: // break; //case gviFieldType.gviFieldString: // break; //case gviFieldType.gviFieldDate: default: DataRow dr = this._dt.NewRow(); dr["FN"] = fi1.ToString(); dr["FV"] = null; dr["F"] = fi; this._dt.Rows.Add(dr); break; } } } } } catch (Exception ex) { } }
private void MainForm_Load(object sender, System.EventArgs e) { // 初始化RenderControl控件 IPropertySet ps = new PropertySet(); ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL); this.axRenderControl1.Initialize(true, ps); 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 = 1; #region 加载SDKDEMO场景 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]); //遍历FeatureClass string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable); if (fcnames.Length == 0) { return; } fcMap = 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; } geoNames.Add(fieldinfo.Name); } fcMap.Add(fc, geoNames); } } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); return; } // CreateFeautureLayer bool hasfly = false; foreach (IFeatureClass fc in fcMap.Keys) { List <string> geoNames = (List <string>)fcMap[fc]; foreach (string geoName in geoNames) { if (!geoName.Equals("Geometry")) { continue; } IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer( fc, geoName, null, null, rootId); flayerList.Add(featureLayer); if (!hasfly) { IFieldInfoCollection fieldinfos = fc.GetFields(); IFieldInfo fieldinfo = fieldinfos.Get(fieldinfos.IndexOf(geoName)); IGeometryDef geometryDef = fieldinfo.GeometryDef; IEnvelope env = geometryDef.Envelope; if (env == null || (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 && env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0)) { continue; } IEulerAngle angle = new EulerAngle(); angle.Set(0, -90, 0); this.axRenderControl1.Camera.LookAt(env.Center, 1000, angle); } hasfly = true; } } #endregion //注册地形 string tmpTedPath = (strMediaPath + @"\terrain\SingaporePlanarTerrain.ted"); this.axRenderControl1.Terrain.RegisterTerrain(tmpTedPath, ""); if (player == null) { player = this.axRenderControl1.HeatMapPlayer; } // 加载FDB场景 try { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\HeatMap.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]); string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable); if (fcnames.Length == 0) { return; } fcMap = 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; } geoNames.Add(fieldinfo.Name); } fcMap.Add(fc, geoNames); if (fc.HasTemporal()) { ITemporalManager tm = fc.TemporalManager; DateTime[] times = tm.GetKeyDatetimes(); for (int i = 0; i < times.Length; i++) { if (keyDatetimesList.Contains(times[i])) { continue; } keyDatetimesList.Add(times[i]); } } } } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); return; } // 设置时间轴 if (keyDatetimesList.Count == 0) { this.cbKeyTimes.Enabled = false; this.btnPlay.Enabled = false; this.btnPause.Enabled = false; this.btnStop.Enabled = false; } else { keyDatetimesList.Sort(); for (int t = 0; t < keyDatetimesList.Count; t++) { DateTime d = keyDatetimesList[t]; cbKeyTimes.Items.Add(d); } } // CreateFeautureLayer foreach (IFeatureClass fc in fcMap.Keys) { List <string> geoNames = (List <string>)fcMap[fc]; foreach (string geoName in geoNames) { heatmap = this.axRenderControl1.ObjectManager.CreateHeatMap( fc, geoName, "HotValue", rootId); if (heatmap == null) { continue; } this.txtMinValue.Text = heatmap.MinHeatValue.ToString(); this.txtMaxValue.Text = heatmap.MaxHeatValue.ToString(); } } //设置curLayer的时刻为最新时刻 if (keyDatetimesList.Count > 0) { DateTime dmax = (keyDatetimesList[keyDatetimesList.Count - 1]); player.SetTime(dmax); //设置时间轴为最小 cbKeyTimes.SelectedIndex = keyDatetimesList.Count - 1; } //测试自定义颜色 //System.Drawing.Color[] colors = new System.Drawing.Color[2]; //colors[0] = System.Drawing.Color.White; //colors[1] = System.Drawing.Color.Gray; //bool suc = player.SetColor(colors, 2); //if(suc) //{ // System.Drawing.Color[] colorvec; // byte c; // bool suc2 = player.GetColor(out colorvec, out c); // if (suc2) // this.Text = c.ToString(); //} this.cbShowHeatMap.Checked = true; this.cbShowFeatureLayer.Checked = true; { this.helpProvider1.SetShowHelp(this.axRenderControl1, true); this.helpProvider1.SetHelpString(this.axRenderControl1, ""); this.helpProvider1.HelpNamespace = "Temporal.html"; } }
private void treelist_AfterCheckNode(object sender, NodeEventArgs e) { this.teValue.Text = ""; this.listBoxControlValues.Items.Clear(); if (string.IsNullOrEmpty(this._sysFieldName)) { return; } IFdeCursor cursor = null; IRowBuffer row = null; try { WaitForm.Start("正在加载列表...", "请稍后"); HashSet <string> list = new HashSet <string>(); bool bBreak = false; foreach (TreeListNode node in this.treelist.GetAllCheckedNodes()) { object obj = node.GetValue("NodeObject"); if (obj != null && obj is SubClass) { SubClass sc = obj as SubClass; if (sc.Parent == null) { continue; } string cacheType = sc.Parent.Name + "_" + sc.GroupId + "_3D_" + this._sysFieldName; object objCache = CacheHelper.GetCache(cacheType); if (objCache != null && objCache is HashSet <string> ) { HashSet <string> temphs = objCache as HashSet <string>; foreach (string tempstr in temphs) { list.Add(tempstr); } continue; } HashSet <string> listsc = new HashSet <string>(); string[] arrFc3DId = sc.Parent.Fc3D.Split(';'); if (arrFc3DId == null) { continue; } foreach (string fc3DId in arrFc3DId) { DF3DFeatureClass dffc = DF3DFeatureClassManager.Instance.GetFeatureClassByID(fc3DId); if (dffc == null) { continue; } FacilityClass facClass = dffc.GetFacilityClass(); IFeatureClass fc = dffc.GetFeatureClass(); if (fc == null || facClass == null || facClass.Name != this._facType) { continue; } DFDataConfig.Class.FieldInfo fi = facClass.GetFieldInfoBySystemName(this._sysFieldName); if (fi == null) { continue; } IFieldInfoCollection fiCol = fc.GetFields(); int index = fiCol.IndexOf(fi.Name); if (index < 0) { continue; } Gvitech.CityMaker.FdeCore.FieldInfo gfi = (Gvitech.CityMaker.FdeCore.FieldInfo)fiCol.Get(index); IQueryFilter filter = new QueryFilter(); filter.SubFields = gfi.Name; filter.ResultBeginIndex = 0; filter.ResultLimit = 1; while (true) { string strTempClause = gfi.Name + " is not null and "; string fClause = strTempClause; foreach (string strtemp in listsc) { fClause += gfi.Name + " <> " + strtemp + " and "; } fClause = fClause.Substring(0, fClause.Length - 5); filter.WhereClause = "GroupId = " + sc.GroupId + " and " + fClause; cursor = fc.Search(filter, true); if ((row = cursor.NextRow()) != null) { if (row.IsNull(0)) { break; } object temp = row.GetValue(0); string strtemp = ""; switch (gfi.FieldType) { case gviFieldType.gviFieldFID: case gviFieldType.gviFieldFloat: case gviFieldType.gviFieldDouble: case gviFieldType.gviFieldInt16: case gviFieldType.gviFieldInt32: case gviFieldType.gviFieldInt64: strtemp = temp.ToString(); break; case gviFieldType.gviFieldDate: case gviFieldType.gviFieldString: case gviFieldType.gviFieldUUID: strtemp = "'" + temp.ToString() + "'"; break; case gviFieldType.gviFieldBlob: case gviFieldType.gviFieldGeometry: case gviFieldType.gviFieldUnknown: default: continue; } if (temp != null) { list.Add(strtemp); listsc.Add(strtemp); if (list.Count > 10) { bBreak = true; break;// 列举10个 } } } else { break; } } if (bBreak) { break; } } CacheHelper.SetCache(cacheType, listsc); } if (bBreak) { break; } } foreach (string str2 in list) { //if (!(string.IsNullOrEmpty(str2))) //{ this.listBoxControlValues.Items.Add(str2); //} } } 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; } WaitForm.Stop(); } }
public MainForm() { InitializeComponent(); // 初始化RenderControl控件 IPropertySet ps = new PropertySet(); ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL); this.axRenderControl1.Initialize(true, ps); rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID; this.axRenderControl1.Camera.FlyTime = 1; // 设置天空盒 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; } #region 加载FDB场景 try { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\polyline.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]); string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable); if (fcnames.Length == 0) { return; } fcMap = 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; } geoNames.Add(fieldinfo.Name); } fcMap.Add(fc, geoNames); } } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); return; } // CreateFeautureLayer bool hasfly = false; foreach (IFeatureClass fc in fcMap.Keys) { List <string> geoNames = (List <string>)fcMap[fc]; foreach (string geoName in geoNames) { if (!geoName.Equals("Geometry")) { continue; } ISimpleTextRender tr = new SimpleTextRender(); tr.Expression = "$(oid)"; tr.MinimizeOverlap = true; tr.DynamicPlacement = true; ITextSymbol ts = new TextSymbol(); tr.Symbol = ts; featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer(fc, geoName, tr, null, rootId); if (!hasfly) { IFieldInfoCollection fieldinfos = fc.GetFields(); IFieldInfo fieldinfo = fieldinfos.Get(fieldinfos.IndexOf(geoName)); IGeometryDef geometryDef = fieldinfo.GeometryDef; IEnvelope env = geometryDef.Envelope; if (env == null || (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 && env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0)) { continue; } IEulerAngle angle = new EulerAngle(); angle.Set(0, -20, 0); this.axRenderControl1.Camera.LookAt(env.Center, 600, angle); } hasfly = true; } } #endregion 加载FDB场景 #region 查询所有值 foreach (IFeatureClass fc in fcMap.Keys) { DataTable dt = CreateDataTable(fc); pipeMap = new Hashtable(); GetResultSet(fc, null, dt); this.dataGridViewPolyline.DataSource = dt; } #endregion this.comboBoxPlayMode.SelectedIndex = 2; this.axRenderControl1.InteractMode = gviInteractMode.gviInteractSelect; this.axRenderControl1.MouseSelectObjectMask = gviMouseSelectObjectMask.gviSelectRenderPipeLine; this.axRenderControl1.MouseSelectMode = gviMouseSelectMode.gviMouseSelectDrag; //this.axRenderControl1.RcMouseClickSelect += AxRenderControl1_RcMouseClickSelect; this.axRenderControl1.RcMouseDragSelect += AxRenderControl1_RcMouseDragSelect; { this.helpProvider1.SetShowHelp(this.axRenderControl1, true); this.helpProvider1.SetHelpString(this.axRenderControl1, ""); this.helpProvider1.HelpNamespace = "RenderPipeLine.html"; } }
private void AddGeometry() { try { this.beforeRowBufferMap.Clear(); SelectCollection.Instance().Clear(); DF3DFeatureClass featureClassInfo = CommonUtils.Instance().CurEditLayer; if (featureClassInfo == null) { return; } IFeatureClass fc = featureClassInfo.GetFeatureClass(); if (fc == null) { return; } IFieldInfoCollection fields = fc.GetFields(); int indexGeo = fields.IndexOf(this._strGeometryFieldName); if (indexGeo == -1) { return; } IGeometry geo = this._drawTool.GetGeo(); IGeometry geoOut = null; switch (geo.GeometryType) { case gviGeometryType.gviGeometryModelPoint: geoOut = geo; break; case gviGeometryType.gviGeometryPoint: IPoint pt = geo as IPoint; IPoint pt1 = pt.Clone2(gviVertexAttribute.gviVertexAttributeZM) as IPoint; pt1.SetCoords(pt.X, pt.Y, pt.Z, 0, 0); geoOut = pt1; break; case gviGeometryType.gviGeometryPolyline: IPolyline line = geo as IPolyline; IPolyline line1 = this._geoFact.CreateGeometry(gviGeometryType.gviGeometryPolyline, gviVertexAttribute.gviVertexAttributeZM) as IPolyline; for (int i = 0; i < line.PointCount; i++) { IPoint ptGet = line.GetPoint(i); IPoint pttemp = ptGet.Clone2(gviVertexAttribute.gviVertexAttributeZM) as IPoint; pttemp.SetCoords(ptGet.X, ptGet.Y, ptGet.Z, 0, 0); line1.AppendPoint(pttemp); } geoOut = line1; break; case gviGeometryType.gviGeometryPolygon: IPolygon polygon = geo as IPolygon; IPolygon polygon1 = this._geoFact.CreateGeometry(gviGeometryType.gviGeometryPolygon, gviVertexAttribute.gviVertexAttributeZM) as IPolygon; for (int i = 0; i < polygon.ExteriorRing.PointCount; i++) { IPoint ptGet = polygon.ExteriorRing.GetPoint(i); IPoint pttemp = ptGet.Clone2(gviVertexAttribute.gviVertexAttributeZM) as IPoint; pttemp.SetCoords(ptGet.X, ptGet.Y, ptGet.Z, 0, 0); polygon1.ExteriorRing.AppendPoint(pttemp); } geoOut = polygon1; break; } if (geoOut == null) { return; } if (geo.GeometryType == gviGeometryType.gviGeometryModelPoint) { //导入模型到数据库中 string mn = BitConverter.ToString(ObjectIdGenerator.Generate()).Replace("-", string.Empty).ToLowerInvariant(); IModelPoint mp = geoOut as IModelPoint; bool bRes = this.ImportOsg(mn, mp.ModelName); if (!bRes) { return; } mp.ModelName = mn; geoOut = mp; } IRowBufferCollection rowCol = new RowBufferCollection(); IRowBufferFactory fac = new RowBufferFactory(); IRowBuffer row = fac.CreateRowBuffer(fields); row.SetValue(indexGeo, geoOut); rowCol.Add(row); beforeRowBufferMap[featureClassInfo] = rowCol; } catch (Exception ex) { } }
// 公共方法 void FeatureLayerVisualize(IConnectionInfo ci, bool needfly, string sourceName) { try { 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]); string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable); if (fcnames.Length == 0) { return; } fcMap = new Hashtable(fcnames.Length); foreach (string name in fcnames) { IFeatureClass fc = dataset.OpenFeatureClass(name); _featureClass = fc; // 找到空间列字段 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; } geoNames.Add(fieldinfo.Name); } fcMap.Add(fc, geoNames); } } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); return; } // CreateFeautureLayer bool hasfly = !needfly; foreach (IFeatureClass fc in fcMap.Keys) { List <string> geoNames = (List <string>)fcMap[fc]; foreach (string geoName in geoNames) { IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer( fc, geoName, null, null, rootId); IFieldInfoCollection fieldinfos = fc.GetFields(); IFieldInfo fieldinfo = fieldinfos.Get(fieldinfos.IndexOf(geoName)); IGeometryDef geometryDef = fieldinfo.GeometryDef; IEnvelope env = geometryDef.Envelope; if (env == null || (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 && env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0)) { continue; } // 相机飞入 if (!hasfly) { IEulerAngle angle = new EulerAngle(); angle.Set(0, -20, 0); this.axRenderControl1.Camera.LookAt(env.Center, 1000, angle); } hasfly = true; } } }
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; 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; } #region 加载FDB场景 try { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\MultiSpatialColumns.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]); string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable); if (fcnames.Length == 0) { return; } // 仅仅加载“建筑”要素类 _featureClass = dataset.OpenFeatureClass("建筑"); { // 用名为"Geometry"的空间列创建模型FeautureLayer IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer(_featureClass, "Geometry", null, null, rootId); // 添加节点到界面控件上 myListNode item = new myListNode(string.Format("{0}_{1}_{2}", "ModelPoint", _featureClass.Name, featureLayer.MaxVisibleDistance.ToString()), featureLayer); item.Checked = true; listView1.Items.Add(item); } { //用名为"Surface"的空间列创建模型FeautureLayer IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer(_featureClass, "Surface", null, null, rootId); // 添加节点到界面控件上 myListNode item = new myListNode(string.Format("{0}_{1}_{2}", "Surface", _featureClass.Name, featureLayer.MaxVisibleDistance.ToString()), featureLayer); item.Checked = true; listView1.Items.Add(item); } { //用名为"Polygon"的空间列创建模型FeautureLayer IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer(_featureClass, "Polygon", null, null, rootId); // 添加节点到界面控件上 myListNode item = new myListNode(string.Format("{0}_{1}_{2}", "Polygon", _featureClass.Name, featureLayer.MaxVisibleDistance.ToString()), featureLayer); item.Checked = true; listView1.Items.Add(item); } //{ // //用名为"Point"的空间列创建模型FeautureLayer // IFeatureLayer featureLayer = this.axRenderControl1.FeatureLayerManager.CreateFeatureLayer(_featureClass, "Point", null, null); // // 添加节点到界面控件上 // myListNode item = new myListNode(string.Format("{0}_{1}_{2}", "Point", _featureClass.Name, featureLayer.MaxVisibleDistance.ToString()), featureLayer); // item.Checked = true; // listView1.Items.Add(item); //} IFieldInfoCollection fieldinfos = _featureClass.GetFields(); IFieldInfo fieldinfo = fieldinfos.Get(fieldinfos.IndexOf("Geometry")); IGeometryDef geometryDef = fieldinfo.GeometryDef; IEnvelope env = geometryDef.Envelope; IEulerAngle angle = new EulerAngle(); angle.Set(0, -20, 0); this.axRenderControl1.Camera.LookAt(env.Center, 400, angle); } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); return; } #endregion { this.helpProvider1.SetShowHelp(this.axRenderControl1, true); this.helpProvider1.SetHelpString(this.axRenderControl1, ""); this.helpProvider1.HelpNamespace = "MultiSpatialColumns.html"; } }
void init() { // 初始化RenderControl控件 IPropertySet ps = new PropertySet(); ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL); this.axRenderControl1.Initialize(true, ps); this.axRenderControl1.Camera.FlyTime = 1; rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID; // 注册出图事件 this.axRenderControl1.RcPictureExportBegin += new _IRenderControlEvents_RcPictureExportBeginEventHandler(axRenderControl1_RcPictureExportBegin); this.axRenderControl1.RcPictureExporting += new _IRenderControlEvents_RcPictureExportingEventHandler(axRenderControl1_RcPictureExporting); this.axRenderControl1.RcPictureExportEnd += new _IRenderControlEvents_RcPictureExportEndEventHandler(axRenderControl1_RcPictureExportEnd); // 注册相机“返回”和“前进”事件 this.axRenderControl1.RcCameraUndoRedoStatusChanged += new _IRenderControlEvents_RcCameraUndoRedoStatusChangedEventHandler(axRenderControl1_RcCameraUndoRedoStatusChanged); _rcCameraUndoRedo = new _IRenderControlEvents_RcCameraUndoRedoStatusChangedEventHandler(axRenderControl1_RcCameraUndoRedoStatusChanged); // 设置天空盒 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; } // 加载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]); string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable); if (fcnames.Length == 0) { return; } fcMap = 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; } geoNames.Add(fieldinfo.Name); } fcMap.Add(fc, geoNames); } } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); return; } // CreateFeautureLayer bool hasfly = false; foreach (IFeatureClass fc in fcMap.Keys) { List <string> geoNames = (List <string>)fcMap[fc]; foreach (string geoName in geoNames) { if (!geoName.Equals("Geometry")) { continue; } IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer( fc, geoName, null, null, rootId); if (!hasfly) { IFieldInfoCollection fieldinfos = fc.GetFields(); IFieldInfo fieldinfo = fieldinfos.Get(fieldinfos.IndexOf(geoName)); IGeometryDef geometryDef = fieldinfo.GeometryDef; env = geometryDef.Envelope; if (env == null || (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 && env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0)) { continue; } IEulerAngle angle = new EulerAngle(); angle.Set(0, -20, 0); this.axRenderControl1.Camera.LookAt(env.Center, 1000, angle); } hasfly = true; } } // 加载动画导航 BindingSource bindingSource1 = new BindingSource(); { string tmpXMLPath = (strMediaPath + @"\xml\CameraTour_1.xml"); tour = this.axRenderControl1.ObjectManager.CreateCameraTour(rootId); if (File.Exists(tmpXMLPath)) { StreamReader sr = new StreamReader(tmpXMLPath); string xmlstring = ""; string line = sr.ReadLine(); while (!string.IsNullOrEmpty(line)) { xmlstring += line; line = sr.ReadLine(); } sr.Close(); tour.FromXml(xmlstring); } bindingSource1.Add(new Knight("CameraTour_1", tour)); } { string tmpXMLPath = (strMediaPath + @"\xml\CameraTour_2.xml"); tour = this.axRenderControl1.ObjectManager.CreateCameraTour(rootId); if (File.Exists(tmpXMLPath)) { StreamReader sr = new StreamReader(tmpXMLPath); string xmlstring = ""; string line = sr.ReadLine(); while (!string.IsNullOrEmpty(line)) { xmlstring += line; line = sr.ReadLine(); } sr.Close(); tour.FromXml(xmlstring); } bindingSource1.Add(new Knight("CameraTour_2", tour)); } dataGridView1.DataSource = bindingSource1; dataGridView1.Columns[1].Visible = false; this.btnPause.Enabled = false; this.btnStop.Enabled = false; this.toolStripComboBoxWeather.SelectedIndex = 0; { this.helpProvider1.SetShowHelp(this.axRenderControl1, true); this.helpProvider1.SetHelpString(this.axRenderControl1, ""); this.helpProvider1.HelpNamespace = "HelloWorld.html"; } }
// 公共方法 void FeatureLayerVisualize(IConnectionInfo ci, bool needfly, string sourceName, ITextRender textRender, IGeometryRender geoRender) { IDataSourceFactory dsFactory = null; IDataSource ds = null; IFeatureDataSet dataset = null; try { dsFactory = new DataSourceFactory(); ds = dsFactory.OpenDataSource(ci); string[] setnames = (string[])ds.GetFeatureDatasetNames(); if (setnames.Length == 0) { return; } dataset = ds.OpenFeatureDataset(setnames[0]); string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable); if (fcnames.Length == 0) { return; } fcMap = 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; } geoNames.Add(fieldinfo.Name); } fcMap.Add(fc, geoNames); } // CreateFeautureLayer bool hasfly = !needfly; foreach (IFeatureClass fcInMap in fcMap.Keys) { List <string> geoNames = (List <string>)fcMap[fcInMap]; foreach (string geoName in geoNames) { IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer( fcInMap, geoName, textRender, geoRender, rootId); // 设置featureLayer组可见 if (!geoRender.RenderGroupField.Equals("")) { SetGroupVisiable(dataset, featureLayer); } // 添加节点到界面控件上 myListNode item = new myListNode(string.Format("{0}_{1}_{2}", sourceName, fcInMap.Name, featureLayer.MaxVisibleDistance.ToString()), featureLayer); item.Checked = true; listView1.Items.Add(item); layerFcMap.Add(featureLayer, fcInMap); IFieldInfoCollection fieldinfos = fcInMap.GetFields(); IFieldInfo fieldinfo = fieldinfos.Get(fieldinfos.IndexOf(geoName)); IGeometryDef geometryDef = fieldinfo.GeometryDef; IEnvelope env = geometryDef.Envelope; layerEnvelopeMap.Add(featureLayer, env); if (env == null || (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 && env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0)) { continue; } // 相机飞入 if (!hasfly) { angle.Set(0, -20, 0); this.axRenderControl1.Camera.LookAt(env.Center, 1000, angle); } hasfly = true; } } } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); return; } catch (System.Exception e) { System.Diagnostics.Trace.WriteLine(e.Message); return; } finally { if (dsFactory != null) { //Marshal.ReleaseComObject(dsFactory); dsFactory = null; } if (ds != null) { //Marshal.ReleaseComObject(ds); ds = null; } if (dataset != null) { //Marshal.ReleaseComObject(dataset); dataset = null; } //if (fc != null) //{ // //Marshal.ReleaseComObject(fc); // fc = null; //} } }
private void init() { // 初始化RenderControl控件 IPropertySet ps = new PropertySet(); ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL); this.axRenderControl1.Initialize(true, ps); this.axRenderControl1.Camera.FlyTime = 1; 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 + "\\7_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\7_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\7_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\7_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\7_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\7_UP.jpg"); } else { MessageBox.Show("请不要随意更改SDK目录名"); return; } #region 加载shp try { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionShapeFile; string tmpFDBPath = (strMediaPath + @"\shp\road\road.shp"); 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; string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable); if (fcnames.Length == 0) { return; } fcMap = 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; } geoNames.Add(fieldinfo.Name); } fcMap.Add(fc, geoNames); } } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); return; } // CreateFeautureLayer bool hasfly = false; foreach (IFeatureClass fc in fcMap.Keys) { List <string> geoNames = (List <string>)fcMap[fc]; foreach (string geoName in geoNames) { if (!geoName.Equals("Geometry")) { continue; } IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer( fc, geoName, null, null, rootId); if (!hasfly) { IFieldInfoCollection fieldinfos = fc.GetFields(); IFieldInfo fieldinfo = fieldinfos.Get(fieldinfos.IndexOf(geoName)); IGeometryDef geometryDef = fieldinfo.GeometryDef; env = geometryDef.Envelope; if (env == null || (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 && env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0)) { continue; } IEulerAngle angle = new EulerAngle(); angle.Set(0, -20, 0); IPoint point = new GeometryFactory().CreatePoint(gviVertexAttribute.gviVertexAttributeZ); point.Position = env.Center; point.SpatialCRS = fc.FeatureDataSet.SpatialReference; this.axRenderControl1.Camera.LookAt2(point, 1000, angle); } hasfly = true; } } #endregion }
/// <summary> /// 初始化 /// </summary> private void init() { // 初始化RenderControl控件 IPropertySet ps = new PropertySet(); ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL); this.axRenderControl1.Initialize(true, ps); this.axRenderControl1.Camera.FlyTime = 1; 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"); skybox = this.axRenderControl1.ObjectManager.GetSkyBox(1); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\2_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\2_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\2_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\2_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\2_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\2_UP.jpg"); skybox = this.axRenderControl1.ObjectManager.GetSkyBox(2); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\04_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\04_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\04_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\04_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\04_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\04_UP.jpg"); skybox = this.axRenderControl1.ObjectManager.GetSkyBox(3); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\9_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\9_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\9_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\9_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\9_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\9_UP.jpg"); } else { MessageBox.Show("请不要随意更改SDK目录名"); return; } #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]); string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable); if (fcnames.Length == 0) { return; } fcMap = 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; } geoNames.Add(fieldinfo.Name); } fcMap.Add(fc, geoNames); } } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); return; } // CreateFeautureLayer bool hasfly = false; foreach (IFeatureClass fc in fcMap.Keys) { List <string> geoNames = (List <string>)fcMap[fc]; foreach (string geoName in geoNames) { if (!geoName.Equals("Geometry")) { continue; } IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer( fc, geoName, null, null, rootId); if (!hasfly) { IFieldInfoCollection fieldinfos = fc.GetFields(); IFieldInfo fieldinfo = fieldinfos.Get(fieldinfos.IndexOf(geoName)); IGeometryDef geometryDef = fieldinfo.GeometryDef; IEnvelope env = geometryDef.Envelope; if (env == null || (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 && env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0)) { continue; } IEulerAngle angle = new EulerAngle(); angle.Set(0, -20, 0); this.axRenderControl1.Camera.LookAt(env.Center, 1000, angle); } hasfly = true; } } #endregion 加载FDB场景 { this.helpProvider1.SetShowHelp(this.axRenderControl1, true); this.helpProvider1.SetHelpString(this.axRenderControl1, ""); this.helpProvider1.HelpNamespace = "HideSelectedArea.html"; } // 注册控件拾取事件 this.axRenderControl1.RcMouseClickSelect += new _IRenderControlEvents_RcMouseClickSelectEventHandler(axRenderControl1_RcMouseClickSelect); this.axRenderControl1.RcMouseDragSelect += new _IRenderControlEvents_RcMouseDragSelectEventHandler(axRenderControl1_RcMouseDragSelect); this.axRenderControl1.MouseSelectObjectMask = gviMouseSelectObjectMask.gviSelectFeatureLayer; this.axRenderControl1.InteractMode = gviInteractMode.gviInteractSelect; this.axRenderControl1.MouseSelectMode = gviMouseSelectMode.gviMouseSelectClick | gviMouseSelectMode.gviMouseSelectDrag; }
/// <summary> /// 初始化 /// </summary> private void init() { // 初始化RenderControl控件 IPropertySet ps = new PropertySet(); ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL); // Unknown this.axRenderControl1.Initialize(true, ps); rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID; // 平面坐标系 //string wkt = @"PROJCS['Beijing_1954_3_Degree_GK_CM_102E',GEOGCS['GCS_Beijing_1954',DATUM['D_Beijing_1954',SPHEROID['Krasovsky_1940',6378245.0,298.3]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Gauss_Kruger'],PARAMETER['False_Easting',500000],PARAMETER['False_Northing',0],PARAMETER['Central_Meridian',102],PARAMETER['Scale_Factor',1],PARAMETER['Latitude_Of_Origin',0],UNIT['metre',1]]"; //this.axRenderControl1.Initialize2(wkt, ps); // 球面1 //this.axRenderControl1.Initialize(false, ps); // 球面2 //IGeographicCRS crs = new CRSFactory().CreateWGS84(); //this.axRenderControl1.Initialize2(crs.AsWKT(), ps); // 设置天空盒 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; } #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; string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable); if (fcnames.Length == 0) { return; } fcMap = 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; } geoNames.Add(fieldinfo.Name); } fcMap.Add(fc, geoNames); } } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); return; } // CreateFeautureLayer bool hasfly = false; foreach (IFeatureClass fc in fcMap.Keys) { List <string> geoNames = (List <string>)fcMap[fc]; foreach (string geoName in geoNames) { if (!geoName.Equals("Geometry")) { continue; } IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer( fc, geoName, null, null, rootId); if (!hasfly) { IFieldInfoCollection fieldinfos = fc.GetFields(); IFieldInfo fieldinfo = fieldinfos.Get(fieldinfos.IndexOf(geoName)); IGeometryDef geometryDef = fieldinfo.GeometryDef; IEnvelope env = geometryDef.Envelope; if (env == null || (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 && env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0)) { continue; } angle.Set(0, -20, 0); this.axRenderControl1.Camera.LookAt(env.Center, 1000, angle); } hasfly = true; } } #endregion 加载FDB场景 this.axRenderControl1.Camera.FlyTime = 0; { this.helpProvider1.SetShowHelp(this.axRenderControl1, true); this.helpProvider1.SetHelpString(this.axRenderControl1, ""); this.helpProvider1.HelpNamespace = "ParticleEffect.html"; } }