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; } #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, 600, angle); } hasfly = true; } } #endregion 加载FDB场景 #region 查询所有值 foreach (IFeatureClass fc in fcMap.Keys) { DataTable dt = CreateDataTable(fc); GetResultSet(fc, null, dt); switch (fc.Name) { case "Road": this.dataGridView0Road.DataSource = dt; break; case "Building": this.dataGridView1Building.DataSource = dt; break; case "Trees": this.dataGridView2Trees.DataSource = dt; break; case "Facility": this.dataGridView3Facility.DataSource = dt; break; case "Landscape": this.dataGridView4LandScape.DataSource = dt; break; } } #endregion { this.helpProvider1.SetShowHelp(this.axRenderControl1, true); this.helpProvider1.SetHelpString(this.axRenderControl1, ""); this.helpProvider1.HelpNamespace = "FeatureLocateAndGlow.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]); crs = 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); } // 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); // 添加节点到界面控件上 object[] registeredFields = GetRegisteredRenderIndexFields(fcInMap); myListNode item = new myListNode(string.Format("{0}_{1}_{2}", sourceName, fcInMap.Name, featureLayer.MaxVisibleDistance.ToString()), featureLayer, registeredFields); 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); IPoint pos = (new GeometryFactory()).CreatePoint(gviVertexAttribute.gviVertexAttributeZ); pos.SpatialCRS = crs; pos.Position = env.Center; this.axRenderControl1.Camera.LookAt2(pos, 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 (ds != null) { ds.Dispose(); ds = null; } if (dataset != null) { dataset.Dispose(); dataset = null; } //if (fc != null) //{ // fc.Dispose(); // fc = null; //} } }
private void LineQuery() { IFdeCursor cursor = null; IRowBuffer row = null; try { IGeometry geo = this._drawTool.GetGeo(); if (geo == null || geo.GeometryType != gviGeometryType.gviGeometryPolyline) { return; } IPolyline line = geo as IPolyline; IPolyline l = line.Clone2(gviVertexAttribute.gviVertexAttributeNone) as IPolyline; if (l.Length > 500) { XtraMessageBox.Show("横断面线超过500米,分析效率很低,请重新绘制", "提示"); return; } WaitForm.Start("正在进行横断面分析...", "请稍后"); DF3DApplication app = DF3DApplication.Application; if (app == null || app.Current3DMapControl == null) { return; } List <MajorClass> list = LogicDataStructureManage3D.Instance.GetAllMajorClass(); if (list == null) { return; } string road1 = ""; string road2 = ""; bool bAlert = false; double hmax = double.MinValue; double hmin = double.MaxValue; List <PPLine> pplines = new List <PPLine>(); foreach (MajorClass mc in list) { foreach (SubClass sc in mc.SubClasses) { if (!sc.Visible3D) { continue; } string[] arrFc3DId = mc.Fc3D.Split(';'); if (arrFc3DId == null) { continue; } foreach (string fc3DId in arrFc3DId) { DF3DFeatureClass dffc = DF3DFeatureClassManager.Instance.GetFeatureClassByID(fc3DId); if (dffc == null) { continue; } IFeatureClass fc = dffc.GetFeatureClass(); FacilityClass fac = dffc.GetFacilityClass(); if (fc == null || fac == null || fac.Name != "PipeLine") { continue; } IFieldInfoCollection fields = fc.GetFields(); int indexShape = fields.IndexOf("Shape"); if (indexShape == -1) { continue; } int indexFootPrint = fields.IndexOf("FootPrint"); if (indexFootPrint == -1) { continue; } DFDataConfig.Class.FieldInfo fiDiameter = fac.GetFieldInfoBySystemName("Diameter"); if (fiDiameter == null) { continue; } int indexDiameter = fields.IndexOf(fiDiameter.Name); if (indexDiameter == -1) { continue; } DFDataConfig.Class.FieldInfo fiRoad = fac.GetFieldInfoBySystemName("Road"); int indexRoad = -1; if (fiRoad != null) { indexRoad = fields.IndexOf(fiRoad.Name); } DFDataConfig.Class.FieldInfo fiHLB = fac.GetFieldInfoBySystemName("HLB"); int indexHLB = -1; if (fiHLB != null) { indexHLB = fields.IndexOf(fiHLB.Name); } int indexClassify = fields.IndexOf(mc.ClassifyField); ISpatialFilter pSpatialFilter = new SpatialFilter(); pSpatialFilter.Geometry = l; pSpatialFilter.GeometryField = "FootPrint"; pSpatialFilter.SpatialRel = gviSpatialRel.gviSpatialRelIntersects; pSpatialFilter.WhereClause = mc.ClassifyField + " = '" + sc.Name + "'"; cursor = fc.Search(pSpatialFilter, false); while ((row = cursor.NextRow()) != null) { if (indexRoad != -1 && !row.IsNull(indexRoad)) { if (road2 == "") { road1 = row.GetValue(indexRoad).ToString(); road2 = row.GetValue(indexRoad).ToString(); } else { road1 = row.GetValue(indexRoad).ToString(); if (road1 != road2) { if (!bAlert) { XtraMessageBox.Show("横断面线跨越多条道路,当前只绘制在【" + road2 + "】上的管线横断面图。", "提示"); bAlert = true; } continue; } } } double startSurfHeight = double.MaxValue; double endSurfHeight = double.MaxValue; if (!app.Current3DMapControl.Terrain.IsRegistered) { DFDataConfig.Class.FieldInfo fiStartSurfHeight = fac.GetFieldInfoBySystemName("StartSurfHeight"); if (fiStartSurfHeight == null) { continue; } int indexStartSurfHeight = fields.IndexOf(fiStartSurfHeight.Name); if (indexStartSurfHeight == -1) { continue; } DFDataConfig.Class.FieldInfo fiEndSurfHeight = fac.GetFieldInfoBySystemName("EndSurfHeight"); if (fiEndSurfHeight == null) { continue; } int indexEndSurfHeight = fields.IndexOf(fiEndSurfHeight.Name); if (indexEndSurfHeight == -1) { continue; } if (!row.IsNull(indexStartSurfHeight)) { startSurfHeight = double.Parse(row.GetValue(indexStartSurfHeight).ToString()); } if (!row.IsNull(indexEndSurfHeight)) { endSurfHeight = double.Parse(row.GetValue(indexEndSurfHeight).ToString()); } } if (!row.IsNull(indexShape) && !row.IsNull(indexFootPrint)) { object objFootPrint = row.GetValue(indexFootPrint); object objShape = row.GetValue(indexShape); if (objFootPrint is IPolyline && objShape is IPolyline) { IPolyline polylineFootPrint = objFootPrint as IPolyline; IPolyline polylineShape = objShape as IPolyline; IGeometry geoIntersect = (geo as ITopologicalOperator2D).Intersection2D(polylineFootPrint); if (geoIntersect == null) { continue; } PPLine ppline = new PPLine(); if (indexClassify == -1 || row.IsNull(indexClassify)) { ppline.facType = mc.Name; } else { ppline.facType = row.GetValue(indexClassify).ToString(); } if (!row.IsNull(indexDiameter)) { string diameter = row.GetValue(indexDiameter).ToString(); if (diameter.Trim() == "") { continue; } ppline.dia = diameter; int indexDia = diameter.IndexOf('*'); if (indexDia != -1) { ppline.isrect = true; int iDia1; bool bDia1 = int.TryParse(diameter.Substring(0, indexDia), out iDia1); if (!bDia1) { continue; } int iDia2; bool bDia2 = int.TryParse(diameter.Substring(indexDia + 1, diameter.Length - indexDia - 1), out iDia2); if (!bDia2) { continue; } ppline.gj.Add(iDia1); ppline.gj.Add(iDia2); } else { ppline.isrect = false; int iDia; bool bDia = int.TryParse(diameter, out iDia); if (!bDia) { continue; } ppline.gj.Add(iDia); ppline.gj.Add(iDia); } } int hlb = 0; if (indexHLB != -1 && !row.IsNull(indexHLB)) { string strhlb = row.GetValue(indexHLB).ToString(); if (strhlb.Contains("内")) { hlb = 1; } else if (strhlb.Contains("外")) { hlb = -1; } else { hlb = 0; } ppline.hlb = hlb; } #region 交点为一个 if (geoIntersect.GeometryType == gviGeometryType.gviGeometryPoint) //交点为1个 { IPoint ptIntersect = geoIntersect as IPoint; ppline.interPoint = new PPPoint(ptIntersect.X, ptIntersect.Y, ptIntersect.Z); ppline.clh = GetInterPointHeight(ptIntersect, polylineShape, polylineFootPrint); if (ppline.clh > hmax) { hmax = ppline.clh; } if (ppline.clh < hmin) { hmin = ppline.clh; } if (app.Current3DMapControl.Terrain.IsRegistered) { ppline.cgh = app.Current3DMapControl.Terrain.GetElevation(ptIntersect.X, ptIntersect.Y, Gvitech.CityMaker.RenderControl.gviGetElevationType.gviGetElevationFromDatabase); } else { ppline.cgh = startSurfHeight + (endSurfHeight - startSurfHeight) * Math.Sqrt((polylineFootPrint.StartPoint.X - ptIntersect.X) * (polylineFootPrint.StartPoint.X - ptIntersect.X) + (polylineFootPrint.StartPoint.Y - ptIntersect.Y) * (polylineFootPrint.StartPoint.Y - ptIntersect.Y)) / polylineFootPrint.Length; } if (ppline.cgh > hmax) { hmax = ppline.cgh; } if (ppline.cgh < hmin) { hmin = ppline.cgh; } // 辅助画图 ppline.startPt = new PPPoint(l.StartPoint.X, l.StartPoint.Y, l.StartPoint.Z); pplines.Add(ppline); } #endregion #region 交点为多个 else if (geoIntersect.GeometryType == gviGeometryType.gviGeometryMultiPoint) //交点为多个 { IMultiPoint multiPts = geoIntersect as IMultiPoint; for (int m = 0; m < multiPts.GeometryCount; m++) { IPoint ptIntersect = multiPts.GetPoint(m); ppline.interPoint = new PPPoint(ptIntersect.X, ptIntersect.Y, ptIntersect.Z); ppline.clh = GetInterPointHeight(ptIntersect, polylineShape, polylineFootPrint); if (ppline.clh > hmax) { hmax = ppline.clh; } if (ppline.clh < hmin) { hmin = ppline.clh; } if (app.Current3DMapControl.Terrain.IsRegistered) { ppline.cgh = app.Current3DMapControl.Terrain.GetElevation(ptIntersect.X, ptIntersect.Y, Gvitech.CityMaker.RenderControl.gviGetElevationType.gviGetElevationFromDatabase); } else { ppline.cgh = startSurfHeight + (endSurfHeight - startSurfHeight) * Math.Sqrt((polylineFootPrint.StartPoint.X - ptIntersect.X) * (polylineFootPrint.StartPoint.X - ptIntersect.X) + (polylineFootPrint.StartPoint.Y - ptIntersect.Y) * (polylineFootPrint.StartPoint.Y - ptIntersect.Y)) / polylineFootPrint.Length; } if (ppline.cgh > hmax) { hmax = ppline.cgh; } if (ppline.cgh < hmin) { hmin = ppline.cgh; } // 辅助画图 ppline.startPt = new PPPoint(l.StartPoint.X, l.StartPoint.Y, l.StartPoint.Z); pplines.Add(ppline); } } #endregion else { continue; } } } } } } } WaitForm.Stop(); if (pplines.Count < 2) { XtraMessageBox.Show("相交管线少于2个", "提示"); return; } pplines.Sort(new PPLineCompare()); double spacesum = 0.0; for (int i = 1; i < pplines.Count; i++) { PPLine line1 = pplines[i - 1]; PPLine line2 = pplines[i]; line2.space = Math.Sqrt((line1.interPoint.X - line2.interPoint.X) * (line1.interPoint.X - line2.interPoint.X) + (line1.interPoint.Y - line2.interPoint.Y) * (line1.interPoint.Y - line2.interPoint.Y)); spacesum += line2.space; } ; var str1 = (pplines[0].interPoint.X / 1000).ToString("0.00"); var str2 = (pplines[0].interPoint.Y / 1000).ToString("0.00"); string mapNum = str2 + "-" + str1; string mapName = SystemInfo.Instance.SystemFullName + "横断面图"; FrmSectionAnalysis dialog = new FrmSectionAnalysis("横断面分析结果", 0); dialog.SetInfo(mapName, mapNum, pplines, hmax, hmin, spacesum, road2); dialog.Show(); } catch (Exception ex) { WaitForm.Stop(); } finally { if (cursor != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor); cursor = null; } if (row != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(row); row = null; } } }
private void MainForm_Load(object sender, System.EventArgs e) { // 初始化RenderControl控件 IPropertySet ps = new PropertySet(); ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL); this.axRenderControl1.Initialize(true, ps); this.axRenderControl1.Camera.FlyTime = 1; ICRSFactory crsfac = new CRSFactory(); _currentCRS = (crsfac.CreateFromWKT(this.axRenderControl1.GetCurrentCrsWKT())) as ISpatialCRS; rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID; // 设置天空盒 if (System.IO.Directory.Exists(strMediaPath)) { string tmpSkyboxPath = strMediaPath + @"\skybox"; ISkyBox skybox = this.axRenderControl1.ObjectManager.GetSkyBox(0); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg"); } else { MessageBox.Show("请不要随意更改SDK目录名"); return; } this.axRenderControl1.Camera.FlyTime = 0; // 加载瓦片图层 string tilelayerString = (strMediaPath + @"\sdk.tdb"); I3DTileLayer layer = this.axRenderControl1.ObjectManager.Create3DTileLayer(tilelayerString, "", rootId); this.axRenderControl1.Camera.FlyToObject(layer.Guid, gviActionCode.gviActionFlyTo); // 添加节点到界面控件上 myListNode item = new myListNode("tilelayer", TreeNodeType.NT_TiltedLAYER, layer); item.Checked = true; listView1.Items.Add(item); #region 加载FDB try { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\SDKDEMO.FDB"); ci.Database = tmpFDBPath; IDataSourceFactory dsFactory = new DataSourceFactory(); IDataSource ds = dsFactory.OpenDataSource(ci); string[] setnames = (string[])ds.GetFeatureDatasetNames(); if (setnames.Length == 0) { return; } IFeatureDataSet dataset = ds.OpenFeatureDataset(setnames[0]); _datasetCRS = dataset.SpatialReference; //遍历FeatureClass string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable); if (fcnames.Length == 0) { return; } fcMap = new Hashtable(fcnames.Length); fcuidMap = new Hashtable(fcnames.Length); foreach (string name in fcnames) { IFeatureClass fc = dataset.OpenFeatureClass(name); // 找到空间列字段 List <string> geoNames = new List <string>(); IFieldInfoCollection fieldinfos = fc.GetFields(); for (int i = 0; i < fieldinfos.Count; i++) { IFieldInfo fieldinfo = fieldinfos.Get(i); if (null == fieldinfo) { continue; } IGeometryDef geometryDef = fieldinfo.GeometryDef; if (null == geometryDef) { continue; } if (geometryDef.GeometryColumnType == gviGeometryColumnType.gviGeometryColumnPolygon) { geoNames.Add(fieldinfo.Name); } } fcMap.Add(fc, geoNames); fcuidMap.Add(fc.Guid, fc); } } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); return; } #endregion //CreateFeautureLayer for 矢量贴地 foreach (IFeatureClass fc in fcMap.Keys) { List <string> geoNames = (List <string>)fcMap[fc]; if (geoNames.Count == 0) { continue; } #region 定义几何物体渲染风格 ICurveSymbol cs = new CurveSymbol(); cs.Color = System.Drawing.Color.Empty; //防止贴瓦片时出现绿色竖边 IValueMapGeometryRender geoRender = new ValueMapGeometryRender(); { IRangeRenderRule rangeRule = new RangeRenderRule(); rangeRule.LookUpField = "oid"; rangeRule.MaxValue = 1100; rangeRule.MinValue = 1000; rangeRule.IncludeMin = false; ISurfaceSymbol geoSymbol = new SurfaceSymbol(); geoSymbol.Color = System.Drawing.Color.Yellow; geoSymbol.BoundarySymbol = cs; IGeometryRenderScheme grs = new GeometryRenderScheme(); grs.AddRule(rangeRule); grs.Symbol = geoSymbol; geoRender.AddScheme(grs); } { IRangeRenderRule rangeRule = new RangeRenderRule(); rangeRule.LookUpField = "oid"; rangeRule.MaxValue = 1200; rangeRule.MinValue = 1100; rangeRule.IncludeMin = false; ISurfaceSymbol geoSymbol = new SurfaceSymbol(); geoSymbol.Color = System.Drawing.Color.Blue; geoSymbol.BoundarySymbol = cs; IGeometryRenderScheme grs = new GeometryRenderScheme(); grs.AddRule(rangeRule); grs.Symbol = geoSymbol; geoRender.AddScheme(grs); } { IRangeRenderRule rangeRule = new RangeRenderRule(); rangeRule.LookUpField = "oid"; rangeRule.MaxValue = 1300; rangeRule.MinValue = 1200; rangeRule.IncludeMin = false; ISurfaceSymbol geoSymbol = new SurfaceSymbol(); geoSymbol.Color = System.Drawing.Color.Green; geoSymbol.BoundarySymbol = cs; IGeometryRenderScheme grs = new GeometryRenderScheme(); grs.AddRule(rangeRule); grs.Symbol = geoSymbol; geoRender.AddScheme(grs); } { IRangeRenderRule rangeRule = new RangeRenderRule(); rangeRule.LookUpField = "oid"; rangeRule.MaxValue = 1400; rangeRule.MinValue = 1300; rangeRule.IncludeMin = false; ISurfaceSymbol geoSymbol = new SurfaceSymbol(); geoSymbol.Color = System.Drawing.Color.Goldenrod; geoSymbol.BoundarySymbol = cs; IGeometryRenderScheme grs = new GeometryRenderScheme(); grs.AddRule(rangeRule); grs.Symbol = geoSymbol; geoRender.AddScheme(grs); } { ISurfaceSymbol geoSymbol = new SurfaceSymbol(); geoSymbol.Color = System.Drawing.Color.Fuchsia; geoSymbol.BoundarySymbol = cs; IGeometryRenderScheme geoSchemeOther = new GeometryRenderScheme(); geoSchemeOther.Symbol = geoSymbol; geoRender.AddScheme(geoSchemeOther); } #endregion geoRender.HeightStyle = gviHeightStyle.gviHeightOnEverything; IFeatureLayer fcLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer(fc, geoNames[0], null, geoRender, rootId); if (fcLayer != null) { fcLayer.VisibleMask = gviViewportMask.gviViewNone; // 添加节点到界面控件上 myListNode item2 = new myListNode(fc.Name + "_" + geoNames[0], TreeNodeType.NT_FeatureLayer, fcLayer); item.Checked = false; listView1.Items.Add(item2); } else { MessageBox.Show("Create FeatureLayer Failed! " + this.axRenderControl1.GetLastError().ToString()); } } // 注册事件 this.axRenderControl1.RcMouseClickSelect += new Gvitech.CityMaker.Controls._IRenderControlEvents_RcMouseClickSelectEventHandler(axRenderControl1_RcMouseClickSelect); //设置highlight可用 this.axRenderControl1.HighlightHelper.VisibleMask = 1; { this.helpProvider1.SetShowHelp(this.axRenderControl1, true); this.helpProvider1.SetHelpString(this.axRenderControl1, ""); this.helpProvider1.HelpNamespace = "TileHole.html"; } }
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; } // 加载FDB场景 try { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\TemporalOldSummerPalace.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); bool hasSetTime = false; 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.Name.Equals("水系")) { ///* 准备数据时打开,执行完后注释掉 // 开启时态 //if (!fc.HasTemporal()) //{ // fc.LockType = gviLockType.gviLockExclusiveSchema; // DateTime defaultBirthDatetime = new DateTime(2010, 1, 1); // fc.EnableTemporal(defaultBirthDatetime, "StartDate", "EndDate"); // fc.LockType = gviLockType.gviLockSharedSchema; //} if (!hasSetTime) { ITemporalManager tm = fc.TemporalManager; DateTime[] times = tm.GetKeyDatetimes(); for (int tt = 0; tt < times.Length; tt++) { double keytime = times[tt].ToOADate(); timelist.Add(keytime); } if (timelist.Count > 3) { this.trackBarTime.Minimum = (int)((double)timelist[0]); this.trackBarTime.Maximum = (int)((double)timelist[timelist.Count - 1] - 1); } // 设置时间轴 this.trackBarTime.Value = this.trackBarTime.Minimum; // 创建OverlayLabel label = this.axRenderControl1.ObjectManager.CreateOverlayLabel(rootId); label.Text = "乾隆初期"; label.SetX(0, 0.5f, 0); label.SetY(0, 0, 0.5f); label.SetWidth(0, 1, 0); label.SetHeight(0, 0, 1); label.Alignment = gviPivotAlignment.gviPivotAlignTopLeft; TextAttribute att = new TextAttribute(); att.Font = "幼圆"; att.TextColor = System.Drawing.Color.Red; att.TextSize = 25; label.TextStyle = att; hasSetTime = true; } } } //end of fc } 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) { IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer( fc, geoName, null, null, rootId); if (!fc.Name.Equals("水系") && geoName.Equals("Geometry")) { featureLayer.EnableTemporal = true; layers.Add(featureLayer); //设置curLayer的时刻 if (featureLayer != null) { DateTime d = DateTime.FromOADate((double)this.trackBarTime.Value); featureLayer.Time = d; } } 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, -40, 0); this.axRenderControl1.Camera.LookAt(env.Center, 100, angle); } hasfly = true; } } { this.helpProvider1.SetShowHelp(this.axRenderControl1, true); this.helpProvider1.SetHelpString(this.axRenderControl1, ""); this.helpProvider1.HelpNamespace = "TemporalOldSummerPalace.html"; } }
private void sbtn_Split_Click(object sender, System.EventArgs e) { DF3DApplication app = DF3DApplication.Application; if (app == null || app.Current3DMapControl == null) { return; } if (System.Windows.Forms.DialogResult.No != XtraMessageBox.Show("模型拆分不支持撤销操作,是否继续?", "询问", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Exclamation)) { IFeatureClass featureClass = null; IFdeCursor fdeCursor = null; app.Current3DMapControl.PauseRendering(false); WaitDialogForm waitDialogForm = null; try { int count = SelectCollection.Instance().GetCount(true); if (count <= 0) { XtraMessageBox.Show("未选中要拆分的模型!"); } else { if (this._renderGeo == null || this._renderGeo.GetFdeGeometry() == null) { XtraMessageBox.Show("请先绘制或选择拆分多边形!"); } else { IMultiPolygon multiPolygon = null; if (this.radioGroup1.SelectedIndex == 1) { IGeometryFactory geometryFactory = new GeometryFactoryClass(); multiPolygon = (geometryFactory.CreateGeometry(gviGeometryType.gviGeometryMultiPolygon, gviVertexAttribute.gviVertexAttributeZ) as IMultiPolygon); multiPolygon.AddPolygon(this._renderGeo.GetFdeGeometry() as IPolygon); } else { if (this.radioGroup1.SelectedIndex == 0) { multiPolygon = (this._renderGeo.GetFdeGeometry() as IMultiPolygon); } } if (multiPolygon == null) { XtraMessageBox.Show("获取裁剪多边形失败!"); } else { waitDialogForm = new WaitDialogForm(string.Empty, "正在拆分模型,请稍后..."); HashMap featureClassInfoMap = SelectCollection.Instance().FeatureClassInfoMap; System.Collections.Hashtable hashtable = new System.Collections.Hashtable(); foreach (DF3DFeatureClass featureClassInfo in featureClassInfoMap.Keys) { if (featureClassInfo.GetFeatureLayer().GeometryType == gviGeometryColumnType.gviGeometryColumnModelPoint) { System.Collections.Generic.List <int> list = new System.Collections.Generic.List <int>(); System.Collections.Generic.List <int> list2 = new System.Collections.Generic.List <int>(); IRowBufferCollection rowBufferCollection = new RowBufferCollectionClass(); IRowBufferCollection rowBufferCollection2 = new RowBufferCollectionClass(); ResultSetInfo resultSetInfo = featureClassInfoMap[featureClassInfo] as ResultSetInfo; DataTable resultSetTable = resultSetInfo.ResultSetTable; if (resultSetTable.Rows.Count >= 1) { featureClass = featureClassInfo.GetFeatureClass(); IResourceManager resourceManager = featureClass.FeatureDataSet as IResourceManager; string fidFieldName = featureClass.FidFieldName; int num = featureClass.GetFields().IndexOf(fidFieldName); foreach (DataRow dataRow in resultSetTable.Rows) { int num2 = int.Parse(dataRow[fidFieldName].ToString()); IRowBuffer row = featureClass.GetRow(num2); int position = row.FieldIndex(featureClassInfo.GetFeatureLayer().GeometryFieldName); IModelPoint modelPoint = row.GetValue(position) as IModelPoint; if (modelPoint != null) { Gvitech.CityMaker.Resource.IModel model = resourceManager.GetModel(modelPoint.ModelName); IGeometryConvertor geometryConvertor = new GeometryConvertorClass(); Gvitech.CityMaker.Resource.IModel model2 = null; Gvitech.CityMaker.Resource.IModel model3 = null; IModelPoint modelPoint2 = null; IModelPoint modelPoint3 = null; bool flag = geometryConvertor.SplitModelPointByPolygon2D(multiPolygon, model, modelPoint, out model2, out modelPoint2, out model3, out modelPoint3); if (flag && model2 != null && !model2.IsEmpty && modelPoint2 != null && model3 != null && !model3.IsEmpty && modelPoint3 != null) { System.Guid guid = System.Guid.NewGuid(); string text = guid.ToString(); resourceManager.AddModel(text, model2, null); resourceManager.RebuildSimplifiedModel(text); guid = System.Guid.NewGuid(); string text2 = guid.ToString(); resourceManager.AddModel(text2, model3, null); resourceManager.RebuildSimplifiedModel(text2); modelPoint3.ModelName = text2; row.SetValue(position, modelPoint3); rowBufferCollection.Add(row); list.Add(num2); modelPoint2.ModelName = text; IRowBuffer rowBuffer = row.Clone(false); rowBuffer.SetNull(num); rowBuffer.SetValue(position, modelPoint2); fdeCursor = featureClass.Insert(); fdeCursor.InsertRow(rowBuffer); int lastInsertId = fdeCursor.LastInsertId; rowBuffer.SetValue(num, lastInsertId); rowBufferCollection2.Add(rowBuffer); list2.Add(lastInsertId); System.Runtime.InteropServices.Marshal.ReleaseComObject(fdeCursor); fdeCursor = null; } } } featureClass.UpdateRows(rowBufferCollection, false); app.Current3DMapControl.FeatureManager.EditFeatures(featureClass, rowBufferCollection); app.Current3DMapControl.FeatureManager.CreateFeatures(featureClass, rowBufferCollection2); hashtable[featureClassInfo] = list2; //System.Runtime.InteropServices.Marshal.ReleaseComObject(featureClass); featureClass = null; System.Runtime.InteropServices.Marshal.ReleaseComObject(resourceManager); resourceManager = null; } } } SelectCollection.Instance().UpdateSelection(hashtable); base.Close(); base.DialogResult = System.Windows.Forms.DialogResult.OK; } } } } catch (System.Runtime.InteropServices.COMException ex) { XtraMessageBox.Show(ex.Message); } catch (System.UnauthorizedAccessException var_35_4EC) { XtraMessageBox.Show("拒绝访问"); } catch (System.Exception ex2) { XtraMessageBox.Show(ex2.Message); } finally { if (waitDialogForm != null) { waitDialogForm.Close(); } if (fdeCursor != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(fdeCursor); fdeCursor = null; } //if (featureClass != null && System.Runtime.InteropServices.Marshal.IsComObject(featureClass)) //{ // System.Runtime.InteropServices.Marshal.ReleaseComObject(featureClass); // featureClass = null; //} app.Current3DMapControl.ResumeRendering(); } } }
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 + @"\community.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]); //此处把dataset作为全局对象,以便后面调用 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; layerList = new List <IFeatureLayer>(); foreach (IFeatureClass fc in fcMap.Keys) { List <string> geoNames = (List <string>)fcMap[fc]; foreach (string geoName in geoNames) { //****特别注意**** ISimpleGeometryRender geoRender = new SimpleGeometryRender(); geoRender.RenderGroupField = "Groupid"; // 逻辑组 //如果是IValueMapGeometryRender,默认被分到other组里,比如加上otherScheme,否则不显示 //IValueMapGeometryRender geoRender = new ValueMapGeometryRender(); //geoRender.RenderGroupField = "Groupid"; // 逻辑组 //IGeometryRenderScheme other = new GeometryRenderScheme(); //geoRender.AddScheme(other); //**************** IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer(fc, geoName, null, geoRender, rootId); layerList.Add(featureLayer); // 设置featureLayer可见 SetGroupVisiable(dataset, 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; } } // 加载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.treeView1.Nodes[0].Nodes) { if (node.Text.Equals("回收站")) { this.treeView1.Nodes.Remove(node); } } { this.helpProvider1.SetShowHelp(this.axRenderControl1, true); this.helpProvider1.SetHelpString(this.axRenderControl1, ""); this.helpProvider1.HelpNamespace = "LogicGroupTree.html"; } }
private static List <Project> SelectProjects(IDataSource ds, string WhereClause) { List <Project> list = new List <Project>(); IFdeCursor cursor = null; IRowBuffer row = null; try { if (ds == null) { return(list); } IFeatureDataSet fds = ds.OpenFeatureDataset("UP_PlanLibDs_Indication"); if (fds == null) { return(list); } IFeatureClass class2 = fds.OpenFeatureClass("UP_Project"); if (class2 != null) { IQueryFilter filter = new QueryFilter { WhereClause = WhereClause }; IFieldInfoCollection fiCol = class2.GetFields(); cursor = class2.Search(filter, true); while ((row = cursor.NextRow()) != null) { Project item = new Project { ProjectID = (row.IsNull(fiCol.IndexOf("oid"))) ? -1 : Convert.ToInt32(row.GetValue(fiCol.IndexOf("oid"))), ProjectName = (row.IsNull(fiCol.IndexOf("projectName"))) ? "" : row.GetValue(fiCol.IndexOf("projectName")).ToString(), ProjectCode = (row.IsNull(fiCol.IndexOf("projectCode"))) ? "" : row.GetValue(fiCol.IndexOf("projectCode")).ToString(), ProjectType = (row.IsNull(fiCol.IndexOf("projectType"))) ? ProjectType.None : (ProjectType)row.GetValue(fiCol.IndexOf("projectType")), ChangeState = (row.IsNull(fiCol.IndexOf("changeState"))) ? ProjectChangeState.None : (ProjectChangeState)Convert.ToInt32(row.GetValue(fiCol.IndexOf("changeState"))), ProjectTime = (row.IsNull(fiCol.IndexOf("projectTime"))) ? DateTime.MinValue : (DateTime)row.GetValue(fiCol.IndexOf("projectTime")), ProjectOwner = (row.IsNull(fiCol.IndexOf("projectOwner"))) ? "" : row.GetValue(fiCol.IndexOf("projectOwner")).ToString(), Description = (row.IsNull(fiCol.IndexOf("description"))) ? "" : row.GetValue(fiCol.IndexOf("description")).ToString(), ProjectBound = (row.IsNull(fiCol.IndexOf("projectBound"))) ? "" : row.GetValue(fiCol.IndexOf("projectBound")).ToString(), ProjectLandUse = (row.IsNull(fiCol.IndexOf("projectLandUse"))) ? null : (row.GetValue(fiCol.IndexOf("projectLandUse")) as IGeometry), ProjectElevation = (row.IsNull(fiCol.IndexOf("projectElevation"))) ? double.NaN : Convert.ToDouble(row.GetValue(fiCol.IndexOf("projectElevation"))), ProjectRemark1 = (row.IsNull(fiCol.IndexOf("projectRemark1"))) ? "" : row.GetValue(fiCol.IndexOf("projectRemark1")).ToString(), ProjectLocation = (row.IsNull(fiCol.IndexOf("projectRemark2"))) ? "" : row.GetValue(fiCol.IndexOf("projectRemark2")).ToString(), ProjectQuo = (row.IsNull(fiCol.IndexOf("projectQuo"))) ? null : (row.GetValue(fiCol.IndexOf("projectQuo")) as IBinaryBuffer) }; list.Add(item); } } return(list); } catch (Exception exception) { } finally { if (cursor != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor); cursor = null; } if (row != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(row); row = null; } } return(list); }
private void btnAnalyse_Click(object sender, EventArgs e) { try { ClearRes(); WaitForm.Start("正在分析...", "请稍后"); if (this._rLine == null) { return; } List <DF3DFeatureClass> list = DF3DFeatureClassManager.Instance.GetAllFeatureClass(); if (list == null || list.Count == 0) { return; } IPolyline line = this._rLine.GetFdeGeometry() as IPolyline; ILine l = this._geoFactory.CreateGeometry(gviGeometryType.gviGeometryLine, gviVertexAttribute.gviVertexAttributeZ) as ILine; l.StartPoint = line.StartPoint; l.EndPoint = line.EndPoint; ISpatialFilter filter = new SpatialFilter(); filter.SpatialRel = gviSpatialRel.gviSpatialRelEnvelope; filter.GeometryField = "Geometry"; List <InterPt> listInterPts = new List <InterPt>(); foreach (DF3DFeatureClass dffc in list) { IFeatureClass fc = dffc.GetFeatureClass(); if (fc == null) { continue; } IFeatureLayer fl = dffc.GetFeatureLayer(); if (fl != null) { if (fl.VisibleMask == gviViewportMask.gviViewNone) { continue; } } int indexGeo = fc.GetFields().IndexOf("Geometry"); if (indexGeo == -1) { continue; } filter.Geometry = l; IFdeCursor cursor = null; IRowBuffer row = null; try { cursor = fc.Search(filter, false); while ((row = cursor.NextRow()) != null) { if (!row.IsNull(indexGeo)) { IGeometry geo = row.GetValue(indexGeo) as IGeometry; if (geo.GeometryType == gviGeometryType.gviGeometryModelPoint) { IModelPoint modelPoint = geo as IModelPoint; IModel model = (fc.FeatureDataSet as IResourceManager).GetModel(modelPoint.ModelName); IGeometryConvertor gc = new GeometryConvertor(); IMultiTriMesh triMesh = gc.ModelPointToTriMesh(model, modelPoint, false); if (triMesh != null) { IVector3 v3 = triMesh.LineSegmentIntersect(l); if (v3 != null) { IPoint pttemp = this._geoFactory.CreatePoint(gviVertexAttribute.gviVertexAttributeZ); pttemp.X = v3.X; pttemp.Y = v3.Y; pttemp.Z = v3.Z; double dis = (pttemp.X - line.StartPoint.X) * (pttemp.X - line.StartPoint.X) + (pttemp.Y - line.StartPoint.Y) * (pttemp.Y - line.StartPoint.Y) + (pttemp.Z - line.StartPoint.Z) * (pttemp.Z - line.StartPoint.Z); InterPt ip = new InterPt(); ip.pt = pttemp; ip.dis = dis; listInterPts.Add(ip); } } } } } } catch (Exception ex) { } finally { if (row != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(row); row = null; } if (cursor != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor); cursor = null; } } } if (listInterPts.Count > 0) { this._rLine.VisibleMask = gviViewportMask.gviViewNone; listInterPts.Sort(new CmpInterPt()); IPoint pt = listInterPts[0].pt; IPolyline lineStart = this._geoFactory.CreateGeometry(gviGeometryType.gviGeometryPolyline, gviVertexAttribute.gviVertexAttributeZ) as IPolyline; lineStart.AppendPoint(line.StartPoint); lineStart.AppendPoint(pt); ICurveSymbol csS = new CurveSymbolClass(); csS.Color = 0xff0000ff; csS.Width = -2; IRenderPolyline rLineStart = this._3DControl.ObjectManager.CreateRenderPolyline(lineStart, csS, this._3DControl.ProjectTree.RootID); this._listRes.Add(rLineStart.Guid); IPolyline lineEnd = this._geoFactory.CreateGeometry(gviGeometryType.gviGeometryPolyline, gviVertexAttribute.gviVertexAttributeZ) as IPolyline; lineEnd.AppendPoint(line.EndPoint); lineEnd.AppendPoint(pt); ICurveSymbol csE = new CurveSymbolClass(); csE.Color = 0xffff0000; csE.Width = -2; IRenderPolyline rLineEnd = this._3DControl.ObjectManager.CreateRenderPolyline(lineEnd, csE, this._3DControl.ProjectTree.RootID); this._listRes.Add(rLineEnd.Guid); } else { this._rLine.VisibleMask = gviViewportMask.gviViewNone; ICurveSymbol csS = new CurveSymbolClass(); csS.Color = 0xff0000ff; csS.Width = -2; IRenderPolyline rLine = this._3DControl.ObjectManager.CreateRenderPolyline(line, csS, this._3DControl.ProjectTree.RootID); this._listRes.Add(rLine.Guid); } } catch (Exception ex) { } finally { WaitForm.Stop(); } }
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"; } }
private void btnAnalyse_Click(object sender, EventArgs e) { try { WaitForm.Start("正在分析...", "请稍后"); this._3DControl.VisualAnalysis.StopAnalyse(); IGeometry geoRegion = this._3DControl.HighlightHelper.GetRegion(); if (geoRegion == null) { return; } ISpatialFilter filter = new SpatialFilterClass(); filter.Geometry = geoRegion; filter.SpatialRel = gviSpatialRel.gviSpatialRelIntersects; filter.GeometryField = "Geometry"; List <DF3DFeatureClass> list = DF3DFeatureClassManager.Instance.GetAllFeatureClass(); if (list == null || list.Count == 0) { return; } this._3DControl.VisualAnalysis.ClearOccluders(); foreach (DF3DFeatureClass dffc in list) { IFeatureClass fc = dffc.GetFeatureClass(); if (fc == null) { continue; } IFeatureLayer fl = dffc.GetFeatureLayer(); if (fl != null) { if (fl.VisibleMask == gviViewportMask.gviViewNone) { continue; } } int indexGeo = fc.GetFields().IndexOf("Geometry"); if (indexGeo == -1) { continue; } IFdeCursor cursor = null; IRowBuffer row = null; try { cursor = fc.Search(filter, false); while ((row = cursor.NextRow()) != null) { if (!row.IsNull(indexGeo)) { IGeometry geo = row.GetValue(indexGeo) as IGeometry; this._3DControl.VisualAnalysis.AddOccluder(fl, geo); } } } catch (Exception ex) { } finally { if (row != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(row); row = null; } if (cursor != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor); cursor = null; } } } IPoint ptStart = this._geoFactory.CreatePoint(gviVertexAttribute.gviVertexAttributeZ); ptStart.X = (double)this.seObserX.Value; ptStart.Y = (double)this.seObserY.Value; ptStart.Z = (double)this.seObserZ.Value + (double)this.seObserZOff.Value; IPoint ptEnd = this._geoFactory.CreatePoint(gviVertexAttribute.gviVertexAttributeZ); ptEnd.X = (double)this.seObjX.Value; ptEnd.Y = (double)this.seObjY.Value; ptEnd.Z = (double)this.seObjZ.Value + (double)this.seObjZ.Value; double HorizontalAngle = (double)this.seAngle.Value; this._3DControl.VisualAnalysis.StartViewshedAnalyse(ptStart, ptEnd, HorizontalAngle); this._3DControl.HighlightHelper.VisibleMask = 0; } catch (Exception ex) { } finally { WaitForm.Stop(); } }
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; 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; } // 加载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; } 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); IPoint p = (new GeometryFactory()).CreatePoint(gviVertexAttribute.gviVertexAttributeZ); p.SpatialCRS = fc.FeatureDataSet.SpatialReference; p.Position = env.Center; this.axRenderControl1.Camera.LookAt2(p, 1000, angle); } hasfly = true; } } crs = crsFactory.CreateFromWKT(this.axRenderControl1.GetCurrentCrsWKT()); if (helper == null) { helper = this.axRenderControl1.HighlightHelper; helper.VisibleMask = 1; } // 注册事件 this.axRenderControl1.RcObjectEditing += new _IRenderControlEvents_RcObjectEditingEventHandler(axRenderControl1_RcObjectEditing); this.axRenderControl1.RcObjectEditFinish += new _IRenderControlEvents_RcObjectEditFinishEventHandler(axRenderControl1_RcObjectEditFinish); { this.helpProvider1.SetShowHelp(this.axRenderControl1, true); this.helpProvider1.SetHelpString(this.axRenderControl1, ""); this.helpProvider1.HelpNamespace = "FeaturelayerHole.html"; } }
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.gviGeometryPolyline) { return; } IPolyline line = geo as IPolyline; IPolyline geoOut = this._geoFact.CreateGeometry(gviGeometryType.gviGeometryPolyline, fiGeo.GeometryDef.VertexAttribute) as IPolyline; for (int i = 0; i < line.PointCount; i++) { IPoint ptGet = line.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.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) { } }
private void AddRecord(IGeometry geo) { try { if (geo.GeometryType != gviGeometryType.gviGeometryModelPoint) { return; } this.beforeRowBufferMap.Clear(); SelectCollection.Instance().Clear(); DF3DFeatureClass featureClassInfo = CommonUtils.Instance().CurEditLayer; if (featureClassInfo == null) { return; } IFeatureClass fc = featureClassInfo.GetFeatureClass(); if (fc == null) { return; } IFeatureDataSet fds = fc.FeatureDataSet; if (fds == 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; } IModelPoint pt = geo as IModelPoint; string mname = Path.GetFileNameWithoutExtension(pt.ModelName); IEnvelope envelope = ImportOsg(fc, pt.ModelName); if (envelope == null) { return; } IModelPoint geoOut = pt.Clone2(fiGeo.GeometryDef.VertexAttribute) as IModelPoint; if (fiGeo.GeometryDef.HasZ) { geoOut.SetCoords(pt.X, pt.Y, pt.Z, 0, 0); } else { geoOut.SetCoords(pt.X, pt.Y, 0, 0, 0); } geoOut.ModelName = mname; geoOut.ModelEnvelope = new EnvelopeClass { MinX = envelope.MinX, MaxX = envelope.MaxX, MinY = envelope.MinY, MaxY = envelope.MaxY, MinZ = envelope.MinZ, MaxZ = envelope.MaxZ }; 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(); Clear(); (this._drawTool as Draw3DModel).Set3DModelFilePath(this.beFilePath.Text); } catch (Exception ex) { } }
private void toolStripMenuItemFieldInfo_Click(object sender, EventArgs e) { string fieldinfo_name = selectNode.Text; string fc_name = selectNode.Parent.Text; string set_name = selectNode.Parent.Parent.Text; myTreeNode node = (myTreeNode)selectNode.Parent.Parent.Parent; IConnectionInfo ci = node.con; IDataSource ds = null; IFeatureDataSet dataset = null; IFeatureClass fc = null; IFieldInfoCollection fieldinfos = null; try { ds = dsFactory.OpenDataSource(ci); dataset = ds.OpenFeatureDataset(set_name); fc = dataset.OpenFeatureClass(fc_name); fieldinfos = fc.GetFields(); for (int i = 0; i < fieldinfos.Count; i++) { IFieldInfo fieldinfo = fieldinfos.Get(i); if (null == fieldinfo) { continue; } if (fieldinfo_name == fieldinfo.Name) { FieldInfoForm form = new FieldInfoForm(fieldinfo); form.Show(); } } } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); } finally { if (ds != null) { //Marshal.ReleaseComObject(ds); ds = null; } if (dataset != null) { //Marshal.ReleaseComObject(dataset); dataset = null; } if (fc != null) { //Marshal.ReleaseComObject(fc); fc = null; } if (fieldinfos != null) { //Marshal.ReleaseComObject(fieldinfos); fieldinfos = null; } } }
public void CompareFeatureDataSet(IFeatureDataSet target, IFeatureDataSet origin, out System.Collections.Hashtable fcmap) { fcmap = new System.Collections.Hashtable(); IFeatureClass featureClass = null; IFeatureClass featureClass2 = null; try { string[] namesByType = target.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable); string[] namesByType2 = origin.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable); string[] array = namesByType2; for (int i = 0; i < array.Length; i++) { string text = array[i]; featureClass = origin.OpenFeatureClass(text); if (namesByType != null) { string[] array2 = namesByType; for (int j = 0; j < array2.Length; j++) { string text2 = array2[j]; if (text.Equals(text2)) { featureClass2 = target.OpenFeatureClass(text2); if (this.CompareFeatureClass(featureClass.GetFields(), featureClass2.GetFields())) { fcmap.Add(text, text2); } } } } } } catch (System.Runtime.InteropServices.COMException) { } catch (System.Exception) { } finally { if (featureClass != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(featureClass); featureClass = null; } if (featureClass2 != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(featureClass2); featureClass2 = null; } } }
private void toolStripMenuItemQuery_Click(object sender, EventArgs e) { string fc_name = selectNode.Text; string set_name = selectNode.Parent.Text; myTreeNode node = (myTreeNode)selectNode.Parent.Parent; IConnectionInfo ci = node.con; IDataSource ds = null; IFeatureDataSet dataset = null; IFeatureClass fc = null; try { ds = dsFactory.OpenDataSource(ci); dataset = ds.OpenFeatureDataset(set_name); fc = dataset.OpenFeatureClass(fc_name); QueryFilterDlg pQueryFilterDlg = new QueryFilterDlg(); for (int index = 0; index < fc.GetFields().Count; index++) { pQueryFilterDlg.FieldList_listBox.Items.Add(fc.GetFields().Get(index).Name); } if (DialogResult.OK == pQueryFilterDlg.ShowDialog()) { IQueryFilter filter = new QueryFilter(); filter.WhereClause = pQueryFilterDlg.QueryFilter_txt.Text; int nCount = fc.GetCount(filter); if (nCount == 0) { return; } // 初始化表格 DataTable dt = CreateDataTable(fc); // 查找数据 GetResultSet(fc, filter, dt); // 显示表格 new AttributeFrm(dt, fc.Name, filter.WhereClause).Show(); } } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); } finally { 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 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; } // 加载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); //设置资源目录树DataSource节点 myTreeNode catalogDsNode = new myTreeNode(System.IO.Path.GetFileNameWithoutExtension(tmpFDBPath), NodeObjectType.DataSource, ds); this.tv_CatalogTree.Nodes.Add(catalogDsNode); string[] setnames = (string[])ds.GetFeatureDatasetNames(); if (setnames.Length == 0) { return; } IFeatureDataSet dataset = ds.OpenFeatureDataset(setnames[0]); //设置资源目录树DataSet节点 myTreeNode catalogFdsNode = new myTreeNode(setnames[0], NodeObjectType.DataSet, dataset); catalogDsNode.Nodes.Add(catalogFdsNode); //遍历FeatureClass string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable); if (fcnames.Length == 0) { return; } fcMap = new Hashtable(fcnames.Length); fcuidMap = new Hashtable(fcnames.Length); foreach (string name in fcnames) { IFeatureClass fc = dataset.OpenFeatureClass(name); // 找到空间列字段 List <string> geoNames = new List <string>(); IFieldInfoCollection fieldinfos = fc.GetFields(); for (int i = 0; i < fieldinfos.Count; i++) { IFieldInfo fieldinfo = fieldinfos.Get(i); if (null == fieldinfo) { continue; } IGeometryDef geometryDef = fieldinfo.GeometryDef; if (null == geometryDef) { continue; } geoNames.Add(fieldinfo.Name); } fcMap.Add(fc, geoNames); fcuidMap.Add(fc.Guid, fc); //设置资源目录FeatureClass节点 myTreeNode catalogFcNode = new myTreeNode(name, NodeObjectType.FeatureClass, fc); catalogFdsNode.Nodes.Add(catalogFcNode); this.tv_CatalogTree.ExpandAll(); } } 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); 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; } } this.axRenderControl1.MouseSelectObjectMask = gviMouseSelectObjectMask.gviSelectAll; this.axRenderControl1.MouseSelectMode = gviMouseSelectMode.gviMouseSelectClick; this.axRenderControl1.RcMouseClickSelect += new _IRenderControlEvents_RcMouseClickSelectEventHandler(axRenderControl1_RcMouseClickSelect); { this.helpProvider1.SetShowHelp(this.axRenderControl1, true); this.helpProvider1.SetHelpString(this.axRenderControl1, ""); this.helpProvider1.HelpNamespace = "DataIndex.html"; } }
// 公共方法 private void bindDataToCatalogTree(IConnectionInfo ci) { try { if (dsFactory == null) { dsFactory = new DataSourceFactory(); } IDataSource ds = dsFactory.OpenDataSource(ci); myTreeNode sourceNode = null; if (ci.ConnectionType == gviConnectionType.gviConnectionMySql5x) { sourceNode = new myTreeNode(ci.Database + "@" + ci.Server, ci); } else { sourceNode = new myTreeNode(ci.Database, ci); } this.treeView1.Nodes.Add(sourceNode); // 获取dataset string[] setnames = (string[])ds.GetFeatureDatasetNames(); if (setnames.Length == 0) { return; } foreach (string setname in setnames) { IFeatureDataSet dataset = ds.OpenFeatureDataset(setname); TreeNode setNode = new TreeNode(setname, 1, 1); sourceNode.Nodes.Add(setNode); // 获取featureclass string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable); if (fcnames == null || fcnames.Length == 0) { continue; } foreach (string fcname in fcnames) { IFeatureClass fc = dataset.OpenFeatureClass(fcname); TreeNode fcNode = new TreeNode(fcname, 2, 2); fcNode.ContextMenuStrip = this.contextMenuStrip2; setNode.Nodes.Add(fcNode); // 获取属性字段 IFieldInfoCollection fieldinfos = fc.GetFields(); for (int i = 0; i < fieldinfos.Count; i++) { IFieldInfo fieldinfo = fieldinfos.Get(i); if (null == fieldinfo) { continue; } TreeNode fieldinfoNode = new TreeNode(fieldinfo.Name); fieldinfoNode.ContextMenuStrip = this.contextMenuStrip1; // 绑定右键菜单 fcNode.Nodes.Add(fieldinfoNode); } } } } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); return; } }
private IMultiPolygon GetMultiPolygonFromFile(string sFilePath) { IDataSource dataSource = null; IFeatureDataSet featureDataSet = null; IFeatureClass featureClass = null; IFdeCursor fdeCursor = null; IMultiPolygon result; try { IConnectionInfo connectionInfo = new ConnectionInfoClass(); connectionInfo.ConnectionType = gviConnectionType.gviConnectionShapeFile; connectionInfo.Database = sFilePath; dataSource = ((IDataSourceFactory) new DataSourceFactoryClass()).OpenDataSource(connectionInfo); string[] featureDatasetNames = dataSource.GetFeatureDatasetNames(); if (featureDatasetNames != null && featureDatasetNames.Length > 0) { featureDataSet = dataSource.OpenFeatureDataset(featureDatasetNames[0]); string[] namesByType = featureDataSet.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable); if (namesByType != null && namesByType.Length > 0) { featureClass = featureDataSet.OpenFeatureClass(namesByType[0]); IFieldInfoCollection fields = featureClass.GetFields(); int num = -1; gviGeometryColumnType gviGeometryColumnType = gviGeometryColumnType.gviGeometryColumnUnknown; gviVertexAttribute vertexAttribute = gviVertexAttribute.gviVertexAttributeNone; for (int i = 0; i < fields.Count; i++) { IFieldInfo fieldInfo = fields.Get(i); if (fieldInfo.FieldType == gviFieldType.gviFieldGeometry && fieldInfo.GeometryDef != null) { num = i; gviGeometryColumnType = fieldInfo.GeometryDef.GeometryColumnType; vertexAttribute = fieldInfo.GeometryDef.VertexAttribute; break; } } if (num == -1 || gviGeometryColumnType != gviGeometryColumnType.gviGeometryColumnPolygon) { XtraMessageBox.Show("应选择面状矢量数据!"); result = null; } else { IGeometryFactory geometryFactory = new GeometryFactoryClass(); IMultiPolygon multiPolygon = geometryFactory.CreateGeometry(gviGeometryType.gviGeometryMultiPolygon, vertexAttribute) as IMultiPolygon; multiPolygon.SpatialCRS = featureDataSet.SpatialReference; fdeCursor = featureClass.Search(null, true); IRowBuffer rowBuffer; while ((rowBuffer = fdeCursor.NextRow()) != null) { object value = rowBuffer.GetValue(num); if (value != null && value is IGeometry) { IGeometry geometry = value as IGeometry; if (geometry.GeometryType == gviGeometryType.gviGeometryPolygon) { multiPolygon.AddPolygon(geometry as IPolygon); } else { if (geometry.GeometryType == gviGeometryType.gviGeometryMultiPolygon) { IMultiPolygon multiPolygon2 = geometry as IMultiPolygon; for (int j = 0; j < multiPolygon2.GeometryCount; j++) { IPolygon polygon = multiPolygon2.GetPolygon(j); if (polygon != null) { multiPolygon.AddPolygon(polygon); } } } } } } if (multiPolygon.GeometryCount < 1) { XtraMessageBox.Show("无可用范围数据!"); result = null; } else { result = multiPolygon; } } } else { XtraMessageBox.Show("打开shp文件失败!"); result = null; } } else { XtraMessageBox.Show("名称为空"); result = null; } } catch (System.Runtime.InteropServices.COMException ex) { XtraMessageBox.Show(ex.Message); result = null; } finally { if (dataSource != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(dataSource); dataSource = null; } if (featureDataSet != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(featureDataSet); featureDataSet = null; } if (featureClass != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(featureClass); featureClass = null; } if (fdeCursor != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(fdeCursor); fdeCursor = null; } } return(result); }
private void init() { // 设置RenderControl控件为球 string tmpTedPath = (strMediaPath + @"\terrain\SingaporeGlobeTerrain.ted"); wkt = this.axRenderControl1.GetTerrainCrsWKT(tmpTedPath, ""); IPropertySet ps = new PropertySet(); ps.SetProperty("RenderSystem", "OpenGL"); this.axRenderControl1.Initialize2(wkt, ps); this.axRenderControl1.Camera.FlyTime = 1; rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID; // 注册地形 this.axRenderControl1.Terrain.RegisterTerrain(tmpTedPath, ""); this.axRenderControl1.Terrain.FlyTo(gviTerrainActionCode.gviFlyToTerrain); this.axRenderControl1.RcFrame += new Gvitech.CityMaker.Controls._IRenderControlEvents_RcFrameEventHandler(axRenderControl1_RcFrame); this.OnFrame = new _IRenderControlEvents_RcFrameEventHandler(OnFrameUpdateUI); #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; // 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, 500, angle); //} //hasfly = true; } } #endregion }
public void OnInitialize() { // 初始化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; } // 加载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; } } }
// 公共方法 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; } } }
// 初始化表结构 public DataTable CreateDataTable(IFeatureClass fc) { DataTable dt = new DataTable(); if (fc != null) { IFieldInfoCollection fInfoColl = fc.GetFields(); DataColumn dc = null; for (int i = 0; i < fInfoColl.Count; ++i) { IFieldInfo fInfo = fInfoColl.Get(i); if (fInfo.FieldType == gviFieldType.gviFieldGeometry || fInfo.FieldType == gviFieldType.gviFieldBlob) { continue; } dc = new DataColumn(fInfo.Name); switch (fInfo.FieldType) { case gviFieldType.gviFieldInt16: { dc.DataType = typeof(Int16); } break; case gviFieldType.gviFieldInt32: { dc.DataType = typeof(Int32); } break; case gviFieldType.gviFieldFID: { dc.DataType = typeof(Int32); dc.ReadOnly = true; } break; case gviFieldType.gviFieldInt64: dc.DataType = typeof(Int64); break; case gviFieldType.gviFieldString: case gviFieldType.gviFieldUUID: dc.DataType = typeof(String); break; case gviFieldType.gviFieldFloat: { dc.DataType = typeof(float); } break; case gviFieldType.gviFieldDouble: dc.DataType = typeof(Double); break; case gviFieldType.gviFieldDate: dc.DataType = typeof(DateTime); break; case gviFieldType.gviFieldGeometry: dc.DataType = typeof(object); break; default: dc.DataType = typeof(string); break; } dt.Columns.Add(dc); } dt.DefaultView.Sort = "oid asc"; } return(dt); }
private DataTable RegionAnalysis() { IGeometry geo = this._drawTool.GetGeo(); if (geo == null) { return(null); } ISpatialFilter filter = new SpatialFilter(); filter.Geometry = geo; filter.SpatialRel = gviSpatialRel.gviSpatialRelEnvelope; filter.GeometryField = "Geometry"; DataTable dtResult = new DataTable(); dtResult.Columns.AddRange(new DataColumn[] { new DataColumn("PIPELINETYPE"), new DataColumn("PVALUE"), new DataColumn("LENGTH", typeof(double)), new DataColumn("TOTALLENGTH", typeof(double)) }); foreach (MajorClass mc in LogicDataStructureManage3D.Instance.GetAllMajorClass()) { string[] arrFc3DId = mc.Fc3D.Split(';'); if (arrFc3DId == null) { continue; } double majorclasslength = 0.0; int indexStart = dtResult.Rows.Count; foreach (SubClass sc in mc.SubClasses) { if (!sc.Visible3D) { continue; } double subclasslength = 0.0; bool bHave = false; foreach (string fc3DId in arrFc3DId) { DF3DFeatureClass dffc = DF3DFeatureClassManager.Instance.GetFeatureClassByID(fc3DId); if (dffc == null) { continue; } FacilityClass facc = dffc.GetFacilityClass(); IFeatureClass fc = dffc.GetFeatureClass(); if (fc == null || facc == null || facc.Name != "PipeLine") { continue; } DFDataConfig.Class.FieldInfo fiPipeLength = facc.GetFieldInfoBySystemName("PipeLength"); if (fiPipeLength == null) { continue; } int indexPipeLength = fc.GetFields().IndexOf(fiPipeLength.Name); int geometryIndex = fc.GetFields().IndexOf("Geometry"); if (indexPipeLength == -1 || geometryIndex == -1) { continue; } filter.WhereClause = "GroupId = " + sc.GroupId; filter.SubFields = fiPipeLength.Name + ",Geometry"; int count = fc.GetCount(filter); if (count == 0) { continue; } int loop = (int)Math.Ceiling(count / 800.0); for (int k = 1; k <= loop; k++) { if (k == 1) { filter.ResultBeginIndex = 0; } else { filter.ResultBeginIndex = (k - 1) * 800; } filter.ResultLimit = 800; IFdeCursor cursor = fc.Search(filter, true); IRowBuffer row = null; while ((row = cursor.NextRow()) != null) { IModelPoint modelPoint = row.GetValue(1) as IModelPoint; if ((geo as IRelationalOperator2D).Contains2D(modelPoint)) { subclasslength += double.Parse(row.GetValue(0).ToString()); bHave = true; } } } } if (bHave) { DataRow dr = dtResult.NewRow(); dr["PIPELINETYPE"] = mc; dr["PVALUE"] = sc; dr["LENGTH"] = subclasslength.ToString("0.00"); majorclasslength += subclasslength; dtResult.Rows.Add(dr); } } int indexEnd = dtResult.Rows.Count; for (int i = indexStart; i < indexEnd; i++) { DataRow dr = dtResult.Rows[i]; dr["TOTALLENGTH"] = majorclasslength.ToString("0.00"); } } return(dtResult); }
private DataTable DoStats() { DataTable dtResult = new DataTable(); dtResult.TableName = "DataStats"; dtResult.Columns.AddRange(new DataColumn[] { new DataColumn("PIPELINETYPE"), new DataColumn("FIELDNAME"), new DataColumn("PVALUE"), new DataColumn("LENGTH", typeof(double)), new DataColumn("TOTALLENGTH", typeof(double)) }); string localDataPath = SystemInfo.Instance.LocalDataPath; string tmpPath = ""; tmpPath = Path.Combine(localDataPath, "Stats"); if (!Directory.Exists(tmpPath)) { Directory.CreateDirectory(tmpPath); } string filePath = tmpPath + "\\全库3D管线统计.xml"; bool bHaveXml = false; if (File.Exists(filePath)) { dtResult.ReadXml(filePath); if (dtResult != null && dtResult.Rows.Count != 0) { bHaveXml = true; return(dtResult); } else { bHaveXml = false; } } List <MajorClass> list = LogicDataStructureManage3D.Instance.GetAllMajorClass(); foreach (MajorClass mc in list) { string[] arrFc3DId = mc.Fc3D.Split(';'); if (arrFc3DId == null) { continue; } double majorclasslength = 0.0; int indexStart = dtResult.Rows.Count; foreach (SubClass sc in mc.SubClasses) { double subclasslength = 0.0; bool bHave = false; foreach (string fc3DId in arrFc3DId) { DF3DFeatureClass dffc = DF3DFeatureClassManager.Instance.GetFeatureClassByID(fc3DId); if (dffc == null) { continue; } FacilityClass facc = dffc.GetFacilityClass(); IFeatureClass fc = dffc.GetFeatureClass(); if (fc == null || facc == null || facc.Name != "PipeLine") { continue; } DFDataConfig.Class.FieldInfo fiPipeLength = facc.GetFieldInfoBySystemName("PipeLength"); if (fiPipeLength == null) { continue; } int indexPipeLength = fc.GetFields().IndexOf(fiPipeLength.Name); if (indexPipeLength == -1) { continue; } IQueryFilter filter = new QueryFilter(); filter.SubFields = fiPipeLength.Name; filter.WhereClause = "GroupId = " + sc.GroupId; int count = fc.GetCount(filter); if (count == 0) { continue; } int loop = (int)Math.Ceiling(count / 800.0); for (int k = 1; k <= loop; k++) { if (k == 1) { filter.ResultBeginIndex = 0; } else { filter.ResultBeginIndex = (k - 1) * 800; } filter.ResultLimit = 800; IFdeCursor cur = null; IRowBuffer rowBuf = null; try { cur = fc.Search(filter, true); while ((rowBuf = cur.NextRow()) != null) { if (!rowBuf.IsNull(0)) { object tempobj = rowBuf.GetValue(0); double dtemp = 0.0; if (tempobj != null && double.TryParse(tempobj.ToString(), out dtemp)) { subclasslength += dtemp; bHave = true; } } } } catch { } finally { if (cur != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(cur); cur = null; } if (rowBuf != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(rowBuf); rowBuf = null; } } } } if (bHave) { DataRow dr = dtResult.NewRow(); dr["PIPELINETYPE"] = mc; dr["FIELDNAME"] = ""; dr["PVALUE"] = sc; dr["LENGTH"] = subclasslength.ToString("0.00"); majorclasslength += subclasslength; dtResult.Rows.Add(dr); } } int indexEnd = dtResult.Rows.Count; for (int i = indexStart; i < indexEnd; i++) { DataRow dr = dtResult.Rows[i]; dr["TOTALLENGTH"] = majorclasslength.ToString("0.00"); } } if (!bHaveXml) { dtResult.WriteXml(filePath); } return(dtResult); }
private void UpdateGeometry(object param) { try { DF3DApplication app = DF3DApplication.Application; if (app == null || app.Current3DMapControl == null) { return; } EditParameters editParameters = (EditParameters)param; if (editParameters != null) { System.Collections.Generic.Dictionary <DF3DFeatureClass, IRowBufferCollection> geometryMap = editParameters.geometryMap; if (geometryMap != null) { CommandManagerServices.Instance().StartCommand(); FDECommand cmd = new FDECommand(false, true); int nTotalCount = editParameters.nTotalCount; int num = 0; foreach (DF3DFeatureClass current in geometryMap.Keys) { if (this._bgWorker.CancellationPending) { break; } IRowBufferCollection rowBufferCollection = geometryMap[current]; if (current.GetFeatureClass().HasTemporal() && CommonUtils.Instance().EnableTemproalEdit) { IConnectionInfo connectionInfo = new ConnectionInfoClass(); connectionInfo.FromConnectionString(current.GetFeatureClass().DataSource.ConnectionInfo.ToConnectionString()); IDataSource dataSource = ((IDataSourceFactory) new DataSourceFactoryClass()).OpenDataSource(connectionInfo); IFeatureDataSet featureDataSet = dataSource.OpenFeatureDataset(CommonUtils.Instance().GetCurrentFeatureDataset().Name); IFeatureClass featureClass = featureDataSet.OpenFeatureClass(current.GetFeatureClass().Name); int position = featureClass.GetFields().IndexOf(featureClass.FidFieldName); System.Collections.Generic.Dictionary <int, IRowBuffer> dictionary = new System.Collections.Generic.Dictionary <int, IRowBuffer>(); for (int i = 0; i < rowBufferCollection.Count; i++) { IRowBuffer rowBuffer = rowBufferCollection.Get(i); int key = (int)rowBuffer.GetValue(position); dictionary[key] = rowBuffer; } ITemporalManager temporalManager = featureClass.TemporalManager; ITemporalCursor temporalCursor = temporalManager.Search(new TemporalFilterClass { IdsFilter = dictionary.Keys.ToArray <int>() }); while (temporalCursor.MoveNext() && !this._bgWorker.CancellationPending) { this._manualResult.WaitOne(); System.Threading.Thread.Sleep(1); num++; string userState = string.Format(StringParser.Parse("${res:feature_progress_finished}"), num, nTotalCount); int percentProgress = num * 100 / nTotalCount; this._bgWorker.ReportProgress(percentProgress, userState); bool flag = false; int currentId = temporalCursor.CurrentId; ITemporalInstanceCursor temporalInstances = temporalCursor.GetTemporalInstances(false); TemporalInstance temporalInstance; while ((temporalInstance = temporalInstances.NextInstance()) != null) { if (temporalInstance.StartDatetime == editParameters.TemproalTime) { flag = true; temporalInstances.Update(dictionary[currentId]); break; } } System.Runtime.InteropServices.Marshal.ReleaseComObject(temporalInstances); if (!flag) { temporalCursor.Insert(editParameters.TemproalTime, dictionary[currentId]); } } System.Runtime.InteropServices.Marshal.ReleaseComObject(temporalCursor); System.Runtime.InteropServices.Marshal.ReleaseComObject(temporalManager); System.Runtime.InteropServices.Marshal.ReleaseComObject(featureClass); System.Runtime.InteropServices.Marshal.ReleaseComObject(featureDataSet); System.Runtime.InteropServices.Marshal.ReleaseComObject(dataSource); } else { IFeatureClass featureClass2 = current.GetFeatureClass(); int num2 = 0; while (num2 < rowBufferCollection.Count && !this._bgWorker.CancellationPending) { this._manualResult.WaitOne(); System.Threading.Thread.Sleep(1); num++; string userState2 = string.Format(StringParser.Parse("${res:feature_progress_finished}"), num, nTotalCount); int percentProgress2 = num * 100 / nTotalCount; this._bgWorker.ReportProgress(percentProgress2, userState2); num2++; } CommonUtils.Instance().FdeUndoRedoManager.UpdateFeatures(featureClass2, rowBufferCollection); } } CommandManagerServices.Instance().CallCommand(cmd); app.Workbench.UpdateMenu(); } } } catch (System.Runtime.InteropServices.COMException ex) { XtraMessageBox.Show(ex.Message); } catch (System.UnauthorizedAccessException) { XtraMessageBox.Show(StringParser.Parse("${res:Dataset_InsufficientPermission}")); } catch (System.Exception e) { LoggingService.Error(e.Message); } }
// 公共方法 void FeatureLayerVisualize(IConnectionInfo ci, bool needfly, string sourceName, ITextRender textRender, IGeometryRender geoRender, LayerType type) { 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; } fcGeoMap = new Hashtable(fcnames.Length); foreach (string name in fcnames) { IFeatureClass fc = dataset.OpenFeatureClass(name); fcGuidMap.Add(fc.Guid, 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); } fcGeoMap.Add(fc, geoNames); } } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); return; } // CreateFeautureLayer bool hasfly = !needfly; foreach (IFeatureClass fc in fcGeoMap.Keys) { List <string> geoNames = (List <string>)fcGeoMap[fc]; foreach (string geoName in geoNames) { if (!geoName.Equals("Geometry")) { continue; } IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer( fc, geoName, textRender, geoRender, rootId); // 添加节点到界面控件上 myListNode item = new myListNode(string.Format("{0}_{1}_{2}", sourceName, fc.Name, featureLayer.MaxVisibleDistance.ToString()), featureLayer, type); item.Checked = true; listView1.Items.Add(item); IFieldInfoCollection fieldinfos = fc.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; } } }
private void DoQuery() { List <TreeListNode> list = this.treelist.GetAllCheckedNodes(); if (list == null) { XtraMessageBox.Show("请勾选图层树。", "提示"); return; } foreach (TreeListNode node in list) { object obj = node.GetValue("NodeObject"); if (obj != null && obj is SubClass) { SubClass sc = obj as SubClass; if (sc.Parent == null) { continue; } 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 facc = dffc.GetFacilityClass(); IFeatureClass fc = dffc.GetFeatureClass(); if (fc == null || facc == null || facc.Name != this._facType) { continue; } DFDataConfig.Class.FieldInfo fiStartDepth = facc.GetFieldInfoBySystemName("StartDepth"); DFDataConfig.Class.FieldInfo fiEndDepth = facc.GetFieldInfoBySystemName("EndDepth"); if (fiStartDepth == null || fiEndDepth == null) { continue; } int indexStartDepth = fc.GetFields().IndexOf(fiStartDepth.Name); int indexEndDepth = fc.GetFields().IndexOf(fiEndDepth.Name); if (indexStartDepth == -1 || indexEndDepth == -1) { continue; } IFieldInfo fcfiStartDepth = fc.GetFields().Get(indexStartDepth); switch (fcfiStartDepth.FieldType) { case gviFieldType.gviFieldBlob: case gviFieldType.gviFieldGeometry: case gviFieldType.gviFieldUnknown: continue; } IFieldInfo fcfiEndDepth = fc.GetFields().Get(indexEndDepth); switch (fcfiEndDepth.FieldType) { case gviFieldType.gviFieldBlob: case gviFieldType.gviFieldGeometry: case gviFieldType.gviFieldUnknown: continue; } string whereCluase = ""; foreach (DataRow dr in this._dt.Rows) { double mind = double.Parse(dr["MinDepth"].ToString()); double maxd = double.Parse(dr["MaxDepth"].ToString()); whereCluase += "( " + fcfiStartDepth.Name + " >= " + mind + " and " + fcfiStartDepth.Name + " <= " + maxd + " and " + fcfiEndDepth.Name + " >= " + mind + " and " + fcfiEndDepth.Name + " <= " + maxd + " )"; whereCluase += " or "; } if (this._dt.Rows.Count == 0) { whereCluase = "GroupId = " + sc.GroupId; } else { whereCluase = "GroupId = " + sc.GroupId + " and (" + whereCluase.Substring(0, whereCluase.Length - 4) + ")"; } _dict.Add(sc, whereCluase); } } } }