双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

求指出错误。被狠批了。

candyvoice candyvoice 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
为什么字段选择的时候,会有多个重复的选项?我的数据没问题的。我保证。
public partial class AttributeQueryForm : Form
{
//地图数据
private AxMapControl mMapControl;
//选中图层
private IFeatureLayer mFeatureLayer;

public AttributeQueryForm(AxMapControl mapControl)
{
InitializeComponent();
this.mMapControl = mapControl;
}

private void AttributeQueryForm_Load(object sender, EventArgs e)
{
//MapControl中没有图层时返回
if (this.mMapControl.LayerCount <= 0)
return;

//获取MapControl中的全部图层名称,并加入ComboBox
//图层
ILayer pLayer;
//图层名称
string strLayerName;
for (int i = 0; i < this.mMapControl.LayerCount; i++)
{
pLayer = this.mMapControl.get_Layer(i);
strLayerName = pLayer.Name;
//图层名称加入cboLayer
this.cboLayer.Items.Add(strLayerName);
}
//默认显示第一个选项
this.cboLayer.SelectedIndex = 0;
}

private void cboLayer_SelectedIndexChanged(object sender, EventArgs e)
{
//获取cboLayer中选中的图层
mFeatureLayer = mMapControl.get_Layer(cboLayer.SelectedIndex) as IFeatureLayer;
IFeatureClass pFeatureClass = mFeatureLayer.FeatureClass;
//字段名称
string strFldName;
for (int i = 0; i < pFeatureClass.Fields.FieldCount; i++)
{
strFldName = pFeatureClass.Fields.get_Field(i).Name;
//图层名称加入cboField
this.cboField.Items.Add(strFldName);
}
//默认显示第一个选项
this.cboField.SelectedIndex = 0;
}

private void btnOk_Click(object sender, EventArgs e)
{
//定义图层,要素游标,查询过滤器,要素
IFeatureLayer pFeatureLayer;
IFeatureCursor pFeatureCursor;
IQueryFilter pQueryFilter;
IFeature pFeature;
//获取图层
pFeatureLayer = this.mMapControl.Map.get_Layer(cboLayer.SelectedIndex) as IFeatureLayer;
IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;


string strFldName;
//int i = cboField.SelectedIndex;
strFldName = pFeatureClass.Fields.get_Field(cboField.SelectedIndex).Name;
//如果图层名称不是states,程序退出
//if (pFeatureLayer.Name != "cboLayer.Text")
// return;
//清除上次查询结果
this.mMapControl.Map.ClearSelection();


//pQueryFilter的实例化
pQueryFilter = new QueryFilterClass();
//设置查询过滤条件
pQueryFilter.WhereClause = txtStateName.Text; ////"strFldName='" + txtStateName.Text + "'";
//查询
pFeatureCursor = pFeatureLayer.Search(pQueryFilter, false);
//获取查询到的要素
pFeature = pFeatureCursor.NextFeature();


//判断是否获取到要素
if (pFeature != null)
{
//选择要素
this.mMapControl.Map.SelectFeature(pFeatureLayer, pFeature);
//放大到要素
this.mMapControl.Extent = pFeature.Shape.Envelope;
}
else
{
//没有得到pFeature的提示
MessageBox.Show("没有找到名为" + txtStateName.Text + "的设施", "提示");
}
mMapControl.Refresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
}
}

...全文
评论 10
收藏 已收藏
分享
返回顶部
candyvoice
C# 111,129 成员 642,540 内容