private bool SelectFeatures() { try { string strTemp = (string)this.cboFields.SelectedItem; string strFieldAliasName = strTemp;//.Substring(1, strTemp.Length - 2); string strFieldName = m_FieldTable[strFieldAliasName].ToString(); IFeatureClass pFtCls = m_FeatureLayer.FeatureClass; int nFieldIndex = pFtCls.Fields.FindField(strFieldName); string strWhereClause = ""; if (pFtCls.Fields.get_Field(nFieldIndex).Type == esriFieldType.esriFieldTypeString) { strWhereClause = strFieldName + " = '" + (string)this.cboFieldsValue.SelectedItem + "'"; } else { strWhereClause = strFieldName + " =" + (string)this.cboFieldsValue.SelectedItem; } if (m_FeatureLayer == null) { return(false); } IQueryFilter _queryFilter; IFeatureSelection _featureSelection; _featureSelection = m_FeatureLayer as IFeatureSelection; _queryFilter = new QueryFilterClass(); _queryFilter.SubFields = "*"; _queryFilter.WhereClause = strWhereClause; m_Map.ClearSelection(); _featureSelection.SelectFeatures(_queryFilter, esriSelectionResultEnum.esriSelectionResultNew, false); if (_featureSelection.SelectionSet.Count == 0) { XtraMessageBox.Show("没有符合查询条件的要素!", "提示", MessageBoxButtons.OK); return(false); } if (m_FeatureLayer.Visible == false) { m_FeatureLayer.Visible = true; object obj = MapOperAPI.GetLayerParent((IBasicMap)m_Map, (ILayer)m_FeatureLayer); if (obj is ICompositeLayer) { ILayer pParentLayer = (ILayer)obj; pParentLayer.Visible = true; } } m_activeView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); } catch (Exception ex) { XtraMessageBox.Show("没有匹配的查询结果,请重新设置查询条件!", "提示"); return(false); } return(true); }
/// <summary> /// 获取选中图层的字段 /// </summary> private void GetFields() { try { string sLayerName = (string)cboLayers.SelectedItem; IFeatureLayer _featureLayer; IFeatureClass _featureClass = null; IFields _fields; IDataset _dataSet; _featureLayer = (IFeatureLayer)MapOperAPI.GetLayerFromMapByName(m_Map, sLayerName); m_FeatureLayer = _featureLayer; if (_featureLayer != null) { _featureClass = _featureLayer.FeatureClass; } this.cboFields.Properties.Items.Clear(); this.cboFieldsValue.Properties.Items.Clear(); m_FieldTable = new Hashtable(); if (_featureClass != null) { _dataSet = _featureClass as IDataset; _fields = _featureClass.Fields; if (_dataSet.Workspace.Type == esriWorkspaceType.esriFileSystemWorkspace || _dataSet.Workspace.Type == esriWorkspaceType.esriRemoteDatabaseWorkspace) { for (int i = 0; i < _fields.FieldCount; i++) { IField pField = _fields.get_Field(i); if (pField.Type != esriFieldType.esriFieldTypeGeometry && pField.Type != esriFieldType.esriFieldTypeBlob && pField.Type != esriFieldType.esriFieldTypeRaster) { cboFields.Properties.Items.Add(pField.AliasName); m_FieldTable.Add(pField.AliasName, pField.Name); //TreeListNode node = this.treeListFields.AppendNode(new object[] { '[' + _fields.get_Field(i).Name + ']', '[' + _fields.get_Field(i).AliasName + ']' }, null); } } } else if (_dataSet.Workspace.Type == esriWorkspaceType.esriLocalDatabaseWorkspace) { for (int i = 0; i < _fields.FieldCount; i++) { IField pField = _fields.get_Field(i); if (pField.Type != esriFieldType.esriFieldTypeGeometry && pField.Type != esriFieldType.esriFieldTypeBlob && pField.Type != esriFieldType.esriFieldTypeRaster) { if (pField.Name.ToUpper().Contains("OBJECTID") || pField.AliasName.ToLower().Contains("shape")) { continue; } cboFields.Properties.Items.Add(pField.AliasName); m_FieldTable.Add(pField.AliasName, pField.Name); //TreeListNode node = this.treeListFields.AppendNode(new object[] { '[' + _fields.get_Field(i).Name + ']', '[' + _fields.get_Field(i).AliasName + ']' }, null); } } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }