public override void Run(object sender, EventArgs e) { try { app = DF3DApplication.Application; if (app == null || app.Current3DMapControl == null) { return; } this._geoFact = new GeometryFactory(); Map3DCommandManager.Push(this); DF3DFeatureClass dffc = CommonUtils.Instance().CurEditLayer; if (dffc != null) { this._facType = dffc.GetFacilityClassName(); _strGeometryFieldName = ""; if (this._facType == "PipeLine" || this._facType == "PipeNode" || this._facType == "PipeBuild" || this._facType == "PipeBuild1") { _strGeometryFieldName = "Shape"; } else { IFeatureLayer fl = dffc.GetFeatureLayer(); if (fl != null) { _strGeometryFieldName = fl.GeometryFieldName; } } if (!string.IsNullOrEmpty(_strGeometryFieldName)) { IFeatureClass fc = dffc.GetFeatureClass(); if (fc != null) { IFieldInfoCollection fiCol = fc.GetFields(); int index = fiCol.IndexOf(_strGeometryFieldName); if (index != -1) { IFieldInfo fi = fiCol.Get(index); if (fi.GeometryDef != null) { this._geoType = fi.GeometryDef.GeometryColumnType; } } } switch (this._geoType) { case gviGeometryColumnType.gviGeometryColumnModelPoint: //添加方式:1、鼠标添加;2、文件添加 FrmInsertModel dlg = new FrmInsertModel(); if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string filePath = dlg.FilePath; string ext = Path.GetExtension(filePath); if (File.Exists(filePath)) { int insertType = dlg.InsertType; if (insertType == 0 && ext.ToLower() == ".osg") { this._drawTool = DrawToolService.Instance.CreateDrawTool(DrawType._3DModel); if (this._drawTool != null) { (this._drawTool as Draw3DModel).Set3DModelFilePath(filePath); this._drawTool.OnStartDraw += new OnStartDraw(this.OnStartDraw); this._drawTool.OnFinishedDraw += new OnFinishedDraw(this.OnFinishedDraw); this._drawTool.Start(); } } else if (insertType == 1 && ext.ToLower() == ".xml") { } } } break; case gviGeometryColumnType.gviGeometryColumnPoint: if (this._facType == "PipeNode") { // 添加附属设施或者管点 } else { // 添加点 this._drawTool = DrawToolService.Instance.CreateDrawTool(DrawType.Point); if (this._drawTool != null) { this._drawTool.OnStartDraw += new OnStartDraw(this.OnStartDraw); this._drawTool.OnFinishedDraw += new OnFinishedDraw(this.OnFinishedDraw); this._drawTool.Start(); } } break; case gviGeometryColumnType.gviGeometryColumnPolyline: if (this._facType == "PipeLine" || this._facType == "PipeBuild" || this._facType == "PipeBuild1") { // 选择管线或辅助样式 } else { // 添加线 this._drawTool = DrawToolService.Instance.CreateDrawTool(DrawType.Polyline); if (this._drawTool != null) { this._drawTool.OnStartDraw += new OnStartDraw(this.OnStartDraw); this._drawTool.OnFinishedDraw += new OnFinishedDraw(this.OnFinishedDraw); this._drawTool.Start(); } } break; case gviGeometryColumnType.gviGeometryColumnPolygon: if (this._facType == "PipeBuild" || this._facType == "PipeBuild1") { // 选择管线辅助样式 } else { // 添加面 this._drawTool = DrawToolService.Instance.CreateDrawTool(DrawType.Polygon); if (this._drawTool != null) { this._drawTool.OnStartDraw += new OnStartDraw(this.OnStartDraw); this._drawTool.OnFinishedDraw += new OnFinishedDraw(this.OnFinishedDraw); this._drawTool.Start(); } } break; default: return; } } } } catch (Exception ex) { } finally { } }
private 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 IFieldInfoCollection CreateFieldInfoCollection(List <CMFieldConfig> list, string facType) { if (list == null) { return(null); } IFieldInfoCollection infos = new FieldInfoCollection(); IFieldInfo newVal = null; foreach (CMFieldConfig cmfc in list) { newVal = new FieldInfoClass(); newVal.Name = cmfc.Name; newVal.Alias = cmfc.Alias; newVal.FieldType = cmfc.FieldType; newVal.Nullable = cmfc.Nullable; if (newVal.FieldType == gviFieldType.gviFieldString) { newVal.Length = cmfc.Length; } if (infos.IndexOf(newVal.Name) == -1) { infos.Add(newVal); } if (cmfc.SystemName == "Diameter") { newVal = new FieldInfoClass { Name = cmfc.Name + "1", Alias = "横截面宽", FieldType = gviFieldType.gviFieldDouble }; if (infos.IndexOf(newVal.Name) == -1) { infos.Add(newVal); } newVal = new FieldInfoClass { Name = cmfc.Name + "2", Alias = "横截面高", FieldType = gviFieldType.gviFieldDouble }; if (infos.IndexOf(newVal.Name) == -1) { infos.Add(newVal); } } } newVal = new FieldInfoClass { Name = "FacilityId", Alias = "设施编号", FieldType = gviFieldType.gviFieldString, Length = 50 }; infos.Add(newVal); newVal = new FieldInfoClass { Name = "GroupId", Alias = "逻辑组ID", FieldType = gviFieldType.gviFieldInt32, RegisteredRenderIndex = true }; infos.Add(newVal); newVal = new FieldInfoClass { Name = "StyleId", Alias = "风格编号", FieldType = gviFieldType.gviFieldString, Length = 50 }; infos.Add(newVal); newVal = new FieldInfoClass { Name = "ModelName", Alias = "模型名称", FieldType = gviFieldType.gviFieldString, Length = 80 }; infos.Add(newVal); newVal = new FieldInfoClass { Name = "Metadata", Alias = "Metadata", FieldType = gviFieldType.gviFieldBlob }; infos.Add(newVal); newVal = new FieldInfoClass { Name = "Geometry", Alias = "三维空间列", RegisteredRenderIndex = true, FieldType = gviFieldType.gviFieldGeometry }; IGeometryDef def = new GeometryDefClass { GeometryColumnType = gviGeometryColumnType.gviGeometryColumnModelPoint, HasZ = true }; newVal.GeometryDef = def; infos.Add(newVal); newVal = new FieldInfoClass { Name = "Shape", Alias = "二维空间列", RegisteredRenderIndex = true, FieldType = gviFieldType.gviFieldGeometry }; gviGeometryColumnType gviGeometryColumnUnknown = gviGeometryColumnType.gviGeometryColumnUnknown; switch (facType) { case "PipeNode": gviGeometryColumnUnknown = gviGeometryColumnType.gviGeometryColumnPoint; break; case "PipeLine": gviGeometryColumnUnknown = gviGeometryColumnType.gviGeometryColumnPolyline; break; case "PipeBuild": gviGeometryColumnUnknown = gviGeometryColumnType.gviGeometryColumnPolygon; break; case "PipeBuild1": gviGeometryColumnUnknown = gviGeometryColumnType.gviGeometryColumnPolyline; break; } IGeometryDef def2 = new GeometryDefClass { GeometryColumnType = gviGeometryColumnUnknown, HasZ = true }; newVal.GeometryDef = def2; infos.Add(newVal); newVal = new FieldInfoClass { Name = "FootPrint", Alias = "投影二维", RegisteredRenderIndex = true, FieldType = gviFieldType.gviFieldGeometry }; IGeometryDef def3 = new GeometryDefClass { GeometryColumnType = gviGeometryColumnUnknown, HasZ = false }; newVal.GeometryDef = def3; infos.Add(newVal); return(infos); }
public UCRangeSymbol(gviGeometryColumnType geoType) { InitializeComponent(); this._geoType = geoType; }