private void DisplayOnDistrict(string DistrictName) { if (m_SkylineHook.SGWorld.Project.Name != "") { try { int LayerID = m_SkylineHook.SGWorld.ProjectTree.FindItem("分区"); if (LayerID >= 0) { int ModelID = m_SkylineHook.SGWorld.ProjectTree.FindItem(ConfigurationManager.AppSettings["LayerPath"]); if (ModelID >= 0) { //根据DistricName从分区shp表中读取相应Code,再将SGModel中相应Code的模型显示出来 ILayer61 DistrictLayer = m_SkylineHook.SGWorld.ProjectTree.GetLayer(LayerID); IFeatureGroup61 Polygons = DistrictLayer.FeatureGroups.Polygon; string Code = "all"; foreach (IFeature61 a in Polygons) { if (a.FeatureAttributes.GetFeatureAttribute("Name").Value == DistrictName) { Code = a.FeatureAttributes.GetFeatureAttribute("Code").Value; } } ILayer61 ModelLayer = m_SkylineHook.SGWorld.ProjectTree.GetLayer(ModelID); IFeatureGroup61 Models = ModelLayer.FeatureGroups.Point; //MessageBox.Show(Models.GetProperty("File Name").ToString()); foreach (IFeature61 m in Models) { if (Code == "all") { m.FeatureAttributes.GetFeatureAttribute("Display").Value = m.FeatureAttributes.GetFeatureAttribute("ModelPath").Value; } else { if (m.FeatureAttributes.GetFeatureAttribute("Code").Value == Code) { m.FeatureAttributes.GetFeatureAttribute("Display").Value = m.FeatureAttributes.GetFeatureAttribute("ModelPath").Value; } else { m.FeatureAttributes.GetFeatureAttribute("Display").Value = ""; } } } ModelLayer.Save(); ModelLayer.Refresh(); //由于Display字段变化,二次加载时可能无法全部显示 } } } catch { MessageBox.Show("对不起,分区显示过程出现了错误!这通常是由于配置不当引起的。"); } } }
/// <summary> /// 窗口数据的初始化 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void FrmAttributeMapQuery_Load(object sender, EventArgs e) { try { gridView1.OptionsView.ColumnAutoWidth = false; IFeatureWorkspace pFeatureWorkspace = Program.pWorkspace as IFeatureWorkspace; this.tFeatureClass = pFeatureWorkspace.OpenFeatureClass(ConfigurationManager.AppSettings["ModleTable"]); ILayer61 _pLayer61; int layerid = Program.sgworld.ProjectTree.FindItem(ConfigurationManager.AppSettings["LayerPath"]); _pLayer61 = Program.sgworld.ProjectTree.GetLayer(layerid); IFeatureGroups61 pfGroups = _pLayer61.FeatureGroups; this.pf = pfGroups.Point; this.m_OracleHelper = new ADODBHelper(ConnString, true); DataSet ds = new DataSet(); ds = this.m_OracleHelper.OpenDS("select t.* from FILE3DATTRIBUTE t"); //m_SqlHelper = new SqlHelper(); //ds = new DataSet(); //ds = m_SqlHelper.selectTableAll("builderObject"); this.gridControl1.DataSource = ds.Tables[0]; foreach (DevExpress.XtraGrid.Columns.GridColumn item in this.gridView1.Columns) { string Asql = "select t.fieldalias from ATTR3DFIELDMAPPING t where t.fieldname ='" + item.FieldName + "'"; try { item.Caption = this.m_OracleHelper.ExecSQLScalar(Asql).ToString(); } catch (Exception ex) { continue; } } this.gridView1.BestFitColumns(); // this.gridView1.FocusedRowHandle = 3; Program.TE.OnLButtonDown += new TerraExplorerX._ITerraExplorerEvents5_OnLButtonDownEventHandler(TE_OnLButtonDown); } catch (Exception ex) { MessageBox.Show("没有可查询图层!", "SUNZ", MessageBoxButtons.OK, MessageBoxIcon.Information); /// throw; } }
/// <summary> /// 加载shape文件添加模型 /// 模型数据要与shape在同一路径下 /// 2012-09-21 张航宇 /// 添加Z修正 -56 /// </summary> /// <param name="FileName"></param> /// public void LoadShapeAdd3model(ISGWorld61 sgworld, ITerraExplorer te, string FileName) { IInformationTree5 infoTree5 = te as IInformationTree5; if (string.IsNullOrEmpty(FileName)) { return; } if (File.Exists(FileName)) { bool PathType = true; string PathFileName = ""; string GroupName = "模型组群" + System.Guid.NewGuid().ToString().Substring(0, 6); infoTree5.CreateGroup(GroupName, 0); int GroupID = sgworld.ProjectTree.FindItem(GroupName); string ModelFilename = ""; string UNModelFilename = ""; string _XMLLayerInfo = "<PlugData>" + "<PlugType>shape</PlugType>" + "<LayerName>" + FileName + "</LayerName>" + "<Server></Server>" + "<user></user>" + "<password></password>" + "<TableName></TableName>" + "<AttributesToLoad>*</AttributesToLoad >" + "<Feature>1</Feature >" + "<Annotation>1</Annotation>" + "<SaveItems>0</SaveItems>" + "<GroupKey>LAT-LONG</GroupKey>" + "<SysKey>LAT-LONG</SysKey>" + "<DatumKey>WGS84</DatumKey>" + "<UnitKey>METERS</UnitKey>" + "<UseZValue>0</UseZValue>" + "<AltitudeUnit>Meters</AltitudeUnit>" + "<Reproject>1</Reproject>" + "<StreamedLayer>0</StreamedLayer></PlugData >"; ILayer5 iLyr = infoTree5.CreateLayer("3DModleGoto", _XMLLayerInfo, GroupID);//在根目录下装载shp数据 iLyr.Load(); IFeature61 sqfeature61 = null; int itemid = sgworld.ProjectTree.FindItem("" + GroupName + "\\3DModleGoto"); ILayer61 m_layer61 = sgworld.ProjectTree.GetLayer(itemid); m_layer61.Streaming = false; IFeatureGroups61 pFeatureGroups61 = m_layer61.FeatureGroups; IFeatureGroup61 pFeatureGroup61 = pFeatureGroups61.Point as IFeatureGroup61; if (pFeatureGroup61 == null) { MessageBox.Show("当前操作要求是正确的点图层"); return; } else { if (pFeatureGroup61.Count == 0) { MessageBox.Show("图层为空!"); return; } else { sqfeature61 = pFeatureGroup61[0] as IFeature61; IFeatureAttributes61 m_FeatureAttributes = sqfeature61.FeatureAttributes; int AttributesCount = m_FeatureAttributes.Count; string[] FiledArry = new string[AttributesCount]; for (int f = 0; f < AttributesCount; f++) { IFeatureAttribute61 m_FeatureAttribute = m_FeatureAttributes[f] as IFeatureAttribute61; FiledArry[f] = m_FeatureAttribute.Name; } Skyline.Core.UI.FrmAddModelShape pFrmAddModelShape = new Skyline.Core.UI.FrmAddModelShape(); pFrmAddModelShape.GetFiledName = FiledArry; pFrmAddModelShape.ShowDialog(); PathFileName = pFrmAddModelShape.Filed; PathType = pFrmAddModelShape.PathType; pFrmAddModelShape.Dispose(); int m_FeatureCount = pFeatureGroup61.Count; int ImportFeatureCount = pFeatureGroup61.Count; for (int i = 0; i < m_FeatureCount; i++) { sqfeature61 = pFeatureGroup61[i] as IFeature61; IFeatureAttributes61 _FeatureAttributes = sqfeature61.FeatureAttributes; TerraExplorerX.IGeometry _Geometry = sqfeature61.GeometryZ; TerraExplorerX.IPoint pPoint = _Geometry as TerraExplorerX.IPoint; //IPosition61 TPosition61 = sgworld.Window.PixelToWorld(pPoint.X, pPoint.Y, WorldPointType.WPT_ALL).Position; IPosition61 TPosition61 = sgworld.Creator.CreatePosition(pPoint.X, pPoint.Y, -56, AltitudeTypeCode.ATC_TERRAIN_RELATIVE, 0, 0); IFeatureAttribute61 _FeatureAttribute = _FeatureAttributes.GetFeatureAttribute(PathFileName); UNModelFilename = _FeatureAttribute.Value.ToString(); if (PathType) { ModelFilename = System.IO.Path.GetDirectoryName(FileName) + "\\" + UNModelFilename; } else { ModelFilename = UNModelFilename; } try { sgworld.Creator.CreateModel(TPosition61, ModelFilename, 1, ModelTypeCode.MT_NORMAL, GroupID, UNModelFilename); } catch { ImportFeatureCount--; continue; } } MessageBox.Show(ImportFeatureCount + "个模型加载成功," + (m_FeatureCount - ImportFeatureCount) + "个模型加载失败!"); /****20130227杨漾(添加文件有效性判断,分步判断图层有效性,增加加载统计情况提示)****/ } } } }