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; } // 可视化ModelPoint类型FeatureLayer { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\community.FDB"); ci.Database = tmpFDBPath; // *******定义文字渲染风格******* IValueMapTextRender textRender = new ValueMapTextRender(); textRender.Expression = "''..$(Name)"; { TextAttribute textAttribute = new TextAttribute(); textAttribute.TextColor = System.Drawing.Color.Yellow; textAttribute.Font = "黑体"; textAttribute.TextSize = 15; ITextSymbol textSymbol = new TextSymbol(); textSymbol.TextAttribute = textAttribute; textSymbol.PivotAlignment = gviPivotAlignment.gviPivotAlignBottomCenter; IUniqueValuesRenderRule uniqValRule = new UniqueValuesRenderRule(); uniqValRule.LookUpField = "type"; uniqValRule.AddValue("写字楼"); ITextRenderScheme textScheme = new TextRenderScheme(); textScheme.Symbol = textSymbol; textScheme.AddRule(uniqValRule); textRender.AddScheme(textScheme); } { TextAttribute textAttribute = new TextAttribute(); textAttribute.TextColor = Color.Black; textAttribute.TextSize = 11; textAttribute.Font = "华文新魏"; ITextSymbol textSymbol = new TextSymbol(); textSymbol.TextAttribute = textAttribute; textSymbol.PivotAlignment = gviPivotAlignment.gviPivotAlignBottomCenter; IUniqueValuesRenderRule uniqValRule = new UniqueValuesRenderRule(); uniqValRule.LookUpField = "type"; uniqValRule.AddValue("别墅"); ITextRenderScheme textScheme = new TextRenderScheme(); textScheme.Symbol = textSymbol; textScheme.AddRule(uniqValRule); textRender.AddScheme(textScheme); } { TextAttribute textAttribute = new TextAttribute(); textAttribute.TextColor = Color.Red; textAttribute.TextSize = 20; textAttribute.Font = "幼圆"; ITextSymbol textSymbol = new TextSymbol(); textSymbol.TextAttribute = textAttribute; textSymbol.PivotAlignment = gviPivotAlignment.gviPivotAlignBottomCenter; IUniqueValuesRenderRule uniqValRule = new UniqueValuesRenderRule(); uniqValRule.LookUpField = "type"; uniqValRule.AddValue("商场"); ITextRenderScheme textScheme = new TextRenderScheme(); textScheme.Symbol = textSymbol; textScheme.AddRule(uniqValRule); textRender.AddScheme(textScheme); } // *****定义几何物体渲染风格***** IValueMapGeometryRender geoRender = new ValueMapGeometryRender(); { IRangeRenderRule rangeRule = new RangeRenderRule(); rangeRule.LookUpField = "storey"; rangeRule.MaxValue = 3; rangeRule.MinValue = 0; rangeRule.IncludeMin = false; IModelPointSymbol geoSymbol = new ModelPointSymbol(); geoSymbol.Color = Color.Yellow; //模型颜色为浅黄 geoSymbol.EnableColor = true; //需开启,否则颜色设置无效 IGeometryRenderScheme grs = new GeometryRenderScheme(); grs.AddRule(rangeRule); grs.Symbol = geoSymbol; geoRender.AddScheme(grs); } { IRangeRenderRule rangeRule = new RangeRenderRule(); rangeRule.LookUpField = "storey"; rangeRule.MaxValue = 9; rangeRule.MinValue = 3; rangeRule.IncludeMin = false; IModelPointSymbol geoSymbol = new ModelPointSymbol(); geoSymbol.Color = Color.YellowGreen; //模型颜色为中黄 geoSymbol.EnableColor = true; //需开启,否则颜色设置无效 IGeometryRenderScheme grs = new GeometryRenderScheme(); grs.AddRule(rangeRule); grs.Symbol = geoSymbol; geoRender.AddScheme(grs); } { IRangeRenderRule rangeRule = new RangeRenderRule(); rangeRule.LookUpField = "storey"; rangeRule.MaxValue = 12; rangeRule.MinValue = 9; rangeRule.IncludeMin = false; IModelPointSymbol geoSymbol = new ModelPointSymbol(); geoSymbol.Color = Color.Red; //模型颜色为深黄 geoSymbol.EnableColor = true; //需开启,否则颜色设置无效 IGeometryRenderScheme grs = new GeometryRenderScheme(); grs.AddRule(rangeRule); grs.Symbol = geoSymbol; geoRender.AddScheme(grs); } { IRangeRenderRule rangeRule = new RangeRenderRule(); rangeRule.LookUpField = "storey"; rangeRule.MaxValue = 15; rangeRule.MinValue = 12; rangeRule.IncludeMin = false; IModelPointSymbol geoSymbol = new ModelPointSymbol(); geoSymbol.Color = Color.PowderBlue; //模型颜色为深黄 geoSymbol.EnableColor = true; //需开启,否则颜色设置无效 IGeometryRenderScheme grs = new GeometryRenderScheme(); grs.AddRule(rangeRule); grs.Symbol = geoSymbol; geoRender.AddScheme(grs); } { IGeometryRenderScheme geoSchemeOther = new GeometryRenderScheme(); geoRender.AddScheme(geoSchemeOther); } FeatureLayerVisualize(ci, true, "建筑", textRender, geoRender); } { this.helpProvider1.SetShowHelp(this.axRenderControl1, true); this.helpProvider1.SetHelpString(this.axRenderControl1, ""); this.helpProvider1.HelpNamespace = "FeatureLayerValueMapRender.html"; } }
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 = 0; this.cbOrderPolicy.SelectedIndex = 0; if (geoFac == null) { geoFac = new GeometryFactory(); } #region 加载road FDB try { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\Network.FDB"); ci.Database = tmpFDBPath; IDataSourceFactory dsFactory = new DataSourceFactory(); IDataSource ds = dsFactory.OpenDataSource(ci); string[] setnames = (string[])ds.GetFeatureDatasetNames(); if (setnames.Length == 0) { return; } dataset_Road = ds.OpenFeatureDataset(setnames[0]); string[] fcnames = (string[])dataset_Road.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable); if (fcnames.Length == 0) { return; } fcMap_Road = new Hashtable(fcnames.Length); foreach (string name in fcnames) { IFeatureClass fc = dataset_Road.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_Road.Add(fc, geoNames); } } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); return; } // CreateFeautureLayer bool hasfly = false; foreach (IFeatureClass fc in fcMap_Road.Keys) { List <string> geoNames = (List <string>)fcMap_Road[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; } } Thread.Sleep(2000); // 加载网络 try { dsManager = dataset_Road.GetNetworkManager(); string[] networkDatasetNames = dsManager.GetNetworkNames(); bool hasNetworkDataset = false; for (int i = 0; i < networkDatasetNames.Length; i++) { if (networkDatasetNames[i] == "newNetworkDataset") { hasNetworkDataset = true; } } if (!hasNetworkDataset) { dsLoader = dsManager.CreateNetworkLoader(); dsLoader.Name = "newNetworkDataset"; dsLoader.XYTolerance = double.Parse(txtLoaderTolerance.Text); edgeNS = new EdgeNetworkSource(); edgeNS.SourceName = "road"; edgeNS.ConnectivityPolicy = gviNetworkEdgeConnectivityPolicy.gviEndVertex; edgeNS.GeoColumnName = "Geometry"; edgeNS.ClassConnectivityGroup = 1; dsLoader.AddSource(edgeNS); INetworkAttribute attr = new NetworkAttribute(); attr.FieldType = gviFieldType.gviFieldDouble; attr.Name = "Length"; attr.UsageType = gviNetworkAttributeUsageType.gviUseAsCost; INetworkFieldEvaluator fieldEvaluator = new NetworkFieldEvaluator(); fieldEvaluator.FieldName = "Geometry"; attr.SetEvaluator(edgeNS, gviEdgeDirection.gviAlongDigitized, fieldEvaluator); attr.SetEvaluator(edgeNS, gviEdgeDirection.gviAgainstDigitized, fieldEvaluator); dsLoader.AddNetworkAttribute(attr); dsLoader.LoadNetwork(); } network = dsManager.GetNetwork("newNetworkDataset"); routeSolver = network.CreateRouteSolver(); routeSolver.ImpedanceAttributeName = "Length"; routeSolver.LocationSearchTolerance = double.Parse(txtSearchTolerance.Text); ////Marshal.ReleaseComObject(dsManager); ////Marshal.ReleaseComObject(dsLoader); ////Marshal.ReleaseComObject(attr); ////Marshal.ReleaseComObject(edgeNS); ////Marshal.ReleaseComObject(fieldEvaluator); } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); } #endregion #region 加载POI FDB try { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\POI-1.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_POI = 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_POI.Add(fc, geoNames); } } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); return; } //解析配置文件 string featurelayerName = ""; IValueMapGeometryRender render_JingDian = new ValueMapGeometryRender(); IValueMapGeometryRender render_MeiShi = new ValueMapGeometryRender(); IValueMapGeometryRender render_ZhuSu = new ValueMapGeometryRender(); IValueMapGeometryRender render_HuoDong = new ValueMapGeometryRender(); IValueMapGeometryRender render_GouWu = new ValueMapGeometryRender(); IValueMapGeometryRender render_ATM = new ValueMapGeometryRender(); IValueMapGeometryRender render_WC = new ValueMapGeometryRender(); string[] fn = Directory.GetFiles((strMediaPath + @"\xml\xml")); foreach (string str in fn) { IValueMapGeometryRender render = new ValueMapGeometryRender(); try { XmlDocument docReader = new XmlDocument(); docReader.Load(str); if (docReader.SelectSingleNode("FeatureLayer") != null) { featurelayerName = docReader.SelectSingleNode("FeatureLayer").Attributes["Name"].Value; XmlNode GeometryRenderNode = docReader.SelectSingleNode("FeatureLayer").ChildNodes[0]; switch (GeometryRenderNode.Attributes["HeightStyle"].Value) { case "gviHeightAbsolute": render.HeightStyle = gviHeightStyle.gviHeightAbsolute; break; case "gviHeightOnTerrain": render.HeightStyle = gviHeightStyle.gviHeightOnTerrain; break; case "gviHeightRelative": render.HeightStyle = gviHeightStyle.gviHeightRelative; break; } render.RenderGroupField = GeometryRenderNode.Attributes["GroupField"].Value; XmlNodeList xnl = docReader.SelectSingleNode("FeatureLayer").ChildNodes[0].ChildNodes[0].ChildNodes; if (xnl.Count > 0) { foreach (XmlNode RenderSchemeNode in xnl) { IGeometryRenderScheme renderScheme = new GeometryRenderScheme(); IUniqueValuesRenderRule uniqueRenderRule = new UniqueValuesRenderRule(); IImagePointSymbol imagePointSym = new ImagePointSymbol(); XmlNodeList renderSchemeChilds = RenderSchemeNode.ChildNodes; if (renderSchemeChilds.Count > 0) { XmlNode renderRuleNode = renderSchemeChilds.Item(0); uniqueRenderRule.LookUpField = renderRuleNode.Attributes["LookUpField"].Value; uniqueRenderRule.AddValue(renderRuleNode.Attributes["UniqueValue"].Value); XmlNode geometrySymbolNode = renderSchemeChilds.Item(1); imagePointSym.ImageName = geometrySymbolNode.Attributes["ImageName"].Value; //imagePointSym.Size = int.Parse(geometrySymbolNode.Attributes["Size"].Value); imagePointSym.Size = 60; imagePointSym.Alignment = gviPivotAlignment.gviPivotAlignBottomCenter; } renderScheme.AddRule(uniqueRenderRule); renderScheme.Symbol = imagePointSym; render.AddScheme(renderScheme); } } switch (featurelayerName) { case "景点347": render_JingDian = render; break; case "ATM611": render_ATM = render; break; case "购物67": render_GouWu = render; break; case "活动927": render_HuoDong = render; break; case "WC968": render_WC = render; break; case "美食563": render_MeiShi = render; break; case "住宿513": render_ZhuSu = render; break; } } } catch (System.Exception ex) { MessageBox.Show(str + " 解析失败"); return; } } ISimpleTextRender textRender = new SimpleTextRender(); textRender.Expression = "$(Name)"; textRender.DynamicPlacement = true; textRender.MinimizeOverlap = true; ITextSymbol textSymbol = new TextSymbol(); TextAttribute textAttribute = new TextAttribute(); textAttribute.TextColor = System.Drawing.Color.Blue; textAttribute.Font = "微软雅黑"; textSymbol.TextAttribute = textAttribute; textSymbol.PivotAlignment = gviPivotAlignment.gviPivotAlignBottomCenter; textSymbol.VerticalOffset = 10; textRender.Symbol = textSymbol; // CreateFeautureLayer foreach (IFeatureClass fc in fcMap_POI.Keys) { List <string> geoNames = (List <string>)fcMap_POI[fc]; foreach (string geoName in geoNames) { if (!geoName.Equals("Geometry")) { continue; } switch (fc.Name) { case "景点347": this.axRenderControl1.ObjectManager.CreateFeatureLayer(fc, geoName, textRender, render_JingDian, rootId); break; case "ATM611": this.axRenderControl1.ObjectManager.CreateFeatureLayer(fc, geoName, textRender, render_ATM, rootId); break; case "购物67": this.axRenderControl1.ObjectManager.CreateFeatureLayer(fc, geoName, textRender, render_GouWu, rootId); break; case "活动927": this.axRenderControl1.ObjectManager.CreateFeatureLayer(fc, geoName, textRender, render_HuoDong, rootId); break; case "WC968": this.axRenderControl1.ObjectManager.CreateFeatureLayer(fc, geoName, textRender, render_WC, rootId); break; case "美食563": this.axRenderControl1.ObjectManager.CreateFeatureLayer(fc, geoName, textRender, render_MeiShi, rootId); break; case "住宿513": this.axRenderControl1.ObjectManager.CreateFeatureLayer(fc, geoName, textRender, render_ZhuSu, rootId); break; } } } #endregion { this.helpProvider1.SetShowHelp(this.axRenderControl1, true); this.helpProvider1.SetHelpString(this.axRenderControl1, ""); this.helpProvider1.HelpNamespace = "Network.html"; } }