/// <summary> /// 初始化过滤条件面板 /// </summary> private void initFilterCondition() { listField.Items.Clear(); listValue.Items.Clear(); txtCondition.Text = (this.m_FeaLay as IFeatureLayerDefinition).DefinitionExpression; //得到当前要素图层的所有字段 ITableFields pTableFields = m_FeaLay as ITableFields; IField pField; for (int i = 0; i < pTableFields.FieldCount; i++) { if (pTableFields.get_FieldInfo(i).Visible == true) { pField = pTableFields.get_Field(i); if (pField.Type == esriFieldType.esriFieldTypeOID || pField.Type == esriFieldType.esriFieldTypeSmallInteger || pField.Type == esriFieldType.esriFieldTypeInteger || pField.Type == esriFieldType.esriFieldTypeSingle || pField.Type == esriFieldType.esriFieldTypeDouble || pField.Type == esriFieldType.esriFieldTypeDate || pField.Type == esriFieldType.esriFieldTypeString) { //ListViewItem item = new ListViewItem(new string[] { pField.Name, pField.AliasName }); //item.Tag = pField; Class.Item item = new Class.Item(pField.AliasName, pField); listField.Items.Add(item); } } } }
private void InitControls() { lbx_Value.Items.Clear(); //te_Condition.Text = (this.featureLayer as IFeatureLayerDefinition).DefinitionExpression; ITableFields tableFields = featureLayer as ITableFields; IGeoFeatureLayer geoFL = featureLayer as IGeoFeatureLayer; IField field; _dt = new DataTable(); _dt.Columns.AddRange(new DataColumn[] { new DataColumn("Name"), new DataColumn("AliasName"), new DataColumn("Object", typeof(object)) }); if (geoFL.Renderer is IUniqueValueRenderer) { field = tableFields.get_Field(tableFields.FindField((geoFL.Renderer as IUniqueValueRenderer).get_Field(0))); AddRowToDT(field); } else if (geoFL.Renderer is ISimpleRenderer) { for (int i = 0; i < tableFields.FieldCount; i++) { if (tableFields.get_FieldInfo(i).Visible) { field = tableFields.get_Field(i); switch (field.Type) { case esriFieldType.esriFieldTypeOID: case esriFieldType.esriFieldTypeSmallInteger: case esriFieldType.esriFieldTypeInteger: case esriFieldType.esriFieldTypeSingle: case esriFieldType.esriFieldTypeDouble: case esriFieldType.esriFieldTypeDate: case esriFieldType.esriFieldTypeString: AddRowToDT(field); break; } } } } this.gridControl1.DataSource = _dt; }
private bool ExportTable(Excel.Workbook ExcelWbk, IMxDocument MxDoc, IStandaloneTable StandTable, ref IProgressDialog2 progressDialog, ref IStepProgressor stepProgressor, ref ITrackCancel trackCancel) { ITableProperties TableProperties = null; IEnumTableProperties EnumTableProperties = null; ITableProperty3 TableProperty = null; ITableCharacteristics TableCharacteristics = null; ITableSelection TabSel = null; IDisplayTable DisplayTable = null; ITable Table = null; IRow TabRow = null; IObjectClass ObjectClass = null; ISubtypes Subtypes = null; ITableFields TableFields = null; ICursor Cursor = null; IField CurField = null; IDomain Domain = null; ICodedValueDomain CodedValueDomain = null; object missing = null; object sheet = null; Microsoft.Office.Interop.Excel.Style style = null; try { bool UseDescriptions; int subtype; string SheetName; int Col = 0; int Row = 0; int i; int j; missing = System.Reflection.Missing.Value; sheet = ExcelWbk.Sheets[ExcelWbk.Sheets.Count]; Excel.Worksheet ExcelSheet; Excel.Range ExcelRange; //Add new Excel worksheet ExcelSheet = (Excel.Worksheet)ExcelWbk.Sheets.Add(missing, sheet, missing, missing); //style = ExcelWbk.Styles.Add("Style1"); //style.NumberFormat = "@"; //style.Font.Name = "Arial"; //style.Font.Bold = True //style.Font.Size = 12; //style.Interior.Pattern = Microsoft.Office.Interop.Excel.XlPattern.xlPattern Solid //style.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlighLe ft SheetName = StandTable.Name; if (SheetName.Length > 30) { SheetName = SheetName.Substring(0, 30); } ExcelSheet.Name = SheetName; //Determine whether to use descriptions or codes for domains UseDescriptions = true; TableProperties = MxDoc.TableProperties; EnumTableProperties = (IEnumTableProperties)TableProperties; EnumTableProperties.Reset(); TableProperty = (ITableProperty3)EnumTableProperties.Next(); while (TableProperty != null) { if (TableProperty.StandaloneTable != null) { if (TableProperty.StandaloneTable.Equals(StandTable)) { TableCharacteristics = (ITableCharacteristics)TableProperty; UseDescriptions = TableCharacteristics.ShowCodedValueDomainDescriptions; break; } } TableProperty = (ITableProperty3)EnumTableProperties.Next(); } TabSel = (ITableSelection)StandTable; DisplayTable = (IDisplayTable)StandTable; Table = (ITable)DisplayTable.DisplayTable; //Get subtype info ObjectClass = Table as IObjectClass; Subtypes = ObjectClass as ISubtypes; //Get TableFields so later we can determine whether that field is visible TableFields = (ITableFields)StandTable; //loop through each field and write column headings Row = 1; for (j = 0; j < TableFields.FieldCount; j++) { CurField = TableFields.get_Field(j); //skip blob and geometry fields if ((CurField.Type != esriFieldType.esriFieldTypeBlob) && (CurField.Type != esriFieldType.esriFieldTypeGeometry)) { Col += 1; //Write field alias name as Excel column header ExcelSheet.Cells[Row, Col] = TableFields.get_FieldInfo(j).Alias; if (CurField.Type == esriFieldType.esriFieldTypeString) { ExcelSheet.get_Range(ExcelSheet.Cells[1, Col], ExcelSheet.Cells[65535, Col]).EntireColumn.NumberFormat = "@"; } } } //Get all selected records for this table (use IDisplayTable to get any joined data) DisplayTable.DisplaySelectionSet.Search(null, true, out Cursor); //subtype = Subtypes.DefaultSubtypeCode; //For each selected record TabRow = Cursor.NextRow(); //stepProgressor.Step(); // progressDialog.Description = A4LGSharedFunctions.Localizer.GetString("ExportAsset") + stepProgressor.Position + A4LGSharedFunctions.Localizer.GetString("Of") + MxDoc.FocusMap.SelectionCount.ToString() + "."; while (TabRow != null) { Row += 1; if (Subtypes != null && Subtypes.HasSubtype == true && (TabRow.get_Value(Subtypes.SubtypeFieldIndex) != null)) { subtype = Convert.ToInt32(TabRow.get_Value(Subtypes.SubtypeFieldIndex)); } else { subtype = -99999; } //For each column Col = 0; for (j = 0; j < TableFields.FieldCount; j++) { CurField = TableFields.get_Field(j); //skip blob and geometry fields in data also if ((CurField.Type != esriFieldType.esriFieldTypeBlob) && (CurField.Type != esriFieldType.esriFieldTypeGeometry)) { Col += 1; ExcelSheet.Cells[Row, Col] = TabRow.get_Value(j); if (UseDescriptions == true && subtype == -99999) { Domain = CurField.Domain; if (Domain != null) { if (Domain.Type == esriDomainType.esriDTCodedValue) { CodedValueDomain = (ICodedValueDomain)CurField.Domain; for (i = 0; i < CodedValueDomain.CodeCount; i++) { if ((CodedValueDomain.get_Value(i)).ToString() == (TabRow.get_Value(j)).ToString()) { //System.Diagnostics.Debug.Print(CodedValueDomain.get_Name(0).ToString()); ExcelSheet.Cells[Row, Col] = CodedValueDomain.get_Name(i); i = CodedValueDomain.CodeCount; } } } } } else if (UseDescriptions == true && subtype != -99999) { if (Subtypes.SubtypeFieldIndex == j) { ExcelSheet.Cells[Row, Col] = Subtypes.get_SubtypeName(subtype); } else { Domain = Subtypes.get_Domain(subtype, CurField.Name); if ((Domain != null) && (Domain.Type == esriDomainType.esriDTCodedValue)) { CodedValueDomain = (ICodedValueDomain)Domain; for (i = 0; i < CodedValueDomain.CodeCount; i++) { if ((CodedValueDomain.get_Value(i)).ToString() == (TabRow.get_Value(j)).ToString()) { //System.Diagnostics.Debug.Print(CodedValueDomain.get_Name(0).ToString()); ExcelSheet.Cells[Row, Col] = CodedValueDomain.get_Name(i); i = CodedValueDomain.CodeCount; } } } } } } } stepProgressor.Step(); progressDialog.Description = A4LGSharedFunctions.Localizer.GetString("ExportAsset") + stepProgressor.Position + A4LGSharedFunctions.Localizer.GetString("Of") + MxDoc.FocusMap.SelectionCount.ToString() + "."; if (!trackCancel.Continue()) { return(false); } TabRow = Cursor.NextRow(); } //Hide Columns Col = 0; for (j = 0; j < TableFields.FieldCount; j++) { CurField = TableFields.get_Field(j); //skip blob and geometry fields in data also if ((CurField.Type != esriFieldType.esriFieldTypeBlob) && (CurField.Type != esriFieldType.esriFieldTypeGeometry)) { Col += 1; //Autofit ExcelRange = ExcelSheet.get_Range(ExcelSheet.Cells[1, Col], ExcelSheet.Cells[Row, Col]); ExcelRange.EntireColumn.AutoFit(); //Hide column if invisible in ArcMap if (TableFields.get_FieldInfo(j).Visible == false) { ExcelRange = ExcelSheet.get_Range(ExcelSheet.Cells[1, Col], ExcelSheet.Cells[Row, Col]); ExcelRange.EntireColumn.Hidden = true; } } } return(true); } catch { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("ExportXLError")); return(true); } finally { TableProperties = null; EnumTableProperties = null; TableProperty = null; TableCharacteristics = null; TabSel = null; DisplayTable = null; Table = null; TabRow = null; ObjectClass = null; Subtypes = null; TableFields = null; if (Cursor != null) { Marshal.ReleaseComObject(Cursor); } Cursor = null; CurField = null; Domain = null; CodedValueDomain = null; missing = null; sheet = null; style = null; } }
private bool ExportLayer(Excel.Workbook ExcelWbk, IMxDocument MxDoc, IFeatureLayer FLayer, ref IProgressDialog2 progressDialog, ref IStepProgressor stepProgressor, ref ITrackCancel trackCancel) { IFeatureClass FC = null; ISubtypes Subtypes = null; ITableProperties TableProperties = null; IEnumTableProperties EnumTableProperties = null; ITableProperty3 TableProperty = null; ITableCharacteristics TableCharacteristics = null; IFeatureSelection FeatSel = null; IDisplayTable DisplayTable = null; ITable Table = null; ILayerFields LayerFields = null; ITableFields TableFields = null; ILayer LayerTest = null; ICursor Cursor = null; IFeatureCursor FCursor = null; IField CurField = null; IDomain Domain = null; ICodedValueDomain CodedValueDomain = null; IFeature Feat = null; List <IPoint> pGeo = null; object missing = null; object sheet = null; Excel.Worksheet ExcelSheet = null; Excel.Range ExcelRange = null; Microsoft.Office.Interop.Excel.Style style = null; try { int Col = 0; int Row = 0; int i; int j; bool UseDescriptions; int subtype; string SheetName; missing = System.Reflection.Missing.Value; sheet = ExcelWbk.Sheets[ExcelWbk.Sheets.Count]; //Add new Excel worksheet ExcelSheet = (Excel.Worksheet)ExcelWbk.Sheets.Add(missing, sheet, missing, missing); SheetName = FLayer.Name; if (SheetName.Length > 30) { SheetName = SheetName.Substring(0, 30); } ExcelSheet.Name = SheetName; //style = ExcelWbk.Styles.Add("Style1"); //style.NumberFormat = "@"; LayerTest = (ILayer)FLayer; //Get Subtype info FC = FLayer.FeatureClass; Subtypes = FC as ISubtypes; //Determine whether to use descriptions or codes for domains and subtypes UseDescriptions = true; TableProperties = MxDoc.TableProperties; EnumTableProperties = (IEnumTableProperties)TableProperties; EnumTableProperties.Reset(); TableProperty = (ITableProperty3)EnumTableProperties.Next(); while (TableProperty != null && TableProperty.Layer != null) //Fixed { if (TableProperty.Layer.Equals(LayerTest)) { TableCharacteristics = (ITableCharacteristics)TableProperty; UseDescriptions = TableCharacteristics.ShowCodedValueDomainDescriptions; } TableProperty = (ITableProperty3)EnumTableProperties.Next(); } FeatSel = (IFeatureSelection)FLayer; DisplayTable = (IDisplayTable)FLayer; Table = (ITable)DisplayTable.DisplayTable; //Get TableFields so later we can determine whether that field is visible LayerFields = (ILayerFields)FLayer; TableFields = (ITableFields)FLayer; //loop through each field and write column headings Row = 1; for (j = 0; j < TableFields.FieldCount; j++) { CurField = TableFields.get_Field(j); //skip blob and geometry fields if ((CurField.Type != esriFieldType.esriFieldTypeBlob) && (CurField.Type != esriFieldType.esriFieldTypeGeometry)) { Col += 1; //Write field alias name as Excel column header ExcelSheet.Cells[Row, Col] = TableFields.get_FieldInfo(j).Alias; if (CurField.Type == esriFieldType.esriFieldTypeString) { ExcelSheet.get_Range(ExcelSheet.Cells[1, Col], ExcelSheet.Cells[65535, Col]).EntireColumn.NumberFormat = "@"; } } } Col += 1; ExcelSheet.Cells[Row, Col] = "X_COORD"; Col += 1; ExcelSheet.Cells[Row, Col] = "Y_COORD"; Col += 1; ExcelSheet.Cells[Row, Col] = "Lat"; Col += 1; ExcelSheet.Cells[Row, Col] = "Long"; IField pFieldTest = FLayer.FeatureClass.Fields.get_Field(FLayer.FeatureClass.Fields.FindField(FLayer.FeatureClass.ShapeFieldName)); IGeometryDef pGeometryDefTest = null; pGeometryDefTest = pFieldTest.GeometryDef; bool bZAware = false; bool bMAware = false; //Determine if M or Z aware if (pGeometryDefTest.GeometryType == esriGeometryType.esriGeometryPoint) { bZAware = pGeometryDefTest.HasZ; bMAware = pGeometryDefTest.HasM; } if (bZAware) { Col += 1; ExcelSheet.Cells[Row, Col] = "Z_COORD"; } pFieldTest = null; pGeometryDefTest = null; //Get all selected records for this table (use IDisplayTable to get any joined data) DisplayTable.DisplaySelectionSet.Search(null, true, out Cursor); FCursor = (IFeatureCursor)Cursor; //subtype = Subtypes.DefaultSubtypeCode; //For each selected record Feat = FCursor.NextFeature(); // stepProgressor.Step(); // progressDialog.Description = A4LGSharedFunctions.Localizer.GetString("ExportAsset") + stepProgressor.Position + A4LGSharedFunctions.Localizer.GetString("Of") + MxDoc.FocusMap.SelectionCount.ToString() + "."; while (Feat != null) { Row += 1; if (Subtypes != null && Subtypes.HasSubtype == true && (Feat.get_Value(Subtypes.SubtypeFieldIndex) != null)) { subtype = Convert.ToInt32(Feat.get_Value(Subtypes.SubtypeFieldIndex)); } else { subtype = -99999; } //For each column Col = 0; for (j = 0; j < TableFields.FieldCount; j++) { CurField = TableFields.get_Field(j); //skip blob and geometry fields in data also if ((CurField.Type != esriFieldType.esriFieldTypeBlob) && (CurField.Type != esriFieldType.esriFieldTypeGeometry)) { Col += 1; ExcelSheet.Cells[Row, Col] = Feat.get_Value(j); if (UseDescriptions == true && subtype == -99999) { Domain = CurField.Domain; if (Domain != null) { if (Domain.Type == esriDomainType.esriDTCodedValue) { CodedValueDomain = (ICodedValueDomain)CurField.Domain; for (i = 0; i < CodedValueDomain.CodeCount; i++) { if ((CodedValueDomain.get_Value(i)).ToString() == (Feat.get_Value(j)).ToString()) { //System.Diagnostics.Debug.Print(CodedValueDomain.get_Name(0).ToString()); ExcelSheet.Cells[Row, Col] = CodedValueDomain.get_Name(i); i = CodedValueDomain.CodeCount; } } } } } else if (UseDescriptions == true && subtype != -99999) { if (Subtypes.SubtypeFieldIndex == j) { ExcelSheet.Cells[Row, Col] = Subtypes.get_SubtypeName(subtype); } else { Domain = Subtypes.get_Domain(subtype, CurField.Name); if ((Domain != null) && (Domain.Type == esriDomainType.esriDTCodedValue)) { CodedValueDomain = (ICodedValueDomain)Domain; for (i = 0; i < CodedValueDomain.CodeCount; i++) { if ((CodedValueDomain.get_Value(i)).ToString() == (Feat.get_Value(j)).ToString()) { //System.Diagnostics.Debug.Print(CodedValueDomain.get_Name(0).ToString()); ExcelSheet.Cells[Row, Col] = CodedValueDomain.get_Name(i); i = CodedValueDomain.CodeCount; } } } } } } } if (Feat.Shape != null) { if (Feat.Shape.IsEmpty == false) { pGeo = Globals.GetGeomCenter(Feat.Shape); if (pGeo != null) { if (pGeo.Count > 0) { if (pGeo[0].X != null) { ExcelSheet.Cells[Row, Col + 1] = pGeo[0].X; } if (pGeo[0].Y != null) { ExcelSheet.Cells[Row, Col + 2] = pGeo[0].Y; } if (pGeo[0] != null) { pGeo[0].Project(srWGS84); ExcelSheet.Cells[Row, Col + 3] = pGeo[0].Y; ExcelSheet.Cells[Row, Col + 4] = pGeo[0].X; } if (bZAware) { ExcelSheet.Cells[Row, Col + 5] = pGeo[0].Z; } } } } } stepProgressor.Step(); progressDialog.Description = A4LGSharedFunctions.Localizer.GetString("ExportAsset") + stepProgressor.Position + A4LGSharedFunctions.Localizer.GetString("Of") + MxDoc.FocusMap.SelectionCount.ToString() + "."; if (!trackCancel.Continue()) { return(false); } Feat = FCursor.NextFeature(); } //Hide Columns Col = 0; for (j = 0; j < TableFields.FieldCount; j++) { CurField = TableFields.get_Field(j); //skip blob and geometry fields in data also if ((CurField.Type != esriFieldType.esriFieldTypeBlob) && (CurField.Type != esriFieldType.esriFieldTypeGeometry)) { Col += 1; //Autofit ExcelRange = ExcelSheet.get_Range(ExcelSheet.Cells[1, Col], ExcelSheet.Cells[Row, Col]); ExcelRange.EntireColumn.AutoFit(); //Hide column if invisible in ArcMap if (TableFields.get_FieldInfo(j).Visible == false) { ExcelRange = ExcelSheet.get_Range(ExcelSheet.Cells[1, Col], ExcelSheet.Cells[Row, Col]); ExcelRange.EntireColumn.Hidden = true; } } } return(true); } catch { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("ExportXLError")); return(true); } finally { FC = null; Subtypes = null; TableProperties = null; if (EnumTableProperties != null) { Marshal.ReleaseComObject(EnumTableProperties); } EnumTableProperties = null; TableProperty = null; TableCharacteristics = null; FeatSel = null; DisplayTable = null; Table = null; LayerFields = null; TableFields = null; LayerTest = null; if (Cursor != null) { Marshal.ReleaseComObject(Cursor); } Cursor = null; if (FCursor != null) { Marshal.ReleaseComObject(FCursor); } FCursor = null; CurField = null; Domain = null; CodedValueDomain = null; Feat = null; pGeo = null; missing = null; sheet = null; ExcelSheet = null; ExcelRange = null; style = null; } }
/// <summary>Returns the index of a particular field given the Name or Alias of a given field.</summary> /// <param name="o">Object that could either be a layer, featurelayer, featureclass, feature, row, table, standalone table or tablefields</param> /// <param name="FieldName"> Field name to search</param> /// <returns>Integer denoting the field index</returns> public int FindField(object o, string FieldName) { try { if (o is ILayer) { ILayer layer = (ILayer)o; if (!(layer == null)) { IFeatureLayer featurelayer = (IFeatureLayer)layer; if (!(featurelayer == null)) { int i = featurelayer.FeatureClass.Fields.FindField(FieldName); if (i > -1) { return(i); } else { for (int j = 0; j < featurelayer.FeatureClass.Fields.FieldCount; j++) { if (FieldName.CompareTo(featurelayer.FeatureClass.Fields.get_Field(j).AliasName) == 0) { return(j); } } } } } } if (o is IFeatureLayer) { IFeatureLayer featurelayer = (IFeatureLayer)o; if (!(featurelayer == null)) { int i = featurelayer.FeatureClass.Fields.FindField(FieldName); if (i > -1) { return(i); } else { for (int j = 0; j < featurelayer.FeatureClass.Fields.FieldCount; j++) { if (FieldName.CompareTo(featurelayer.FeatureClass.Fields.get_Field(j).AliasName) == 0) { return(j); } } } } } if (o is IFeatureClass) { IFeatureClass featureclass = (IFeatureClass)o; if (!(featureclass == null)) { int i = featureclass.Fields.FindField(FieldName); if (i > -1) { return(i); } else { for (int j = 0; j < featureclass.Fields.FieldCount; j++) { if (FieldName.CompareTo(featureclass.Fields.get_Field(j).AliasName) == 0) { return(j); } } } } } if (o is IFeature) { IFeature feature = (IFeature)o; if (!(feature == null)) { int i = feature.Fields.FindField(FieldName); if (i > -1) { return(i); } else { for (int j = 0; j < feature.Fields.FieldCount; j++) { if (FieldName.CompareTo(feature.Fields.get_Field(j).AliasName) == 0) { return(j); } } } } } if (o is IRow) { IRow row = (IRow)o; if (!(row == null)) { int i = row.Fields.FindField(FieldName); if (i > -1) { return(i); } else { for (int j = 0; j < row.Fields.FieldCount; j++) { if (FieldName.CompareTo(row.Fields.get_Field(j).AliasName) == 0) { return(j); } } } } } if (o is ITable) { ITable table = (ITable)o; if (!(table == null)) { int i = table.FindField(FieldName); if (i > -1) { return(i); } else { for (int j = 0; j < table.Fields.FieldCount; j++) { if (FieldName.CompareTo(table.Fields.get_Field(j).AliasName) == 0) { return(j); } } } } } if (o is IStandaloneTable) { IStandaloneTable standalonetable = (IStandaloneTable)o; int i = standalonetable.Table.FindField(FieldName); if (i > -1) { return(i); } else { for (int j = 0; j < standalonetable.Table.Fields.FieldCount; j++) { if (FieldName.CompareTo(standalonetable.Table.Fields.get_Field(j).AliasName) == 0) { return(j); } } } } if (o is ITableFields) { ITableFields tablefields = (ITableFields)o; int i = tablefields.FindField(FieldName); if (i > -1) { return(i); } else { for (int j = 0; j < tablefields.FieldCount; j++) { if (FieldName.CompareTo(tablefields.get_FieldInfo(j).Alias) == 0) { return(j); } } } } if (o is IGeoFeatureLayer) { IGeoFeatureLayer geofeaturelayer = (IGeoFeatureLayer)o; if (!(geofeaturelayer == null)) { IFeatureLayer featurelayer = (IFeatureLayer)geofeaturelayer; if (!(featurelayer == null)) { int i = featurelayer.FeatureClass.Fields.FindField(FieldName); if (i > -1) { return(i); } else { for (int j = 0; j < featurelayer.FeatureClass.Fields.FieldCount; j++) { if (FieldName.CompareTo(featurelayer.FeatureClass.Fields.get_Field(j).AliasName) == 0) { return(j); } } } } } } if (o is IFields) { IFields fields = (IFields)o; if (!(fields == null)) { int i = fields.FindField(FieldName); if (i > -1) { return(i); } else { for (int j = 0; j < fields.FieldCount; j++) { if (FieldName.CompareTo(fields.get_Field(j).AliasName) == 0) { return(j); } } } } } return(-1); } catch (Exception ex) { if (SupressMessaging == false) { MessageBox.Show(ex.Message, "Release COM Objects", MessageBoxButtons.OK, MessageBoxIcon.Information); } } return(-1); }
/// <summary> /// 保存图层属性 /// </summary> /// <returns></returns> public bool SaveProperties() { if (txtLayerName.Text.Trim() == "") { return(false); } if (this.rdoGroupScale.SelectedIndex == 1) { try { if (double.Parse(txtScaleMin.Text) <= double.Parse(txtScaleMax.Text)) { return(false); } } catch { return(false); } } m_FeaLay.Name = txtLayerName.Text; if (this.rdoGroupScale.SelectedIndex == 0) { m_FeaLay.MinimumScale = 0; m_FeaLay.MaximumScale = 0; } else if (this.rdoGroupScale.SelectedIndex == 1) { m_FeaLay.MinimumScale = double.Parse(txtScaleMin.Text); m_FeaLay.MaximumScale = double.Parse(txtScaleMax.Text); } (m_FeaLay as ILayerGeneralProperties).LayerDescription = txtDescription.Text; //地图描述 Class.Item item = cboDisplayField.SelectedItem as Class.Item; m_FeaLay.DisplayField = item.Value.ToString(); //主显示字段 m_FeaLay.Visible = chkVisible.Checked; //可见性 (m_FeaLay as ILayerEffects).Transparency = short.Parse(txtTransparency.Text); //透明度 m_FeaLay.ShowTips = chkShowTip.Checked; //显示主显示字段 if (m_FeaLay is IGeoFeatureLayer) { if (chkLabelAll.Checked) { ChangeLayerAnno(m_FeaLay); } (m_FeaLay as IGeoFeatureLayer).DisplayAnnotation = chkLabelAll.Checked; //标注图层中所有要素 } m_FeaLay.ScaleSymbols = chkScaleSymbol.Checked;//符号随比例尺缩放 ////////字段信息 m_pTableFields = m_FeaLay as ITableFields; for (int i = 0; i < listViewFieldInfo.Nodes.Count; i++) { int index = m_pTableFields.FindField(listViewFieldInfo.Nodes[i][2].ToString()); if (index > -1) { IFieldInfo pFieldInfo = m_pTableFields.get_FieldInfo(index); pFieldInfo.Visible = listViewFieldInfo.Nodes[i].Checked == true ? true : false; } } if (!CheckCondition(this.m_FeaLay, txtCondition.Text)) { MessageBox.Show("查询条件错误!"); } else { (this.m_FeaLay as IFeatureLayerDefinition).DefinitionExpression = txtCondition.Text; m_MapCtrl.ActiveView.Refresh(); } return(true); }
/// <summary> /// 初始化控件 /// </summary> private void initControls() { IFeatureLayer pFeaLayer = (IFeatureLayer)m_FeaLay; if (pFeaLayer == null) { return; } IDatasetEditInfo pEdit = (IDatasetEditInfo)pFeaLayer.FeatureClass; ILayerEffects pLayerEff = (ILayerEffects)m_FeaLay; //数据源 IDataLayer pDataLayer = (IDataLayer)m_FeaLay; IDatasetName pDatasetName = pDataLayer.DataSourceName as IDatasetName; IWorkspaceName pWSName = pDatasetName.WorkspaceName; IFeatureClassName pFCName = pDatasetName as IFeatureClassName; string strDataSourceType = ""; string strFeatureDataSet = ""; if (pFCName.FeatureDatasetName == null) { strDataSourceType = "数据类型 :" + "个人空间数据库 要素类"; strFeatureDataSet = "数 据 集 :" + "无"; } else { strDataSourceType = "数据类型 :" + pFCName.FeatureDatasetName.Category + "(" + pFeaLayer.DataSourceType + ")"; strFeatureDataSet = "数 据 集 :" + pFCName.FeatureDatasetName.Name; } string strFeatureClass = "要 素 类 :" + pDatasetName.Name; string strFeatureType = "要素类型 :" + pFCName.FeatureType.ToString(); string strGeometyrType = "几何类型 :" + pFCName.ShapeType.ToString(); string strLocationPath = "位 置 :" + pWSName.PathName; string strRelativeBase = "相对路径 :" + pDataLayer.RelativeBase; this.txtSoureFile.Text = strDataSourceType + "\r\n" + strFeatureDataSet + "\r\n" + strFeatureClass + "\r\n" + strFeatureType + "\r\n" + strGeometyrType + "\r\n" + strRelativeBase + "\r\n" + strLocationPath; this.txtXMin.Text = m_FeaLay.AreaOfInterest.XMin.ToString(".##"); this.txtXMax.Text = m_FeaLay.AreaOfInterest.XMax.ToString(".##"); this.txtYMin.Text = m_FeaLay.AreaOfInterest.YMin.ToString(".##"); this.txtYMax.Text = m_FeaLay.AreaOfInterest.YMax.ToString(".##"); //基本信息 this.txtLayerName.Text = m_FeaLay.Name; if (pEdit != null) { this.chkEdit.Checked = pEdit.CanEdit; } if (m_FeaLay.FeatureClass != null) { int dfIndex = -1; this.chkVisible.Checked = pFeaLayer.Visible; this.cboDisplayField.Properties.Items.Clear(); for (int i = 0; i < m_FeaLay.FeatureClass.Fields.FieldCount; i++) { IField pField = m_FeaLay.FeatureClass.Fields.get_Field(i); if (pField.Name == pFeaLayer.DisplayField) { dfIndex = i; } Class.Item item = new Class.Item(pField.AliasName, pField.Name); cboDisplayField.Properties.Items.Add(item); } this.cboDisplayField.SelectedIndex = dfIndex; this.txtTransparency.Text = pLayerEff.Transparency.ToString(); //this.txtScaleMin.Text = (pFeaLayer as ILayerGeneralProperties).LastMinimumScale.ToString(); //this.txtScaleMax.Text = (pFeaLayer as ILayerGeneralProperties).LastMaximumScale.ToString(); this.txtScaleMin.Text = pFeaLayer.MinimumScale.ToString(); this.txtScaleMax.Text = pFeaLayer.MaximumScale.ToString(); this.txtDescription.Text = (pFeaLayer as ILayerGeneralProperties).LayerDescription; if (pFeaLayer.MinimumScale == 0 && pFeaLayer.MaximumScale == 0) { this.rdoGroupScale.SelectedIndex = 0; txtScaleMin.Enabled = false; txtScaleMax.Enabled = false; } else { this.rdoGroupScale.SelectedIndex = 1; txtScaleMin.Enabled = true; txtScaleMax.Enabled = true; } chkShowTip.Checked = pFeaLayer.ShowTips; if (pFeaLayer is IGeoFeatureLayer) { chkLabelAll.Checked = (pFeaLayer as IGeoFeatureLayer).DisplayAnnotation; } chkScaleSymbol.Checked = pFeaLayer.ScaleSymbols; m_pTableFields = pFeaLayer as ITableFields; //字段信息 string strType = ""; for (int i = 0; i < m_pTableFields.FieldCount; i++) { IField pField = m_pTableFields.get_Field(i); IFieldInfo pFieldInfo = m_pTableFields.get_FieldInfo(i); switch (pField.Type)//类型 { case esriFieldType.esriFieldTypeBlob: strType = "二进制块"; break; case esriFieldType.esriFieldTypeDate: strType = "日期型"; break; case esriFieldType.esriFieldTypeDouble: strType = "双精度"; break; case esriFieldType.esriFieldTypeGeometry: strType = "几何形体"; break; case esriFieldType.esriFieldTypeGlobalID: strType = "GlobalID"; break; case esriFieldType.esriFieldTypeGUID: strType = "GUID"; break; case esriFieldType.esriFieldTypeOID: strType = "OID"; break; case esriFieldType.esriFieldTypeRaster: strType = "栅格"; break; case esriFieldType.esriFieldTypeSingle: strType = "单精度"; break; case esriFieldType.esriFieldTypeSmallInteger: strType = "短整形"; break; case esriFieldType.esriFieldTypeString: strType = "字符型"; break; } TreeListNode node = this.listViewFieldInfo.Nodes.Add(new object[] { pField.AliasName, pField.Name, strType }); node.Checked = pFieldInfo.Visible; } //初始化过滤条件面板 initFilterCondition(); } }